Пример #1
0
 public override void ReceiveCommand(Command command)
 {
     base.ReceiveCommand(command);
     if (CommandReceived != null)
     {
         CommandReceived(command);
     }
 }
Пример #2
0
 public void AddCommand(Command cmd)
 {
     if (cmd != null)
     {
         _commandQueue.Enqueue(cmd);
         _resetEvent.Set();
     }
 }
Пример #3
0
        public void ExecuteCommand(Command cmd)
        {
            try
            {
                OnExecuteCommand(cmd);

                if (CommandExecuted != null)
                    CommandExecuted(this, cmd);
            }
            catch (Exception ex)
            {
                _exception = new Exception("OnExecuteCommand() got a error.", ex);
            }
        }
Пример #4
0
 private void DataClient_CommandReceived(Command command)
 {
     //Action action = new Action(() =>
     //{
     ProcessReceivedCommand(command);
     //});
     //action.BeginInvoke(null, null);
 }
Пример #5
0
 public void SetStrategy(string strategyTableStr)
 {
     Command command = new Command()
     {
         Code = CommandCode.UpdateStrategy,
         Source = "MonitorUIClient",
         Target = TargetType.ToRuleEngine,
         CommandText = strategyTableStr
     };
     _dataClient.SendCommand(command);
 }
Пример #6
0
 public void SetPointDeteConfig(string configStr)
 {
     Command command = new Command()
     {
         Code = CommandCode.SetSpotInspectionConfigInfo,
         Source = "MonitorUIClient",
         Target = TargetType.ToDataSource,
         CommandText = configStr
     };
     _dataClient.SendCommand(command);
 }
Пример #7
0
 public void SetLedMonitoringConfig(string configStr)
 {
     Command command = new Command()
     {
         Code = CommandCode.SetLedMonitoringConfigInfo,
         Source = "MonitorUIClient",
         Target = TargetType.ToDataSource,
         CommandText = configStr
     };
     _dataClient.SendCommand(command);
 }
Пример #8
0
 public void SetBrightnessConfigToLCT(string configStr)
 {
     Command command = new Command()
     {
         Code = CommandCode.BrightnessConfigToLCT,
         Source = "MonitorUIClient",
         Target = TargetType.ToClient,
         CommandText = configStr
     };
     _dataClient.SendCommand(command);
     _logService.Info("亮度配置命令已发送给LCT:" + CommandCode.BrightnessConfigToLCT);
 }
Пример #9
0
        private static void SmokeStrategyTask(string ledSN, List<DataPoint> inputDatas)
        {
            if (!_strategyTable.Keys.Contains(ledSN))
                return;

            Strategy strategy = _strategyTable[ledSN].FirstOrDefault(s => s.Type == StrategyType.SmokeStrategy);

            if (strategy == null)
                return;

            if (inputDatas == null || inputDatas.Count == 0)
                return;

            foreach (var ruleItem in strategy.RuleTable)
            {
                bool conditionResult = true;
                foreach (var conditionItem in ruleItem.RuleCondition.ConditionCollection)
                {
                    Expression<Func<List<bool>, int, bool>> expression;
                    expression = (a, b) => a.Count(t => t == false) > b;
                    conditionResult &= expression.Compile()(inputDatas.Select(t => bool.Parse(t.Value.ToString())).ToList(), conditionItem.RightExpression);
                    //switch (conditionItem.Algorithm)
                    //{
                    //    case ConditionAlgorithm.MaxValueAlgorithm:
                    //        Expression<Func<List<int>, int, bool>> maxExpression;
                    //        if (conditionItem.Operator == OperatorType.GreaterThan)
                    //        {
                    //            maxExpression = (a, b) => a.Max() > b;
                    //        }
                    //        else
                    //        {
                    //            maxExpression = (a, b) => a.Max() < b;
                    //        }

                    //        conditionResult &= maxExpression.Compile()(inputDatas.Select(t => int.Parse(t.Value as string)).ToList(), conditionItem.RightExpression);
                    //        break;
                    //    case ConditionAlgorithm.AverageAlgorithm:
                    //        Expression<Func<List<int>, int, bool>> averageExpression;
                    //        if (conditionItem.Operator == OperatorType.GreaterThan)
                    //        {
                    //            averageExpression = (a, b) => (a.Max() / a.Count) > b;
                    //        }
                    //        else
                    //        {
                    //            averageExpression = (a, b) => (a.Max() / a.Count) < b;
                    //        }

                    //        conditionResult &= averageExpression.Compile()(inputDatas.Select(t => int.Parse(t.Value as string)).ToList(), conditionItem.RightExpression);
                    //        break;
                    //    default:
                    //        break;
                    //}
                }
                if (conditionResult)
                {
                    foreach (var actionItem in ruleItem.RuleAction.ActionCommandCollection)
                    {
                        if (actionItem.ActionTarget.TargetType == ActionTargetType.Parameter)
                        {
                            Command command = new Command()
                            {
                                Code = CommandCode.SetBrightness,
                                Target = TargetType.ToDataSource,
                                CommandText = string.Empty
                            };
                            DataEngine.AddCommand(command);
                            System.Threading.Thread.Sleep(50);
                        }
                        else if (actionItem.ActionTarget.TargetType == ActionTargetType.Device)
                        {
                            if (actionItem.ActionType == ActionType.Open)
                            {
                                Command command = new Command()
                                {
                                    Code = CommandCode.OpenDevice,
                                    Target = TargetType.ToDataSource,
                                    CommandText = string.Empty
                                };
                                DataEngine.AddCommand(command);
                                System.Threading.Thread.Sleep(50);
                            }
                            else if (actionItem.ActionType == ActionType.Close)
                            {
                                Command command = new Command()
                                {
                                    Code = CommandCode.CloseDevice,
                                    Target = TargetType.ToDataSource,
                                    CommandText = string.Empty
                                };
                                DataEngine.AddCommand(command);
                                System.Threading.Thread.Sleep(50);
                            }
                        }
                    }
                }
            }
        }
Пример #10
0
 public static void UpdateStrategy(Command updateStrategyCommand)
 {
     UpdateStrategy(updateStrategyCommand.CommandText);
     _fLogService.Info(string.Format("@CommandLog@Command Execute finished####Code={0},id={1},source={2},Target={3},updateStrategyCommandText={4},Description={5}", updateStrategyCommand.Code.ToString(), updateStrategyCommand.Id, updateStrategyCommand.Source, updateStrategyCommand.Target.ToString(), updateStrategyCommand.CommandText, updateStrategyCommand.Description));
 }
Пример #11
0
        internal static void ExecuteCommand(Command command)
        {
            try
            {
                if (command.Target == TargetType.ToRuleEngine && command.Code == CommandCode.UpdateStrategy)
                {
                    RuleEngine.UpdateStrategy(command);
                }

                foreach (var ds in _dataSources)
                {
                    if (command.Target == TargetType.ToDataSource || command.Target == TargetType.ToAll)//&& command.Target == ds.Name
                        ds.ExecuteCommand(command);
                }

                foreach (DataService service in innerServiceCollection.Where(i => !i.IsInterrupted))
                {
                    try
                    {
                        if (command.Target == TargetType.ToClient || command.Target == TargetType.ToAll)//&& command.Target == service.Name
                            service.Client.ReceiveCommand(command);
                    }
                    catch (Exception ex)
                    {
                        service.IsInterrupted = true;
                        service.Exception = ex;
                    }
                }
            }
            catch (Exception ex)
            {
                _logService.Error(string.Format("ExistCatch:Error:<-{0}->:{1} \r\n Error detail:{2}", "ExecuteCommand", ex.Message, ex.ToString()));
            }
        }
Пример #12
0
 internal static void AddCommand(Command command)
 {
     _logService.Info(string.Format("@CommandLog@SendCommand####Code={0},id={1},source={2},Target={3},CommandText={4},Description={5}", command.Code.ToString(), command.Id, command.Source, command.Target.ToString(), command.CommandText, command.Description));
     if (_cmdManager == null) return;
     _cmdManager.AddCommand(command);
 }
Пример #13
0
 private void CommandReceivedBeginInvoke(Command commad)
 {
     try
     {
         switch (commad.Code)
         {
             case CommandCode.GetBrightnessConfig:
                 _fLogService.Info("收到亮度读取命令:" + commad.Code);
                 DataDispatcher.ClientDispatcher.Instance.SetBrightnessConfigToLCT(CommandTextParser.GetJsonSerialization<List<SmartLightConfigInfo>>(_brightnessConfigList));
                 break;
             #region 收到的界面命令
             case CommandCode.ViewMonitoringUI:
                 _fLogService.Info("开始收到打开主界面的命令..." + commad.Code);
                 if (OpenUIHandlerEvent != null)
                 {
                     string[] str = commad.CommandText.Split('|');
                     if (str.Length < 2)
                     {
                         OpenUIHandlerEvent(str[0], string.Empty);
                     }
                     else
                     {
                         string[] para = str[1].Split('~');
                         string sn = null;
                         if (_ledInfoList == null)
                         {
                             WriteLogToFile("Catch:在亮度打开时,监控的屏为空怎么可能?? Why???", true);
                             break;
                         }
                         var ledBInfo = _ledInfoList.Find(a => a.Commport == para[0] && a.LedIndexOfCom == Convert.ToInt32(para[1]));
                         if (ledBInfo == null)
                         {
                             break;
                         }
                         sn = ledBInfo.Sn;
                         if (str[0] == "OpenSmartBrightness")
                         {
                             if (para[2] == "3")
                             {
                                 if (para[3] == "0")
                                 {
                                     var cfg = _brightnessConfigList.Find(a => a.ScreenSN == sn);
                                     if (cfg != null)
                                     {
                                         cfg.AdjustType = BrightAdjustType.Smart;
                                         SaveBrightnessConfig(cfg);
                                     }
                                 }
                                 else
                                 {
                                     OpenUIHandlerEvent(str[0], para[0] + "~" + para[1] + "~" + sn);
                                 }
                             }
                             else if (para[2] == "0")
                             {
                                 //手动
                                 var cfg = _brightnessConfigList.Find(a => a.ScreenSN == sn);
                                 if (cfg != null)
                                 {
                                     if (cfg.DispaySoftWareConfig != null && cfg.DispaySoftWareConfig.OneDayConfigList != null)
                                     {
                                         foreach (var smartCfg in cfg.DispaySoftWareConfig.OneDayConfigList)
                                         {
                                             if (smartCfg != null) smartCfg.IsConfigEnable = false;
                                         }
                                     }
                                     if (cfg.DisplayHardcareConfig != null && cfg.DisplayHardcareConfig.OneDayConfigList != null)
                                     {
                                         foreach (var smartCfg in cfg.DisplayHardcareConfig.OneDayConfigList)
                                         {
                                             if (smartCfg != null) smartCfg.IsConfigEnable = false;
                                         }
                                     }
                                     cfg.AdjustType = BrightAdjustType.Mannual;
                                     SaveBrightnessConfig(cfg);
                                 }
                             }
                             else if (para[2] == "1" || para[2] == "2")
                             {
                                 if (para[3] != null)
                                 {
                                     var smartLightConfigInfo = CommandTextParser.GetDeJsonSerialization<SmartLightConfigInfo>(para[3]);
                                     var cfg = _brightnessConfigList.Find(a => a.ScreenSN == sn);
                                     if (cfg != null)
                                     {
                                         if (smartLightConfigInfo.DisplayHardcareConfig !=null && cfg.DisplayHardcareConfig != null)
                                         {
                                             smartLightConfigInfo.DisplayHardcareConfig.AutoAdjustPeriod = cfg.DisplayHardcareConfig.AutoAdjustPeriod;
                                             smartLightConfigInfo.DisplayHardcareConfig.AutoBrightReadLuxCnt = cfg.DisplayHardcareConfig.AutoBrightReadLuxCnt;
                                         }
                                         if (smartLightConfigInfo.DispaySoftWareConfig != null && cfg.DispaySoftWareConfig != null)
                                         {
                                             smartLightConfigInfo.DispaySoftWareConfig.AutoAdjustPeriod = cfg.DispaySoftWareConfig.AutoAdjustPeriod;
                                             smartLightConfigInfo.DispaySoftWareConfig.AutoBrightReadLuxCnt = cfg.DispaySoftWareConfig.AutoBrightReadLuxCnt;
                                         }
                                     }
                                     smartLightConfigInfo.ScreenSN = sn;
                                     SaveBrightnessConfig(smartLightConfigInfo);
                                 }
                             }
                         }
                     }
                 }
                 _fLogService.Info("完成收到打开主界面的命令...");
                 break;
             #endregion
             #region 收到的点检命令
             case CommandCode.SetSpotInspectionConfigInfo:
                 _fLogService.Info("收到配置点检参数命令..." + commad.Code);
                 if (_ledInfoList == null || _ledInfoList.Count == 0)
                 {
                     _fLogService.Error("显示屏信息为空...");
                     _fLogService.Info(string.Format("@CommandLog@Command Execute finished(error)####Code={0},id={1},source={2},Target={3},commadText={4},Description={5}\n{Errorinfo={6}", commad.Code.ToString(), commad.Id, commad.Source, commad.Target.ToString(), commad.CommandText, commad.Description, "LedInfo is null"));
                     return;
                 }
                 List<string> detectParamStrList = CommandTextParser.GetDeJsonSerialization<List<string>>(commad.CommandText);
                 string[] ledInfoStrList;
                 int indexOfCom;
                 DetectConfigParams detectParam;
                 LedBasicInfo ledInfo;
                 foreach (var item in detectParamStrList)
                 {
                     ledInfoStrList = item.Split('|');
                     if (ledInfoStrList.Length < 3) continue;
                     if (!Int32.TryParse(ledInfoStrList[1], out indexOfCom)) continue;
                     if (ledInfoStrList[2] == "") continue;
                     detectParam = CommandTextParser.GetDeJsonSerialization<DetectConfigParams>(ledInfoStrList[2]);
                     if (detectParam == null) continue;
                     ledInfo = _ledInfoList.Find(a => a.Commport == ledInfoStrList[0] && a.LedIndexOfCom == indexOfCom);
                     if (ledInfo == null) continue;
                     bool res = DataDispatcher.ClientDispatcher.Instance.UpdatePointDeteConfig(ledInfo.Sn, detectParam);
                     _fLogService.Info("显示屏:" + ledInfo.Sn + ",点检参数保存完成,结果:" + res.ToString());
                 }
                 break;
             #endregion
             case CommandCode.LCTGetMonitorData:
                 SendMonitorDataToLCT(_lctMainData);
                 break;
             case CommandCode.LCTGetScreenInfo:
                 ClientDispatcher.Instance.SendCommand(new Command()
                 {
                     Code = CommandCode.ScreenInfoToLCT,
                     CommandText = CommandTextParser.GetJsonSerialization<List<LedBasicInfo>>(_ledInfoList),
                     Target = TargetType.ToClient
                 });
                 break;
             default:
                 _fLogService.Debug("收到未处理的命令..." + commad.Code);
                 break;
         }
         _fLogService.Info(string.Format("@CommandLog@Command Execute finished(normal)####Code={0},id={1},source={2},Target={3},commadText={4},Description={5}", commad.Code.ToString(), commad.Id, commad.Source, commad.Target.ToString(), commad.CommandText, commad.Description));
     }
     catch (Exception ex)
     {
         _fLogService.Info(string.Format("@CommandLog@Command Execute finished(error)####Code={0},id={1},source={2},Target={3},commadText={4},Description={5}\n{Errorinfo={6}", commad.Code.ToString(), commad.Id, commad.Source, commad.Target.ToString(), commad.CommandText, commad.Description, ex.ToString()));
         WriteLogToFile("ExistCatch:收到命令处理时出错:" + ex.ToString(), true);
     }
 }
Пример #14
0
 void MainWindow_CommandReceived(Command commad)
 {
     //Action action = new Action(() =>
     //{
     CommandReceivedBeginInvoke(commad);
     //});
     //action.BeginInvoke(null, null);
 }
Пример #15
0
        private void ExecuteCommandBeginInvoke(Command cmd)
        {
            try
            {
                if (cmd.Code.Equals(CommandCode.SetLedAlarmConfigInfo))
                {
                    LedAlarmConfig ledAlarm = CommandTextParser.GetDeJsonSerialization<LedAlarmConfig>(cmd.CommandText);
                    if (ledAlarm != null && !string.IsNullOrEmpty(ledAlarm.SN))
                    {
                        if (_ledAlarmConfigDic.ContainsKey(ledAlarm.SN))
                            _ledAlarmConfigDic[ledAlarm.SN] = ledAlarm;
                        else
                            _ledAlarmConfigDic.Add(ledAlarm.SN, ledAlarm);
                    }
                }
                else if (cmd.Code == CommandCode.SetLedAcquisitionConfigInfo)
                {
                    LedAcquisitionConfig obj = CommandTextParser.GetDeJsonSerialization<LedAcquisitionConfig>(cmd.CommandText);
                    _dataReadTimer.Enabled = obj.IsAutoRefresh;
                    _timerIsEnable = obj.IsAutoRefresh;
                    _dataReadTimer.Interval = obj.DataPeriod;
                    if (_moniDatareader != null) _moniDatareader.ReadFailedRetryTimes = obj.RetryCount;
                    _retryCount = obj.RetryCount;
                    WriteLog("命令执行:周期变更了:" + obj.DataPeriod);
                    _fLogService.Info("命令执行:周期变更了:" + obj.DataPeriod);
                    _fLogService.Info(string.Format("@CommandLog@Command Execute finished(normal)####Code={0},id={1},source={2},Target={3},cmdText={4},Description={5}", cmd.Code.ToString(), cmd.Id, cmd.Source, cmd.Target.ToString(), cmd.CommandText, cmd.Description));
                    return;
                }
                else if (cmd.Code == CommandCode.SetSpotInspectionConfigInfo)
                {
                    Dictionary<string, DetectConfigParams> detectConfigParamList = CommandTextParser.GetDeJsonSerialization<Dictionary<string, DetectConfigParams>>(cmd.CommandText);
                    if (detectConfigParamList != null)
                    {
                        foreach (var item in detectConfigParamList)
                        {
                            if (!_detectConfigParamList.ContainsKey(item.Key))
                            {
                                _detectConfigParamList.Add(item.Key, item.Value);
                            }
                            else _detectConfigParamList[item.Key] = item.Value;
                        }
                    }
                }
                else if (cmd.Code == CommandCode.SetPeriodicInspectionConfigInfo)
                {
                    var cycleConfig = CommandTextParser.GetDeJsonSerialization<ParameterInspectionCycleConfig>(cmd.CommandText);
                    if (_spotInspectionConfigTable.Keys.Contains(cmd.Description))
                    {
                        _spotInspectionConfigTable[cmd.Description] = cycleConfig;
                    }
                    else
                    {
                        _spotInspectionConfigTable.Add(cmd.Description, cycleConfig);
                    }

                    #region 点检周期解析及执行 - Modify by Lixc
                    //long timerTicks = 0;
                    //if (cycleConfig.Cycle == PeriodType.Daily)
                    //{
                    //    var difference = (new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, cycleConfig.Hour, cycleConfig.Minute, 0) - DateTime.Now).Ticks;
                    //    if (difference >= 0)
                    //    {
                    //        timerTicks = difference;
                    //    }
                    //    else
                    //    {
                    //        timerTicks = (new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, cycleConfig.Hour, cycleConfig.Minute, 0).AddDays(1) - DateTime.Now).Ticks;
                    //    }
                    //}
                    //else if (cycleConfig.Cycle == PeriodType.Weekly)
                    //{
                    //    int differenceDay = cycleConfig.Sign - (int)DateTime.Now.DayOfWeek;
                    //    if (differenceDay > 0)
                    //    {
                    //        timerTicks = (new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, cycleConfig.Hour, cycleConfig.Minute, 0).AddDays(differenceDay) - DateTime.Now).Ticks;
                    //    }
                    //    else if (differenceDay == 0)
                    //    {
                    //        timerTicks = (new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, cycleConfig.Hour, cycleConfig.Minute, 0).AddDays(differenceDay) - DateTime.Now).Ticks;
                    //        if (timerTicks < 0)
                    //        {
                    //            timerTicks = (new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, cycleConfig.Hour, cycleConfig.Minute, 0).AddDays(7) - DateTime.Now).Ticks;
                    //        }
                    //    }
                    //    else
                    //    {
                    //        timerTicks = (new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, cycleConfig.Hour, cycleConfig.Minute, 0).AddDays(7+differenceDay) - DateTime.Now).Ticks;
                    //    }
                    //}
                    //else if (cycleConfig.Cycle == PeriodType.Monthly)
                    //{
                    //    int differenceDay = cycleConfig.Sign - (int)DateTime.Now.Day;
                    //    if (differenceDay > 0)
                    //    {
                    //        timerTicks = (new DateTime(DateTime.Now.Year, DateTime.Now.Month, cycleConfig.Sign, cycleConfig.Hour, cycleConfig.Minute, 0) - DateTime.Now).Ticks;
                    //    }
                    //    else if (differenceDay == 0)
                    //    {
                    //        timerTicks = (new DateTime(DateTime.Now.Year, DateTime.Now.Month, cycleConfig.Sign, cycleConfig.Hour, cycleConfig.Minute, 0) - DateTime.Now).Ticks;
                    //        if (timerTicks < 0)
                    //        {
                    //            timerTicks = (new DateTime(DateTime.Now.Year, DateTime.Now.Month, cycleConfig.Sign, cycleConfig.Hour, cycleConfig.Minute, 0).AddMonths(1) - DateTime.Now).Ticks;
                    //        }
                    //    }
                    //    else
                    //    {
                    //        timerTicks = (new DateTime(DateTime.Now.Year, DateTime.Now.Month, cycleConfig.Sign, cycleConfig.Hour, cycleConfig.Minute, 0).AddMonths(1) - DateTime.Now).Ticks;
                    //    }
                    //}
                    //var _spotInspectionTimer = new System.Threading.Timer(ProcessSpotInspection, cmd.Description, timerTicks / 10000, timerTicks / 10000);
                    #endregion

                    if (cycleConfig == null || cycleConfig.Cycle == PeriodType.Disable)
                    {
                        if (_spotInspectionScheduler != null)
                            _spotInspectionScheduler.DeleteJob(new JobKey(cmd.Description));
                        if (_spotInspectionJobTable.Keys.Contains(cmd.Description))
                            _spotInspectionJobTable.Remove(cmd.Description);
                    }
                    else
                    {
                        lock (_syncObj)
                        {
                            if (_spotInspectionScheduler == null)
                            {
                                ISchedulerFactory sf = new StdSchedulerFactory();
                                _spotInspectionScheduler = sf.GetScheduler();
                            }
                        }

                        ITrigger trigger = null;
                        if (cycleConfig.Cycle == PeriodType.Daily)
                        {
                            //trigger = TriggerBuilder.Create().StartAt(new DateTimeOffset(DateTime.Now, new TimeSpan(0,0,0,0,random.Next(1000)))).WithSchedule(CronScheduleBuilder.DailyAtHourAndMinute(cycleConfig.Hour, cycleConfig.Minute)).Build();
                            trigger = TriggerBuilder.Create().WithIdentity(cmd.Description).StartNow().WithSchedule(CronScheduleBuilder.DailyAtHourAndMinute(cycleConfig.Hour, cycleConfig.Minute)).Build();
                        }
                        else if (cycleConfig.Cycle == PeriodType.Weekly)
                        {
                            //trigger = TriggerBuilder.Create().StartAt(new DateTimeOffset(DateTime.Now, new TimeSpan(random.Next(1000)))).WithSchedule(CronScheduleBuilder.WeeklyOnDayAndHourAndMinute((DayOfWeek)cycleConfig.Sign, cycleConfig.Hour, cycleConfig.Minute)).Build();
                            trigger = TriggerBuilder.Create().WithIdentity(cmd.Description).StartNow().WithSchedule(CronScheduleBuilder.WeeklyOnDayAndHourAndMinute((DayOfWeek)cycleConfig.Sign, cycleConfig.Hour, cycleConfig.Minute)).Build();
                        }
                        else if (cycleConfig.Cycle == PeriodType.Monthly)
                        {
                            //trigger = TriggerBuilder.Create().StartAt(new DateTimeOffset(DateTime.Now, new TimeSpan(random.Next(1000)))).WithSchedule(CronScheduleBuilder.MonthlyOnDayAndHourAndMinute(cycleConfig.Sign, cycleConfig.Hour, cycleConfig.Minute)).Build();
                            trigger = TriggerBuilder.Create().WithIdentity(cmd.Description).StartNow().WithSchedule(CronScheduleBuilder.MonthlyOnDayAndHourAndMinute(cycleConfig.Sign, cycleConfig.Hour, cycleConfig.Minute)).Build();
                        }
                        IJobDetail job = JobBuilder.Create<SpotInspectionJob>().WithIdentity(cmd.Description).Build();

                        job.JobDataMap.Put("SpotInspectionJob_SN", cmd.Description);
                        job.JobDataMap.Put("Sender", this);

                        if (_spotInspectionJobTable.Keys.Contains(cmd.Description))
                        {
                            if (_spotInspectionScheduler.DeleteJob(new JobKey(cmd.Description)))
                            {
                                _spotInspectionJobTable[cmd.Description] = job;
                            }
                        }
                        else
                        {
                            _spotInspectionJobTable.Add(cmd.Description, job);
                        }
                        _spotInspectionScheduler.ScheduleJob(job, trigger);

                        _spotInspectionScheduler.Start();
                    }

                }

                //判断Command类型,如果是设置(亮度调节)命令,单独处理调用SetBrightness()
                if (_moniDatareader != null)
                {
                    switch (cmd.Code)
                    {
                        case CommandCode.SetBrightness:
                            WriteLog("命令执行:调节亮度...");
                            _fLogService.Info("命令执行:调节亮度...");
                            int brightness = 0;
                            string[] strBright = cmd.CommandText.Split('|');
                            if (strBright.Length < 2 || !Int32.TryParse(strBright[1], out brightness))
                            {
                                SendData(CmdResult.CMD_SetBrightness.ToString(), cmd.Source + "|" + Convert.ToInt32(false));
                                SendData("BrightnessLog", strBright[0] + "|" + "4" + "|" + "false" + "|" + "-1");
                                _fLogService.Info(string.Format("@CommandLog@Command Execute finished(error)####Code={0},id={1},source={2},Target={3},cmdText={4},Description={5}\n{Errorinfo={6}", cmd.Code.ToString(), cmd.Id, cmd.Source, cmd.Target.ToString(), cmd.CommandText, cmd.Description, "CommandText analyze error"));
                                return;
                            }
                            byte br = (byte)brightness;
                            byte brValue = (byte)(brightness * 255 / 100);
                            //System.Diagnostics.Trace.WriteLine("brightness:" + br);
                            //TODO:这里需要调节亮度的屏信息
                            if (!SetBrightness(strBright[0], cmd.Source, br))
                            {
                                SendData(CmdResult.CMD_SetBrightness.ToString(), cmd.Source + "|" + Convert.ToInt32(false));
                                SendData("BrightnessLog", strBright[0] + "|" + "4" + "|" + "false" + "|" + brValue);
                            }
                            else
                            {
                                SendData("BrightnessLog", strBright[0] + "|" + "4" + "|" + "true" + "|" + brValue);
                            }
                            break;
                        case CommandCode.OpenDevice:
                            WriteLog("命令执行:打开设备...");
                            _fLogService.Info("命令执行:打开设备...");
                            UpdateConfigMessage(TransferType.M3_OpenDevice, cmd.CommandText);
                            break;
                        case CommandCode.CloseDevice:
                            WriteLog("命令执行:关闭设备...");
                            _fLogService.Info("命令执行:关闭设备...");
                            UpdateConfigMessage(TransferType.M3_CloseDevice, cmd.CommandText);
                            break;
                        case CommandCode.RefreshLedScreenConfigInfo:
                            WriteLog("命令执行:需要获取屏信息!");
                            _fLogService.Info("命令执行:需要获取屏信息!");
                            if (cmd.CommandText == "Get")
                            {
                                GetScreenListInfo();
                            }
                            else
                            {
                                UpdateConfigMessage(TransferType.M3_UpdateLedScreenConfigInfo, cmd.CommandText);
                            }
                            break;
                        case CommandCode.SetLedMonitoringConfigInfo:
                            WriteLog("命令执行:硬件配置变更了!");
                            _fLogService.Info("命令执行:硬件配置变更了!");
                            MarsHWConfig marsconfig = MonitoringConfigToMarsHWConfig(cmd.CommandText);
                            UpdateConfigMessage(TransferType.UpdateLedMonitoringConfigInfo,
                                CommandTextParser.GetJsonSerialization<MarsHWConfig>(marsconfig));
                            break;
                        case CommandCode.RefreshOpticalProbeInfo:
                            WriteLog("命令执行:开始读取光探头信息!");
                            _fLogService.Info("命令执行:开始读取光探头信息!");
                            _moniDatareader.ExecuteCommandCallBack(
                                new TransferParams() { TranType = TransferType.M3_PeripheralsInfo },
                                TransFerParamsDataHandlerCallBack, null);
                            break;
                        case CommandCode.RefreshFunctionCardInfo:
                            WriteLog("命令执行:开始读取多功能卡信息!");
                            _fLogService.Info("命令执行:开始读取多功能卡信息!");
                            _moniDatareader.ExecuteCommandCallBack(
                                new TransferParams() { TranType = TransferType.M3_FunctionCardMonitor },
                                TransFerParamsDataHandlerCallBack, null);
                            break;
                        case CommandCode.RefreshMonitoringData:
                            _fLogService.Debug("命令执行:刷新监控数据!");
                            ReadMonitorData_First();
                            break;
                        case CommandCode.RefreshSmartBrightEasyConfigInfo:
                            //读取硬件亮度配置
                            ReadSmartLightHWconfigInfo(cmd.CommandText);
                            break;
                        case CommandCode.SetSmartBrightEasyConfigInfo:
                            //写入亮度的配置:软硬件
                            UpdateConfigMessage(TransferType.M3_WriteSmartLightHWConfig, cmd.CommandText);
                            break;
                        case CommandCode.StartSmartBrightness:
                        case CommandCode.StopSmartBrightness:
                            UpdateConfigMessage(TransferType.M3_EnableSmartBrightness, cmd.CommandText);
                            break;
                        case CommandCode.SetFromCOMToSN:
                            UpdateConfigMessage(TransferType.M3_COMFindSN, cmd.CommandText);
                            break;
                        case CommandCode.StopDataAcquisition:
                            _fLogService.Debug("Stop Monitor:" + cmd.CommandText);
                            var snList = new List<string>();
                            _screenInfos.ForEach(s => snList.Add(s.LedSN));
                            UpdateConfigMessage(TransferType.M3_MonitorStopNotify, cmd.CommandText + "|" + CommandTextParser.GetJsonSerialization<List<string>>(snList));
                            OnPause();
                            break;
                        case CommandCode.ResumeDataAcquisition:
                            _fLogService.Debug("Renume Monitor:" + cmd.CommandText);
                            var snLists = new List<string>();
                            _screenInfos.ForEach(s => snLists.Add(s.LedSN));
                            UpdateConfigMessage(TransferType.M3_MonitorRenumeNotify, cmd.CommandText + "|" + CommandTextParser.GetJsonSerialization<List<string>>(snLists));
                            OnResume();
                            break;
                    }
                    Thread.Sleep(10);
                }
                _fLogService.Info(string.Format("@CommandLog@Command Execute finished(normal)####Code={0},id={1},source={2},Target={3},cmdText={4},Description={5}", cmd.Code.ToString(), cmd.Id, cmd.Source, cmd.Target.ToString(), cmd.CommandText, cmd.Description));
            }
            catch (Exception ex)
            {
                _fLogService.Info(string.Format("@CommandLog@Command Execute finished(error)####Code={0},id={1},source={2},Target={3},cmdText={4},Description={5}\nErrorinfo={6}", cmd.Code.ToString(), cmd.Id, cmd.Source, cmd.Target.ToString(), cmd.CommandText, cmd.Description, ex.ToString()));
                _fLogService.Error("ExistCatch:ExecuteCommandBeginInvoke->Error:" + ex.ToString());
                MonitorException = ex;
            }
        }
Пример #16
0
 public void RefreshSmartLightConfigInfo()
 {
     Command command = new Command()
     {
         Code = CommandCode.RefreshSmartBrightEasyConfigInfo,
         Source = "MonitorUIClient",
         Target = TargetType.ToDataSource,
         CommandText = string.Empty
     };
     _dataClient.SendCommand(command);
 }
Пример #17
0
 public void SendCommand(Command command)
 {
     _dataClient.SendCommand(command);
 }
Пример #18
0
        private static void TemperatrueStrategyTask(string ledSN, List<DataPoint> inputDatas)
        {
            if (!_strategyTable.Keys.Contains(ledSN))
                return;

            Strategy strategy = _strategyTable[ledSN].FirstOrDefault(s => s.Type == StrategyType.TemperatureStrategy);

            if (strategy == null)
                return;

            if (inputDatas == null || inputDatas.Count == 0)
                return;
            List<Rule> ruleExcuteTable = new List<Rule>();
            foreach (var ruleItem in strategy.RuleTable)
            {
                bool conditionResult = true;
                foreach (var conditionItem in ruleItem.RuleCondition.ConditionCollection)
                {
                    switch (conditionItem.Algorithm)
                    {
                        case ConditionAlgorithm.MaxValueAlgorithm:
                            Expression<Func<List<double>, double, bool>> maxExpression;
                            if (conditionItem.Operator == OperatorType.GreaterThan)
                            {
                                maxExpression = (a, b) => a.Max() > b;
                            }
                            else
                            {
                                maxExpression = (a, b) => a.Max() < b;
                            }
                            var temp = inputDatas.Select(t => double.Parse(t.Value.ToString())).ToList();
                            conditionResult &= maxExpression.Compile()(temp, conditionItem.RightExpression);
                            break;
                        case ConditionAlgorithm.AverageAlgorithm:
                            Expression<Func<List<double>, double, bool>> averageExpression;
                            if (conditionItem.Operator == OperatorType.GreaterThan)
                            {
                                averageExpression = (a, b) => (a.Sum() / a.Count) > b;
                            }
                            else
                            {
                                averageExpression = (a, b) => (a.Sum() / a.Count) < b;
                            }

                            conditionResult &= averageExpression.Compile()(inputDatas.Select(t => double.Parse(t.Value.ToString())).ToList(), conditionItem.RightExpression);
                            break;
                        default:
                            break;
                    }
                }
                if (conditionResult)
                {
                    ruleExcuteTable.Add(ruleItem);
                }
                //if (conditionResult)
                //{
                //    foreach (var actionItem in ruleItem.RuleAction.ActionCommandCollection)
                //    {
                //        if (actionItem.ActionTarget.TargetType == ActionTargetType.Parameter)
                //        {
                //            Command command = new Command()
                //            {
                //                Code = CommandCode.SetBrightness,
                //                Target = TargetType.ToDataSource,
                //                CommandText = strategy.SN + "|" + actionItem.ActionTarget.ParameterTarget.Value.ToString()
                //            };
                //            System.Diagnostics.Debug.WriteLine(string.Format("-------------策略命令{0}发送!-------------",CommandCode.SetBrightness));
                //            DataEngine.ExecuteCommand(command);
                //            System.Threading.Thread.Sleep(100);
                //        }
                //        else if (actionItem.ActionTarget.TargetType == ActionTargetType.Device)
                //        {
                //            if (actionItem.ActionType == ActionType.Open)
                //            {
                //                foreach (var deviceInfo in actionItem.ActionTarget.DeviceTarget)
                //                {
                //                    Command command = new Command()
                //                    {
                //                        Code = CommandCode.OpenDevice,
                //                        Target = TargetType.ToDataSource,
                //                        CommandText = deviceInfo
                //                    };
                //                    System.Diagnostics.Debug.WriteLine(string.Format("-------------策略命令{0}发送!-------------", CommandCode.OpenDevice));

                //                    DataEngine.ExecuteCommand(command);
                //                    System.Threading.Thread.Sleep(100);
                //                }

                //            }
                //            else if (actionItem.ActionType == ActionType.Close)
                //            {
                //                foreach (var deviceInfo in actionItem.ActionTarget.DeviceTarget)
                //                {
                //                    Command command = new Command()
                //                    {
                //                        Code = CommandCode.CloseDevice,
                //                        Target = TargetType.ToDataSource,
                //                        CommandText = deviceInfo
                //                    };
                //                    System.Diagnostics.Debug.WriteLine(string.Format("-------------策略命令{0}发送!-------------", CommandCode.CloseDevice));

                //                    DataEngine.ExecuteCommand(command);
                //                    System.Threading.Thread.Sleep(100);
                //                }
                //            }
                //        }
                //        else if (actionItem.ActionTarget.TargetType == ActionTargetType.SmartFunction)
                //        {
                //            if (actionItem.ActionType == ActionType.Enable)
                //            {
                //                Command command = new Command()
                //                {
                //                    Code = CommandCode.StartSmartBrightness,
                //                    Target = TargetType.ToDataSource,
                //                    CommandText = strategy.SN + "|" + ActionType.Enable.ToString()
                //                };
                //                System.Diagnostics.Debug.WriteLine(string.Format("-------------策略命令{0}发送!-------------", CommandCode.StartSmartBrightness));

                //                DataEngine.ExecuteCommand(command);
                //                System.Threading.Thread.Sleep(100);
                //            }
                //            else if (actionItem.ActionType == ActionType.Disable)
                //            {
                //                Command command = new Command()
                //                {
                //                    Code = CommandCode.StopSmartBrightness,
                //                    Target = TargetType.ToDataSource,
                //                    CommandText = strategy.SN + "|" + ActionType.Disable.ToString()
                //                };
                //                System.Diagnostics.Debug.WriteLine(string.Format("-------------策略命令{0}发送!-------------", CommandCode.StopSmartBrightness));

                //                DataEngine.ExecuteCommand(command);
                //                System.Threading.Thread.Sleep(100);
                //            }
                //        }
                //    }
                //}
            }
            if (ruleExcuteTable.Count > 1 && IsExistSmartFunctionRule(ruleExcuteTable))
            {
                ruleExcuteTable.Remove(ruleExcuteTable.Find(rule => rule.RuleAction.ActionCommandCollection.Any(action => action.ActionTarget.TargetType == ActionTargetType.SmartFunction)));
            }

            foreach (var ruleItem in ruleExcuteTable)
            {
                foreach (var actionItem in ruleItem.RuleAction.ActionCommandCollection)
                {
                    if (actionItem.ActionTarget.TargetType == ActionTargetType.Parameter)
                    {
                        Command command = new Command()
                        {
                            Code = CommandCode.SetBrightness,
                            Target = TargetType.ToDataSource,
                            CommandText = strategy.SN + "|" + actionItem.ActionTarget.ParameterTarget.Value.ToString()
                        };
                        System.Diagnostics.Debug.WriteLine(string.Format("-------------策略命令{0}发送!-------------", CommandCode.SetBrightness));
                        DataEngine.AddCommand(command);
                        System.Threading.Thread.Sleep(100);
                    }
                    else if (actionItem.ActionTarget.TargetType == ActionTargetType.Device)
                    {
                        if (actionItem.ActionType == ActionType.Open)
                        {
                            foreach (var deviceInfo in actionItem.ActionTarget.DeviceTarget)
                            {
                                Command command = new Command()
                                {
                                    Code = CommandCode.OpenDevice,
                                    Target = TargetType.ToDataSource,
                                    CommandText = deviceInfo
                                };
                                System.Diagnostics.Debug.WriteLine(string.Format("-------------策略命令{0}发送!-------------", CommandCode.OpenDevice));

                                DataEngine.AddCommand(command);
                                System.Threading.Thread.Sleep(100);
                            }

                        }
                        else if (actionItem.ActionType == ActionType.Close)
                        {
                            foreach (var deviceInfo in actionItem.ActionTarget.DeviceTarget)
                            {
                                Command command = new Command()
                                {
                                    Code = CommandCode.CloseDevice,
                                    Target = TargetType.ToDataSource,
                                    CommandText = deviceInfo
                                };
                                System.Diagnostics.Debug.WriteLine(string.Format("-------------策略命令{0}发送!-------------", CommandCode.CloseDevice));

                                DataEngine.AddCommand(command);
                                System.Threading.Thread.Sleep(100);
                            }
                        }
                    }
                    else if (actionItem.ActionTarget.TargetType == ActionTargetType.SmartFunction)
                    {
                        if (actionItem.ActionType == ActionType.Enable)
                        {
                            Command command = new Command()
                            {
                                Code = CommandCode.StartSmartBrightness,
                                Target = TargetType.ToDataSource,
                                CommandText = strategy.SN + "|" + ActionType.Enable.ToString()
                            };
                            System.Diagnostics.Debug.WriteLine(string.Format("-------------策略命令{0}发送!-------------", CommandCode.StartSmartBrightness));

                            DataEngine.AddCommand(command);
                            System.Threading.Thread.Sleep(100);
                        }
                        else if (actionItem.ActionType == ActionType.Disable)
                        {
                            Command command = new Command()
                            {
                                Code = CommandCode.StopSmartBrightness,
                                Target = TargetType.ToDataSource,
                                CommandText = strategy.SN + "|" + ActionType.Disable.ToString()
                            };
                            System.Diagnostics.Debug.WriteLine(string.Format("-------------策略命令{0}发送!-------------", CommandCode.StopSmartBrightness));

                            DataEngine.AddCommand(command);
                            System.Threading.Thread.Sleep(100);
                        }
                    }
                }
            }
        }
Пример #19
0
 public void SetLedAlarmConfig(string alarmConfig)
 {
     Command command = new Command()
     {
         Code = CommandCode.SetLedAlarmConfigInfo,
         Source = "MonitorUIClient",
         Target = TargetType.ToAll,
         CommandText = alarmConfig
     };
     _dataClient.SendCommand(command);
 }
Пример #20
0
        private void ProcessCommand()
        {
            if (_commandQueue.Count > 1)
            {

            }
            while (_commandQueue.Count > 0)
            {
                _currentCommand = _commandQueue.Dequeue();
                _logService.Debug(string.Format("<-{0}->:{1}", "ProcessCommand", _currentCommand.Code + "|" + _currentCommand.CommandText));
                _dataClient.SendCommand(_currentCommand);
            }
        }
Пример #21
0
 /// <summary>
 /// 设置点检周期
 /// </summary>
 /// <param name="configStr"></param>
 public void SetPeriodicInspectionConfig(string sn, string configStr)
 {
     Command command = new Command()
     {
         Code = CommandCode.SetPeriodicInspectionConfigInfo,
         Source = "MonitorUIClient",
         Target = TargetType.ToDataSource,
         CommandText = configStr,
         Description = sn
     };
     _dataClient.SendCommand(command);
 }
Пример #22
0
 private void ProcessReceivedCommand(Command command)
 {
     try
     {
         if (command.Code == CommandCode.UpdateSystem)
         {
             var systemVersionInfo = JsonConvert.DeserializeObject<List<VersionUpdateInfo>>(command.CommandText);
             if (systemVersionInfo == null || systemVersionInfo.Count == 0)
                 return;
             if (SystemVersionUpdate != null)
             {
                 SystemVersionUpdate(systemVersionInfo);
             }
         }
         NotifyCommandReceived(command);
     }
     catch (Exception ex)
     {
         _logService.Error(string.Format("ExistCatch:<-{0}->:{1}", "DataClient_CommandReceived", ex.ToString()));
         Debug.WriteLine(string.Format("当前Command信息:{0}-{1} \r\n异常信息:{2}", command.Code, command.CommandText, ex.Message));
     }
 }
Пример #23
0
 public void SetSmartLightConfigInfo(string smartBrightEasyConfigStr)
 {
     Command command = new Command()
     {
         Code = CommandCode.SetSmartBrightEasyConfigInfo,
         Source = "MonitorUIClient",
         Target = TargetType.ToDataSource,
         CommandText = smartBrightEasyConfigStr
     };
     _dataClient.SendCommand(command);
 }
Пример #24
0
 public void FromCOMtoSN(string param)
 {
     Command command = new Command()
     {
         Code = CommandCode.SetFromCOMToSN,
         Source = "MonitorUIClient",
         Target = TargetType.ToDataSource,
         CommandText = param
     };
     _dataClient.SendCommand(command);
 }
Пример #25
0
        /// <summary>
        /// 更新Led采集配置
        /// </summary>
        /// <param name="sn">Led标识号</param>
        /// <param name="acquisitionConfig">采集配置对象</param>
        /// <returns></returns>
        public bool UpdateLedAcquisitionConfig(string sn, LedAcquisitionConfig acquisitionConfig)
        {
            string serializeStr = JsonConvert.SerializeObject(acquisitionConfig);
            Command command = new Command()
            {
                Code = CommandCode.SetLedAcquisitionConfigInfo,
                Source = "MonitorUIClient",
                Target = TargetType.ToDataSource,
                CommandText = serializeStr
            };

            _dataClient.SendCommand(command);

            return MonitorDataAccessor.Instance().UpdateSoftWareCfg(serializeStr, SystemHelper.GetUtcTicksByDateTime(DateTime.Now));
        }
Пример #26
0
 public void NotifyCommandReceived(Command command)
 {
     if (CommandReceived != null)
     {
         //Action<Command> action = new Action<Command>((c) =>
         //{
         CommandReceived(command);
         //});
         //action.BeginInvoke(command, null, null);
     }
 }
Пример #27
0
 public void SendCommand(Command command)
 {
     DataEngine.AddCommand(command);
 }
Пример #28
0
 public void RefreshLedBasicInfo()
 {
     Command command = new Command()
     {
         Code = CommandCode.RefreshLedScreenConfigInfo,
         Source = "MonitorUIClient",
         Target = TargetType.ToDataSource,
         CommandText = "Get"
     };
     _dataClient.SendCommand(command);
 }
Пример #29
0
 protected virtual void OnExecuteCommand(Command cmd)
 {
 }
Пример #30
0
 public void RefreshOpticalProbeInfo()
 {
     Command command = new Command()
     {
         Code = CommandCode.RefreshOpticalProbeInfo,
         Source = "MonitorUIClient",
         Target = TargetType.ToDataSource,
         CommandText = string.Empty
     };
     _dataClient.SendCommand(command);
 }