private ControlConfigSaveRes IsSmokeOk(UC_WHControlConfig_Smoke_VM smoke_VM)
        {
            if (smoke_VM == null)
            {
                return(ControlConfigSaveRes.smoke_objIsNull);
            }
            bool isAllInvalid = true;

            foreach (var item in smoke_VM.PowerCtrlDic)
            {
                if (item.Value == PowerCtrl_Type.still)
                {
                    continue;
                }
                else
                {
                    isAllInvalid = false;
                }
                for (int i = 0; i < _smokeStrategyList.Count; i++)
                {
                    if (IsSmokeConflict(item.Key, _smokeStrategyList[i].PowerCtrlDic))
                    {
                        return(ControlConfigSaveRes.smoke_CtrlCfgIsExist);
                    }
                }
            }
            if (isAllInvalid)
            {
                return(ControlConfigSaveRes.smoke_CtrlCfgIsInvalid);
            }
            return(ControlConfigSaveRes.ok);
        }
 public UC_WHControlConfig_Smoke(UC_WHControlConfig_Smoke_VM stratInfo)
 {
     InitializeComponent();
     UpdateLang(CommonUI.ControlConfigLangPath);
     _smokeVM = stratInfo;
     numericUpDown_smokeCount.Value = SmokeVM.GreaterThan;
     InitialSmokeVM();
     panel_PowerList.Controls.Add(_uc_smokeCtrlCfg);
     _uc_smokeCtrlCfg.Dock = DockStyle.Fill;
 }
        public UC_WHControlConfig_VM_Base CreateStrategy(StrategyType type)
        {
            UC_WHControlConfig_VM_Base strategy = null;

            if (type == StrategyType.SmokeStrategy)
            {
                strategy = new UC_WHControlConfig_Smoke_VM(_selectedScreenSN);
            }
            else if (type == StrategyType.TemperatureStrategy)
            {
                strategy = new UC_WHControlConfig_Tem_VM(_selectedScreenSN);
            }
            else if (type == StrategyType.LightStrategy)
            {
                //处理亮度控制初始化
                return(null);
            }
            return(strategy);
        }
 private ControlConfigSaveRes IsSmokeOk(UC_WHControlConfig_Smoke_VM smoke_VM)
 {
     if (smoke_VM == null) return ControlConfigSaveRes.smoke_objIsNull;
     bool isAllInvalid = true;
     foreach (var item in smoke_VM.PowerCtrlDic)
     {
         if (item.Value == PowerCtrl_Type.still) continue;
         else isAllInvalid = false;
         for (int i = 0; i < _smokeStrategyList.Count; i++)
         {
             if (IsSmokeConflict(item.Key, _smokeStrategyList[i].PowerCtrlDic)) return ControlConfigSaveRes.smoke_CtrlCfgIsExist;
         }
     }
     if (isAllInvalid) return ControlConfigSaveRes.smoke_CtrlCfgIsInvalid;
     return ControlConfigSaveRes.ok;
 }
        public void Initialize(string sn)
        {
            try
            {
                _selectedScreenSN = sn;
                //_mode = MonitorDataManager.Mode.add;
                if (MonitorAllConfig.Instance().LedInfoList.FindAll(a => a.Sn == _selectedScreenSN).Count == 0)
                {
                    _isEnableCtrl = false;
                    return;
                }
                else _isEnableCtrl = true;
                _temStrategyList.Clear();
                _smokeStrategyList.Clear();
                _vm_BaseList.Clear();
                if (MonitorAllConfig.Instance().StrategyConfigDic.Keys.Contains(_selectedScreenSN))
                {
                    //已配置过策略
                    UC_WHControlConfig_Smoke_VM smoke_VM;
                    UC_WHControlConfig_Tem_VM tem_VM;
                    List<Strategy> straList = MonitorAllConfig.Instance().StrategyConfigDic[_selectedScreenSN];
                    Dictionary<string, PowerCtrl_Type> powerCtrlDic;
                    foreach (var item in straList)
                    {
                        if (item.Type == StrategyType.LightStrategy) continue;
                        foreach (var rule in item.RuleTable)
                        {
                            //if (!_strategyDic.Keys.Contains(item.Type))
                            //    _strategyDic.Add(item.Type, new List<Strategy_Tem_Smoke_VM>());
                            if (rule.RuleAction.ActionCommandCollection.FindIndex(a => a.ActionTarget.TargetType == ActionTargetType.SmartFunction) >= 0) continue;
                            List<ActionCommand> aCmdList = rule.RuleAction.ActionCommandCollection.FindAll(a => (a.ActionType != ActionType.Set && a.ActionTarget.TargetType != ActionTargetType.SmartFunction));
                            powerCtrlDic = new Dictionary<string, PowerCtrl_Type>();

                            if (aCmdList.Count != 0)
                            {
                                PowerCtrl_Type pType = PowerCtrl_Type.still;
                                foreach (var cmd in aCmdList)
                                {
                                    if (cmd.ActionType == ActionType.Open)
                                        pType = PowerCtrl_Type.open;
                                    else if (cmd.ActionType == ActionType.Close)
                                        pType = PowerCtrl_Type.close;
                                    if (cmd.ActionTarget.DeviceTarget != null)
                                    {
                                        foreach (var target in cmd.ActionTarget.DeviceTarget)
                                        {
                                            if (!powerCtrlDic.ContainsKey(target))
                                            {
                                                powerCtrlDic.Add(target, pType);
                                            }
                                        }
                                    }
                                }
                            }
                            var action = rule.RuleAction.ActionCommandCollection.Find(a => a.ActionType == ActionType.Set && item.Type == StrategyType.TemperatureStrategy);
                            bool isBrightness = false;
                            int brightnessValue = 0;
                            if (action != null)
                            {
                                isBrightness = true;
                                int.TryParse(action.ActionTarget.ParameterTarget.Value.ToString(), out brightnessValue);
                            }
                            if (item.Type == StrategyType.SmokeStrategy)
                            {
                                smoke_VM = new UC_WHControlConfig_Smoke_VM(item.SN, Guid.NewGuid(), rule.RuleCondition.ConditionCollection.Find(a => a.Operator == OperatorType.GreaterThan).RightExpression, powerCtrlDic);
                                _smokeStrategyList.Add(smoke_VM);
                                _vm_BaseList.Add(smoke_VM);
                            }
                            else if (item.Type == StrategyType.TemperatureStrategy)
                            {
                                var lessRule = rule.RuleCondition.ConditionCollection.Find(a => a.Operator == OperatorType.LessThan);
                                var greaterRule = rule.RuleCondition.ConditionCollection.Find(a => a.Operator == OperatorType.GreaterThan);
                                int lessRightEx = 0, greaterRightEx = 0;
                                if (lessRule != null) lessRightEx = lessRule.RightExpression;
                                if (greaterRule != null) greaterRightEx = greaterRule.RightExpression;
                                tem_VM = new UC_WHControlConfig_Tem_VM(item.SN, Guid.NewGuid(), rule.RuleCondition.ConditionCollection[0].Algorithm, lessRightEx, greaterRightEx, isBrightness, brightnessValue, powerCtrlDic);
                                _temStrategyList.Add(tem_VM);
                                _vm_BaseList.Add(tem_VM);
                            }
                        }
                    }
                    //if (_temStrategyList.Count != 0 || _smokeStrategyList.Count != 0) _mode = MonitorDataManager.Mode.modify;
                }
            }
            catch (Exception ex)
            {
                MonitorAllConfig.Instance().WriteLogToFile("ExistCatch:策略主页面初始化异常:" + ex.ToString(), true);
            }
        }
 public UC_WHControlConfig_VM_Base CreateStrategy(StrategyType type)
 {
     UC_WHControlConfig_VM_Base strategy = null;
     if (type == StrategyType.SmokeStrategy)
     {
         strategy = new UC_WHControlConfig_Smoke_VM(_selectedScreenSN);
     }
     else if (type == StrategyType.TemperatureStrategy)
     {
         strategy = new UC_WHControlConfig_Tem_VM(_selectedScreenSN);
     }
     else if (type == StrategyType.LightStrategy)
     {
         //处理亮度控制初始化
         return null;
     }
     return strategy;
 }
        public void Initialize(string sn)
        {
            try
            {
                _selectedScreenSN = sn;
                //_mode = MonitorDataManager.Mode.add;
                if (MonitorAllConfig.Instance().LedInfoList.FindAll(a => a.Sn == _selectedScreenSN).Count == 0)
                {
                    _isEnableCtrl = false;
                    return;
                }
                else
                {
                    _isEnableCtrl = true;
                }
                _temStrategyList.Clear();
                _smokeStrategyList.Clear();
                _vm_BaseList.Clear();
                if (MonitorAllConfig.Instance().StrategyConfigDic.Keys.Contains(_selectedScreenSN))
                {
                    //已配置过策略
                    UC_WHControlConfig_Smoke_VM         smoke_VM;
                    UC_WHControlConfig_Tem_VM           tem_VM;
                    List <Strategy>                     straList = MonitorAllConfig.Instance().StrategyConfigDic[_selectedScreenSN];
                    Dictionary <string, PowerCtrl_Type> powerCtrlDic;
                    foreach (var item in straList)
                    {
                        if (item.Type == StrategyType.LightStrategy)
                        {
                            continue;
                        }
                        foreach (var rule in item.RuleTable)
                        {
                            //if (!_strategyDic.Keys.Contains(item.Type))
                            //    _strategyDic.Add(item.Type, new List<Strategy_Tem_Smoke_VM>());
                            if (rule.RuleAction.ActionCommandCollection.FindIndex(a => a.ActionTarget.TargetType == ActionTargetType.SmartFunction) >= 0)
                            {
                                continue;
                            }
                            List <ActionCommand> aCmdList = rule.RuleAction.ActionCommandCollection.FindAll(a => (a.ActionType != ActionType.Set && a.ActionTarget.TargetType != ActionTargetType.SmartFunction));
                            powerCtrlDic = new Dictionary <string, PowerCtrl_Type>();

                            if (aCmdList.Count != 0)
                            {
                                PowerCtrl_Type pType = PowerCtrl_Type.still;
                                foreach (var cmd in aCmdList)
                                {
                                    if (cmd.ActionType == ActionType.Open)
                                    {
                                        pType = PowerCtrl_Type.open;
                                    }
                                    else if (cmd.ActionType == ActionType.Close)
                                    {
                                        pType = PowerCtrl_Type.close;
                                    }
                                    if (cmd.ActionTarget.DeviceTarget != null)
                                    {
                                        foreach (var target in cmd.ActionTarget.DeviceTarget)
                                        {
                                            if (!powerCtrlDic.ContainsKey(target))
                                            {
                                                powerCtrlDic.Add(target, pType);
                                            }
                                        }
                                    }
                                }
                            }
                            var  action          = rule.RuleAction.ActionCommandCollection.Find(a => a.ActionType == ActionType.Set && item.Type == StrategyType.TemperatureStrategy);
                            bool isBrightness    = false;
                            int  brightnessValue = 0;
                            if (action != null)
                            {
                                isBrightness = true;
                                int.TryParse(action.ActionTarget.ParameterTarget.Value.ToString(), out brightnessValue);
                            }
                            if (item.Type == StrategyType.SmokeStrategy)
                            {
                                smoke_VM = new UC_WHControlConfig_Smoke_VM(item.SN, Guid.NewGuid(), rule.RuleCondition.ConditionCollection.Find(a => a.Operator == OperatorType.GreaterThan).RightExpression, powerCtrlDic);
                                _smokeStrategyList.Add(smoke_VM);
                                _vm_BaseList.Add(smoke_VM);
                            }
                            else if (item.Type == StrategyType.TemperatureStrategy)
                            {
                                var lessRule = rule.RuleCondition.ConditionCollection.Find(a => a.Operator == OperatorType.LessThan);
                                var greaterRule = rule.RuleCondition.ConditionCollection.Find(a => a.Operator == OperatorType.GreaterThan);
                                int lessRightEx = 0, greaterRightEx = 0;
                                if (lessRule != null)
                                {
                                    lessRightEx = lessRule.RightExpression;
                                }
                                if (greaterRule != null)
                                {
                                    greaterRightEx = greaterRule.RightExpression;
                                }
                                tem_VM = new UC_WHControlConfig_Tem_VM(item.SN, Guid.NewGuid(), rule.RuleCondition.ConditionCollection[0].Algorithm, lessRightEx, greaterRightEx, isBrightness, brightnessValue, powerCtrlDic);
                                _temStrategyList.Add(tem_VM);
                                _vm_BaseList.Add(tem_VM);
                            }
                        }
                    }
                    //if (_temStrategyList.Count != 0 || _smokeStrategyList.Count != 0) _mode = MonitorDataManager.Mode.modify;
                }
            }
            catch (Exception ex)
            {
                MonitorAllConfig.Instance().WriteLogToFile("ExistCatch:策略主页面初始化异常:" + ex.ToString(), true);
            }
        }