Exemplo n.º 1
0
        /// <inheritdoc />
        public void Configure(ZConfiguration config)
        {
            if (_config != null)
            {
                throw new InvalidOperationException("This method can only be called once.");
            }
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }
            if (config.SynchronizationContext == null)
            {
                throw new ArgumentException(nameof(config.SynchronizationContext));
            }

            ZSynchronizationWrapper.Initialize(config);
            _config = config;
        }
Exemplo n.º 2
0
        /// <summary>
        /// 验证配置
        /// </summary>
        /// <param name="zConfiguration"></param>
        private void VerifySettings(ZConfiguration zConfiguration)
        {
            try
            {
                if (zConfiguration == null)
                {
                    throw new Exception("读取配置文件出错");
                }
                if (zConfiguration.Node.Groups.Count <= 0)
                {
                    throw new Exception("配置文件中, node节点至少包含一个Group节点");
                }

                /*var Repeat = (from o in zConfiguration.Node.Groups group o by o.Name into g where g.Count() > 1 select g).ToList();
                 * if (Repeat.Count > 0)
                 *  throw new Exception(string.Format("配置文件中,Group节点不能包含多个重复的Name属性值:{0}", Repeat[0].Key));*/

                var NoFieldsList = zConfiguration.Node.Groups.Where(o => { return(o.Fields.Count <= 0); }).ToList();
                if (NoFieldsList.Count > 0)
                {
                    throw new Exception(string.Format("配置文件中, name={0}的Group节点必须至少包含一个field节点", NoFieldsList[0].Name));
                }

                if (zConfiguration.ZookeeprtServer.ConnectUrls.Count <= 0)
                {
                    throw new Exception("配置文件中, zookeeperServer节点必须至少包含一个url节点");
                }

                var modeMatchCount = zConfiguration.ZookeeprtServer.ConnectUrls.Count(o => { return(o.Mode.Trim().ToLower() == ConfigurationInfo.Mode.Trim().ToLower()); });
                if (modeMatchCount <= 0)
                {
                    throw new Exception("配置文件中, configuration节点属性mode:" + zConfiguration.Mode + ",不包含在zookeeperServer节点的url节点mode中");
                }
            }
            catch (Exception e)
            {
                ZookeeperConfigCenterManagerEvents.ZookpeerWriteLog(e.Message, LogerType.Error);
                throw new Exception(e.Message);
            }
        }
Exemplo n.º 3
0
 public static void Initialize(ZConfiguration config) => _context = config.SynchronizationContext;