private void WorkProcess(object sender, ElapsedEventArgs e) { var currentDate = DateTime.Parse(DateTime.Now.ToString("HH:mm:ss")); var timeValue = _appSettings.Settings["TimeRun"]; var timeRescan = _appSettings.Settings["TimeReScan"] == null ? 60000 : int.Parse(_appSettings.Settings["TimeReScan"].Value); DateTime time = DateTime.Parse(timeValue == null ? "18:30:00" : timeValue.Value.ToString()); DateTime timeRun = DateTime.Today.AddHours(time.Hour).AddMinutes(time.Minute); //_logService.LogError("timeRun: " + timeRun); //_logService.LogError("currentDate: " + currentDate); //_logService.LogError("lastRun: " + lastRun); if (currentDate >= timeRun && lastRun < timeRun) { timer.Stop(); importRequest = new ImportRequest { FileName = _appSettings.Settings["FileName"]?.Value, PathFolder = _appSettings.Settings["PathFolder"]?.Value, FileNameNew = _appSettings.Settings["FileNew"]?.Value }; var checkFile = FileHelper.CheckFile(importRequest); //check if file exits if (checkFile.ToString().Equals("EXTENSION")) { reScanBarCode = 0; try { var results = service.Import(importRequest, _appSettings); //timer.Interval = 3 * 60 * 1000; if (results.Status) { FileHelper.CopyFile(importRequest); //_logService.LogError("importRequest: " + importRequest); } else { //if Barcode Scanner Batch run got Error if (!string.IsNullOrEmpty(results.Message)) { var sendMail = EmailHelper.SendMail(_appSettings, new EmailContent { Body = results.Message, Subject = "Barcode Scanner Batch run got Error and Stop" }, results.StartDate); if (sendMail.Message == "") { _logService.LogError("Send mail is successfully "); } else { _logService.LogError("Send mail is error " + sendMail.Message.ToString()); } _logService.LogInfo("End: " + DateTime.Now.ToString()); _logService.LogInfo("##############################################"); } } lastRun = DateTime.Now; } catch (Exception) { } } else if (checkFile.ToString().Equals("NOTEXSIT")) { reScanBarCode++; //auto re-scan after 1 minutes if could not fould //_logService.LogError("reScanBarCode" + reScanBarCode); timer.Interval = timeRescan; if (reScanBarCode == 3) { var sendMail = EmailHelper.SendMail(_appSettings, new EmailContent { Body = "Can not find Raw data file", Subject = "Barcode Scanner Batch run got Error and Stop" }, DateTime.Now); reScanBarCode = 0; _logService.LogError("Can not find Raw data file"); //_logService.LogError(sendMail.Message); if (sendMail.Message == "") { _logService.LogError("Send mail successfully "); } else { _logService.LogError("Send mail is error " + sendMail.Message.ToString()); } lastRun = DateTime.Now; _logService.LogInfo("End: " + DateTime.Now.ToString()); _logService.LogInfo("##############################################"); } } if (reScanBarCode == 0) { //auto scan after interval minutes after success timer.Interval = minutes; //_logService.LogError("Interval " + timer.Interval); } timer.Start(); } }
private void WorkProcess(object sender, ElapsedEventArgs e) { service.Import(importRequest, _appSettings); }