예제 #1
0
        private static void ProduceDeviceDayRunningTime(long hotelIdentity)
        {
            if (ProcessInvoke.Instance <MonitorDataProcess>().GetDataCount(obj => obj.ProjectIdentity == hotelIdentity))
            {
                return;
            }
            Log($"【{DateTime.Now:yyyy-MM-dd HH:mm:ss}】开始处理每日设备运行时间数据。");
            var process = ProcessInvoke.Instance <RunningTimeProcess>();

            var lastDate         = process.LastRecordDateTime(hotelIdentity, RunningTimeType.Device);
            var firstMonitorData = ProcessInvoke.Instance <MonitorDataProcess>().GetFirst(obj => obj.ProjectIdentity == hotelIdentity);
            var startDate        = lastDate == DateTime.MinValue
                    ? firstMonitorData.UpdateTime
                    : lastDate.AddDays(1);

            while (startDate <= _produceEndDay)
            {
                var date    = startDate;
                var runTime = ProcessInvoke.Instance <HotelRestaurantProcess>()
                              .GetDeviceRunTime(hotelIdentity, date);

                var runningTime = new RunningTimeRepository().CreateDefaultModel();
                runningTime.UpdateTime      = date.GetToday();
                runningTime.ProjectIdentity = hotelIdentity;
                runningTime.RunningTimeSpan = runTime;
                runningTime.DeviceIdentity  = firstMonitorData.DeviceIdentity;
                runningTime.Type            = RunningTimeType.Device;
                ProcessInvoke.Instance <RunningTimeProcess>().StoreRunningTime(runningTime);

                startDate = startDate.AddDays(1);
            }
        }
예제 #2
0
        /// <summary>
        /// 油烟系统报警信息处理
        /// </summary>
        /// <param name="package"></param>
        /// <param name="source"></param>
        public static void LampblackAlarm(IProtocolPackage <byte[]> package, IPackageSource source)
        {
            var exception = package[ProtocolDataName.LampblackException];

            if (exception == null)
            {
                return;
            }

            var alarmList = new List <Alarm>();

            var flag = Globals.BytesToUint16(exception.ComponentContent, 0, false);

            for (var i = 0; i < 8; i++)
            {
                var error = (1 << i);

                if ((flag & error) == 0)
                {
                    continue;
                }
                var record = new AlarmRepository().CreateDefaultModel();
                record.AlarmType     = AlarmType.Lampblack;
                record.AlarmCode     = error;
                record.AlarmDeviceId = package.Device.Id;
                record.UpdateTime    = package.ReceiveDateTime;
                record.DomainId      = package.Device.DomainId;
                alarmList.Add(record);
            }

            if (alarmList.Count > 0)
            {
                ProcessInvoke.Instance <ProtocolPackageProcess>().AddOrUpdateAlarm(alarmList);
            }
        }
예제 #3
0
        /// <summary>
        /// 初始化网站全局信息
        /// </summary>
        private void GlobalInitial()
        {
            DbRepository.ConnectionName = "Lampblack_Platform";
            GeneralProcess.LoadBaseInfomations();

            var deviceModels = GeneralProcess.GetDeviceModels();

            foreach (var model in deviceModels)
            {
                var rate = new CleanessRate(model);
                PlatformCaches.Add($"CleanessRate-{model.Id}", rate, false, "deviceModels");
            }

            var configDictionary = new Dictionary <string, object>
            {
                {
                    "deviceTypeGuid",
                    ((IList <DeviceType>)
                     GeneralProcess.GetConfig <DeviceType>(obj => obj.DeviceTypeCode == "WD_Lampblack"))
                    .FirstOrDefault()?.Id
                },
                {
                    "firmwareSetGuid",
                    ((IList <FirmwareSet>)
                     GeneralProcess.GetConfig <FirmwareSet>(obj => obj.FirmwareSetName == "油烟协议第一版"))
                    .FirstOrDefault()?.Id
                }
            };

            var userDiscticts =
                (IList <SysDictionary>)GeneralProcess.GetConfig <SysDictionary>(c => c.ItemName == "userDistrict");

            PlatformCaches.Add("userDistrict", userDiscticts, false, "SystemConfig");

            LampblackConfig.InitConfig(configDictionary);
            WdControllerBase.LoginName = LampblackConfig.LoginName;
            PlatformCaches.Add("Cleaness", ProcessInvoke.Instance <HotelRestaurantProcess>().GetHotelCleanessList());
            var updateCleaness = new WdScheduler(SchedulerType.Interval)
            {
                Interval = 120000
            };

            updateCleaness.OnExecuting += () =>
            {
                PlatformCaches.Add("Cleaness", ProcessInvoke.Instance <HotelRestaurantProcess>().GetHotelCleanessList());
            };
            WdSchedulerManager.Register(updateCleaness);
            PlatformCaches.Add("HotelLocations", ProcessInvoke.Instance <HotelRestaurantProcess>().GetHotelLocations());
            var updateLocations = new WdScheduler(SchedulerType.Interval)
            {
                Interval = 120000
            };

            updateLocations.OnExecuting += () =>
            {
                PlatformCaches.Add("HotelLocations", ProcessInvoke.Instance <HotelRestaurantProcess>().GetHotelLocations());
            };
            WdSchedulerManager.Register(updateLocations);
        }
예제 #4
0
 /// <summary>
 /// 获取所有协议信息
 /// </summary>
 /// <returns></returns>
 private static void GetProtocolsFullLoaded()
 {
     foreach (var protocol in ProcessInvoke.Instance <ProtocolCodingProcess>().GetProtocolsFullLoaded()
              .Where(protocol => !ProtocolsCache.ContainsValue(protocol)))
     {
         ProtocolsCache.Add(protocol.ProtocolName, protocol);
     }
 }
예제 #5
0
 /// <summary>
 /// 检测数据接收事件
 /// </summary>
 protected static void OnMonitorDataReceived()
 {
     lock (TempMonitorDatas)
     {
         while (TempMonitorDatas.Count > 0)
         {
             var executeDatas = TempMonitorDatas.ToArray();
             ProcessInvoke.Instance <ProtocolPackageProcess>().AddOrUpdateMonitorData(executeDatas);
             TempMonitorDatas.Clear();
         }
     }
 }
예제 #6
0
        private static CommandTask GetTask(Guid taskGuid)
        {
            var task = ResponingTasks.FirstOrDefault(obj => obj.Id == taskGuid);

            if (task != null)
            {
                return(task);
            }
            task = ProcessInvoke.Instance <CommandTaskProcess>().GetTaskByGuid(taskGuid);
            ResponingTasks.Add(task);

            return(task);
        }
예제 #7
0
        private static void StoreDataStatistic(MonitorData data, DateTime endDate, StatisticsType type)
        {
            var dataStatistic = new DataStatisticsRepository().CreateDefaultModel();

            dataStatistic.DoubleValue     = data.DoubleValue;
            dataStatistic.CommandDataId   = data.CommandDataId;
            dataStatistic.DataChannel     = data.DataChannel;
            dataStatistic.DeviceIdentity  = data.DeviceIdentity;
            dataStatistic.ProjectIdentity = data.ProjectIdentity;
            dataStatistic.Type            = type;
            dataStatistic.UpdateTime      = endDate;

            ProcessInvoke.Instance <DataStatisticsProcess>().StoreDataStatistic(dataStatistic);
        }
예제 #8
0
        /// <summary>
        /// 存储协议包数据
        /// </summary>
        /// <param name="package">协议数据包</param>
        /// <returns>保存数据包相关信息</returns>
        public static void ParseProtocolData(IProtocolPackage package)
        {
            var protocolData = new ProtocolDataRepository().CreateDefaultModel();

            protocolData.DeviceIdentity  = package.Device.Identity;
            protocolData.ProtocolId      = package.Protocol.Id;
            protocolData.ProtocolTime    = package.ReceiveDateTime;
            protocolData.UpdateTime      = DateTime.Now;
            protocolData.DomainId        = package.Device.DomainId;
            protocolData.ProtocolContent = package.GetBytes();
            protocolData.Length          = protocolData.ProtocolContent.Length;

            package.ProtocolData = protocolData;
            ProcessInvoke.Instance <ProtocolPackageProcess>().AddOrUpdateProtocolData(protocolData);
        }
예제 #9
0
        /// <summary>
        /// 通过协议名称获取协议
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static Protocol GetProtocolByName(string name)
        {
            if (ProtocolsCache.ContainsKey(name))
            {
                return(ProtocolsCache[name]);
            }

            var protocol = ProcessInvoke.Instance <ProtocolCodingProcess>().GetProtocolFullLoadedByName(name);

            if (protocol == null)
            {
                return(null);
            }

            ProtocolsCache.Add(protocol.ProtocolName, protocol);
            return(ProtocolsCache[name]);
        }
예제 #10
0
        static AppConfig()
        {
            TcpBufferSize = int.Parse(ConfigurationManager.AppSettings["TcpBufferSize"]);

            ServerIpAddress = IPAddress.Parse(ConfigurationManager.AppSettings["ServerAddress"]);

            ServerPort = int.Parse(ConfigurationManager.AppSettings["ServerPort"]);

            ServerAccount = ConfigurationManager.AppSettings["ServerAccount"];

            var configs = ProcessInvoke.Instance <SysConfigProcess>().GetSysConfigsByType(SysConfigType.ProtocolAdminTools);

            CommandQueue = configs.FirstOrDefault(obj => obj.SysConfigName == "CommandMessageQueueName")?.SysConfigValue;

            CommandMessageQueueCategory = ConfigurationManager.AppSettings["CommandMessageQueueCategory"];

            DeviceConnectionChevkInterval = double.Parse(ConfigurationManager.AppSettings["DeviceConnectionChevkInterval"]);

            DeviceDisconnectInterval = new TimeSpan(0, 0, int.Parse(ConfigurationManager.AppSettings["DeviceDisconnectInterval"]));
        }
예제 #11
0
        static void ProduceHourDatas(long hotelIdentity)
        {
            foreach (var data in ProduceDatas)
            {
                if (!ProcessInvoke.Instance <MonitorDataProcess>().GetDataCount(obj => obj.ProjectIdentity == hotelIdentity && obj.CommandDataId == data.Id))
                {
                    continue;
                }

                Log($"【{DateTime.Now:yyyy-MM-dd HH:mm:ss}】开始处理小时历史数据,数据名称:{data.DataName}");
                var lastDate = ProcessInvoke.Instance <DataStatisticsProcess>()
                               .GetLastUpdateDataDate(obj => obj.Type == StatisticsType.Hour && obj.ProjectIdentity == hotelIdentity && obj.CommandDataId == data.Id);

                var startDate = lastDate == DateTime.MinValue
                    ? ProcessInvoke.Instance <MonitorDataProcess>().GetFirst(obj => obj.ProjectIdentity == hotelIdentity && obj.CommandDataId == data.Id).UpdateTime
                    : lastDate;

                startDate = startDate.GetCurrentHour();

                while (startDate < _produceEndDayHour)
                {
                    var endDate = startDate.AddHours(1);
                    var date    = startDate;
                    var min     = ProcessInvoke.Instance <MonitorDataProcess>()
                                  .GetMinHotelMonitorData(obj =>
                                                          obj.ProjectIdentity == hotelIdentity && obj.UpdateTime > date && obj.UpdateTime < endDate &&
                                                          obj.CommandDataId == data.Id);

                    if (min == null)
                    {
                        startDate = startDate.AddHours(1);
                        continue;
                    }

                    StoreDataStatistic(min, endDate, StatisticsType.Hour);

                    startDate = startDate.AddHours(1);
                }
            }
        }
예제 #12
0
        private static void ProduceDayRunningTime(long hotelIdentity)
        {
            foreach (var data in RunningTimeDatas)
            {
                if (!ProcessInvoke.Instance <MonitorDataProcess>().GetDataCount(obj => obj.ProjectIdentity == hotelIdentity && obj.CommandDataId == data.Id))
                {
                    continue;
                }
                Log($"【{DateTime.Now:yyyy-MM-dd HH:mm:ss}】开始处理每日运行时间数据,数据名称:{data.DataName}");
                var process = ProcessInvoke.Instance <RunningTimeProcess>();

                var type             = GetRunningType(data.DataName);
                var lastDate         = process.LastRecordDateTime(hotelIdentity, type);
                var firstMonitorData = ProcessInvoke.Instance <MonitorDataProcess>().GetFirst(obj => obj.ProjectIdentity == hotelIdentity && obj.CommandDataId == data.Id);
                var startDate        = lastDate == DateTime.MinValue
                        ? firstMonitorData.UpdateTime
                        : lastDate.AddDays(1);

                while (startDate <= _produceEndDay)
                {
                    var date    = startDate;
                    var runTime = ProcessInvoke.Instance <HotelRestaurantProcess>()
                                  .GetRunTime(hotelIdentity, date, data.Id);

                    var runningTime = new RunningTimeRepository().CreateDefaultModel();
                    runningTime.UpdateTime      = date.GetToday();
                    runningTime.ProjectIdentity = hotelIdentity;
                    runningTime.RunningTimeSpan = runTime;
                    runningTime.DeviceIdentity  = firstMonitorData.DeviceIdentity;
                    runningTime.Type            = type;

                    ProcessInvoke.Instance <RunningTimeProcess>().StoreRunningTime(runningTime);

                    startDate = startDate.AddDays(1);
                }
            }
        }
 /// <summary>
 /// 获取授权设备
 /// </summary>
 /// <param name="package"></param>
 /// <returns></returns>
 private static IDevice GetAuthedDevice(IProtocolPackage package)
 => ProcessInvoke.Instance <DeviceProcess>().GetDeviceByNodeId(package.DeviceNodeId, true);
예제 #14
0
        /// <summary>
        /// 更新任务执行状态
        /// </summary>
        /// <param name="taskGuid">任务GUID</param>
        /// <param name="exceteStatus">任务执行状态</param>
        public static void UpdateTaskExceteStatus(Guid taskGuid, TaskExceteStatus exceteStatus)
        {
            var task = GetTask(taskGuid);

            ProcessInvoke.Instance <CommandTaskProcess>().UpdateExecuteStatus(task, exceteStatus);
        }
예제 #15
0
        /// <summary>
        /// 更新任务状态
        /// </summary>
        /// <param name="taskGuid">任务GUID</param>
        /// <param name="status">任务状态</param>
        public static void UpdateTaskStatus(Guid taskGuid, TaskStatus status)
        {
            var task = GetTask(taskGuid);

            ProcessInvoke.Instance <CommandTaskProcess>().UPdateTaskStatus(task, status);
        }