Nancy
This commit is contained in:
@ -6,8 +6,10 @@ using Adaptation.Shared.Methods;
|
||||
using log4net;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
|
||||
namespace Adaptation.FileHandlers.Priority;
|
||||
|
||||
@ -16,6 +18,7 @@ namespace Adaptation.FileHandlers.Priority;
|
||||
public class FileRead : Shared.FileRead, IFileRead
|
||||
{
|
||||
|
||||
private readonly Timer _Timer;
|
||||
internal static ILog Log => _Log;
|
||||
internal static Settings Settings => _Settings;
|
||||
internal static Dictionary<int, WorkItem> WorkItems => _WorkItems;
|
||||
@ -49,16 +52,22 @@ public class FileRead : Shared.FileRead, IFileRead
|
||||
sourceFileFilter: _FileConnectorConfiguration.SourceFileFilter,
|
||||
sourceFileLocation: _FileConnectorConfiguration.SourceFileLocation,
|
||||
targetFileLocation: _FileConnectorConfiguration.TargetFileLocation);
|
||||
string? json = WeightedShortestJobFirstHub.PopulatedWorkItemsAndGetJson(_Settings);
|
||||
if (!string.IsNullOrEmpty(json))
|
||||
WeightedShortestJobFirstHub.WriteJson(json);
|
||||
_Timer = new Timer(Callback, null, Timeout.Infinite, Timeout.Infinite);
|
||||
string cellInstanceNamed = string.Concat("CellInstance.", _EquipmentType);
|
||||
string url = GetPropertyValue(cellInstanceConnectionName, modelObjectParameters, $"{cellInstanceNamed}.Microsoft.Owin.Hosting.WebApp.Start.URL");
|
||||
if (_IsEAFHosted)
|
||||
{
|
||||
_ = Microsoft.Owin.Hosting.WebApp.Start(url);
|
||||
_ = Microsoft.Owin.Hosting.WebApp.Start<Startup>(url);
|
||||
_Log.Info($"Server running on {url}");
|
||||
}
|
||||
if (Debugger.IsAttached || fileConnectorConfiguration.PreProcessingMode == FileConnectorConfiguration.PreProcessingModeEnum.Process)
|
||||
Callback(null);
|
||||
else
|
||||
{
|
||||
long fileScanningIntervalInSeconds = _FileConnectorConfiguration.FileScanningIntervalInSeconds is null ? 0 : _FileConnectorConfiguration.FileScanningIntervalInSeconds.Value;
|
||||
TimeSpan timeSpan = new(DateTime.Now.AddSeconds(fileScanningIntervalInSeconds).Ticks - DateTime.Now.Ticks);
|
||||
_ = _Timer.Change((long)timeSpan.TotalMilliseconds, Timeout.Infinite);
|
||||
}
|
||||
}
|
||||
|
||||
void IFileRead.Move(Tuple<string, Test[], JsonElement[], List<FileInfo>> extractResults, Exception exception) => Move(extractResults);
|
||||
@ -138,4 +147,28 @@ public class FileRead : Shared.FileRead, IFileRead
|
||||
return results;
|
||||
}
|
||||
|
||||
private void Callback(object? state)
|
||||
{
|
||||
try
|
||||
{
|
||||
_Log.Info($"Enter-{nameof(WeightedShortestJobFirstModule.PopulatedWorkItemsAndGetJson)}");
|
||||
string? json = WeightedShortestJobFirstModule.PopulatedWorkItemsAndGetJson(_Settings);
|
||||
if (!string.IsNullOrEmpty(json))
|
||||
WeightedShortestJobFirstModule.WriteJson(json);
|
||||
_Log.Info($"End-{nameof(WeightedShortestJobFirstModule.PopulatedWorkItemsAndGetJson)}");
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
string subject = string.Concat("Exception:", _CellInstanceConnectionName);
|
||||
string body = string.Concat(exception.Message, Environment.NewLine, Environment.NewLine, exception.StackTrace);
|
||||
_Log.Fatal($"Exception-{nameof(WeightedShortestJobFirstModule.PopulatedWorkItemsAndGetJson)}{Environment.NewLine}{body}");
|
||||
try
|
||||
{
|
||||
_SMTP.SendHighPriorityEmailMessage(subject, body);
|
||||
File.WriteAllText(".email", body);
|
||||
}
|
||||
catch (Exception) { }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user