コード例 #1
0
        internal static void SendData(string key, object data)
        {
            try
            {
                if (_recordEnable)
                {
                    DataPoint dp = new DataPoint();
                    dp.Key = key;
                    //dp.TimeStamp = DateTime.Now.Ticks;
                    dp.Value = data;
                    string mapKey = key;
                    lock (_sync)
                    {
                        if (_datamap != null)
                        {
                            if (key == "MonitoringData")
                            {
                                var tempVar = data as DataPoint;
                                if (tempVar != null)
                                {
                                    mapKey = "(" + key + ")" + tempVar.Key;
                                }
                            }
                            if (!_datamap.ContainsKey(mapKey))
                            {
                                _datamap.Add(mapKey, dp);
                            }
                            else
                            {
                                _datamap[mapKey] = dp;
                            }
                        }
                    }
                }


                foreach (DataService service in innerServiceCollection)
                {
                    if (service.IsInterrupted)
                    {
                        continue;
                    }
                    if (!service.Need(key))
                    {
                        continue;
                    }
                    try
                    {
                        service.Client.ReceiveData(key, data);
                    }
                    catch (Exception ex)
                    {
                        service.IsInterrupted = true;
                        service.Exception     = ex;
                    }
                }
                //策略引擎获取实时数据
                Task task = Task.Factory.StartNew(() =>
                {
                    RuleEngine.ReceiveData(key, data);
                });
            }
            catch (Exception ex)
            {
                _logService.Error(string.Format("ExistCatch:error:<-{0}->:{1} \r\n Error detail:{2}", "SendData", ex.Message, ex.ToString()));
            }
        }