Esempio n. 1
0
 /// <summary>
 /// 试着取配置
 /// </summary>
 /// <param name="stationName"></param>
 /// <param name="stationConfig"></param>
 /// <returns></returns>
 public bool TryGetConfig(string stationName, out StationConfig stationConfig)
 {
     if (stationName == null)
     {
         stationConfig = null;
         return(false);
     }
     lock (_configs)
     {
         return(_configs.TryGetValue(stationName, out stationConfig));
     }
 }
Esempio n. 2
0
 bool CheckName(StationConfig config, string name)
 {
     if (_configs.Values.Where(p => p != config).Any(p => p.StationName == name))
     {
         return(false);
     }
     if (_configs.Values.Where(p => p != config).Any(p => p.ShortName == name))
     {
         return(false);
     }
     if (_configs.Values.Where(p => p != config && p.StationAlias != null).Any(p => p.StationAlias.Any(a => string.Equals(a, name))))
     {
         return(false);
     }
     return(true);
 }
Esempio n. 3
0
        private void AddStation(StationConfig station)
        {
            lock (_configs)
            {
                if (_configs.ContainsKey(station.Name))
                {
                    _configs[station.Name].Copy(station);
                }
                else
                {
                    _configs.Add(station.Name, station);
                }

                if (!_configMap.ContainsKey(station.Name))
                {
                    _configMap.Add(station.Name, station.Name);
                }
                else
                {
                    _configMap[station.Name] = station.Name;
                }

                if (!_configMap.ContainsKey(station.ShortName))
                {
                    _configMap.Add(station.ShortName, station.Name);
                }
                else
                {
                    _configMap[station.ShortName] = station.Name;
                }
                if (station.StationAlias == null)
                {
                    return;
                }
                foreach (var ali in station.StationAlias)
                {
                    if (!_configMap.ContainsKey(ali))
                    {
                        _configMap.Add(ali, station.Name);
                    }
                    else
                    {
                        _configMap[ali] = station.Name;
                    }
                }
            }
        }
Esempio n. 4
0
 internal void Remove(StationConfig station)
 {
     lock (_configs)
     {
         _configs.Remove(station.Name);
         _configMap.Remove(station.Name);
         _configMap.Remove(station.ShortName);
         if (station.StationAlias == null)
         {
             return;
         }
         foreach (var ali in station.StationAlias)
         {
             _configMap.Remove(ali);
         }
     }
 }
Esempio n. 5
0
 /// <summary>
 ///     系统启动时调用
 /// </summary>
 internal static void OnStationStateChanged(StationConfig config)
 {
     using (OnceScope.CreateScope(ZeroObjects))
     {
         ZeroTrace.WriteLine("[OnStationStateChanged>>");
         Parallel.ForEach(ActiveObjects.ToArray(), obj =>
         {
             try
             {
                 obj.OnStationStateChanged(config);
             }
             catch (Exception e)
             {
                 ZeroTrace.WriteException(obj.Name, e, "OnStationStateChanged");
             }
         });
         ZeroTrace.WriteLine("<<OnStationStateChanged]");
     }
 }
Esempio n. 6
0
 /// <summary>
 ///     系统启动时调用
 /// </summary>
 internal static void OnStationStateChanged(StationConfig config)
 {
     using (OnceScope.CreateScope(ZeroObjects))
     {
         ZeroTrace.SystemLog($"[OnStationStateChanged({config.StationName})>>");
         Parallel.ForEach(ActiveObjects.Where(p => string.Equals(config.StationName, p.StationName, StringComparison.OrdinalIgnoreCase)).ToArray(),
                          obj =>
         {
             try
             {
                 obj.OnStationStateChanged(config);
             }
             catch (Exception e)
             {
                 ZeroTrace.WriteException(obj.Name, e, "OnStationStateChanged");
             }
         });
         ZeroTrace.SystemLog($"<<OnStationStateChanged({config.StationName})]");
     }
 }
Esempio n. 7
0
 /// <summary>
 /// 试着取配置
 /// </summary>
 /// <param name="stationName"></param>
 /// <param name="json"></param>
 /// <param name="config"></param>
 /// <returns></returns>
 public bool UpdateConfig(string stationName, string json, out StationConfig config)
 {
     if (stationName == null || string.IsNullOrEmpty(json) || json[0] != '{')
     {
         ZeroTrace.WriteError("UpdateConfig", "argument error", stationName, json);
         config = null;
         return(false);
     }
     try
     {
         config = JsonConvert.DeserializeObject <StationConfig>(json);
         AddStation(config);
         return(true);
     }
     catch (Exception e)
     {
         ZeroTrace.WriteException("UpdateConfig", e, stationName, json);
         config = null;
         return(false);
     }
 }
Esempio n. 8
0
 /// <summary>
 /// 检查重名情况
 /// </summary>
 /// <param name="old"></param>
 /// <param name="config"></param>
 /// <returns></returns>
 public bool Check(StationConfig old, StationConfig config)
 {
     if (!CheckName(old, config.Name))
     {
         return(false);
     }
     if (!CheckName(old, config.ShortName))
     {
         return(false);
     }
     if (config.StationAlias == null || config.StationAlias.Count == 0)
     {
         return(true);
     }
     foreach (var al in config.StationAlias)
     {
         if (!CheckName(old, al))
         {
             return(false);
         }
     }
     return(true);
 }
Esempio n. 9
0
        /// <summary>
        /// 系统启动时调用
        /// </summary>
        void IZeroObject.OnStationStateChanged(StationConfig config)
        {
            StationSocketPool pool;

            lock (Pools)
            {
                if (!Pools.TryGetValue(config.StationName, out pool))
                {
                    return;
                }
            }
            switch (config.State)
            {
            case ZeroCenterState.Run when pool != null:
                pool.Resume();
                break;

            case ZeroCenterState.Run:
                lock (Pools)
                {
                    if (!Pools.ContainsKey(config.StationName))
                    {
                        Pools.Add(config.StationName, new StationSocketPool
                        {
                            Config = config
                        });
                    }
                }

                break;

            default:
                pool?.Dispose();
                break;
            }
        }
Esempio n. 10
0
 /// <summary>
 /// 构造
 /// </summary>
 /// <param name="eventName"></param>
 /// <param name="config"></param>
 public StationEventArgument(string eventName, StationConfig config)
 {
     EventConfig = config;
     EventName   = eventName;
 }
Esempio n. 11
0
 /// <summary>
 /// 构造
 /// </summary>
 /// <param name="centerEvent"></param>
 /// <param name="context"></param>
 /// <param name="config"></param>
 public ZeroNetEventArgument(ZeroNetEventType centerEvent, string context, StationConfig config)
 {
     EventConfig = config;
     Event       = centerEvent;
     Context     = context;
 }