From e50a90f0fcd3e3939ed0d688260a26c155a90ce1 Mon Sep 17 00:00:00 2001 From: Mike Phares Date: Tue, 29 Apr 2025 14:33:00 -0700 Subject: [PATCH] decryptedPassword --- File-Watcher.csproj | 6 +++--- Helpers/HelperInfinityQS.cs | 9 +++++---- Models/InfinityQSConfiguration.cs | 1 + Worker.cs | 20 ++++++++++++-------- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/File-Watcher.csproj b/File-Watcher.csproj index 43fcf66..5a61b98 100644 --- a/File-Watcher.csproj +++ b/File-Watcher.csproj @@ -1,4 +1,4 @@ - + enable enable @@ -12,7 +12,7 @@ - + @@ -20,7 +20,7 @@ - + diff --git a/Helpers/HelperInfinityQS.cs b/Helpers/HelperInfinityQS.cs index 07f82e6..4a88836 100644 --- a/Helpers/HelperInfinityQS.cs +++ b/Helpers/HelperInfinityQS.cs @@ -17,7 +17,7 @@ internal static partial class HelperInfinityQS } } - private static void RunMI() + private static void RunMI(string decryptedPassword) { #pragma warning disable CA1416 string processName = "iispcmi.exe"; @@ -27,7 +27,7 @@ internal static partial class HelperInfinityQS Domain = "Infineon", UseShellExecute = false, UserName = "ecfisysadmin", - PasswordInClearText = "j(1(P%xB=g}3w9db", + PasswordInClearText = decryptedPassword, WorkingDirectory = "C:/Program Files (x86)/InfinityQS International/ProFicient/Applications" }; TimeSpan timeSpan = new(DateTime.Now.AddDays(7).Ticks - DateTime.Now.Ticks); @@ -36,10 +36,11 @@ internal static partial class HelperInfinityQS #pragma warning restore CA1416 } - internal static bool Select(AppSettings appSettings, ILogger logger) + internal static bool ProcessStart(AppSettings appSettings, ILogger logger) { logger.LogInformation(appSettings.FileWatcherConfiguration.Company); - RunMI(); + string decrypted = RijndaelEncryption.Decrypt(appSettings.InfinityQSConfiguration.EncryptedPassword, appSettings.FileWatcherConfiguration.Company); + RunMI(decrypted); return true; } } \ No newline at end of file diff --git a/Models/InfinityQSConfiguration.cs b/Models/InfinityQSConfiguration.cs index d83f1b6..4e2ec5b 100644 --- a/Models/InfinityQSConfiguration.cs +++ b/Models/InfinityQSConfiguration.cs @@ -14,6 +14,7 @@ internal partial class TestCollectionSourceGenerationContext : JsonSerializerCon public record InfinityQSConfiguration(string ConnectionString, string DestinationDirectory, + string EncryptedPassword, long SubGroupTime, string TestsFile, Test[] Tests) diff --git a/Worker.cs b/Worker.cs index 6f6c887..d01bb42 100644 --- a/Worker.cs +++ b/Worker.cs @@ -1,4 +1,4 @@ -using File_Watcher.Models; +using File_Watcher.Models; using Microsoft.Extensions.Hosting.WindowsServices; using System.Data; @@ -7,7 +7,7 @@ namespace File_Watcher; public partial class Worker : BackgroundService { - private bool? _First; + private int _First; private readonly bool _IsWindowsService; private readonly ILogger _Logger; private readonly AppSettings _AppSettings; @@ -22,7 +22,6 @@ public partial class Worker : BackgroundService try { logger.LogInformation("<{folder}>", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)); } catch (Exception) { } - _First = null; _IsWindowsService = collection.Contains(nameof(WindowsServiceLifetime)); } @@ -35,6 +34,7 @@ public partial class Worker : BackgroundService protected override async Task ExecuteAsync(CancellationToken cancellationToken) => await Body(cancellationToken); + private async Task Body(CancellationToken cancellationToken) { if (!_IsWindowsService) @@ -52,17 +52,21 @@ public partial class Worker : BackgroundService } while (_IsWindowsService && !cancellationToken.IsCancellationRequested) { - BodyInner(cancellationToken); - await Task.Delay(_AppSettings.FileWatcherConfiguration.MillisecondsDelay, cancellationToken); + try + { + BodyInner(cancellationToken); + await Task.Delay(_AppSettings.FileWatcherConfiguration.MillisecondsDelay, cancellationToken); + } + catch (Exception ex) { _Logger.LogError(ex, "Unexpected Error!"); } } } private void BodyInner(CancellationToken cancellationToken) { _Logger.LogInformation("A) Next execute will be at {date}", DateTime.Now.AddMilliseconds(_AppSettings.FileWatcherConfiguration.MillisecondsDelay).ToString("yyyy-MM-dd hh:mm:ss.fff tt")); - if (_First is null || _First.Value) + if (_First < 9) { - _First = false; + _First += 1; if (_AppSettings.FileWatcherConfiguration.Helper == nameof(Helpers.HelperCamstarOracle)) Helpers.HelperCamstarOracle.Heartbeat(_AppSettings, _HttpClientFactory, _Logger, Infineon.Monitoring.MonA.State.Up, cancellationToken); } @@ -78,7 +82,7 @@ public partial class Worker : BackgroundService nameof(Helpers.HelperCompass) => Helpers.HelperCompass.CopyFile(_AppSettings, _Logger), nameof(Helpers.HelperStratus) => Helpers.HelperStratus.MoveFile(_AppSettings, _Logger), nameof(Helpers.HelperEAFLog) => Helpers.HelperEAFLog.DeleteFiles(_AppSettings, _Logger), - nameof(Helpers.HelperInfinityQS) => Helpers.HelperInfinityQS.Select(_AppSettings, _Logger), + nameof(Helpers.HelperInfinityQS) => Helpers.HelperInfinityQS.ProcessStart(_AppSettings, _Logger), nameof(Helpers.HelperEventLog) => Helpers.HelperEventLog.ClearEventLogs(_AppSettings, _Logger), nameof(Helpers.HelperWaferCounter) => Helpers.HelperWaferCounter.MoveFile(_AppSettings, _Logger), nameof(Helpers.HelperSerial) => Helpers.HelperSerial.ReadWrite(_AppSettings, _Logger, cancellationToken),