public List <RmsReportMonitoringRaw> Monitoring() { List <RmsReportMonitoringRaw> lRmsReportMonitoringRaws = new List <RmsReportMonitoringRaw>(); RmsReportMonitoringRaw raw = new RmsReportMonitoringRaw(); raw.ClientCode = clientResult.Client.ClientCode; raw.DeviceCode = clientResult.ListDevices[0].DeviceCode; int ret = _device.CheckDeviceManager(); if (ret == 0) { raw.Message = "OK"; } else if (ret == -1) { raw.Message = "DEVICE_NOT_FOUND"; } else { raw.Message = "DEVICE_NOT_READY"; } raw.MessageDateTime = DateTime.Now; raw.MonitoringProfileDeviceId = clientResult.ListMonitoringProfileDevices[0].MonitoringProfileDeviceId; lRmsReportMonitoringRaws.Add(raw); return(lRmsReportMonitoringRaws); }
private static void TestClientProxy() { ClientProxy.ClientServiceClient cp = new ClientServiceClient(); var clientResult = cp.GetClient(GetClientBy.ClientID, 1, null, null, true, true); MonitoringProxy.MonitoringServiceClient mp = new MonitoringServiceClient(); List <RmsReportMonitoringRaw> lRawMessage = new List <RmsReportMonitoringRaw>(); foreach (var mpd in clientResult.ListMonitoringProfileDevices) { var rawMessage = new RmsReportMonitoringRaw(); rawMessage.ClientCode = clientResult.Client.ClientCode; rawMessage.DeviceCode = clientResult.ListDevices.First(d => d.DeviceId == mpd.DeviceId).DeviceCode; if (mpd.MonitoringProfileDeviceId != 16) { rawMessage.Message = "OK"; } else { rawMessage.Message = "DEVICE_NOT_READY"; } rawMessage.MessageDateTime = DateTime.Now; rawMessage.MonitoringProfileDeviceId = mpd.MonitoringProfileDeviceId; lRawMessage.Add(rawMessage); } mp.AddMessages(lRawMessage); }
public void AddMessage(RmsReportMonitoringRaw rawMessage) { try { AddMessageWithAttachFiles(rawMessage, null); } catch (Exception ex) { new RMSWebException(this, "0500", "AddMessage failed. " + ex.Message, ex, true); } }
private static void SendBusinessMessage() { MonitoringProxy.MonitoringServiceClient msc = new MonitoringServiceClient(); var raw = new RmsReportMonitoringRaw(); raw.ClientCode = "SKSSGWS01"; raw.Message = "BATCH_COMPLETE"; raw.MessageGroupCode = "B011"; raw.MessageRemark = "Testing Business Message"; msc.AddBusinessMessage(raw); }
public void AddMessageWithAttachFiles(RmsReportMonitoringRaw rawMessage, List <RMSAttachment> lAttachments) { try { var ip = GetIP(); rawMessage.ClientIpAddress = ip; var lRawMessages = new List <RmsReportMonitoringRaw>(); lRawMessages.Add(rawMessage); AddTechnicalMessages(lRawMessages, lAttachments); } catch (Exception ex) { new RMSWebException(this, "0500", "AddMessageWithAttachFiles failed. " + ex.Message, ex, true); } }
public void AddBusinessMessage(RmsReportMonitoringRaw rawMessage) { try { var ip = GetIP(); rawMessage.ClientIpAddress = ip; using (var db = new MyDbContext()) { db.Configuration.AutoDetectChangesEnabled = false; db.RmsReportMonitoringRaws.Add(rawMessage); db.SaveChanges(); } if (string.IsNullOrEmpty(rawMessage.ClientCode)) { return; } if (string.IsNullOrEmpty(rawMessage.MessageGroupCode)) { return; } if (string.IsNullOrEmpty(rawMessage.Message)) { return; } var sv = new SummaryService(); var caller = new SummaryService.DoSummaryMonitoringForBusinessAsync(sv.DoSummaryMonitoringForBusiness); caller.BeginInvoke(rawMessage, null, null); } catch (Exception ex) { new RMSWebException(this, "0500", "AddBusinessMessage failed. " + ex.Message, ex, true); } }
public List <RmsReportMonitoringRaw> Monitoring() { try { List <RmsReportMonitoringRaw> lRmsReportMonitoringRaws = new List <RmsReportMonitoringRaw>(); RmsReportMonitoringRaw raw = new RmsReportMonitoringRaw(); raw.ClientCode = clientResult.Client.ClientCode; raw.DeviceCode = clientResult.ListDevices[0].DeviceCode; int ret = _device.CheckDeviceManager(); if (ret == 0) { raw.Message = "OK"; } else if (ret == -1) { raw.Message = "DEVICE_NOT_FOUND"; } else { raw.Message = "DEVICE_NOT_READY"; } raw.MessageDateTime = DateTime.Now; raw.MonitoringProfileDeviceId = clientResult.ListMonitoringProfileDevices[0].MonitoringProfileDeviceId; lRmsReportMonitoringRaws.Add(raw); return(lRmsReportMonitoringRaws); } catch (Exception ex) { throw new RMSAppException(this, "0500", "Monitoring failed. " + ex.Message, ex, false); } }
public List <RmsReportMonitoringRaw> Monitoring() { try { List <RmsReportMonitoringRaw> lRmsReportMonitoringRaws = new List <RmsReportMonitoringRaw>(); int ret = _device.CheckDeviceManager(); if (ret != 0) { RmsReportMonitoringRaw raw = new RmsReportMonitoringRaw(); raw.ClientCode = clientResult.Client.ClientCode; raw.DeviceCode = clientResult.ListDevices[0].DeviceCode; if (ret == -1) { raw.Message = "DEVICE_NOT_FOUND"; } else { raw.Message = "DEVICE_NOT_READY"; } raw.MessageDateTime = DateTime.Now; raw.MonitoringProfileDeviceId = clientResult.ListMonitoringProfileDevices[0].MonitoringProfileDeviceId; lRmsReportMonitoringRaws.Add(raw); } else { string messageStorageFolder = ConfigurationManager.AppSettings["RMS.MessageStorageFolder"]; messageStorageFolder = (messageStorageFolder.EndsWith(@"\")) ? messageStorageFolder : messageStorageFolder + @"\"; List <string> arrRet = new List <string>(); // Port Cannot Open string txtFileName = "PORT_CANNOT_OPEN_" + _device.comPort + ".txt"; if (File.Exists(messageStorageFolder + txtFileName)) { arrRet.Add("port_cannot_open"); } if (arrRet != null) { foreach (var s in arrRet) { RmsReportMonitoringRaw raw = new RmsReportMonitoringRaw(); raw.ClientCode = clientResult.Client.ClientCode; raw.DeviceCode = clientResult.ListDevices[0].DeviceCode; if (s.ToLower() == "port_cannot_open") { raw.Message = "PORT_CANNOT_OPEN"; } else { continue; } raw.MessageDateTime = DateTime.Now; raw.MonitoringProfileDeviceId = clientResult.ListMonitoringProfileDevices[0].MonitoringProfileDeviceId; lRmsReportMonitoringRaws.Add(raw); } } } if (lRmsReportMonitoringRaws.Count == 0) { RmsReportMonitoringRaw raw = new RmsReportMonitoringRaw(); raw.ClientCode = clientResult.Client.ClientCode; raw.DeviceCode = clientResult.ListDevices[0].DeviceCode; raw.Message = "OK"; raw.MessageDateTime = DateTime.Now; raw.MonitoringProfileDeviceId = clientResult.ListMonitoringProfileDevices[0].MonitoringProfileDeviceId; lRmsReportMonitoringRaws.Add(raw); } return(lRmsReportMonitoringRaws); } catch (Exception ex) { throw new RMSAppException(this, "0500", "Monitoring failed. " + ex.Message, ex, false); } }
public List <RmsReportMonitoringRaw> Monitoring() { try { List <RmsReportMonitoringRaw> lRmsReportMonitoringRaws = new List <RmsReportMonitoringRaw>(); RmsReportMonitoringRaw raw = new RmsReportMonitoringRaw(); raw.ClientCode = clientResult.Client.ClientCode; raw.DeviceCode = clientResult.ListDevices[0].DeviceCode; int ret = _device.CheckDeviceManager(); raw.MessageDateTime = DateTime.Now; raw.MonitoringProfileDeviceId = clientResult.ListMonitoringProfileDevices[0].MonitoringProfileDeviceId; bool _ok = true; if (ret == 0) { raw.Message = "OK"; if (clientResult.ListMonitoringProfileDevices[0].BooleanValue == true) { var alarmStatus = _device.CheckAlarmStatus(); foreach (string s in alarmStatus) { RmsReportMonitoringRaw monitoringRaw = new RmsReportMonitoringRaw(); monitoringRaw.ClientCode = clientResult.Client.ClientCode; monitoringRaw.DeviceCode = clientResult.ListDevices[0].DeviceCode; monitoringRaw.MessageDateTime = DateTime.Now; monitoringRaw.MonitoringProfileDeviceId = clientResult.ListMonitoringProfileDevices[0].MonitoringProfileDeviceId; if (s.ToLower() == "alarm_door") { monitoringRaw.Message = "ALARM_DOOR"; } else if (s.ToLower() == "alarm_temperature_external") { monitoringRaw.Message = "ALARM_TEMPERATURE_EXTERNAL"; } else if (s.ToLower() == "alarm_temperature") { monitoringRaw.Message = "ALARM_TEMPERATURE"; } else if (s.ToLower() == "alarm_vibration") { monitoringRaw.Message = "ALARM_VIBRATION"; } else if (s.ToLower() == "alarm_angle") { monitoringRaw.Message = "ALARM_ANGLE"; } else if (s.ToLower() == "alarm_power") { monitoringRaw.Message = "ALARM_POWER"; } else if (s.ToLower() == "port_cannot_open") { monitoringRaw.Message = "PORT_CANNOT_OPEN"; } if (!string.IsNullOrEmpty(monitoringRaw.Message)) { lRmsReportMonitoringRaws.Add(monitoringRaw); _ok = false; } } } } else if (ret == -1) { raw.Message = "DEVICE_NOT_FOUND"; } else { raw.Message = "DEVICE_NOT_READY"; } if (_ok) //ป้องกันการใส่ OK Message ซ้ำลงไป เมื่อพบว่า Alarm ไม่ปกติ { lRmsReportMonitoringRaws.Add(raw); } // ถ้า BooleanValue เป็น TRUE, สามารถตรวจสอบ ปริมาณการ์ดที่เหลืออยู่ได้ return(lRmsReportMonitoringRaws); } catch (Exception ex) { throw new RMSAppException(this, "0500", "Monitoring failed. " + ex.Message, ex, false); } }
public List<RmsReportMonitoringRaw> Monitoring() { try { List<RmsReportMonitoringRaw> lRmsReportMonitoringRaws = new List<RmsReportMonitoringRaw>(); int ret = _device.CheckDeviceManager(); if (ret == -1) { // ถ้า Device Not Found ให้หน่วงแล้วลอง check device manager อีกครั้ง System.Threading.Thread.Sleep(1500); ret = _device.CheckDeviceManager(); } if (ret != 0) { RmsReportMonitoringRaw raw = new RmsReportMonitoringRaw(); raw.ClientCode = clientResult.Client.ClientCode; raw.DeviceCode = clientResult.ListDevices[0].DeviceCode; raw.MessageDateTime = DateTime.Now; raw.MonitoringProfileDeviceId = clientResult.ListMonitoringProfileDevices[0].MonitoringProfileDeviceId; if (ret == -1) { raw.Message = "DEVICE_NOT_FOUND"; counterRelay[0]++; if (counterRelay[0] >= 2) //ถ้าพบ Device Not Found ตั้งแต่ 2 ครั้งติดกันขึ้นไป จึงส่ง Issue Message ไปยัง Server { lRmsReportMonitoringRaws.Add(raw); counterRelay[0] = 0; //ทำการ reset Not Found counter ค่าเป็น 0 เพราะส่ง Issue Message แจ้งเตือนแล้ว } else // ถ้าเจอ Device Not Found 1 ครั้ง ให้จบการทำงานได้เลย { return lRmsReportMonitoringRaws; } } else { counterRelay[0] = 0; //ทำการ reset Not Found counter ค่าเป็น 0 เพราะเจออุปกรณ์แล้ว raw.Message = "DEVICE_NOT_READY"; lRmsReportMonitoringRaws.Add(raw); } } else { bool checkA4PaperViaTextFile = (ConfigurationManager.AppSettings["RMS.CheckA4PaperViaTextFile"] != null && Convert.ToBoolean(ConfigurationManager.AppSettings["RMS.CheckA4PaperViaTextFile"])); List<string> arrRet = null; if (checkA4PaperViaTextFile) { string messageStorageFolder = ConfigurationManager.AppSettings["RMS.MessageStorageFolder"]; messageStorageFolder = (messageStorageFolder.EndsWith(@"\")) ? messageStorageFolder : messageStorageFolder + @"\"; arrRet = new List<string>(); string txtFileName = string.Empty; // Check Low Paper txtFileName = "LOW_PAPER_" + _device.brand + ".txt"; if (File.Exists(messageStorageFolder + txtFileName)) { arrRet.Add("low_paper"); } // Check End Paper txtFileName = "END_PAPER_" + _device.brand + ".txt"; if (File.Exists(messageStorageFolder + txtFileName)) { arrRet.Add("end_paper"); } // Check Paper Jam txtFileName = "PAPER_JAM_" + _device.brand + ".txt"; if (File.Exists(messageStorageFolder + txtFileName)) { arrRet.Add("paper_jam"); } // Check Low Toner txtFileName = "LOW_TONER_" + _device.brand + ".txt"; if (File.Exists(messageStorageFolder + txtFileName)) { arrRet.Add("low_toner"); } // Check End Toner txtFileName = "END_TONER_" + _device.brand + ".txt"; if (File.Exists(messageStorageFolder + txtFileName)) { arrRet.Add("end_toner"); } // Check Low Drum txtFileName = "LOW_DRUM_" + _device.brand + ".txt"; if (File.Exists(messageStorageFolder + txtFileName)) { arrRet.Add("low_drum"); } // Check End Drum txtFileName = "END_DRUM_" + _device.brand + ".txt"; if (File.Exists(messageStorageFolder + txtFileName)) { arrRet.Add("end_drum"); } // Check Drum Error txtFileName = "DRUM_ERROR_" + _device.brand + ".txt"; if (File.Exists(messageStorageFolder + txtFileName)) { arrRet.Add("drum_error"); } // Check Drum Error txtFileName = "DRUM_ERROR_" + _device.brand + ".txt"; if (File.Exists(messageStorageFolder + txtFileName)) { arrRet.Add("cover_oepn"); } // Check Printer Error txtFileName = "PRINTER_ERROR_" + _device.brand + ".txt"; if (File.Exists(messageStorageFolder + txtFileName)) { arrRet.Add("printer_error"); } } else { try { string[] checkPaperStatus = _device.CheckPaperStatus(); if (checkPaperStatus != null) arrRet = new List<string>(checkPaperStatus); } catch (Exception ex) { new RMSAppException(this, "500", "CheckPaperStatus failed. " + ex.Message, ex, true); } } if (arrRet != null) { foreach (var s in arrRet) { RmsReportMonitoringRaw raw = new RmsReportMonitoringRaw(); raw.ClientCode = clientResult.Client.ClientCode; raw.DeviceCode = clientResult.ListDevices[0].DeviceCode; if (s.ToLower() == "low_paper") raw.Message = "LOW_PAPER"; else if (s.ToLower() == "end_paper") raw.Message = "END_PAPER"; else if (s.ToLower() == "paper_jam") raw.Message = "PAPER_JAM"; else if (s.ToLower() == "low_toner") raw.Message = "LOW_TONER"; else if (s.ToLower() == "end_toner") raw.Message = "END_TONER"; else if (s.ToLower() == "low_drum") raw.Message = "LOW_DRUM"; else if (s.ToLower() == "end_drum") raw.Message = "END_DRUM"; else if (s.ToLower() == "drum_error") raw.Message = "DRUM_ERROR"; else if (s.ToLower() == "cover_open") raw.Message = "COVER_OPEN"; else if (s.ToLower() == "printer_error") raw.Message = "PRINTER_ERROR"; else continue; raw.MessageDateTime = DateTime.Now; raw.MonitoringProfileDeviceId = clientResult.ListMonitoringProfileDevices[0].MonitoringProfileDeviceId; lRmsReportMonitoringRaws.Add(raw); } try { var NumOfQueues = _device.CheckPrintQueueStatus(12); if (NumOfQueues > 0) { RmsReportMonitoringRaw raw = new RmsReportMonitoringRaw(); raw.ClientCode = clientResult.Client.ClientCode; raw.DeviceCode = clientResult.ListDevices[0].DeviceCode; raw.Message = "CANNOT_PRINT"; raw.MessageDateTime = DateTime.Now; raw.MonitoringProfileDeviceId = clientResult.ListMonitoringProfileDevices[0].MonitoringProfileDeviceId; lRmsReportMonitoringRaws.Add(raw); } } catch (Exception ex) { //Console.WriteLine(ex); } } // ถ้าไม่มี error msg ใน list และพบว่าเกิด error ระหว่างการตรวจสอบ paper status // จะทำอย่างไร? ยังต้องส่ง OK กลับไป server หรือไม่? } if (lRmsReportMonitoringRaws.Count == 0) { RmsReportMonitoringRaw raw = new RmsReportMonitoringRaw(); raw.ClientCode = clientResult.Client.ClientCode; raw.DeviceCode = clientResult.ListDevices[0].DeviceCode; raw.Message = "OK"; raw.MessageDateTime = DateTime.Now; raw.MonitoringProfileDeviceId = clientResult.ListMonitoringProfileDevices[0].MonitoringProfileDeviceId; lRmsReportMonitoringRaws.Add(raw); } return lRmsReportMonitoringRaws; } catch (Exception ex) { throw new RMSAppException(this, "0500", "Monitoring failed. " + ex.Message, ex, false); } }
public List <RmsReportMonitoringRaw> Monitoring(ClientResult clientResult) { List <RmsReportMonitoringRaw> lRmsReportMonitoringRaws = new List <RmsReportMonitoringRaw>(); try { /* * 1. Check CPU * 2. Check RAM * 3. Check Disk * */ #region 1. Check CPU try { var list = Helper.Common.GetRmsMonitoringProfileDevicebyDeviceCode(clientResult, "CPU", Models.DeviceCode.Performance); if (list.Count > 0) { decimal?highThreshold = list[0].HighThreshold; var processorUsage = GetProcessorUsage(); RmsReportMonitoringRaw raw = new RmsReportMonitoringRaw(); raw.ClientCode = clientResult.Client.ClientCode; raw.DeviceCode = "CPU"; if (processorUsage > highThreshold) { raw.Message = "OVER_CPU_USAGE"; } else { raw.Message = "OK"; } raw.MessageDateTime = DateTime.Now; raw.MonitoringProfileDeviceId = list[0].MonitoringProfileDeviceId; lRmsReportMonitoringRaws.Add(raw); } } catch (Exception ex) { throw new RMSAppException(this, "0500", "Check CPU failed. " + ex.Message, ex, false); } #endregion #region 2. Check RAM try { var list = Helper.Common.GetRmsMonitoringProfileDevicebyDeviceCode(clientResult, "MEMORY", Models.DeviceCode.Performance); if (list.Count > 0) { decimal?lowThreshold = list[0].LowThreshold; var availableMemory = GetAvailableMemory(); RmsReportMonitoringRaw raw = new RmsReportMonitoringRaw(); raw.ClientCode = clientResult.Client.ClientCode; raw.DeviceCode = "MEMORY"; if (availableMemory < lowThreshold) { raw.Message = "LOW_MEMORY"; } else { raw.Message = "OK"; } raw.MessageDateTime = DateTime.Now; raw.MonitoringProfileDeviceId = list[0].MonitoringProfileDeviceId; lRmsReportMonitoringRaws.Add(raw); } } catch (Exception ex) { throw new RMSAppException(this, "0500", "Check RAM failed. " + ex.Message, ex, false); } #endregion #region 3. Check Disk try { var list = Helper.Common.GetRmsMonitoringProfileDevicebyDeviceCode(clientResult, "DISK", Models.DeviceCode.Performance); foreach (var rmsMonitoringProfileDevice in list) { decimal?lowThreshold = rmsMonitoringProfileDevice.LowThreshold; var diskFreeSpace = GetDiskFreeSpace(rmsMonitoringProfileDevice.StringValue); RmsReportMonitoringRaw raw = new RmsReportMonitoringRaw(); raw.ClientCode = clientResult.Client.ClientCode; raw.DeviceCode = "DISK"; if (diskFreeSpace < lowThreshold) { raw.Message = "LOW_DISK_SPACE"; } else { raw.Message = "OK"; } raw.MessageDateTime = DateTime.Now; raw.MonitoringProfileDeviceId = rmsMonitoringProfileDevice.MonitoringProfileDeviceId; lRmsReportMonitoringRaws.Add(raw); } } catch (Exception ex) { throw new RMSAppException(this, "0500", "Check Disk failed. " + ex.Message, ex, false); } #endregion } catch (Exception ex) { new RMSAppException(this, "0500", "Monitoring failed. " + ex.Message, ex, true); } return(lRmsReportMonitoringRaws); }
public List <RmsReportMonitoringRaw> Monitoring() { try { List <RmsReportMonitoringRaw> lRmsReportMonitoringRaws = new List <RmsReportMonitoringRaw>(); RmsReportMonitoringRaw raw = new RmsReportMonitoringRaw(); raw.ClientCode = clientResult.Client.ClientCode; raw.DeviceCode = clientResult.ListDevices[0].DeviceCode; int ret = _device.CheckDeviceManager(); raw.MessageDateTime = DateTime.Now; raw.MonitoringProfileDeviceId = clientResult.ListMonitoringProfileDevices[0].MonitoringProfileDeviceId; bool _levelOK = true; if (ret == 0) { raw.Message = "OK"; if (clientResult.ListMonitoringProfileDevices[0].BooleanValue == true) { var cardLevel = _device.CheckCardLevel(); foreach (string s in cardLevel) { RmsReportMonitoringRaw cardLevelRaw = new RmsReportMonitoringRaw(); cardLevelRaw.ClientCode = clientResult.Client.ClientCode; cardLevelRaw.DeviceCode = clientResult.ListDevices[0].DeviceCode; cardLevelRaw.MessageDateTime = DateTime.Now; cardLevelRaw.MonitoringProfileDeviceId = clientResult.ListMonitoringProfileDevices[0].MonitoringProfileDeviceId; if (s.ToLower() == "low_card") { cardLevelRaw.Message = "LOW_CARD"; } else if (s.ToLower() == "end_card") { cardLevelRaw.Message = "END_CARD"; } else if (s.ToLower() == "card_jam") { cardLevelRaw.Message = "CARD_JAM"; } else if (s.ToLower() == "bin_full") { cardLevelRaw.Message = "BIN_FULL"; } else if (s.ToLower() == "port_cannot_open") { cardLevelRaw.Message = "PORT_CANNOT_OPEN"; } if (!string.IsNullOrEmpty(cardLevelRaw.Message)) { lRmsReportMonitoringRaws.Add(cardLevelRaw); _levelOK = false; } } } } else if (ret == -1) { raw.Message = "DEVICE_NOT_FOUND"; } else { raw.Message = "DEVICE_NOT_READY"; } if (_levelOK) //ป้องกันการใส่ OK Message ซ้ำลงไป เมื่อพบว่า Card Level ไม่ปกติ { lRmsReportMonitoringRaws.Add(raw); } // ถ้า BooleanValue เป็น TRUE, สามารถตรวจสอบ ปริมาณการ์ดที่เหลืออยู่ได้ return(lRmsReportMonitoringRaws); } catch (Exception ex) { throw new RMSAppException(this, "0500", "Monitoring failed. " + ex.Message, ex, false); } }
public List <RmsReportMonitoringRaw> Monitoring() { try { List <RmsReportMonitoringRaw> lRmsReportMonitoringRaws = new List <RmsReportMonitoringRaw>(); int ret = _device.CheckDeviceManager(); if (ret == -1) { // ถ้า Device Not Found ให้หน่วงแล้วลอง check device manager อีกครั้ง System.Threading.Thread.Sleep(1500); ret = _device.CheckDeviceManager(); } if (ret != 0) { RmsReportMonitoringRaw raw = new RmsReportMonitoringRaw(); raw.ClientCode = clientResult.Client.ClientCode; raw.DeviceCode = clientResult.ListDevices[0].DeviceCode; raw.MessageDateTime = DateTime.Now; raw.MonitoringProfileDeviceId = clientResult.ListMonitoringProfileDevices[0].MonitoringProfileDeviceId; if (ret == -1) { raw.Message = "DEVICE_NOT_FOUND"; counterRelay[0]++; if (counterRelay[0] >= 2) //ถ้าพบ Device Not Found ตั้งแต่ 2 ครั้งติดกันขึ้นไป จึงส่ง Issue Message ไปยัง Server { lRmsReportMonitoringRaws.Add(raw); counterRelay[0] = 0; //ทำการ reset Not Found counter ค่าเป็น 0 เพราะส่ง Issue Message แจ้งเตือนแล้ว } else // ถ้าเจอ Device Not Found 1 ครั้ง ให้จบการทำงานได้เลย { return(lRmsReportMonitoringRaws); } } else { counterRelay[0] = 0; //ทำการ reset Not Found counter ค่าเป็น 0 เพราะเจออุปกรณ์แล้ว raw.Message = "DEVICE_NOT_READY"; lRmsReportMonitoringRaws.Add(raw); } } else { counterRelay[0] = 0; //ทำการ reset Not Found counter ค่าเป็น 0 เพราะเจออุปกรณ์แล้ว int[] arrRet = null; bool checkThermalPaperViaTextFile = (ConfigurationManager.AppSettings["RMS.CheckThermalPaperViaTextFile"] != null && Convert.ToBoolean(ConfigurationManager.AppSettings["RMS.CheckThermalPaperViaTextFile"])); try { if (checkThermalPaperViaTextFile) // ถ้าตรวจสอบ paper status จาก text file, สามารถเข้าไปตรวจสอบได้ทันที { //arrRet = _device.CheckPaperStatus(); var _ret = new int[] { 0, 0, 0, 0, 0 }; string messageStorageFolder = ConfigurationManager.AppSettings["RMS.MessageStorageFolder"]; messageStorageFolder = (messageStorageFolder.EndsWith(@"\")) ? messageStorageFolder : messageStorageFolder + @"\"; // Check Low Paper string lowPaper = "LOW_PAPER_" + _device.brand + ".txt"; if (File.Exists(messageStorageFolder + lowPaper)) { _ret[0] = 1; } // Check End Paper string endPaper = "END_PAPER_" + _device.brand + ".txt"; if (File.Exists(messageStorageFolder + endPaper)) { _ret[1] = 1; } // Check Paper Jam string paperJam = "PAPER_JAM_" + _device.brand + ".txt"; if (File.Exists(messageStorageFolder + paperJam)) { _ret[2] = 1; } // Check Ticket Not Present string ticketNotPresent = "TICKET_NOT_PRESENT_" + _device.brand + ".txt"; if (File.Exists(messageStorageFolder + ticketNotPresent)) { _ret[3] = 1; } // Check Cutter Error string cutterError = "CUTTER_ERROR_" + _device.brand + ".txt"; if (File.Exists(messageStorageFolder + cutterError)) { _ret[4] = 1; } arrRet = _ret; } else // ถ้าตรวจสอบ paper status ผ่าน usb, ต้องทำการ check printer pool เสียก่อน { // 25AUG14 Modified by Sethawat Th. // ถ้าไม่มี คิว ใน pool สามารถทำการตรวจสอบ printer status ได้ if (_device.CheckPrintQueueStatus(0) == 0) { arrRet = _device.CheckPaperStatus(); } else { // กรณีมี คิว อยู่ใน pool int _checkQueueCounter = 0; // ตรวจสอบซ้ำอีกรอบ หากมีคิวนานเกิน 7 วินาที แสดงว่า คิวน่าจะค้างอยู่ if (_device.CheckPrintQueueStatus(7) == _device.CheckPrintQueueStatus(0)) { arrRet = _device.CheckPaperStatus(); } else { // วนรอไม่เกิน 5 รอบ หรือจนกว่าไม่มีคิวใน print pool while (_device.CheckPrintQueueStatus(0) > 0 && _checkQueueCounter < 5) { Thread.Sleep(1500); _checkQueueCounter++; } } } // กรณีที่ได้ผลลัพธ์เป็น 500 ให้ลอง CheckPaperStatus อีกครั้ง if (arrRet != null && arrRet.Length > 0 && arrRet[0] == 500) { Thread.Sleep(1500); arrRet = _device.CheckPaperStatus(); } } } catch (Exception ex) { new RMSWebException(this, "500", "CheckPaperStatus failed. " + ex.Message, ex, true); } if (arrRet != null) { if (arrRet.Length >= 1 && arrRet[0] > 0) { RmsReportMonitoringRaw raw = new RmsReportMonitoringRaw(); raw.ClientCode = clientResult.Client.ClientCode; raw.DeviceCode = clientResult.ListDevices[0].DeviceCode; raw.Message = "LOW_PAPER"; raw.MessageDateTime = DateTime.Now; raw.MonitoringProfileDeviceId = clientResult.ListMonitoringProfileDevices[0].MonitoringProfileDeviceId; lRmsReportMonitoringRaws.Add(raw); } if (arrRet.Length >= 2 && arrRet[1] > 0) { RmsReportMonitoringRaw raw = new RmsReportMonitoringRaw(); raw.ClientCode = clientResult.Client.ClientCode; raw.DeviceCode = clientResult.ListDevices[0].DeviceCode; raw.Message = "END_PAPER"; raw.MessageDateTime = DateTime.Now; raw.MonitoringProfileDeviceId = clientResult.ListMonitoringProfileDevices[0].MonitoringProfileDeviceId; lRmsReportMonitoringRaws.Add(raw); } if (arrRet.Length >= 3 && arrRet[2] > 0) { RmsReportMonitoringRaw raw = new RmsReportMonitoringRaw(); raw.ClientCode = clientResult.Client.ClientCode; raw.DeviceCode = clientResult.ListDevices[0].DeviceCode; raw.Message = "PAPER_JAM"; raw.MessageDateTime = DateTime.Now; raw.MonitoringProfileDeviceId = clientResult.ListMonitoringProfileDevices[0].MonitoringProfileDeviceId; lRmsReportMonitoringRaws.Add(raw); } if (arrRet.Length >= 4 && arrRet[3] > 0) { RmsReportMonitoringRaw raw = new RmsReportMonitoringRaw(); raw.ClientCode = clientResult.Client.ClientCode; raw.DeviceCode = clientResult.ListDevices[0].DeviceCode; raw.Message = "TICKET_NOT_PRESENT"; raw.MessageDateTime = DateTime.Now; raw.MonitoringProfileDeviceId = clientResult.ListMonitoringProfileDevices[0].MonitoringProfileDeviceId; lRmsReportMonitoringRaws.Add(raw); } if (arrRet.Length >= 5 && arrRet[4] > 0) { RmsReportMonitoringRaw raw = new RmsReportMonitoringRaw(); raw.ClientCode = clientResult.Client.ClientCode; raw.DeviceCode = clientResult.ListDevices[0].DeviceCode; raw.Message = "CUTTER_ERROR"; raw.MessageDateTime = DateTime.Now; raw.MonitoringProfileDeviceId = clientResult.ListMonitoringProfileDevices[0].MonitoringProfileDeviceId; lRmsReportMonitoringRaws.Add(raw); } } else if (arrRet == null && checkThermalPaperViaTextFile) { RmsReportMonitoringRaw raw = new RmsReportMonitoringRaw(); raw.ClientCode = clientResult.Client.ClientCode; raw.DeviceCode = clientResult.ListDevices[0].DeviceCode; raw.Message = "DEVICE_NOT_READY"; raw.MessageDateTime = DateTime.Now; raw.MonitoringProfileDeviceId = clientResult.ListMonitoringProfileDevices[0].MonitoringProfileDeviceId; lRmsReportMonitoringRaws.Add(raw); } var NumOfQueues = _device.CheckPrintQueueStatus(7); if (NumOfQueues > 0) { RmsReportMonitoringRaw raw = new RmsReportMonitoringRaw(); raw.ClientCode = clientResult.Client.ClientCode; raw.DeviceCode = clientResult.ListDevices[0].DeviceCode; raw.Message = "CANNOT_PRINT"; raw.MessageDateTime = DateTime.Now; raw.MonitoringProfileDeviceId = clientResult.ListMonitoringProfileDevices[0].MonitoringProfileDeviceId; lRmsReportMonitoringRaws.Add(raw); } } if (lRmsReportMonitoringRaws.Count == 0) { RmsReportMonitoringRaw raw = new RmsReportMonitoringRaw(); raw.ClientCode = clientResult.Client.ClientCode; raw.DeviceCode = clientResult.ListDevices[0].DeviceCode; raw.Message = "OK"; raw.MessageDateTime = DateTime.Now; raw.MonitoringProfileDeviceId = clientResult.ListMonitoringProfileDevices[0].MonitoringProfileDeviceId; lRmsReportMonitoringRaws.Add(raw); } return(lRmsReportMonitoringRaws); } catch (Exception ex) { throw new RMSAppException(this, "0500", "Monitoring failed. " + ex.Message, ex, false); } }
private void ExecuteCommand(string clientCode) { /* * * 1. Call Centralize to Get Client & Device Info for Monitoring * 2. Check Application Running * 3. Check Maintenance State * 4. Check Device Monitoring * */ try { #region 1. Call Centralize to Get Client & Device Info for Monitoring ClientServiceClient cs = new ClientService().clientService; var clientResult = cs.GetClient(GetClientBy.ClientCode, null, clientCode, null, true, true); string localStorage = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + @"\LocalStorage"; localStorage = (ConfigurationManager.AppSettings["RMS.LocalStorage"] ?? localStorage); try { string localClientFile = localStorage + @"\clientResult.xml"; var directoryName = Path.GetDirectoryName(localClientFile); if (directoryName != null && !Directory.Exists(directoryName)) { Directory.CreateDirectory(directoryName); } string strResultList = Serializer.XML.SerializeObject(clientResult); lock (_lockClientFile) { using (TextWriter tw = new StreamWriter(localClientFile, false)) // Create & open the file { tw.Write(strResultList); tw.Close(); } } } catch (Exception myEx2) { new RMSAppException(this, "0500", "SelfMonitoring failed. " + myEx2.Message, myEx2, true); } int?deviceId = null; int?monitoringProfileDeviceId = null; var rmsMonitoringProfileDevicebyDeviceCode = RMS.Monitoring.Helper.Common.GetRmsMonitoringProfileDevicebyDeviceCode(clientResult, "CLIENT", RMS.Monitoring.Helper.Models.DeviceCode.Client); var rmsMonitoringProfileDevices = rmsMonitoringProfileDevicebyDeviceCode; // for CLIENT code, there are only one rmsMonitoringProfileDevices if (rmsMonitoringProfileDevices.Count > 0) { monitoringProfileDeviceId = rmsMonitoringProfileDevices[0].MonitoringProfileDeviceId; } if (Convert.ToBoolean(ConfigurationManager.AppSettings["RMS.DebugLogEnable"] ?? "false")) { string log = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss") + " Call Centerlize - ClientResult " + Helper.Serializer.XML.SerializeObject(clientResult); new RMSDebugLog(log, true); log = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss") + " Call Centerlize - Monitoring Profile " + Helper.Serializer.XML.SerializeObject(rmsMonitoringProfileDevices); new RMSDebugLog(log, true); } #endregion List <RmsReportMonitoringRaw> monitoringRaws = new List <RmsReportMonitoringRaw>(); MonitoringServiceClient mp = new Proxy.MonitoringService().monitoringService; #region 2. Check Maintenance State bool MAMode = false; try { string maFilePath = ConfigurationManager.AppSettings["RMS.MA_FILE_PATH"]; // MA State? if (File.Exists(maFilePath)) { if (clientResult.Client.State == (int)ClientState.Normal) { var client = new ClientService().clientService; client.SetClientState(clientResult.Client.ClientId, ClientState.Maintenance); } MAMode = true; } // Normal State else { if (clientResult.Client.State == (int)ClientState.Maintenance) { var client = new ClientService().clientService; client.SetClientState(clientResult.Client.ClientId, ClientState.Normal); } } } catch (Exception ex) { throw new RMSAppException(this, "0500", "Check Maintenance State failed. " + ex.Message, ex, false); } #endregion #region 3. Check Application Running bool checkedAgent = false; foreach (var monitoringClient in rmsMonitoringProfileDevices) { if (monitoringClient.StringValue == null) { monitoringClient.StringValue = string.Empty; } List <string> appNameList = new List <string>(monitoringClient.StringValue.Split('|')); // ถ้า device string ไม่มีค่า หรือมีค่าเท่ากับ agent process name แสดงว่า ให้ตรวจสอบ agent ว่ายังทำงานอยู่หรือไม่ if (!checkedAgent && appNameList.Any(s => string.IsNullOrEmpty(s) || s.ToLower().Trim() == ConfigurationManager.AppSettings["RMS.AGENT_PROCESS_NAME"].ToLower().Trim())) { checkedAgent = true; // การที่สามารถทำ process ต่างๆ ได้อยู่ในนี้ แสดงว่า agent ทำงาได้ปกติ // ให้ทำการส่ง message OK ได้ทันที try { var rawMessage = new RmsReportMonitoringRaw(); rawMessage.ClientCode = clientResult.Client.ClientCode; rawMessage.DeviceCode = "CLIENT"; rawMessage.Message = "OK"; rawMessage.MessageDateTime = DateTime.Now; rawMessage.MonitoringProfileDeviceId = monitoringClient.MonitoringProfileDeviceId; monitoringRaws.Add(rawMessage); //mp.AddMessage(rawMessage); } catch (Exception ex) { new RMSAppException(this, "0500", "Send Alive Message failed. " + ex.Message, ex, true); } } else if (!MAMode) // หากเข้า case นี้แสดงว่า ระบบอยากให้ตรวจสอบการทำงานของ application ภายนอก และไม่ต้องอยู่ใน MA Mode { try { if (appNameList.Any(s => IsProcessRunning(s.Trim()))) { var rawMessage = new RmsReportMonitoringRaw(); rawMessage.ClientCode = clientResult.Client.ClientCode; rawMessage.DeviceCode = "CLIENT"; rawMessage.Message = "OK"; rawMessage.MessageDateTime = DateTime.Now; rawMessage.MonitoringProfileDeviceId = monitoringClient.MonitoringProfileDeviceId; monitoringRaws.Add(rawMessage); } else { var rawMessage = new RmsReportMonitoringRaw(); rawMessage.ClientCode = clientResult.Client.ClientCode; rawMessage.DeviceCode = "CLIENT"; rawMessage.Message = "APPLICATION_NOT_RUNNING"; rawMessage.MessageDateTime = DateTime.Now; rawMessage.MonitoringProfileDeviceId = monitoringClient.MonitoringProfileDeviceId; monitoringRaws.Add(rawMessage); } } catch (Exception ex) { new RMSAppException(this, "0500", "Check application (" + monitoringClient.StringValue + ") running failed. " + ex.Message, ex, true); } } } if (MAMode) { return; //ถ้าอยู่ใน MA Mode ให้หยุดการ Monitoring } #endregion #region 4. Check Device Monitoring try { var monitoringService = new RMS.Monitoring.Core.MonitoringService(); // Performance monitoringRaws.AddRange(monitoringService.Monitoring("performance", clientResult)); // Device monitoringRaws.AddRange(monitoringService.Monitoring("device", clientResult)); if (monitoringRaws.Count > 0) { if (Convert.ToBoolean(ConfigurationManager.AppSettings["RMS.DebugLogEnable"] ?? "false")) { string log = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss") + " Check Device Monitoring " + Helper.Serializer.XML.SerializeObject(monitoringRaws); new RMSDebugLog(log, true); } List <RMSAttachment> lRMSAttachment = new List <RMSAttachment>(); if (monitoringRaws.Exists(w => w.DeviceCode == "CLIENT" && w.Message == "APPLICATION_NOT_RUNNING")) { if (Convert.ToBoolean(ConfigurationManager.AppSettings["RMS.EnableAttachEventLog"] ?? "false")) { try { var query = "*[System[TimeCreated[@SystemTime >= '" + DateTime.Now.AddHours(-1).ToUniversalTime().ToString("o") + "']]]"; string eventLogFileName = "EventLog.evtx"; if (Convert.ToBoolean(ConfigurationManager.AppSettings["RMS.EventLog.NeedImpersonate"] ?? "false")) { var userName = ConfigurationManager.AppSettings["RMS.EventLog.UserName"]; var password = ConfigurationManager.AppSettings["RMS.EventLog.Password"]; Helper.Common.ExtractLog(query, localStorage, eventLogFileName, clientCode, clientCode, userName, password); } else { Helper.Common.ExtractLog(query, localStorage, eventLogFileName); } byte[] byteEventLog = File.ReadAllBytes(localStorage + @"\" + eventLogFileName); RMSAttachment rmsAttachment = new RMSAttachment(); rmsAttachment.FileBytes = byteEventLog; rmsAttachment.Message = "APPLICATION_NOT_RUNNING"; rmsAttachment.DeviceCode = "CLIENT"; rmsAttachment.FileName = eventLogFileName; lRMSAttachment.Add(rmsAttachment); } catch (Exception ex) { new RMSAppException(this, "0500", "Check Device Monitoring - Prepare EventLog Attachfile failed. " + ex.Message, ex, true); } } //MainAppTempLog if (Convert.ToBoolean(ConfigurationManager.AppSettings["RMS.EnableAttachMainAppLog"] ?? "false")) { try { string mainAppTempLog = ConfigurationManager.AppSettings["RMS.MainAppTempLog"]; if (!string.IsNullOrEmpty(mainAppTempLog)) { if (File.Exists(mainAppTempLog)) { byte[] byteMainAppTempLog = File.ReadAllBytes(mainAppTempLog); RMSAttachment rmsAttachment = new RMSAttachment(); rmsAttachment.FileBytes = byteMainAppTempLog; rmsAttachment.Message = "APPLICATION_NOT_RUNNING"; rmsAttachment.DeviceCode = "CLIENT"; rmsAttachment.FileName = Path.GetFileName(mainAppTempLog); lRMSAttachment.Add(rmsAttachment); } } } catch (Exception ex) { new RMSAppException(this, "0500", "Check Device Monitoring - Prepare AppLog Attachfile failed. " + ex.Message, ex, true); } } } if (lRMSAttachment.Count == 0) { mp.AddMessages(monitoringRaws); } else { mp.AddMessagesWithAttachFiles(monitoringRaws, lRMSAttachment); } } } catch (Exception ex) { throw new RMSAppException(this, "0500", "Check Device Monitoring failed. " + ex.Message, ex, false); } #endregion } catch (Exception ex) { throw new RMSAppException(this, "0500", "ExecuteCommand failed. " + ex.Message, ex, true); } }