Beispiel #1
0
        public DeviceStatusCache GetDeviceStatus()
        {
            DeviceStatusCache result = null;

            if (Controller.Error)
            {
                result = new DeviceStatusCache(25, "Error", "The 'Controller' class is reporting an error", StatusColor.Red, "192.168.1.18");
            }
            else if (Controller.Run)
            {
                result = new DeviceStatusCache(24, "Run", "The 'Controller' class is ready for operation. Input and output data is being exchanged cyclically", StatusColor.Green, "192.168.1.18");
            }

            return(result);
        }
        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);
        }