Example #1
0
        public IActionResult Update([FromForm] StationInfo info)
        {
            if (string.IsNullOrWhiteSpace(info.Name))
            {
                return(Json(ApiResult.Error(ErrorCode.LogicalError, "参数错误")));
            }
            var old = ZeroApplication.Config[info.Name];

            if (old == null)
            {
                return(Json(ApiResult.Error(ErrorCode.LogicalError, "参数错误")));
            }
            var config = new StationConfig
            {
                Name         = info.Name,
                Description  = info.Description,
                StationAlias = string.IsNullOrWhiteSpace(info.Alias)
                    ? new List <string>()
                    : info.Alias.Trim().Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries).ToList()
            };

            if (!ZeroApplication.Config.Check(old, config))
            {
                return(Json(ApiResult.Error(ErrorCode.LogicalError, "名称存在重复")));
            }

            return(Json(ZeroManager.Update(config)));
        }
Example #2
0
        public static ApiResult Update(StationConfig option)
        {
            if (!ZeroApplication.Config.TryGetConfig(option.Name, out var config))
            {
                return(ApiResult.Error(ErrorCode.NetworkError, "站点不存在"));
            }

            try
            {
                var result = SystemManager.Instance.CallCommand("update", JsonConvert.SerializeObject(option));
                if (!result.InteractiveSuccess)
                {
                    return(ApiResult.Error(ErrorCode.NetworkError, "服务器无法访问"));
                }
                switch (result.State)
                {
                case ZeroOperatorStateType.Ok:
                    var apiResult = ApiResult.Succees();
                    apiResult.Status = new ApiStatusResult
                    {
                        ErrorCode     = ErrorCode.Success,
                        ClientMessage = "安装成功"
                    };
                    return(apiResult);

                default:
                    return(ApiResult.Error(ErrorCode.LogicalError, result.State.Text()));
                }
            }
            catch (Exception e)
            {
                return(ApiResult.Error(ErrorCode.NetworkError, e.Message));
            }
        }
Example #3
0
        //
        //编写测试时,还可使用以下特性:
        //
        //使用 ClassInitialize 在运行类中的第一个测试前先运行代码
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //使用 ClassCleanup 在运行完类中的所有测试后再运行代码
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //使用 TestInitialize 在运行每个测试前先运行代码
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //使用 TestCleanup 在运行完每个测试后运行代码
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///Load 的测试
        ///</summary>
        public void LoadTestHelper <T>()
        {
            string        filePath = @"D:\SVN\Platform\TTSM2_Code\TestFramework\ConfigFiles\StationConfig.xml";
            StationConfig sc       = XmlConfigHelper.Load <StationConfig>(filePath);

            Assert.IsNotNull(sc);
        }
Example #4
0
        public MainWindow()
        {
            StationConfig = new StationConfig();

            InitializeComponent();
            DataContext = _dispenser;
        }
Example #5
0
 public Setting(StationConfig stationConfig)
 {
     InitializeComponent();
     _stationConfig             = stationConfig;
     TabControl.DataContext     = _stationConfig;
     StationInfoTab.DataContext = _stationConfig.StationInfo;
 }
Example #6
0
        /// <summary>
        ///     复制
        /// </summary>
        /// <param name="src"></param>
        public StationInfo(StationConfig src)
        {
            Name        = src.StationName;
            Description = src.Description;
            short_name  = src.ShortName;
            Alias       = src.StationAlias.LinkToString(',');

            switch (src.StationType)
            {
            default:
                Type = "Error"; break;

            case ZeroStationType.Api:
                Type = "API"; break;

            case ZeroStationType.Dispatcher:
                Type = "Dispatcher"; break;

            case ZeroStationType.Publish:
                Type = "Pub"; break;

            case ZeroStationType.Vote:
                Type = "Vote"; break;

            case ZeroStationType.Plan:
                Type = "Plan"; break;
            }
            RequestAddress      = src.RequestAddress;
            WorkerCallAddress   = src.WorkerCallAddress;
            IsGeneralStation    = src.IsGeneralStation;
            IsBaseStation       = src.IsBaseStation;
            WorkerResultAddress = src.WorkerResultAddress;
            State = src.State.ToString();
        }
Example #7
0
 private static void SetZeroHost(StationConfig station, string name)
 {
     if (string.IsNullOrEmpty(name))
     {
         return;
     }
     name = name.Trim();
     if (Router.RouteMap.TryGetValue(name, out var host))
     {
         var zeroHost = host as ZeroHost;
         if (zeroHost == null)
         {
             Router.RouteMap[name] = new ZeroHost
             {
                 ByZero  = true,
                 Station = station.StationName,
                 Alias   = name != station.StationName
                        ? null
                        : station.StationAlias == null
                            ? new string[0]
                            : station.StationAlias.ToArray()
             };
         }
         else
         {
             host.Failed      = false;
             host.ByZero      = true;
             zeroHost.Station = station.StationName;
             if (name == station.StationName)
             {
                 foreach (var alia in host.Alias)
                 {
                     Router.RouteMap.Remove(alia);
                 }
                 host.Alias = station.StationAlias == null ? new string[0] : station.StationAlias.ToArray();
             }
             else
             {
                 host.Alias = null;
             }
         }
     }
     else
     {
         lock (Router.RouteMap)
         {
             Router.RouteMap.Add(name, host = new ZeroHost
             {
                 ByZero  = true,
                 Station = station.StationName,
                 Alias   = name != station.StationName
                     ? null
                     : station.StationAlias == null
                         ? new string[0]
                         : station.StationAlias.ToArray()
             });
         }
     }
 }
Example #8
0
 private static void StationLeft(StationConfig station)
 {
     if (Router.RouteMap.TryGetValue(station.StationName, out var host))
     {
         host.Failed = true;
         host.ByZero = true;
     }
 }
Example #9
0
 /// <summary>
 /// 构造
 /// </summary>
 public ZeroEntityEventProxy()
 {
     _config = StationProgram.GetConfig("EntityEvent");
     if (_config == null)
     {
         throw new Exception("无法拉取配置");
     }
     _socket = new RequestSocket();
     CreateSocket();
 }
Example #10
0
 private static void StationJoin(StationConfig station)
 {
     SetZeroHost(station, station.StationName);
     SetZeroHost(station, station.ShortName);
     if (station.StationAlias == null)
     {
         return;
     }
     foreach (var alia in station.StationAlias)
     {
         SetZeroHost(station, alia);
     }
 }
Example #11
0
        public PIRDetectionSink(ILogger <PIRDetectionSink> logger, IOptions <PIRDetectionSinkConfig> config, IOptions <StationConfig> stationConfig, ITimeProvider timeProvider, IInfluxClient influxClient, IScheduler scheduler = null)
        {
            _logger = logger;

            _config = config.Value;

            _stationConfig = stationConfig.Value;

            _timeProvider = timeProvider;

            _influxClient = influxClient;

            _scheduler = scheduler;
        }
Example #12
0
        public static ApiResult Install(StationConfig option)
        {
            if (ZeroApplication.Config.TryGetConfig(option.Name, out var config))
            {
                var result = ApiResult <StationConfig> .Succees(config);

                result.Status = new ApiStatusResult
                {
                    ErrorCode     = ErrorCode.LogicalError,
                    ClientMessage = "站点已存在"
                };
                return(result);
            }

            try
            {
                var result = SystemManager.Instance.CallCommand("install", JsonConvert.SerializeObject(option));
                if (!result.InteractiveSuccess)
                {
                    return(ApiResult.Error(ErrorCode.NetworkError, "服务器无法访问"));
                }
                switch (result.State)
                {
                case ZeroOperatorStateType.ArgumentInvalid:
                    return(ApiResult.Error(ErrorCode.LogicalError, $"命令格式错误:{result.State.Text()}"));

                case ZeroOperatorStateType.NotSupport:
                    return(ApiResult.Error(ErrorCode.LogicalError, "类型不支持"));

                case ZeroOperatorStateType.Failed:
                    return(ApiResult.Error(ErrorCode.LogicalError, "已存在"));

                case ZeroOperatorStateType.Ok:
                    var apiResult = ApiResult.Succees();
                    apiResult.Status = new ApiStatusResult
                    {
                        ErrorCode     = ErrorCode.Success,
                        ClientMessage = "安装成功"
                    };
                    return(apiResult);

                default:
                    return(ApiResult.Error(ErrorCode.LogicalError, result.State.Text()));
                }
            }
            catch (Exception e)
            {
                return(ApiResult.Error(ErrorCode.NetworkError, e.Message));
            }
        }
Example #13
0
        private void PublishConfig(StationConfig config)
        {
            if (config == null)
            {
                return;
            }
            var info = new StationInfo(config);

            if (StationCountItems.TryGetValue(config.Name, out var status))
            {
                info.Status = status;
            }
            var json = JsonConvert.SerializeObject(info);

            WebSocketNotify.Publish("config", config.StationName, json);
        }
Example #14
0
        private void CreateStationTreeItem(TreeItem <StationConfig> node, StationConfig config)
        {
            if (!SystemManager.Instance.LoadDocument(config.StationName, out var doc))
            {
                return;
            }

            var icon = Application.Current.Resources["tree_item"] as BitmapImage;

            foreach (var api in doc.Aips.Values)
            {
                var eitem = new TreeItem <ApiDocument>(api)
                {
                    Header         = api.Caption ?? api.Name,
                    SoruceTypeIcon = icon
                };
                node.Items.Add(eitem);
            }
        }
Example #15
0
        private void StationSettings_Shown(object sender, EventArgs e)
        {
            sc = XmlConfigHelper.Load <StationConfig>(stationConfigFile);
            this.textBox_Comport.Text = sc.DutComport;

            cpEc = sc.EquipmentConfig.Find(x => x.InstrumentType.Equals("CP"));
            this.comboBox_ConnectType.Text = cpEc.ConnectionType.ToString();
            this.textBox_InstrAddr.Text    = cpEc.Address;

            psEc = sc.EquipmentConfig.Find(x => x.InstrumentType.Equals("PS"));
            this.textBox_PSAddr.Text = psEc.Address;

            foreach (var item in sc.RFNetLossConfigs)
            {
                string[] row = { item.BandName,                     item.UpLinkChannel.ToString(), item.UplinkLossMain.ToString("F2"), item.DownlinkLossMain.ToString("F2"),
                                 item.UplinkLossDiv.ToString("F2"), item.DownlinkLossDiv.ToString("F2") };
                this.dataGridView_RFLossConfig.Rows.Add(row);
            }
        }
Example #16
0
        public IActionResult Install([FromForm] StationInfo info)
        {
            if (string.IsNullOrWhiteSpace(info.Name) || string.IsNullOrWhiteSpace(info.Type))
            {
                return(Json(ApiResult.Error(ErrorCode.LogicalError, "参数错误")));
            }
            ZeroStationType type;

            switch (info.Type.ToLower())
            {
            case "pub":
                type = ZeroStationType.Publish;
                break;

            case "vote":
                type = ZeroStationType.Vote;
                break;

            case "api":
                type = ZeroStationType.Api;
                break;

            default:
                return(Json(ApiResult.Error(ErrorCode.LogicalError, "参数错误")));
            }
            var config = new StationConfig
            {
                Name         = info.Name,
                Description  = info.Description,
                StationType  = type,
                ShortName    = info.short_name ?? info.Name,
                StationAlias = string.IsNullOrWhiteSpace(info.Alias)
                    ? new List <string>()
                    : info.Alias.Trim().Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries).ToList()
            };

            if (!ZeroApplication.Config.Check(config, config))
            {
                return(Json(ApiResult.Error(ErrorCode.LogicalError, "名称存在重复")));
            }

            return(Json(ZeroManager.Install(config)));
        }
Example #17
0
        private static void SetZeroHost(StationConfig station, string name)
        {
            if (string.IsNullOrEmpty(name))
            {
                return;
            }
            name = name.Trim();
            ZeroHost zeroHost;

            if (Router.RouteMap.TryGetValue(name, out var host))
            {
                zeroHost = host as ZeroHost;
                if (zeroHost == null)
                {
                    Router.RouteMap[name] = zeroHost = new ZeroHost
                    {
                        ByZero  = true,
                        Station = station.StationName,
                        Alias   = name != station.StationName
                               ? null
                               : station.StationAlias == null
                                   ? new string[0]
                                   : station.StationAlias.ToArray()
                    };
                }
                else
                {
                    host.Failed      = false;
                    host.ByZero      = true;
                    zeroHost.Station = station.StationName;
                    if (name == station.StationName)
                    {
                        foreach (var alia in host.Alias)
                        {
                            Router.RouteMap.Remove(alia);
                        }
                        host.Alias = station.StationAlias == null ? new string[0] : station.StationAlias.ToArray();
                    }
                    else
                    {
                        host.Alias = null;
                    }
                }
            }
            else
            {
                lock (Router.RouteMap)
                {
                    Router.RouteMap.Add(name, zeroHost = new ZeroHost
                    {
                        ByZero  = true,
                        Station = station.StationName,
                        Alias   = name != station.StationName
                            ? null
                            : station.StationAlias == null
                                ? new string[0]
                                : station.StationAlias.ToArray()
                    });
                }
            }
            zeroHost.Apis = new System.Collections.Generic.Dictionary <string, ApiItem>(StringComparer.OrdinalIgnoreCase);
            if (!SystemManager.Instance.LoadDocument(station.StationName, out var doc))
            {
                return;
            }
            foreach (var api in doc.Aips.Values)
            {
                zeroHost.Apis.Add(api.RouteName, new ApiItem
                {
                    Name   = api.RouteName,
                    Access = api.AccessOption
                });
            }
        }
Example #18
0
        /// <summary>
        ///     执行命令
        /// </summary>
        /// <returns></returns>
        private void Collect(StationConfig station, string json)
        {
            using (OnceScope.CreateScope(minuteLine))
            {
                var now = JsonConvert.DeserializeObject <StationCountItem>(json);
                if (!StationCountItems.TryGetValue(station.StationName, out var item))
                {
                    now.Count = 1;
                    StationCountItems.Add(station.StationName, now);
                    return;
                }

                item.CheckValue(station, now);

                WebSocketNotify.Publish("status", station.StationName, JsonConvert.SerializeObject(item));
                long value = station.StationType == ZeroStationType.Api ||
                             station.StationType == ZeroStationType.Vote
                    ? item.LastTps
                    : item.LastQps;
                if (minuteLine.TryGetValue(station.StationName, out var kLine))
                {
                    if (kLine.Count == 0)
                    {
                        kLine.Total = value;
                        kLine.Open  = value;
                        kLine.Close = value;
                        kLine.Max   = value;
                        kLine.Min   = value;
                    }
                    else
                    {
                        kLine.Total += value;
                        kLine.Close  = value;
                        if (kLine.Max < value)
                        {
                            kLine.Max = value;
                        }
                        if (kLine.Min > value)
                        {
                            kLine.Min = value;
                        }
                    }

                    kLine.Count++;
                }
                else
                {
                    minuteLine.Add(station.StationName, kLine = new KLine
                    {
                        Time  = GetTime(BaseLine),
                        Count = 1,
                        Total = value,
                        Open  = value,
                        Close = value,
                        Max   = value,
                        Min   = value,
                        Avg   = value
                    });
                    KLines.Add(station.StationName, new List <KLine> {
                        kLine
                    });
                }
            }

            if ((DateTime.Now - BaseLine).TotalMinutes < 1)
            {
                return;
            }
            NewBaseTime();
            foreach (var key in KLines.Keys.ToArray())
            {
                if (!minuteLine.TryGetValue(key, out var line))
                {
                    minuteLine.Add(key, line = new KLine
                    {
                        Time  = GetTime(BaseLine),
                        Count = 1
                    });
                }
                if (line.Count == 0)
                {
                    line.Avg = 0;
                }
                else
                {
                    line.Avg = decimal.Round(line.Total / line.Count, 4);
                }
                while (KLines[key].Count > 240)
                {
                    KLines[key].RemoveAt(0);
                }
                KLines[key].Add(line);
                WebSocketNotify.Publish("kline", key, JsonConvert.SerializeObject(line));
                var nLine = new KLine
                {
                    Time = GetTime(BaseLine)
                };
                minuteLine[key] = nLine;
            }
        }
Example #19
0
        /// <summary>
        ///     设置计数值
        /// </summary>
        public void CheckValue(StationConfig station, StationCountItem src)
        {
            Workers       = src.Workers;
            station.State = src.State;
            Station       = station.StationName;
            if (Count == 0)
            {
                TotalQps = 0;
                LastQps  = 0;
                AvgQps   = 0;
                MaxQps   = 0;
                MinQps   = 0;
                TotalTps = 0;
                LastTps  = 0;
                MaxTps   = 0;
                MinTps   = 0;
                AvgTps   = 0;
            }
            else
            {
                if (src.RequestOut < RequestOut)
                {
                    LastQps = src.RequestOut;
                }
                else
                {
                    LastQps = src.RequestOut - RequestOut;
                }
                TotalQps += LastQps;
                if (LastQps > 0)
                {
                    LastQps = LastQps / 2;
                    if (MaxQps == 0 || MaxQps < LastQps)
                    {
                        MaxQps = LastQps;
                    }
                    if (MinQps == 0 || MinQps > LastQps)
                    {
                        MinQps = LastQps;
                    }
                    AvgQps = TotalQps / Count / 2;
                }
                if (src.WorkerIn < WorkerIn)
                {
                    LastTps = src.WorkerIn;
                }
                else
                {
                    LastTps = src.WorkerIn - WorkerIn;
                }
                TotalTps += LastTps;
                if (LastTps > 0)
                {
                    LastTps = LastTps / 2;
                    if (MaxTps == 0 || MaxTps < LastTps)
                    {
                        MaxTps = LastTps;
                    }
                    if (MinTps == 0 || MinTps > LastTps)
                    {
                        MinTps = LastTps;
                    }
                    AvgTps = TotalTps / Count / 2;
                }
            }

            Count     += 1;
            RequestIn  = src.RequestIn;
            RequestOut = src.RequestOut;
            RequestErr = src.RequestErr;
            WorkerIn   = src.WorkerIn;
            WorkerOut  = src.WorkerOut;
            WorkerErr  = src.WorkerErr;
        }
        public async Task airStationLoadTask()
        {
            try
            {
                load_lb.Visible = true;
                string cityCode = "*";
                string cityName = "全国";
                if (cityComboBox.SelectedItem != null)
                {
                    Area areaCityObj = (Area)(cityComboBox.SelectedItem);
                    cityCode = areaCityObj.AreaCode;
                    cityName = areaCityObj.AreaName;
                }
                if (proviceComboBox.SelectedItem != null && (cityCode == "*" || String.IsNullOrEmpty(cityCode)))
                {
                    Area areaProviceObj = (Area)(proviceComboBox.SelectedItem);
                    cityCode = areaProviceObj.AreaCode.Substring(0, 2);
                    cityName = areaProviceObj.AreaName;
                }

                //创建domain客户端
                EnvCnemcPublishDomainContext publishCtx = new EnvCnemcPublishDomainContext(XAP_URL);

                //获取所有检测站,业务上通过citycode与城市对应
                IEnumerable <StationConfig> stations = await publishCtx.Load(publishCtx.GetStationConfigsQuery()).ResultAsync();

                List <JObject> list = new List <JObject>();
                if (stations != null)
                {
                    for (int i = 0; i < stations.Count(); i++)
                    {
                        StationConfig sc = stations.ElementAt(i);

                        if (cityCode == "*" || sc.CityCode.ToString().StartsWith(cityCode))
                        {
                            JObject jo = new JObject();
                            jo["UniqueCode"]   = sc.UniqueCode;
                            jo["Area"]         = sc.Area;
                            jo["CityCode"]     = sc.CityCode;
                            jo["StationCode"]  = sc.StationCode;
                            jo["Latitude"]     = sc.Latitude;
                            jo["Longitude"]    = sc.Longitude;
                            jo["PositionName"] = sc.PositionName;
                            list.Add(jo);
                        }
                    }
                }
                if (list.Count > 0)
                {
                    if (asr.DeleteAirStationInfo())
                    {
                        _ = Task.Run(() =>
                        {
                            bool result     = asr.AddAirStationInfo(list);
                            load_lb.Visible = false;
                            if (result)
                            {
                                stationQueryBtn_Click(null, null);
                                MessageBox.Show(cityName + list.Count + "个空气质量站点同步成功!", " 提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                            else
                            {
                                MessageBox.Show(cityName + "空气质量站点同步失败!", " 提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        });
                    }
                }
                else
                {
                    load_lb.Visible = false;
                    MessageBox.Show(cityName + "没有空气质量站点要同步", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            catch (Exception e)
            {
                load_lb.Visible = false;
                //日志处理
                Loghelper.WriteErrorLog("同步空气质量站点数据失败", e);
                lr.AddLogInfo(e.ToString(), "同步空气质量站点数据失败", "", "Error");
                //throw e;
            }
        }
Example #21
0
 public void LoadStationConfig()
 {
     testEngineLogger.Log(string.Format("Loading station cfg file: {0}", Path.GetFullPath(stationConfigFile)), "LoadStationConfig");
     sc = XmlConfigHelper.Load <StationConfig>(stationConfigFile);
     testEngineLogger.Log("Success.", "LoadStationConfig");
 }