From 0a2f97fd931cb217db14fdfb8f8c19ef54879004 Mon Sep 17 00:00:00 2001 From: Mike Phares Date: Tue, 10 May 2022 16:52:18 -0700 Subject: [PATCH] Bug Fix --- EDA Viewer/.vscode/format-report.json | 21 +-- .../HostedService/TimedHostedService.cs | 6 +- EDA Viewer/Singleton/Background.cs | 141 +++++++++--------- 3 files changed, 73 insertions(+), 95 deletions(-) diff --git a/EDA Viewer/.vscode/format-report.json b/EDA Viewer/.vscode/format-report.json index 30ff645..0637a08 100644 --- a/EDA Viewer/.vscode/format-report.json +++ b/EDA Viewer/.vscode/format-report.json @@ -1,20 +1 @@ -[ - { - "DocumentId": { - "ProjectId": { - "Id": "1c39e10e-5359-42ab-be77-db59c291586c" - }, - "Id": "81852d1e-25b8-4230-9e00-0399608db1e6" - }, - "FileName": "Background.cshtml.cs", - "FilePath": "G:\\Mesa_FI\\EDA-Viewer\\EDA Viewer\\Pages\\Background.cshtml.cs", - "FileChanges": [ - { - "LineNumber": 1, - "CharNumber": 1, - "DiagnosticId": "IMPORTS", - "FormatDescription": "Fix imports ordering." - } - ] - } -] \ No newline at end of file +[] \ No newline at end of file diff --git a/EDA Viewer/HostedService/TimedHostedService.cs b/EDA Viewer/HostedService/TimedHostedService.cs index 5c8c474..38834e8 100644 --- a/EDA Viewer/HostedService/TimedHostedService.cs +++ b/EDA Viewer/HostedService/TimedHostedService.cs @@ -112,7 +112,7 @@ public class TimedHostedService : IHostedService, IDisposable { try { - if (!_BackgroundMethods.IsPrimaryInstance()) + if (_BackgroundMethods.IsPrimaryInstance()) _BackgroundMethods.LogPathCleanUpByWeekCallback(); } catch (Exception e) { _Log.Error(e, "Error: "); } @@ -132,7 +132,7 @@ public class TimedHostedService : IHostedService, IDisposable { try { - if (!_BackgroundMethods.IsPrimaryInstance()) + if (_BackgroundMethods.IsPrimaryInstance()) _BackgroundMethods.EDAOutputArchiveCallback(); } catch (Exception e) { _Log.Error(e, "Error: "); } @@ -152,7 +152,7 @@ public class TimedHostedService : IHostedService, IDisposable { try { - if (!_BackgroundMethods.IsPrimaryInstance()) + if (_BackgroundMethods.IsPrimaryInstance()) _BackgroundMethods.EdaDataCollectionPlansCallback(); } catch (Exception e) { _Log.Error(e, "Error: "); } diff --git a/EDA Viewer/Singleton/Background.cs b/EDA Viewer/Singleton/Background.cs index f65c9aa..2cebcdb 100644 --- a/EDA Viewer/Singleton/Background.cs +++ b/EDA Viewer/Singleton/Background.cs @@ -736,85 +736,82 @@ public class Background : Models.Properties.IBackground, IBackground, IDisposabl configuration = ParseXML(xml, throwExceptions: true); if (configuration is null) continue; - if (!Directory.Exists(Path.GetPathRoot(configuration.Settings.StoragePath))) + common.Update(configuration); + json = JsonSerializer.Serialize(configuration, configuration.GetType(), jsonSerializerOptions); + if (common?.UnitName is null) continue; - else + fileName = string.Concat(edaObjectFile.Replace(replace, "Partial"), ".csv"); + File.WriteAllText(fileName, common.ParametersAsCsv); + try + { File.SetCreationTime(fileName, lastModifiedDate); File.SetLastWriteTime(fileName, lastModifiedDate); } + catch (Exception) { } + fileName = string.Concat(edaObjectFile.Replace(replace, "Partial"), ".json"); + File.WriteAllText(fileName, json); + text = Helper.Background.EdaDCP.GetText(edaObjectFile, common, json); + fileName = string.Concat(edaObjectFile.Replace(replace, "Partial"), ".txt"); + File.WriteAllText(fileName, text); + try + { File.SetCreationTime(fileName, lastModifiedDate); File.SetLastWriteTime(fileName, lastModifiedDate); } + catch (Exception) { } + html = Helper.Background.EdaDCP.GetEdaObjectToHtml(edaObjectFile, common); + fileName = string.Concat(edaObjectFile.Replace(replace, "Partial"), ".html"); + File.WriteAllText(fileName, html); + try + { File.SetCreationTime(fileName, lastModifiedDate); File.SetLastWriteTime(fileName, lastModifiedDate); } + catch (Exception) { } + xml = Helper.Background.EdaDCP.GetEdaObjectToDMSGridFormat(edaObjectFile, common, useAlias: false); + fileName = string.Concat(edaObjectFile.Replace(replace, "DMSGridFormat"), ".xml"); + File.WriteAllText(fileName, xml); + try + { File.SetCreationTime(fileName, lastModifiedDate); File.SetLastWriteTime(fileName, lastModifiedDate); } + catch (Exception) { } + xml = Helper.Background.EdaDCP.GetEdaObjectToDMSGridFormat(edaObjectFile, common, useAlias: true); + fileName = string.Concat(edaObjectFile.Replace(replace, "DMSGridFormat - Alias"), ".xml"); + File.WriteAllText(fileName, xml); + try + { File.SetCreationTime(fileName, lastModifiedDate); File.SetLastWriteTime(fileName, lastModifiedDate); } + catch (Exception) { } + csv = Helper.Background.EdaDCP.GetEdaObjectToAPCParameter(edaObjectFile, common); + fileName = string.Concat(edaObjectFile.Replace(replace, "APCParameter"), ".csv"); + File.WriteAllText(fileName, csv); + try + { File.SetCreationTime(fileName, lastModifiedDate); File.SetLastWriteTime(fileName, lastModifiedDate); } + catch (Exception) { } + csv = Helper.Background.EdaDCP.GetEdaObjectToAPCRunKeyNumber(edaObjectFile, common); + fileName = string.Concat(edaObjectFile.Replace(replace, "APCRunKeyNumber"), ".csv"); + File.WriteAllText(fileName, csv); + try + { File.SetCreationTime(fileName, lastModifiedDate); File.SetLastWriteTime(fileName, lastModifiedDate); } + catch (Exception) { } + fileName = string.Concat(edaObjectFile.Replace(replace, "APC"), ".xlsx"); + if (File.Exists(emptyAPC) && !File.Exists(fileName)) { - common.Update(configuration); - json = JsonSerializer.Serialize(configuration, configuration.GetType(), jsonSerializerOptions); + File.Copy(emptyAPC, fileName); + try + { File.SetCreationTime(fileName, lastModifiedDate); File.SetLastWriteTime(fileName, lastModifiedDate); } + catch (Exception) { } + } + if (string.IsNullOrEmpty(configuration.Settings.StoragePath) || !Directory.Exists(Path.GetPathRoot(configuration.Settings.StoragePath))) + continue; + if (!Directory.Exists(common.StoragePath)) + _ = Directory.CreateDirectory(common.StoragePath); + if (!common.StoragePath.Contains(common.UnitName) && (common.StoragePath.Contains(@"01EquipmentIntegration") || common.StoragePath.Contains(@"02BusinessIntegration"))) + { + common.StoragePath = common.StoragePath.Replace("Traces", "Empty"); if (!Directory.Exists(common.StoragePath)) _ = Directory.CreateDirectory(common.StoragePath); - if (common?.UnitName is null) - continue; - if (!common.StoragePath.Contains(common.UnitName) && (common.StoragePath.Contains(@"01EquipmentIntegration") || common.StoragePath.Contains(@"02BusinessIntegration"))) + if (common.UnitName != "PRF01") { - common.StoragePath = common.StoragePath.Replace("Traces", "Empty"); + unitDirectory = string.Concat(Path.GetDirectoryName(common.StoragePath), @"\", common.UnitName); + common.StoragePath = string.Concat(unitDirectory, @"\BadPath"); + if (!Directory.Exists(common.StoragePath)) + _ = Directory.CreateDirectory(common.StoragePath); + common.StoragePath = string.Concat(unitDirectory, @"\LogFile"); + if (!Directory.Exists(common.StoragePath)) + _ = Directory.CreateDirectory(common.StoragePath); + common.StoragePath = string.Concat(unitDirectory, @"\PollPath"); if (!Directory.Exists(common.StoragePath)) _ = Directory.CreateDirectory(common.StoragePath); - if (common.UnitName != "PRF01") - { - unitDirectory = string.Concat(Path.GetDirectoryName(common.StoragePath), @"\", common.UnitName); - common.StoragePath = string.Concat(unitDirectory, @"\BadPath"); - if (!Directory.Exists(common.StoragePath)) - _ = Directory.CreateDirectory(common.StoragePath); - common.StoragePath = string.Concat(unitDirectory, @"\LogFile"); - if (!Directory.Exists(common.StoragePath)) - _ = Directory.CreateDirectory(common.StoragePath); - common.StoragePath = string.Concat(unitDirectory, @"\PollPath"); - if (!Directory.Exists(common.StoragePath)) - _ = Directory.CreateDirectory(common.StoragePath); - } - } - fileName = string.Concat(edaObjectFile.Replace(replace, "Partial"), ".csv"); - File.WriteAllText(fileName, common.ParametersAsCsv); - try - { File.SetCreationTime(fileName, lastModifiedDate); File.SetLastWriteTime(fileName, lastModifiedDate); } - catch (Exception) { } - fileName = string.Concat(edaObjectFile.Replace(replace, "Partial"), ".json"); - File.WriteAllText(fileName, json); - text = Helper.Background.EdaDCP.GetText(edaObjectFile, common, json); - fileName = string.Concat(edaObjectFile.Replace(replace, "Partial"), ".txt"); - File.WriteAllText(fileName, text); - try - { File.SetCreationTime(fileName, lastModifiedDate); File.SetLastWriteTime(fileName, lastModifiedDate); } - catch (Exception) { } - html = Helper.Background.EdaDCP.GetEdaObjectToHtml(edaObjectFile, common); - fileName = string.Concat(edaObjectFile.Replace(replace, "Partial"), ".html"); - File.WriteAllText(fileName, html); - try - { File.SetCreationTime(fileName, lastModifiedDate); File.SetLastWriteTime(fileName, lastModifiedDate); } - catch (Exception) { } - xml = Helper.Background.EdaDCP.GetEdaObjectToDMSGridFormat(edaObjectFile, common, useAlias: false); - fileName = string.Concat(edaObjectFile.Replace(replace, "DMSGridFormat"), ".xml"); - File.WriteAllText(fileName, xml); - try - { File.SetCreationTime(fileName, lastModifiedDate); File.SetLastWriteTime(fileName, lastModifiedDate); } - catch (Exception) { } - xml = Helper.Background.EdaDCP.GetEdaObjectToDMSGridFormat(edaObjectFile, common, useAlias: true); - fileName = string.Concat(edaObjectFile.Replace(replace, "DMSGridFormat - Alias"), ".xml"); - File.WriteAllText(fileName, xml); - try - { File.SetCreationTime(fileName, lastModifiedDate); File.SetLastWriteTime(fileName, lastModifiedDate); } - catch (Exception) { } - csv = Helper.Background.EdaDCP.GetEdaObjectToAPCParameter(edaObjectFile, common); - fileName = string.Concat(edaObjectFile.Replace(replace, "APCParameter"), ".csv"); - File.WriteAllText(fileName, csv); - try - { File.SetCreationTime(fileName, lastModifiedDate); File.SetLastWriteTime(fileName, lastModifiedDate); } - catch (Exception) { } - csv = Helper.Background.EdaDCP.GetEdaObjectToAPCRunKeyNumber(edaObjectFile, common); - fileName = string.Concat(edaObjectFile.Replace(replace, "APCRunKeyNumber"), ".csv"); - File.WriteAllText(fileName, csv); - try - { File.SetCreationTime(fileName, lastModifiedDate); File.SetLastWriteTime(fileName, lastModifiedDate); } - catch (Exception) { } - fileName = string.Concat(edaObjectFile.Replace(replace, "APC"), ".xlsx"); - if (File.Exists(emptyAPC) && !File.Exists(fileName)) - { - File.Copy(emptyAPC, fileName); - try - { File.SetCreationTime(fileName, lastModifiedDate); File.SetLastWriteTime(fileName, lastModifiedDate); } - catch (Exception) { } } } }