private string ChangeDeviceInfo(HttpContext context)
        {
            string strDeviceId   = context.Request.Params["DeviceId"];
            string strDeviceName = context.Request.Params["DeviceName"];

            Data.DeviceInfo device = new Data.DeviceInfo()
            {
                DeviceId = strDeviceId, DeviceName = strDeviceName
            };

            Data.DataHelper dataHelper = new Data.DataHelper();

            Data.Result <Data.DeviceInfo> result;
            bool isUpdate = dataHelper.UpdateDeviceInfo(device);

            if (isUpdate)
            {
                result = Data.ResultUtil.Success <Data.DeviceInfo>(device);
            }
            else
            {
                result = Data.ResultUtil.SystemError <Data.DeviceInfo>(device);
            }
            return(result.ToJsonString());
        }
 public DeviceDescription(Data.DeviceInfo deviceInfo)
 {
     UniqueId    = deviceInfo.UniqueId;
     Enabled     = deviceInfo.Enabled;
     Index       = deviceInfo.Index;
     Description = deviceInfo.Description;
     Agent       = deviceInfo.Agent;
 }
Ejemplo n.º 3
0
        public void Initialize(DeviceConfiguration config)
        {
            configuration = config;

            deviceInfo          = new Data.DeviceInfo();
            deviceInfo.UniqueId = config.UniqueId;
            deviceInfo.Enabled  = config.Enabled;
            deviceInfo.Index    = config.Index;
        }
Ejemplo n.º 4
0
        private void UpdateDeviceData(string uniqueId, List <Data.HourInfo> infos)
        {
            var deviceInfo = cachedDevicesInfos.Find(o => o.UniqueId == uniqueId);

            if (deviceInfo == null)
            {
                deviceInfo          = new Data.DeviceInfo();
                deviceInfo.UniqueId = uniqueId;
                cachedDevicesInfos.Add(deviceInfo);
            }

            deviceInfo.Hours = infos;
        }
Ejemplo n.º 5
0
        private void UpdateDeviceData(string uniqueId, Data.TimersInfo info)
        {
            var deviceInfo = cachedDevicesInfos.Find(o => o.UniqueId == uniqueId);

            if (deviceInfo == null)
            {
                deviceInfo          = new Data.DeviceInfo();
                deviceInfo.UniqueId = uniqueId;
                cachedDevicesInfos.Add(deviceInfo);
            }

            deviceInfo.Timers = info;
        }
Ejemplo n.º 6
0
 public void Remove(Data.DeviceInfo deviceInfo)
 {
     lock (_lock)
     {
         if (deviceInfo != null)
         {
             int index = queuedInfos.FindIndex(o => o.UniqueId == deviceInfo.UniqueId);
             if (index >= 0)
             {
                 queuedInfos.RemoveAt(index);
             }
         }
     }
 }
Ejemplo n.º 7
0
 public void Add(Data.DeviceInfo deviceInfo)
 {
     lock (_lock)
     {
         if (deviceInfo != null)
         {
             int index = queuedInfos.FindIndex(o => o.UniqueId == deviceInfo.UniqueId);
             if (index >= 0)
             {
                 queuedInfos[index] = deviceInfo;
             }
             else
             {
                 queuedInfos.Add(deviceInfo);
             }
         }
     }
 }
Ejemplo n.º 8
0
        public static List <Data.DeviceInfo> Load(string[] devices)
        {
            var config = Configuration.Read();

            if (File.Exists(config.SQliteDatabasePath))
            {
                try
                {
                    var connection = Connection.Create(config);
                    if (connection != null)
                    {
                        DataTable hoursTable = Table.GetHours(connection, devices);
                        if (hoursTable != null)
                        {
                            var hourRowInfos = new List <Row.HourRowInfo>();

                            // Get HourRowInfo objects from DataRows
                            foreach (DataRow row in hoursTable.Rows)
                            {
                                var hourRowInfo = Row.GetHourInfo(connection, row);
                                if (hourRowInfo != null)
                                {
                                    hourRowInfos.Add(hourRowInfo);
                                }
                            }

                            var result = new List <Data.DeviceInfo>();

                            // Create DeviceInfo object for each HourRowInfo
                            foreach (var hourRowInfo in hourRowInfos)
                            {
                                Data.DeviceInfo deviceInfo = null;
                                deviceInfo = result.Find(o => o.UniqueId == hourRowInfo.UniqueId);
                                if (deviceInfo == null)
                                {
                                    deviceInfo          = new Data.DeviceInfo();
                                    deviceInfo.UniqueId = hourRowInfo.UniqueId;
                                    result.Add(deviceInfo);
                                }

                                deviceInfo.AddHourInfo(hourRowInfo.HourInfo);
                            }

                            logger.Info("Local Data Server : Backup Loaded Successfully");

                            return(result);
                        }

                        Connection.Close(connection);
                    }
                }
                catch (Exception ex)
                {
                    logger.Error(ex);
                }
            }
            else
            {
                logger.Warn("Local Server Backup File Not Found @ " + config.SQliteDatabasePath);
            }

            return(null);
        }