using File_Watcher.Models; using System.Collections.ObjectModel; using System.Data; using System.Data.SqlClient; using System.Diagnostics; using System.Text; using System.Text.Json.Serialization; namespace File_Watcher.Helpers; internal static partial class HelperInfinityQS { internal record Record([property: JsonPropertyName("count_se_sgtm")] int CountSeSubgroupTime, [property: JsonPropertyName("date_time")] DateTime DateTime, [property: JsonPropertyName("max_se_lot")] int MaxSeLot, [property: JsonPropertyName("max_se_prcs")] int MaxSeProcess, [property: JsonPropertyName("max_se_sgrp")] int MaxSeSubgroup, [property: JsonPropertyName("max_se_test")] int MaxSeTest, [property: JsonPropertyName("max_se_val")] float MaxSeValue, [property: JsonPropertyName("min_se_sgrp")] int MinSeSubgroup, [property: JsonPropertyName("test")] string Test); [JsonSourceGenerationOptions(WriteIndented = true)] [JsonSerializable(typeof(Record[]))] internal partial class RecordCollectionSourceGenerationContext : JsonSerializerContext { } private static string GetCommandText(ReadOnlyCollection subGroups) { // cSpell:disable List results = []; results.Add(" update [spcepiworld].[dbo].[sgrp_ext] "); results.Add(" set f_flag = 1 "); results.Add(" where f_flag = 0 "); results.Add($" and f_sgrp in ({string.Join(',', subGroups)}) "); return string.Join(Environment.NewLine, results); } // cSpell:enable private static StringBuilder GetForJsonPath(InfinityQSConfiguration infinityQSConfiguration, string commandText) { StringBuilder stringBuilder = new(); using SqlConnection sqlConnection = new(infinityQSConfiguration.ConnectionString); sqlConnection.Open(); using SqlCommand sqlCommand = new(commandText, sqlConnection); SqlDataReader sqlDataReader = sqlCommand.ExecuteReader(CommandBehavior.SequentialAccess); while (sqlDataReader.Read()) _ = stringBuilder.Append(sqlDataReader.GetString(0)); return stringBuilder; } private static void RunMI() { #pragma warning disable CA1416 ProcessStartInfo processStartInfo = new("iispcmi.exe") { Domain = "Infineon", UseShellExecute = false, UserName = "ecfisysadmin", PasswordInClearText = "j(1(P%xB=g}3w9db", WorkingDirectory = "C:/Program Files (x86)/InfinityQS International/ProFicient/Applications" }; Process process = Process.Start(processStartInfo) ?? throw new NullReferenceException(nameof(Process)); process.WaitForExit(); #pragma warning restore CA1416 } internal static bool Select(AppSettings appSettings, ILogger logger) { logger.LogInformation(appSettings.Company); RunMI(); return true; } }