示例#1
0
 protected override void CommandExecute(object cmd)
 {
     if (cmd is Command)
     {
         DataEngine.ExecuteCommand((Command)cmd);
     }
 }
示例#2
0
        public DataService()
        {
            _client = OperationContext.Current.GetCallbackChannel <IDataClient>();

            MessageProperties properties = OperationContext.Current.IncomingMessageProperties;

            //获取消息发送的远程终结点IP和端口
            //RemoteEndpointMessageProperty endpoint = properties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;
            //ip = string.Format("{0}:{1}", endpoint.Address, endpoint.Port);

            OperationContext.Current.Channel.Closed += new EventHandler(Channel_Closed);
            // OperationContext.Current.Channel.Faulted += Channel_Faulted;
            DataEngine.AddService(this);
        }
示例#3
0
 public void SendData(string key, object data)
 {
     DataEngine.SendData(key, data);
 }
示例#4
0
 public void SendCompositeData(DataPoint dp)
 {
     //if (dp.TimeStamp == 0)
     //    dp.TimeStamp = DateTime.Now.Ticks;
     DataEngine.SendData(dp);
 }
示例#5
0
 public DataPoint GetData(string identity)
 {
     return(DataEngine.GetData(identity));
 }
示例#6
0
 public void SendCommand(Command command)
 {
     DataEngine.AddCommand(command);
 }
示例#7
0
 public DataPoint[] GetAllData()
 {
     return(DataEngine.GetAllData());
 }
示例#8
0
 public void SendData(string identity, object data)
 {
     DataEngine.SendData(identity, data);
 }
示例#9
0
 public List <DataPoint> GetDataList(string[] identity)
 {
     return(DataEngine.GetDataList(identity));
 }
示例#10
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);
                            }
                        }
                    }
                }
            }
        }
示例#11
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);
                        }
                    }
                }
            }
        }