public void CheckDeviceStatus() { SharedLibraryMonitoringDevice.DeviceStatusCache result = null; try { //result = channel.GetDeviceStatus(IPAddress); if (Appl18 != null) { result = Appl18.GetDeviceStatus(); } else if (Appl19 != null) { result = Appl19.GetDeviceStatus(); } } catch (Exception ex) { logger.LogException(LogLevel.Info, string.Format("SaveDeviceStatus.CheckDeviceStatus.{0}", this.IPAddress), ex); return; } if (result == null) { return; } DeviceStatusHistory lastRecord = null; try { lastRecord = channel.GetLastDeviceStatusHistory(IPAddress); } catch (Exception ex) { logger.LogException(LogLevel.Info, string.Format("SaveDeviceStatus.CheckDeviceStatus.{0}", this.IPAddress), ex); //return; } if (lastRecord == null) { try { channel.AddNewDeviceStatusHistory(result.Id, IPAddress); } catch (Exception ex) { logger.LogException(LogLevel.Info, string.Format("SaveDeviceStatus.CheckDeviceStatus.{0}", this.IPAddress), ex); } SaveValueInDeviceStatusLastRecord(result.Id); return; } //TimeSpan timeSpanDiff = DateTime.Now - lastRecord.Date; //if (timeSpanDiff > MaxTimeInterval) //{ // try // { // channel.AddNewDeviceStatusHistory(result.Id, IPAddress); // } // catch (System.Exception ex) // { // //TODO Exception // } // SaveValueInDeviceStatusLastRecord(result.Id); // return; //} if (result.Id != lastRecord.StatusId) { try { channel.AddNewDeviceStatusHistory(result.Id, IPAddress); } catch (Exception ex) { logger.LogException(LogLevel.Info, string.Format("SaveDeviceStatus.CheckDeviceStatus.{0}", this.IPAddress), ex); } SaveValueInDeviceStatusLastRecord(result.Id); return; } SaveValueInDeviceStatusLastRecord(result.Id); }