///<summary> ///* Function: Initialze and assign the Specified share folder location, line name, report and aidata folderlocation /// This function proves that those specific folders exist.!-- ///* @author: Sena.kim ///* @parameter:string Sharefolderlocation, directory name as line name eg line2/3/4 ///* @return: None ///</summary> public int AssignLineStatus(string p_shareFolderLocation, string p_directoryName, int i, string p_reportfolderName, string p_aifolderName) { int Linenumber = i + 2; m_LineName = "MC" + Linenumber + "LINE"; // m_LineName = p_directoryName; //reset variales, m_linefolderLocation = p_shareFolderLocation + p_directoryName; m_reportfolderlocation = m_linefolderLocation + p_reportfolderName; //"/report"; m_aidatafolderlocation = m_linefolderLocation + p_aifolderName; //'"/aidata"; m_ModuleMessageBody = new Queue <ModuleMessageBody>(); m_currentdateFolderInfo = new DateFolderInfo(); m_IsThereLineFolder = DirectoryReader.IsDirectoryExistInThefolder(m_linefolderLocation); if (m_IsThereLineFolder == true) { m_IsThereReportFolder = DirectoryReader.IsDirectoryExistInThefolder(m_reportfolderlocation); m_IsThereAIFolder = DirectoryReader.IsDirectoryExistInThefolder(m_aidatafolderlocation); if (m_IsThereReportFolder == true && m_IsThereAIFolder == true) { LogBuilder.LogWrite(LogBuilder.MessageStatus.Usual, m_LineName + ": ReportFolder & AIFolder Detected and Successfully Assigned."); } else if (m_IsThereReportFolder == false && m_IsThereAIFolder == false) { } else if (m_IsThereReportFolder == false || m_IsThereAIFolder == false) { LogBuilder.LogWrite(LogBuilder.MessageStatus.Usual, m_LineName + ": ReportFolder or AIFolder Is Not Detected."); } } return(Linenumber); }
public static async Task SendData(ModuleClient deviceClient, string messageToSend) { try { var messageString = messageToSend; if (messageString != string.Empty) { var logstring = "@@@@@@@@@" + messageString + ""; LogBuilder.LogWrite(LogBuilder.MessageStatus.Usual, logstring); var messageBytes = Encoding.UTF8.GetBytes(messageString); var message = new Message(messageBytes); message.ContentEncoding = "utf-8"; message.ContentType = "application/json"; await deviceClient.SendEventAsync("messageOutput", message); } } catch (Exception ex) { Console.WriteLine($"[ERROR] Unexpected Exception {ex.Message}"); Console.WriteLine($"\t{ex.ToString()}"); } // await Task.Delay(TimeSpan.FromSeconds(5)); }
///<summary> ///* Function: Initialze and assign the Specified share folder location, line name, report and aidata folderlocation /// This function proves that those specific folders exist.!-- ///* @author: Sena.kim ///* @parameter:string Sharefolderlocation, directory name as line name eg line2/3/4 ///* @return: None ///</summary> public bool ProcessSingleDateFolderInfo(Environment p_currentEnvironment) { bool isThisNewDay = false; // var comparingDates = 1; m_currentdateFolderInfo = SetSingleDateFolderInfo(p_currentEnvironment); if (m_currentdateFolderInfo.WorkingDate.Date > m_previousworkingDate.Date) // relationship = "is earlier than"; { m_previousworkingDate = m_currentdateFolderInfo.WorkingDate; isThisNewDay = true; } else if (m_currentdateFolderInfo.WorkingDate.Date == m_previousworkingDate.Date) //relationship = "is the same time as"; { isThisNewDay = false; m_previousworkingDate = m_currentdateFolderInfo.WorkingDate; SetbadProductsInfoUnderDateFolder(m_currentdateFolderInfo); LogBuilder.LogWrite(LogBuilder.MessageStatus.Usual, "Accessing : " + m_currentdateFolderInfo.DateFolderLocationUnderReport); ProcessBadReportsUnderSingleDates(m_currentdateFolderInfo); } else { } return(isThisNewDay); //relationship = "is later than"; }
public string ReadSQL(string commandstring) { string tempresult = "0"; try { using (SqlConnection connection = new SqlConnection()) { connection.ConnectionString = m_connectionstring; connection.Open(); using (SqlCommand command = new SqlCommand(commandstring, connection)) { command.ExecuteNonQuery(); using (SqlDataReader reader = command.ExecuteReader()) { if (reader.Read()) { tempresult = String.Format(reader[0].ToString()); } reader.Close(); } } } } catch (System.Data.SqlClient.SqlException exception) { LogBuilder.LogWrite(LogBuilder.MessageStatus.Error, "Error See log for detail : " + exception); } return(tempresult); }
///<summary> ///* Function: Initialze and assign the Specified share folder location, line name, report and aidata folderlocation /// This function proves that those specific folders exist.!-- ///* @author: Sena.kim ///* @parameter: fileType ( "*.csv") folder path ///* @return: None ///</summary> public void SetbadProductsInfoUnderDateFolder(DateFolderInfo p_datefolderInfo) { int dataError = 0; if (m_IsThereReportFolder == true && m_IsThereAIFolder == true) { //does directory have csv files? save csv files FileInfo[] di = DirectoryReader.Readfromfolder("*.csv", p_datefolderInfo.DateFolderLocationUnderReport); for (int i = 0; i < di.Length; i++) { if (di[i] != null) { int badcount = 0; int barcodeError = 0; string[] allLines = DirectoryReader.ReadAllLinesOfAFile(di[i].Name, p_datefolderInfo.DateFolderLocationUnderReport);//File.ReadAllLines(fileLocation); var csvLinesData = allLines.Skip(1); var varbadProductsInfo = (from line in csvLinesData let data = line.Split(",") select new { Date = data[0], Model = data[1], BarCode = data[2], Result = data[3] }) .Where(data => data.Result == "NG").ToList(); // end of linq foreach (var s in varbadProductsInfo) { bool IsNotError = DirectoryReader.checkStringForContainingAlphabet(s.BarCode); if (IsNotError == true) { badcount++; p_datefolderInfo.BadProductsToPass.Enqueue(new BadProductInfo() { Date = s.Date, Model = s.Model, BarCode = s.BarCode, Result = s.Result }); } else { barcodeError++; dataError++; } } // m_badProductsInfo.TrimExcess(); LogBuilder.LogWrite(LogBuilder.MessageStatus.Usual, "Reading " + p_datefolderInfo.WorkingDate + " " + di[i].Name + "....." + "No. of BadProducts #" + badcount); } } // end of for loop } // end of if (IsThereReportFolder == true && IsThereAIFolder == true)Z string dateformat = LogBuilder.ParseDateTimeToString(p_datefolderInfo.WorkingDate, "yyyy-MM-dd"); LogBuilder.LogWrite(LogBuilder.MessageStatus.Usual, "Folder :" + dateformat + " Total bad products :" + p_datefolderInfo.BadProductsToPass.Count + " DataError :" + dataError.ToString()); }// end of public SetDecisionResultUnderReportFolder(string p_dateFolderLocation)
///<summary> ///* Function: function to read from content from a file using splitstring to detect the line to get a string ///* @author: Sena.kim ///* @parameter: filepath the absoulte file path ///* @return: string[] Info. assigns the string ///</summary> static public string[] ReadAllLinesOfAFile(string p_filepath) { string[] allLines; if (DoesFileExist(p_filepath)) { string fileLocation = p_filepath; LogBuilder.LogWrite(LogBuilder.MessageStatus.Usual, "start Reading" + p_filepath); // reading csvs, skips the first raw. } return(allLines = File.ReadAllLines(p_filepath)); }
public void CreateTableInSQL(string p_dbname, string p_tablename, string p_keyoptions) { string temp_CreateTableNameInSQLstring = $"IF NOT EXISTS (SELECT * FROM {p_dbname}.dbo.sysobjects WHERE name = N'{p_tablename}') BEGIN CREATE TABLE {p_dbname}.dbo.{p_tablename} {p_keyoptions}; END;"; string temp_errormessageString = "Failed creating table"; bool temp_isProcessSucceeded = ProcessSQL(temp_CreateTableNameInSQLstring, temp_errormessageString); if (temp_isProcessSucceeded) { LogBuilder.LogWrite(LogBuilder.MessageStatus.Usual, "The table'" + p_tablename + "' created;"); } }
public void CreateTableInSQL(string tablename, string keyoptions) { string temp_CreateTableNameInSQLstring = $"create table {tablename} {keyoptions};"; string temp_errormessageString = "Failed creating table"; bool temp_isProcessSucceeded = ProcessSQL(temp_CreateTableNameInSQLstring, temp_errormessageString); if (temp_isProcessSucceeded) { LogBuilder.LogWrite(LogBuilder.MessageStatus.Usual, "The table'" + tablename + "' created"); } }
public void CreateDBInSQL(string p_dbname, string p_filepath) { string temp_CreateDBNameInSQLstring = $"IF NOT EXISTS (SELECT * FROM sys.databases WHERE name = N'{p_dbname}') BEGIN CREATE DATABASE {p_dbname} ON (NAME = {p_dbname}, FILENAME = {p_filepath}) END;"; string temp_errormessageString = "Failed creating table"; bool temp_isProcessSucceeded = ProcessSQL(temp_CreateDBNameInSQLstring, temp_errormessageString); if (temp_isProcessSucceeded) { LogBuilder.LogWrite(LogBuilder.MessageStatus.Usual, "The db'" + p_dbname + "' created;"); } }
public void TruncateTable(string tablename) { //Empty table string temp_CreateTableNameInSQLstring = $"TRUNCATE TABLE {tablename}"; string temp_errormessageString = "Failed TRUNCATING table"; bool temp_isProcessSucceeded = ProcessSQL(temp_CreateTableNameInSQLstring, temp_errormessageString); if (temp_isProcessSucceeded) { LogBuilder.LogWrite(LogBuilder.MessageStatus.Usual, "The table'" + tablename + "' TRUNCATED"); } }
/// <summary> /// Checks if the folder exists /// Return bool parameter fileType : *.csv folderPath : /app/data/ /// </summary> static public bool DoesFileExist(string p_filePath) { bool isExist = false; if (System.IO.File.Exists(p_filePath)) { isExist = true; } else { LogBuilder.LogWrite(LogBuilder.MessageStatus.Warning, "file does not exsit" + p_filePath); } return(isExist); }
/// <summary> /// Checks if the folder exists /// Return bool parameter fileType : *.csv folderPath : /app/data/ /// </summary> static public bool IsDirectoryExistInThefolder(string p_folderpath) { bool isExist = false; if (System.IO.Directory.Exists(p_folderpath)) { isExist = true; } else { LogBuilder.LogWrite(LogBuilder.MessageStatus.Warning, "Folder does not exist. [" + p_folderpath + "]"); } return(isExist); }
public string CheckSqlConnection() { string tempState = "failed"; try { Console.WriteLine("DB Connection State: {0}", OpenSqlConnection()); } catch (System.Data.SqlClient.SqlException exception) { LogBuilder.LogWrite(LogBuilder.MessageStatus.Usual, "Error See log for detail."); Console.WriteLine("ConnectionString: {0}", exception); } return(tempState); }
static void Process(ModuleManager p_moduleManager, Environment p_currentEnvironment, SQLClass p_sqlclass, ModuleClient p_moduleclient) { string tempmessage = "Start Processing Line reports."; LogBuilder.LogWrite(LogBuilder.MessageStatus.Usual, tempmessage); p_moduleManager.ProcessToAssignModuleMessageBody(p_sqlclass, p_currentEnvironment); p_moduleManager.m_totalMessageBodiesOfAllLines.TrimExcess(); int tempMax = p_moduleManager.m_totalMessageBodiesOfAllLines.Count; int count = 0; foreach (var temp in p_moduleManager.m_totalMessageBodiesOfAllLines) { count++; var messageBody = LogBuilder.AssignTempMessageBody(temp.LineName, temp.Raw, temp.Cep); var messageString = JsonConvert.SerializeObject(messageBody); tempmessage = $"This ID : {count} Line Name {temp.LineName}, Barcode {temp.BadProductInfo.BarCode}"; LogBuilder.LogWrite(LogBuilder.MessageStatus.Usual, tempmessage); if (p_sqlclass.ReadSQL($"SELECT COUNT([BarCode]) AS ISEIXSTS FROM [LS_IoTEDGE].[dbo].[T_NG] WHERE [BarCode] = '{ temp.BadProductInfo.BarCode}' ;") == "0") { Random _r = new Random(); int a = _r.Next(2); if (a == 0) { temp.BadProductInfo.Result = "NG"; } else if (a == 1) { temp.BadProductInfo.Result = "OK"; } //Chek if the data already exist p_sqlclass.InsertTableInSQL(temp.LineName, temp.BadProductInfo.Date, temp.BadProductInfo.Model, temp.BadProductInfo.BarCode, temp.BadProductInfo.Result, temp.Raw, temp.Cep, temp.Aps); if (p_currentEnvironment == Environment.productionOnlinux) { ConnectionManager.SendData(p_moduleclient, messageString).Wait(); } else if (p_currentEnvironment == Environment.testOnWindow) { LogBuilder.LogWrite(LogBuilder.MessageStatus.Usual, messageString); } } } }// end of Process void
///<summary> ///* Function: function to read from content from a file using splitstring to detect the line to get a string ///* @author: Sena.kim ///* @parameter: folder path ///* @return: Directory Info[]. assigns the string ///</summary> static public DirectoryInfo[] Readfromfolder(string p_folderPath) { DirectoryInfo[] fi = new DirectoryInfo[1]; if (IsDirectoryExistInThefolder(p_folderPath)) { System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(p_folderPath); fi = di.GetDirectories(); if (fi.Length == 0) { string message = "There is no existing directory"; LogBuilder.LogWrite(LogBuilder.MessageStatus.Error, message); } } return(fi); }
//public Format of YYYYMMDD static public DateTime ParseStringToGetDateTime(string dateString, string dateFormat) { CultureInfo koKR = new CultureInfo("ko-KR"); DateTime dateValue = new DateTime(); string tempmessage = ""; if (DateTime.TryParseExact(dateString, dateFormat, koKR, DateTimeStyles.None, out dateValue)) { // tempmessage = "Converted " + dateString + " to " + dateValue + "," + dateValue.Kind.ToString(); } else { tempmessage = dateString + "Converting Failed"; LogBuilder.LogWrite(LogBuilder.MessageStatus.Error, tempmessage); } return(dateValue); }
public bool ProcessSQL(string commandstring, string errormessage) { bool temp_processComplete = false; try { using (SqlConnection connection = new SqlConnection()) { connection.ConnectionString = m_connectionstring; connection.Open(); using (SqlCommand command = new SqlCommand(commandstring, connection)) { command.ExecuteNonQuery(); if (commandstring.StartsWith("select") == true) { using (SqlDataReader reader = command.ExecuteReader()) { if (reader.Read()) { // Console.WriteLine(reader.GetString(0)); temp_processComplete = true; } else { LogBuilder.LogWrite(LogBuilder.MessageStatus.Usual, errormessage); temp_processComplete = false; } } } else { temp_processComplete = true; } } } } catch (System.Data.SqlClient.SqlException exception) { LogBuilder.LogWrite(LogBuilder.MessageStatus.Usual, "Error See log for detail."); Console.WriteLine("ConnectionString: {0}", exception); temp_processComplete = false; } return(temp_processComplete); }
public void InsertSQL(string commandstring) { try { using (SqlConnection connection = new SqlConnection()) { connection.ConnectionString = m_connectionstring; connection.Open(); using (SqlCommand command = new SqlCommand(commandstring, connection)) { command.ExecuteNonQuery(); } } } catch (System.Data.SqlClient.SqlException exception) { LogBuilder.LogWrite(LogBuilder.MessageStatus.Error, "Error See log for detail."); Console.WriteLine("ConnectionString: {0}", exception); } }
///<summary> ///* Function: function to read from content from a file using splitstring to detect the line to get a string ///* @author: Sena.kim ///* @parameter: fileType ( "*.csv") folder path ///* @return: FileInfo[] Info. assigns the string ///</summary> static public FileInfo[] Readfromfolder(string p_fileType, string p_folderPath) { FileInfo[] fi; fi = new FileInfo[1]; if (IsDirectoryExistInThefolder(p_folderPath)) { System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(p_folderPath); //Check if the CSV files exist. fi = di.GetFiles(p_fileType); if (fi.Length == 0) { string message = "There is no existing " + p_fileType + " files in @ " + p_folderPath; LogBuilder.LogWrite(LogBuilder.MessageStatus.Error, message); } } return(fi); }
/// <summary> /// Initializes the ModuleClient and sets up the callback to receive /// messages containing temperature information /// </summary> public static async Task <ModuleClient> Init() { AmqpTransportSettings amqpSetting = new AmqpTransportSettings(TransportType.Amqp_Tcp_Only); ITransportSettings[] settings = { amqpSetting }; // Open a connection to the Edge runtime ModuleClient ioTHubModuleClient = await ModuleClient.CreateFromEnvironmentAsync(settings); await ioTHubModuleClient.OpenAsync(); LogBuilder.LogWrite(LogBuilder.MessageStatus.Usual, "IoT Hub module client initialized."); var moduleTwin = await ioTHubModuleClient.GetTwinAsync(); var moduleTwinCollection = moduleTwin.Properties.Desired; // as this runs in a loop we don't await return(ioTHubModuleClient); }
///<summary> ///* Function: function to read from content from a file using splitstring to detect the line to get a string ///* @author: Sena.kim ///* @parameter: containing folder can be name or date fileType ( "*.csv") folder path ///* @return: FileInfo[] Info. assigns the string ///</summary> static public FileInfo[] Readfromfolder(string p_containingpartial, string p_fileType, string p_folderPath) { FileInfo[] fi; fi = new FileInfo[1]; if (DirectoryReader.IsDirectoryExistInThefolder(p_folderPath)) { System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(p_folderPath); fi = di.GetFiles("*" + p_containingpartial + p_fileType); if (fi.Length == 0) { string message = "There is no existing " + p_containingpartial + " files in @ " + p_folderPath; LogBuilder.LogWrite(LogBuilder.MessageStatus.Error, message); } else { string message = "@" + p_folderPath + " folder." + "Detecting " + fi.Length + " " + p_containingpartial + " files."; LogBuilder.LogWrite(LogBuilder.MessageStatus.Usual, message); } } return(fi); }
/// <summary> /// Initialize, and Assign some variables.!-- /// </summary> public void Init() { string reportfolderName = string.Empty; string aifolderName = string.Empty; string apsfolderName = string.Empty; string cepfolderName = string.Empty; string rawfolderName = string.Empty; // Assigns some variables. DirectoryReader.ReadContentfromConfigAndReturnStringReference(m_configPath, "SQLconnectionString:", ref m_sqlConnectionString); DirectoryReader.ReadContentfromConfigAndReturnStringReference(m_configPath, "SharedFolderPath:", ref m_shareFolderLocation); DirectoryReader.ReadContentfromConfigAndReturnStringReference(m_configPath, "LogPath:", ref m_logPath); DirectoryReader.ReadContentfromConfigAndReturnStringReference(m_configPath, "ReportFolderName:", ref reportfolderName); DirectoryReader.ReadContentfromConfigAndReturnStringReference(m_configPath, "AiFolderName:", ref aifolderName); DirectoryReader.ReadContentfromConfigAndReturnStringReference(m_configPath, "APSFolderName:", ref apsfolderName); DirectoryReader.ReadContentfromConfigAndReturnStringReference(m_configPath, "CepFolderName:", ref cepfolderName); DirectoryReader.ReadContentfromConfigAndReturnStringReference(m_configPath, "RawFolderName:", ref rawfolderName); bool isApplicationSafeToContinue = DirectoryReader.IsDirectoryExistInThefolder(m_shareFolderLocation); if (isApplicationSafeToContinue == true) { DirectoryInfo[] sharedFolderDirectoryInfo = DirectoryReader.Readfromfolder(m_shareFolderLocation);// thisfolder reads location finding how many lines exist . m_numberOfLines = sharedFolderDirectoryInfo.Length; m_Linestatus = new LineStatus[m_numberOfLines]; for (int i = 0; i < m_numberOfLines; i++)// Access Each line folder. { m_Linestatus[i] = new LineStatus(apsfolderName, cepfolderName, rawfolderName, m_shareFolderLocation, sharedFolderDirectoryInfo[i].Name, i, reportfolderName, aifolderName); m_Linestatus[i].AssignLineStatus(m_shareFolderLocation, sharedFolderDirectoryInfo[i].Name, i, reportfolderName, aifolderName); }// end of for LogBuilder.LogWrite(LogBuilder.MessageStatus.Usual, "Module Initialization Complete. Application is safe to continue."); } else { LogBuilder.LogWrite(LogBuilder.MessageStatus.Usual, "Module Initialization Failed."); } }// end of init
public void InsertTableInSQL(string p_Line, string p_TESTDATE, string p_Model, string p_Barcode, string p_Result, string p_RawLocation, string p_CepLocation, string p_ApsLocation) { string dbname = GetSqlDbName(); string tbname = GetSqlTableName(); string temp_InsertRawDataToSQLstring = $"INSERT INTO {dbname}.dbo.{tbname} ([LINE] ,[시험일자] ,[Model] ,[BarCode] ,[CREATEDT] ,[RAWLocation] ,[CEPLocation] ,[APSLocation]) VALUES( '{p_Line}', '{p_TESTDATE}' , '{p_Model}' , '{p_Barcode}' , GETDATE() , '{p_RawLocation}' , '{p_CepLocation}' , '{p_ApsLocation}' );"; try { using (SqlConnection connection = new SqlConnection()) { connection.ConnectionString = m_connectionstring; connection.Open(); using (SqlCommand command = new SqlCommand(temp_InsertRawDataToSQLstring, connection)) { command.ExecuteNonQuery(); } } } catch (System.Data.SqlClient.SqlException exception) { LogBuilder.LogWrite(LogBuilder.MessageStatus.Error, $"{exception}"); } }
///<summary> ///* Function: Initialze and assign the Specified share folder location, line name, report and aidata folderlocation /// This function proves that those specific folders exist.!-- ///* @author: Sena.kim ///* @parameter: fileType ( "*.csv") folder path ///* @return: None ///</summary> private string GetApsCepRawLocation(string p_fileType, RestultFileType p_resultType, DateTime p_workingdate) { string workingfolder = string.Empty; if (m_currentdateFolderInfo != null) { workingfolder = DirectoryReader.ParseDatetimeToDirectoryStyle(m_aidatafolderlocation, p_workingdate, "yyyy-MM-dd", m_currentEnvironment); workingfolder = workingfolder + p_fileType; bool isdirectoryExist = false; if (DirectoryReader.IsDirectoryEmpty(workingfolder) == false) { isdirectoryExist = true; } switch (p_resultType) { case RestultFileType.APS: LogBuilder.LogWrite(LogBuilder.MessageStatus.Usual, "Is There APS Folder " + isdirectoryExist + " @ " + workingfolder); break; case RestultFileType.CEP: LogBuilder.LogWrite(LogBuilder.MessageStatus.Usual, "Is There CEP Folder " + isdirectoryExist + " @ " + workingfolder); break; case RestultFileType.RAW: LogBuilder.LogWrite(LogBuilder.MessageStatus.Usual, "Is There RAW Folder " + isdirectoryExist + " @ " + workingfolder); break; default: break; } } return(workingfolder); }
static void Main(string[] args) { stopwatch = new Stopwatch(); stopwatch.Start(); ModuleManager moduleManager = null; ModuleClient moduleclient = null; SQLClass sqlclass = null; Environment currentEnvironmet = Environment.productionOnlinux; int count = 0; string logmessage = string.Empty; currentEnvironmet = Environment.productionOnlinux; moduleManager = new ModuleManager(""); string configfile = ""; bool repeat = true; if (currentEnvironmet == Environment.productionOnlinux) { configfile = "/app/documents/config.txt"; moduleclient = ConnectionManager.Init().Result; moduleManager = new ModuleManager("/app/documents/config.txt"); } else if (currentEnvironmet == Environment.testOnWindow) { configfile = "C:\\Users\\sena.kim\\Documents\\Projects\\LS산전\\Azure_LS_EdgeSolution\\LSIoTEdgeSolution\\config\\config.txt"; moduleManager = new ModuleManager("C:\\Users\\sena.kim\\Documents\\Projects\\LS산전\\Azure_LS_EdgeSolution\\LSIoTEdgeSolution\\config\\config.txt"); } moduleManager.Init(); LogBuilder.LogWrite(LogBuilder.MessageStatus.Usual, configfile); sqlclass = new SQLClass(moduleManager.GetsqlConnectionString()); sqlclass.CheckSqlConnection(); CreateDBAndNGTable(sqlclass, currentEnvironmet); ////////////////////////////////////////// Initialization Complete //////////////////////////// logmessage = "Initialization complete : Time elapsed: {" + stopwatch.Elapsed.ToString("hh\\:mm\\:ss\\:ff") + "}"; //local test : {00:00:00:38} LogBuilder.LogWrite(LogBuilder.MessageStatus.Usual, logmessage); while (repeat == true)//count < 1)//true { count++; Process(moduleManager, currentEnvironmet, sqlclass, moduleclient); ////////////////////////////////////////// Process Complete //////////////////////////// moduleManager.Clear(); sqlclass.CloseSQL(); // only print messages that contains raw cep aps stopwatch.Stop(); // Stop if (count == 1) { // Write hours, minutes , seconds , milliseconds/. logmessage = "All Process Complete For the First Time : Time elapsed: {" + stopwatch.Elapsed.ToString("hh\\:mm\\:ss\\:ff") + "}"; // Write hours, minutes , seconds , milliseconds/. } else if (count < 10) { logmessage = " " + count + " Process Complete : Time elapsed: {" + stopwatch.Elapsed.ToString("hh\\:mm\\:ss\\:ff") + "}"; // Write hours, minutes , seconds , milliseconds/. } LogBuilder.LogWrite(LogBuilder.MessageStatus.Usual, logmessage); stopwatch.Reset(); } // Wait until the app unloads or is cancelled var cts = new CancellationTokenSource(); AssemblyLoadContext.Default.Unloading += (ctx) => cts.Cancel(); Console.CancelKeyPress += (sender, cpe) => cts.Cancel(); ConnectionManager.WhenCancelled(cts.Token).Wait(); }