Beispiel #1
0
        /// <summary>
        ///		使用HA方式初始化服务
        /// </summary>
        /// <param name="serviceName">服务名</param>
        /// <param name="computerName">获取配置使用的计算机名</param>
        /// <param name="centerUrl">HACenter的Url</param>
        public static void InitServiceHa(string serviceName, string computerName, string centerUrl)
        {
            if (_current != null && _current.ServiceName != NULL)
            {
                return;
            }

            lock (_syncRoot) {
                _current = new ServiceSettingsConfigProxy(serviceName, computerName);

                RpcHttpClientChannel channel = new RpcHttpClientChannel();
                RpcProxyFactory.RegisterClientChannel(channel);

                HAGetConfigArgs args = new HAGetConfigArgs();
                args.ServiceName  = serviceName;
                args.ComputerName = computerName;

                var proxy = RpcProxyFactory.GetProxy <IHACenterConfigService>(centerUrl);
                HAServiceSettings settings = proxy.Invoke <HAGetConfigArgs, HAServiceSettings>(
                    "LoadServiceSettings",
                    args);

                IICConfigurationManager.Loader = new HAConfigurationLoader(serviceName, computerName, centerUrl);

                _current.UpdateConfig(ServiceRunMode.HAService, settings);
                TracingManager.UpdateConfig();
            }
        }
Beispiel #2
0
        /// <summary>
        ///		初始化Web
        /// </summary>
        public static void InitWeb()
        {
            if (_current != null && _current.ServiceName != NULL)
            {
                return;
            }

            lock (_syncRoot) {
                string runMode      = WebConfigurationManager.AppSettings["RunMode"];
                string centerUrl    = WebConfigurationManager.AppSettings["CenterUrl"];
                string serviceName  = WebConfigurationManager.AppSettings["ServiceName"];
                string computerName = WebConfigurationManager.AppSettings["ComputerName"] ?? Environment.MachineName;

                if (runMode == "LocalWeb")
                {
                    _current = new ServiceSettingsConfigProxy(serviceName);
                    IICConfigurationManager.Loader = new LocalConfigurationLoader();
                    _current.UpdateConfig(ServiceRunMode.LocalWeb, null);
                    RpcProxyFactory.RegisterClientChannel(new RpcPipeClientChannel());
                    TracingManager.UpdateConfig();
                }
                else
                {
                    _current = new ServiceSettingsConfigProxy(serviceName, computerName);
                    RpcProxyFactory.RegisterClientChannel(new RpcHttpClientChannel());
                    RpcProxyFactory.RegisterClientChannel(new RpcPipeClientChannel());
                    HAConfigurationLoader loader   = new HAConfigurationLoader(serviceName, computerName, centerUrl);
                    HAServiceSettings     settings = loader.LoadServiceSettings();
                    IICConfigurationManager.Loader = loader;
                    _current.UpdateConfig(ServiceRunMode.HAWeb, settings);
                    TracingManager.UpdateConfig();
                }
            }
        }
        /// <summary>本地初始化服务, 默认初始化为本地配置, HA会覆盖这个配置</summary>
        public static void InitService(string serviceName)
        {
            if (_current != null && _current.ServiceName != NULL)
                return;

            lock (_syncRoot) {
                IICConfigurationManager.Loader = new LocalConfigurationLoader();

                _current = new ServiceSettingsConfigProxy(serviceName);
                _current.UpdateConfig(ServiceRunMode.LocalService, null);
                TracingManager.UpdateConfig();
            }
        }
Beispiel #4
0
        /// <summary>本地初始化服务, 默认初始化为本地配置, HA会覆盖这个配置</summary>
        public static void InitService(string serviceName)
        {
            if (_current != null && _current.ServiceName != NULL)
            {
                return;
            }

            lock (_syncRoot) {
                IICConfigurationManager.Loader = new LocalConfigurationLoader();

                _current = new ServiceSettingsConfigProxy(serviceName);
                _current.UpdateConfig(ServiceRunMode.LocalService, null);
                TracingManager.UpdateConfig();
            }
        }
        public static void InitServiceHa(string serviceName, string computerName, string centerUrl)
        {
            if (_current != null && _current.ServiceName != NULL)
                return;

            lock (_syncRoot) {
                _current = new ServiceSettingsConfigProxy(serviceName, computerName);

                RpcHttpClientChannel channel = new RpcHttpClientChannel();
                RpcProxyFactory.RegisterClientChannel(channel);

                HAGetConfigArgs args = new HAGetConfigArgs();
                args.ServiceName = serviceName;
                args.ComputerName = computerName;

                var proxy = RpcProxyFactory.GetProxy<IHACenterConfigService>(centerUrl);
                HAServiceSettings settings = proxy.Invoke<HAGetConfigArgs, HAServiceSettings>(
                    "LoadServiceSettings",
                    args);

                IICConfigurationManager.Loader = new HAConfigurationLoader(serviceName, computerName, centerUrl);

                _current.UpdateConfig(ServiceRunMode.HAService, settings);
                TracingManager.UpdateConfig();
            }
        }
        public static void InitWeb()
        {
            if (_current != null && _current.ServiceName != NULL)
                return;

            lock (_syncRoot) {
                string runMode = WebConfigurationManager.AppSettings["RunMode"];
                string centerUrl = WebConfigurationManager.AppSettings["CenterUrl"];
                string serviceName = WebConfigurationManager.AppSettings["ServiceName"];
                string computerName = WebConfigurationManager.AppSettings["ComputerName"] ?? Environment.MachineName;

                if (runMode == "LocalWeb") {
                    _current = new ServiceSettingsConfigProxy(serviceName);
                    IICConfigurationManager.Loader = new LocalConfigurationLoader();
                    _current.UpdateConfig(ServiceRunMode.LocalWeb, null);
                    RpcProxyFactory.RegisterClientChannel(new RpcPipeClientChannel());
                    TracingManager.UpdateConfig();
                } else {
                    _current = new ServiceSettingsConfigProxy(serviceName, computerName);
                    RpcProxyFactory.RegisterClientChannel(new RpcHttpClientChannel());
                    RpcProxyFactory.RegisterClientChannel(new RpcPipeClientChannel());
                    HAConfigurationLoader loader = new HAConfigurationLoader(serviceName, computerName, centerUrl);
                    HAServiceSettings settings = loader.LoadServiceSettings();
                    IICConfigurationManager.Loader = loader;
                    _current.UpdateConfig(ServiceRunMode.HAWeb, settings);
                    TracingManager.UpdateConfig();
                }
            }
        }