public int FetchLogs_SFG(string folder) { int count = 0; string date = folder.Split('\\').Last(); if (!FetchedFileList_SFG.ContainsKey(date)) { FetchedFileList_SFG.Add(date, new List <string>()); } string[] filePaths = Directory.GetFiles(folder); foreach (string oneFilePath in filePaths) { try { string fileName = oneFilePath.Split('\\').Last(); if (!FetchedFileList_SFG[date].Contains(fileName)) { //The file isn't in the fetched file list, add the file name to the list. FetchedFileList_SFG[date].Add(fileName); string[] elemInFileName = fileName.Split('_'); string sn = elemInFileName[0]; if (sn.Trim().Length < 10) //The serial number is 15. { continue; } string project = elemInFileName[3].ToUpper(); string datetime = MTEDatabaseSetup.ConvertDateTimeFormat(elemInFileName[9]); bool newRecord; if (project == "JAGWAR" || project == "JAGWARC") { newRecord = DB_Jagwar.ParseLogIntoDB(DBTable_Jagwar_SFG, StationCategory.SFG, oneFilePath); MTEDatabaseSetup.SFGHeader sfgInformation = DB_Jagwar.ParseSFGHeader(fileName); DB_Jagwar.AddRecordInSummary(DBTable_Jagwar_SFG_Summary, sfgInformation); } else { newRecord = DB_JagwarPlus.ParseLogIntoDB(DBTable_JagwarPlus_SFG, StationCategory.SFG, oneFilePath); MTEDatabaseSetup.SFGHeader sfgInformation = DB_JagwarPlus.ParseSFGHeader(fileName); DB_JagwarPlus.AddRecordInSummary(DBTable_JagwarPlus_SFG_Summary, sfgInformation); } if (newRecord) { count++; } } } catch (Exception ex) { Log($"Error happens in fetching SFG log {oneFilePath}, {ex.Message}, {ex.StackTrace}"); } } return(count); }
protected override void OnStop() { DB_Jagwar.DisconnectDatabase(); DB_JagwarPlus.DisconnectDatabase(); timer.Stop(); EventLogWriter("JUUL MTE Database setup service stops.", EventCategory.ServiceStop); // Update the service state to Stop Pending. ServiceStatus serviceStatus = new ServiceStatus(); serviceStatus.dwCurrentState = ServiceState.SERVICE_STOP_PENDING; serviceStatus.dwWaitHint = 100000; SetServiceStatus(this.ServiceHandle, ref serviceStatus); // Update the service state to Stopped. serviceStatus.dwCurrentState = ServiceState.SERVICE_STOPPED; SetServiceStatus(this.ServiceHandle, ref serviceStatus); Log("The service is stopped."); }
private void MainForm_FormClosed(object sender, FormClosedEventArgs e) { DB_Jagwar.DisconnectDatabase(); DB_JagwarPlus.DisconnectDatabase(); }