dotnet format --verbosity detailed --severity warn
This commit is contained in:
		| @ -13,271 +13,251 @@ using System.Net; | ||||
| using System.Text.Json; | ||||
| using System.Threading; | ||||
|  | ||||
| namespace Adaptation.FileHandlers.DownloadRsMFile | ||||
| namespace Adaptation.FileHandlers.DownloadRsMFile; | ||||
|  | ||||
| public class FileRead : Shared.FileRead, IFileRead | ||||
| { | ||||
|  | ||||
|     public class FileRead : Shared.FileRead, IFileRead | ||||
|     private readonly Timer _Timer; | ||||
|     private readonly WebClient _WebClient; | ||||
|     private readonly string _StaticFileServer; | ||||
|  | ||||
|     public FileRead(ISMTP smtp, Dictionary<string, string> fileParameter, string cellInstanceName, string cellInstanceConnectionName, FileConnectorConfiguration fileConnectorConfiguration, string equipmentTypeName, string parameterizedModelObjectDefinitionType, IList<ModelObjectParameterDefinition> modelObjectParameters, string equipmentDictionaryName, Dictionary<string, List<long>> dummyRuns, bool useCyclicalForDescription, bool isEAFHosted) : | ||||
|         base(new Description(), false, smtp, fileParameter, cellInstanceName, cellInstanceConnectionName, fileConnectorConfiguration, equipmentTypeName, parameterizedModelObjectDefinitionType, modelObjectParameters, equipmentDictionaryName, dummyRuns, useCyclicalForDescription, isEAFHosted) | ||||
|     { | ||||
|  | ||||
|         private readonly Timer _Timer; | ||||
|         private readonly WebClient _WebClient; | ||||
|         private readonly string _StaticFileServer; | ||||
|  | ||||
|         public FileRead(ISMTP smtp, Dictionary<string, string> fileParameter, string cellInstanceName, string cellInstanceConnectionName, FileConnectorConfiguration fileConnectorConfiguration, string equipmentTypeName, string parameterizedModelObjectDefinitionType, IList<ModelObjectParameterDefinition> modelObjectParameters, string equipmentDictionaryName, Dictionary<string, List<long>> dummyRuns, bool useCyclicalForDescription, bool isEAFHosted, int hyphenXToArchive, int hyphenIsArchive) : | ||||
|             base(new Description(), false, smtp, fileParameter, cellInstanceName, cellInstanceConnectionName, fileConnectorConfiguration, equipmentTypeName, parameterizedModelObjectDefinitionType, modelObjectParameters, equipmentDictionaryName, dummyRuns, useCyclicalForDescription, isEAFHosted, hyphenXToArchive, hyphenIsArchive) | ||||
|         _MinFileLength = 10; | ||||
|         _NullData = string.Empty; | ||||
|         _Logistics = new Logistics(this); | ||||
|         if (_FileParameter is null) | ||||
|             throw new Exception(cellInstanceConnectionName); | ||||
|         if (_ModelObjectParameterDefinitions is null) | ||||
|             throw new Exception(cellInstanceConnectionName); | ||||
|         if (_IsDuplicator) | ||||
|             throw new Exception(cellInstanceConnectionName); | ||||
|         _WebClient = new WebClient(); | ||||
|         _StaticFileServer = GetPropertyValue(cellInstanceConnectionName, modelObjectParameters, string.Concat("CellInstance.", cellInstanceName, ".StaticFileServer")); | ||||
|         if (!Debugger.IsAttached && fileConnectorConfiguration.PreProcessingMode != FileConnectorConfiguration.PreProcessingModeEnum.Process) | ||||
|             _Timer = new Timer(Callback, null, (int)(fileConnectorConfiguration.FileScanningIntervalInSeconds * 1000), Timeout.Infinite); | ||||
|         else | ||||
|         { | ||||
|             _MinFileLength = 10; | ||||
|             _NullData = string.Empty; | ||||
|             _Logistics = new Logistics(this); | ||||
|             if (_FileParameter is null) | ||||
|                 throw new Exception(cellInstanceConnectionName); | ||||
|             if (_ModelObjectParameterDefinitions is null) | ||||
|                 throw new Exception(cellInstanceConnectionName); | ||||
|             if (_IsDuplicator) | ||||
|                 throw new Exception(cellInstanceConnectionName); | ||||
|             _WebClient = new WebClient(); | ||||
|             _StaticFileServer = GetPropertyValue(cellInstanceConnectionName, modelObjectParameters, string.Concat("CellInstance.", cellInstanceName, ".StaticFileServer")); | ||||
|             if (!Debugger.IsAttached && fileConnectorConfiguration.PreProcessingMode != FileConnectorConfiguration.PreProcessingModeEnum.Process) | ||||
|                 _Timer = new Timer(Callback, null, (int)(fileConnectorConfiguration.FileScanningIntervalInSeconds * 1000), Timeout.Infinite); | ||||
|             else | ||||
|             _Timer = new Timer(Callback, null, Timeout.Infinite, Timeout.Infinite); | ||||
|             Callback(null); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     void IFileRead.Move(Tuple<string, Test[], JsonElement[], List<FileInfo>> extractResults, Exception exception) => Move(extractResults, exception); | ||||
|  | ||||
|     void IFileRead.WaitForThread() => WaitForThread(thread: null, threadExceptions: null); | ||||
|  | ||||
|     string IFileRead.GetEventDescription() | ||||
|     { | ||||
|         string result = _Description.GetEventDescription(); | ||||
|         return result; | ||||
|     } | ||||
|  | ||||
|     List<string> IFileRead.GetHeaderNames() | ||||
|     { | ||||
|         List<string> results = _Description.GetHeaderNames(); | ||||
|         return results; | ||||
|     } | ||||
|  | ||||
|     string[] IFileRead.Move(Tuple<string, Test[], JsonElement[], List<FileInfo>> extractResults, string to, string from, string resolvedFileLocation, Exception exception) | ||||
|     { | ||||
|         string[] results = Move(extractResults, to, from, resolvedFileLocation, exception); | ||||
|         return results; | ||||
|     } | ||||
|  | ||||
|     JsonProperty[] IFileRead.GetDefault() | ||||
|     { | ||||
|         JsonProperty[] results = _Description.GetDefault(this, _Logistics); | ||||
|         return results; | ||||
|     } | ||||
|  | ||||
|     Dictionary<string, string> IFileRead.GetDisplayNamesJsonElement() | ||||
|     { | ||||
|         Dictionary<string, string> results = _Description.GetDisplayNamesJsonElement(this); | ||||
|         return results; | ||||
|     } | ||||
|  | ||||
|     List<IDescription> IFileRead.GetDescriptions(IFileRead fileRead, List<Test> tests, IProcessData processData) | ||||
|     { | ||||
|         List<IDescription> results = _Description.GetDescriptions(fileRead, _Logistics, tests, processData); | ||||
|         return results; | ||||
|     } | ||||
|  | ||||
|     Tuple<string, Test[], JsonElement[], List<FileInfo>> IFileRead.GetExtractResult(string reportFullPath, string eventName) | ||||
|     { | ||||
|         Tuple<string, Test[], JsonElement[], List<FileInfo>> results; | ||||
|         if (string.IsNullOrEmpty(eventName)) | ||||
|             throw new Exception(); | ||||
|         _ReportFullPath = reportFullPath; | ||||
|         DateTime dateTime = DateTime.Now; | ||||
|         results = GetExtractResult(reportFullPath, dateTime); | ||||
|         if (results.Item3 is null) | ||||
|             results = new Tuple<string, Test[], JsonElement[], List<FileInfo>>(results.Item1, new Test[] { }, JsonSerializer.Deserialize<JsonElement[]>("[]"), results.Item4); | ||||
|         if (results.Item3.Length > 0 && _IsEAFHosted) | ||||
|             WritePDSF(this, results.Item3); | ||||
|         UpdateLastTicksDuration(DateTime.Now.Ticks - dateTime.Ticks); | ||||
|         return results; | ||||
|     } | ||||
|  | ||||
|     Tuple<string, Test[], JsonElement[], List<FileInfo>> IFileRead.ReExtract() | ||||
|     { | ||||
|         Tuple<string, Test[], JsonElement[], List<FileInfo>> results; | ||||
|         List<string> headerNames = _Description.GetHeaderNames(); | ||||
|         Dictionary<string, string> keyValuePairs = _Description.GetDisplayNamesJsonElement(this); | ||||
|         results = ReExtract(this, headerNames, keyValuePairs); | ||||
|         return results; | ||||
|     } | ||||
|  | ||||
|     void IFileRead.CheckTests(Test[] tests, bool extra) => throw new Exception(string.Concat("Not ", nameof(_IsDuplicator))); | ||||
|  | ||||
|     void IFileRead.Callback(object state) => Callback(state); | ||||
|  | ||||
|     private Tuple<string, Test[], JsonElement[], List<FileInfo>> GetExtractResult(string reportFullPath, DateTime dateTime) | ||||
|     { | ||||
|         if (reportFullPath is null) | ||||
|         { } | ||||
|         if (dateTime == DateTime.MinValue) | ||||
|         { } | ||||
|         throw new Exception(string.Concat("See ", nameof(Callback))); | ||||
|     } | ||||
|  | ||||
|     private void DownloadRsMFile() | ||||
|     { | ||||
|         if (_WebClient is null) | ||||
|             throw new Exception(); | ||||
|         if (string.IsNullOrEmpty(_StaticFileServer)) | ||||
|             throw new Exception(); | ||||
|         string logText; | ||||
|         string runJson; | ||||
|         string rootJson; | ||||
|         string[] logLines; | ||||
|         string runFileName; | ||||
|         string[] logSegments; | ||||
|         string targetFileName; | ||||
|         string runFullFileName; | ||||
|         FileInfo targetFileInfo; | ||||
|         FileInfo alternateFileInfo; | ||||
|         List<string> runFullFileNameSegments; | ||||
|         string dateTimeFormat = "yy/MM/dd HH:mm:ss"; | ||||
|         NginxFileSystem[] runNginxFileSystemCollection; | ||||
|         NginxFileSystem[] rootNginxFileSystemCollection; | ||||
|         DateTime fileAgeThresholdDateTime = DateTime.Now; | ||||
|         string nginxFormat = "ddd, dd MMM yyyy HH:mm:ss zzz"; | ||||
|         List<Tuple<DateTime, FileInfo, FileInfo, string>> possibleDownload = new(); | ||||
|         string[] segments = _FileConnectorConfiguration.FileAgeThreshold.Split(':'); | ||||
|         JsonSerializerOptions propertyNameCaseInsensitiveJsonSerializerOptions = new() { PropertyNameCaseInsensitive = true }; | ||||
|         for (int i = 0; i < segments.Length; i++) | ||||
|         { | ||||
|             fileAgeThresholdDateTime = i switch | ||||
|             { | ||||
|                 _Timer = new Timer(Callback, null, Timeout.Infinite, Timeout.Infinite); | ||||
|                 Callback(null); | ||||
|             } | ||||
|                 0 => fileAgeThresholdDateTime.AddDays(double.Parse(segments[i]) * -1), | ||||
|                 1 => fileAgeThresholdDateTime.AddHours(double.Parse(segments[i]) * -1), | ||||
|                 2 => fileAgeThresholdDateTime.AddMinutes(double.Parse(segments[i]) * -1), | ||||
|                 3 => fileAgeThresholdDateTime.AddSeconds(double.Parse(segments[i]) * -1), | ||||
|                 _ => throw new Exception(), | ||||
|             }; | ||||
|         } | ||||
|  | ||||
|         void IFileRead.Move(Tuple<string, Test[], JsonElement[], List<FileInfo>> extractResults, Exception exception) | ||||
|         rootJson = _WebClient.DownloadString(string.Concat("http://", _StaticFileServer)); | ||||
|         rootNginxFileSystemCollection = JsonSerializer.Deserialize<NginxFileSystem[]>(rootJson, propertyNameCaseInsensitiveJsonSerializerOptions); | ||||
|         foreach (NginxFileSystem rootNginxFileSystem in rootNginxFileSystemCollection) | ||||
|         { | ||||
|             Move(this, extractResults, exception); | ||||
|         } | ||||
|  | ||||
|         void IFileRead.WaitForThread() | ||||
|         { | ||||
|             WaitForThread(thread: null, threadExceptions: null); | ||||
|         } | ||||
|  | ||||
|         string IFileRead.GetEventDescription() | ||||
|         { | ||||
|             string result = _Description.GetEventDescription(); | ||||
|             return result; | ||||
|         } | ||||
|  | ||||
|         List<string> IFileRead.GetHeaderNames() | ||||
|         { | ||||
|             List<string> results = _Description.GetHeaderNames(); | ||||
|             return results; | ||||
|         } | ||||
|  | ||||
|         string[] IFileRead.Move(Tuple<string, Test[], JsonElement[], List<FileInfo>> extractResults, string to, string from, string resolvedFileLocation, Exception exception) | ||||
|         { | ||||
|             string[] results = Move(extractResults, to, from, resolvedFileLocation, exception); | ||||
|             return results; | ||||
|         } | ||||
|  | ||||
|         JsonProperty[] IFileRead.GetDefault() | ||||
|         { | ||||
|             JsonProperty[] results = _Description.GetDefault(this, _Logistics); | ||||
|             return results; | ||||
|         } | ||||
|  | ||||
|         Dictionary<string, string> IFileRead.GetDisplayNamesJsonElement() | ||||
|         { | ||||
|             Dictionary<string, string> results = _Description.GetDisplayNamesJsonElement(this); | ||||
|             return results; | ||||
|         } | ||||
|  | ||||
|         List<IDescription> IFileRead.GetDescriptions(IFileRead fileRead, List<Test> tests, IProcessData processData) | ||||
|         { | ||||
|             List<IDescription> results = _Description.GetDescriptions(fileRead, _Logistics, tests, processData); | ||||
|             return results; | ||||
|         } | ||||
|  | ||||
|         Tuple<string, Test[], JsonElement[], List<FileInfo>> IFileRead.GetExtractResult(string reportFullPath, string eventName) | ||||
|         { | ||||
|             Tuple<string, Test[], JsonElement[], List<FileInfo>> results; | ||||
|             if (string.IsNullOrEmpty(eventName)) | ||||
|                 throw new Exception(); | ||||
|             _ReportFullPath = reportFullPath; | ||||
|             DateTime dateTime = DateTime.Now; | ||||
|             results = GetExtractResult(reportFullPath, dateTime); | ||||
|             if (results.Item3 is null) | ||||
|                 results = new Tuple<string, Test[], JsonElement[], List<FileInfo>>(results.Item1, new Test[] { }, JsonSerializer.Deserialize<JsonElement[]>("[]"), results.Item4); | ||||
|             if (results.Item3.Length > 0 && _IsEAFHosted) | ||||
|                 WritePDSF(this, results.Item3); | ||||
|             UpdateLastTicksDuration(DateTime.Now.Ticks - dateTime.Ticks); | ||||
|             return results; | ||||
|         } | ||||
|  | ||||
|         Tuple<string, Test[], JsonElement[], List<FileInfo>> IFileRead.ReExtract() | ||||
|         { | ||||
|             Tuple<string, Test[], JsonElement[], List<FileInfo>> results; | ||||
|             List<string> headerNames = _Description.GetHeaderNames(); | ||||
|             Dictionary<string, string> keyValuePairs = _Description.GetDisplayNamesJsonElement(this); | ||||
|             results = ReExtract(this, headerNames, keyValuePairs); | ||||
|             return results; | ||||
|         } | ||||
|  | ||||
|         void IFileRead.CheckTests(Test[] tests, bool extra) | ||||
|         { | ||||
|             throw new Exception(string.Concat("Not ", nameof(_IsDuplicator))); | ||||
|         } | ||||
|  | ||||
|         void IFileRead.MoveArchive() | ||||
|         { | ||||
|             throw new Exception(string.Concat("Not ", nameof(_IsDuplicator))); | ||||
|         } | ||||
|  | ||||
|         void IFileRead.Callback(object state) | ||||
|         { | ||||
|             Callback(state); | ||||
|         } | ||||
|  | ||||
|         private Tuple<string, Test[], JsonElement[], List<FileInfo>> GetExtractResult(string reportFullPath, DateTime dateTime) | ||||
|         { | ||||
|             if (reportFullPath is null) | ||||
|             { } | ||||
|             if (dateTime == DateTime.MinValue) | ||||
|             { } | ||||
|             throw new Exception(string.Concat("See ", nameof(Callback))); | ||||
|         } | ||||
|  | ||||
|         private void DownloadRsMFile() | ||||
|         { | ||||
|             if (_WebClient is null) | ||||
|                 throw new Exception(); | ||||
|             if (string.IsNullOrEmpty(_StaticFileServer)) | ||||
|                 throw new Exception(); | ||||
|             string logText; | ||||
|             string runJson; | ||||
|             string rootJson; | ||||
|             string[] logLines; | ||||
|             string runFileName; | ||||
|             string[] logSegments; | ||||
|             string targetFileName; | ||||
|             string runFullFileName; | ||||
|             FileInfo targetFileInfo; | ||||
|             FileInfo alternateFileInfo; | ||||
|             List<string> runFullFileNameSegments; | ||||
|             string dateTimeFormat = "yy/MM/dd HH:mm:ss"; | ||||
|             NginxFileSystem[] runNginxFileSystemCollection; | ||||
|             NginxFileSystem[] rootNginxFileSystemCollection; | ||||
|             DateTime fileAgeThresholdDateTime = DateTime.Now; | ||||
|             string nginxFormat = "ddd, dd MMM yyyy HH:mm:ss zzz"; | ||||
|             List<Tuple<DateTime, FileInfo, FileInfo, string>> possibleDownload = new(); | ||||
|             string[] segments = _FileConnectorConfiguration.FileAgeThreshold.Split(':'); | ||||
|             JsonSerializerOptions propertyNameCaseInsensitiveJsonSerializerOptions = new() { PropertyNameCaseInsensitive = true }; | ||||
|             for (int i = 0; i < segments.Length; i++) | ||||
|             if (!(from l in _FileConnectorConfiguration.SourceFileFilters where rootNginxFileSystem.Name == l select false).Any()) | ||||
|                 continue; | ||||
|             logText = _WebClient.DownloadString(string.Concat("http://", _StaticFileServer, '/', rootNginxFileSystem.Name)); | ||||
|             logLines = logText.Split(new string[] { Environment.NewLine }, StringSplitOptions.None); | ||||
|             foreach (string logLine in logLines) | ||||
|             { | ||||
|                 fileAgeThresholdDateTime = i switch | ||||
|                 { | ||||
|                     0 => fileAgeThresholdDateTime.AddDays(double.Parse(segments[i]) * -1), | ||||
|                     1 => fileAgeThresholdDateTime.AddHours(double.Parse(segments[i]) * -1), | ||||
|                     2 => fileAgeThresholdDateTime.AddMinutes(double.Parse(segments[i]) * -1), | ||||
|                     3 => fileAgeThresholdDateTime.AddSeconds(double.Parse(segments[i]) * -1), | ||||
|                     _ => throw new Exception(), | ||||
|                 }; | ||||
|             } | ||||
|             rootJson = _WebClient.DownloadString(string.Concat("http://", _StaticFileServer)); | ||||
|             rootNginxFileSystemCollection = JsonSerializer.Deserialize<NginxFileSystem[]>(rootJson, propertyNameCaseInsensitiveJsonSerializerOptions); | ||||
|             foreach (NginxFileSystem rootNginxFileSystem in rootNginxFileSystemCollection) | ||||
|             { | ||||
|                 if (!(from l in _FileConnectorConfiguration.SourceFileFilters where rootNginxFileSystem.Name == l select false).Any()) | ||||
|                 if (string.IsNullOrEmpty(logLine)) | ||||
|                     continue; | ||||
|                 logText = _WebClient.DownloadString(string.Concat("http://", _StaticFileServer, '/', rootNginxFileSystem.Name)); | ||||
|                 logLines = logText.Split(new string[] { Environment.NewLine }, StringSplitOptions.None); | ||||
|                 foreach (string logLine in logLines) | ||||
|                 logSegments = logLine.Split('<'); | ||||
|                 if (logSegments.Length < 1 || !DateTime.TryParseExact(logSegments[0].Trim(), dateTimeFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime tvsDateTime)) | ||||
|                     continue; | ||||
|                 if (tvsDateTime < fileAgeThresholdDateTime) | ||||
|                     continue; | ||||
|                 if (logSegments.Length < 2) | ||||
|                     continue; | ||||
|                 runFullFileName = logSegments[1].Split('>')[0]; | ||||
|                 if (!(from l in _FileConnectorConfiguration.SourceFileFilters where runFullFileName.EndsWith(l) select false).Any()) | ||||
|                     continue; | ||||
|                 runFullFileNameSegments = runFullFileName.Split('\\').ToList(); | ||||
|                 runFileName = runFullFileNameSegments[runFullFileNameSegments.Count - 1]; | ||||
|                 runFullFileNameSegments.RemoveAt(runFullFileNameSegments.Count - 1); | ||||
|                 runJson = _WebClient.DownloadString(string.Concat("http://", _StaticFileServer, '/', string.Join("/", runFullFileNameSegments))); | ||||
|                 runFullFileNameSegments.Add(runFileName); | ||||
|                 runNginxFileSystemCollection = JsonSerializer.Deserialize<NginxFileSystem[]>(runJson, propertyNameCaseInsensitiveJsonSerializerOptions); | ||||
|                 foreach (NginxFileSystem matchNginxFileSystem in runNginxFileSystemCollection) | ||||
|                 { | ||||
|                     if (string.IsNullOrEmpty(logLine)) | ||||
|                     if (matchNginxFileSystem.Name != runFileName) | ||||
|                         continue; | ||||
|                     logSegments = logLine.Split('<'); | ||||
|                     if (logSegments.Length < 1 || !DateTime.TryParseExact(logSegments[0].Trim(), dateTimeFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime tvsDateTime)) | ||||
|                     if (!(from l in _FileConnectorConfiguration.SourceFileFilters where matchNginxFileSystem.Name.EndsWith(l) select false).Any()) | ||||
|                         continue; | ||||
|                     if (tvsDateTime < fileAgeThresholdDateTime) | ||||
|                     if (!DateTime.TryParseExact(matchNginxFileSystem.MTime.Replace("GMT", "+00:00"), nginxFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime matchNginxFileSystemDateTime)) | ||||
|                         continue; | ||||
|                     if (logSegments.Length < 2) | ||||
|                     if (matchNginxFileSystemDateTime < fileAgeThresholdDateTime) | ||||
|                         continue; | ||||
|                     runFullFileName = logSegments[1].Split('>')[0]; | ||||
|                     if (!(from l in _FileConnectorConfiguration.SourceFileFilters where runFullFileName.EndsWith(l) select false).Any()) | ||||
|                     targetFileInfo = new FileInfo(Path.Combine(_FileConnectorConfiguration.TargetFileLocation, runFullFileName)); | ||||
|                     if (!Directory.Exists(targetFileInfo.Directory.FullName)) | ||||
|                         _ = Directory.CreateDirectory(targetFileInfo.Directory.FullName); | ||||
|                     if (targetFileInfo.Exists && targetFileInfo.LastWriteTime == matchNginxFileSystemDateTime) | ||||
|                         continue; | ||||
|                     runFullFileNameSegments = runFullFileName.Split('\\').ToList(); | ||||
|                     runFileName = runFullFileNameSegments[runFullFileNameSegments.Count - 1]; | ||||
|                     runFullFileNameSegments.RemoveAt(runFullFileNameSegments.Count - 1); | ||||
|                     runJson = _WebClient.DownloadString(string.Concat("http://", _StaticFileServer, '/', string.Join("/", runFullFileNameSegments))); | ||||
|                     runFullFileNameSegments.Add(runFileName); | ||||
|                     runNginxFileSystemCollection = JsonSerializer.Deserialize<NginxFileSystem[]>(runJson, propertyNameCaseInsensitiveJsonSerializerOptions); | ||||
|                     foreach (NginxFileSystem matchNginxFileSystem in runNginxFileSystemCollection) | ||||
|                     { | ||||
|                         if (matchNginxFileSystem.Name != runFileName) | ||||
|                             continue; | ||||
|                         if (!(from l in _FileConnectorConfiguration.SourceFileFilters where matchNginxFileSystem.Name.EndsWith(l) select false).Any()) | ||||
|                             continue; | ||||
|                         if (!DateTime.TryParseExact(matchNginxFileSystem.MTime.Replace("GMT", "+00:00"), nginxFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime matchNginxFileSystemDateTime)) | ||||
|                             continue; | ||||
|                         if (matchNginxFileSystemDateTime < fileAgeThresholdDateTime) | ||||
|                             continue; | ||||
|                         targetFileInfo = new FileInfo(Path.Combine(_FileConnectorConfiguration.TargetFileLocation, runFullFileName)); | ||||
|                         if (!Directory.Exists(targetFileInfo.Directory.FullName)) | ||||
|                             Directory.CreateDirectory(targetFileInfo.Directory.FullName); | ||||
|                         if (targetFileInfo.Exists && targetFileInfo.LastWriteTime == matchNginxFileSystemDateTime) | ||||
|                             continue; | ||||
|                         alternateFileInfo = new(Path.Combine(_FileConnectorConfiguration.AlternateTargetFolder, matchNginxFileSystem.Name)); | ||||
|                         targetFileName = string.Concat("http://", _StaticFileServer, '/', string.Join("/", runFullFileNameSegments)); | ||||
|                         possibleDownload.Add(new(matchNginxFileSystemDateTime, targetFileInfo, alternateFileInfo, targetFileName)); | ||||
|                         break; | ||||
|                     } | ||||
|                     if (possibleDownload.Any()) | ||||
|                         break; | ||||
|                     alternateFileInfo = new(Path.Combine(_FileConnectorConfiguration.AlternateTargetFolder, matchNginxFileSystem.Name)); | ||||
|                     targetFileName = string.Concat("http://", _StaticFileServer, '/', string.Join("/", runFullFileNameSegments)); | ||||
|                     possibleDownload.Add(new(matchNginxFileSystemDateTime, targetFileInfo, alternateFileInfo, targetFileName)); | ||||
|                     break; | ||||
|                 } | ||||
|                 if (possibleDownload.Any()) | ||||
|                     break; | ||||
|             } | ||||
|             if (possibleDownload.Any()) | ||||
|             { | ||||
|                 possibleDownload = (from l in possibleDownload orderby l.Item1 select l).ToList(); | ||||
|                 alternateFileInfo = possibleDownload[0].Item3; | ||||
|                 targetFileName = possibleDownload[0].Item4; | ||||
|                 targetFileInfo = possibleDownload[0].Item2; | ||||
|                 DateTime matchNginxFileSystemDateTime = possibleDownload[0].Item1; | ||||
|                 if (alternateFileInfo.Exists) | ||||
|                     File.Delete(alternateFileInfo.FullName); | ||||
|                 if (targetFileInfo.Exists) | ||||
|                     File.Delete(targetFileInfo.FullName); | ||||
|                 _WebClient.DownloadFile(targetFileName, targetFileInfo.FullName); | ||||
|                 targetFileInfo.LastWriteTime = matchNginxFileSystemDateTime; | ||||
|                 File.Copy(targetFileInfo.FullName, alternateFileInfo.FullName); | ||||
|             } | ||||
|                 break; | ||||
|         } | ||||
|  | ||||
|         private void Callback(object state) | ||||
|         if (possibleDownload.Any()) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 if (_IsEAFHosted) | ||||
|                     DownloadRsMFile(); | ||||
|             } | ||||
|             catch (Exception exception) | ||||
|             { | ||||
|                 string subject = string.Concat("Exception:", _CellInstanceConnectionName); | ||||
|                 string body = string.Concat(exception.Message, Environment.NewLine, Environment.NewLine, exception.StackTrace); | ||||
|                 try | ||||
|                 { _SMTP.SendHighPriorityEmailMessage(subject, body); } | ||||
|                 catch (Exception) { } | ||||
|             } | ||||
|             try | ||||
|             { | ||||
|                 TimeSpan timeSpan = new(DateTime.Now.AddSeconds(_FileConnectorConfiguration.FileScanningIntervalInSeconds.Value).Ticks - DateTime.Now.Ticks); | ||||
|                 _Timer.Change((long)timeSpan.TotalMilliseconds, Timeout.Infinite); | ||||
|             } | ||||
|             catch (Exception exception) | ||||
|             { | ||||
|                 string subject = string.Concat("Exception:", _CellInstanceConnectionName); | ||||
|                 string body = string.Concat(exception.Message, Environment.NewLine, Environment.NewLine, exception.StackTrace); | ||||
|                 try | ||||
|                 { _SMTP.SendHighPriorityEmailMessage(subject, body); } | ||||
|                 catch (Exception) { } | ||||
|             } | ||||
|             possibleDownload = (from l in possibleDownload orderby l.Item1 select l).ToList(); | ||||
|             alternateFileInfo = possibleDownload[0].Item3; | ||||
|             targetFileName = possibleDownload[0].Item4; | ||||
|             targetFileInfo = possibleDownload[0].Item2; | ||||
|             DateTime matchNginxFileSystemDateTime = possibleDownload[0].Item1; | ||||
|             if (alternateFileInfo.Exists) | ||||
|                 File.Delete(alternateFileInfo.FullName); | ||||
|             if (targetFileInfo.Exists) | ||||
|                 File.Delete(targetFileInfo.FullName); | ||||
|             _WebClient.DownloadFile(targetFileName, targetFileInfo.FullName); | ||||
|             targetFileInfo.LastWriteTime = matchNginxFileSystemDateTime; | ||||
|             File.Copy(targetFileInfo.FullName, alternateFileInfo.FullName); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private void Callback(object state) | ||||
|     { | ||||
|         try | ||||
|         { | ||||
|             if (_IsEAFHosted) | ||||
|                 DownloadRsMFile(); | ||||
|         } | ||||
|         catch (Exception exception) | ||||
|         { | ||||
|             string subject = string.Concat("Exception:", _CellInstanceConnectionName); | ||||
|             string body = string.Concat(exception.Message, Environment.NewLine, Environment.NewLine, exception.StackTrace); | ||||
|             try | ||||
|             { _SMTP.SendHighPriorityEmailMessage(subject, body); } | ||||
|             catch (Exception) { } | ||||
|         } | ||||
|         try | ||||
|         { | ||||
|             TimeSpan timeSpan = new(DateTime.Now.AddSeconds(_FileConnectorConfiguration.FileScanningIntervalInSeconds.Value).Ticks - DateTime.Now.Ticks); | ||||
|             _ = _Timer.Change((long)timeSpan.TotalMilliseconds, Timeout.Infinite); | ||||
|         } | ||||
|         catch (Exception exception) | ||||
|         { | ||||
|             string subject = string.Concat("Exception:", _CellInstanceConnectionName); | ||||
|             string body = string.Concat(exception.Message, Environment.NewLine, Environment.NewLine, exception.StackTrace); | ||||
|             try | ||||
|             { _SMTP.SendHighPriorityEmailMessage(subject, body); } | ||||
|             catch (Exception) { } | ||||
|         } | ||||
|     } | ||||
|  | ||||
| } | ||||
		Reference in New Issue
	
	Block a user