/// <summary>
        /// 加载远程对象代理客户端模块
        /// </summary>
        /// <param name="host"></param>
        public void LoadModulesByHost(RemotingHost host)
        {
            string serverUrl = RemotingHostCheck.Instance.GetUsableServerUrl(host);

            foreach (KeyValuePair <string, string> m in host.Modules)
            {
                string objectUrl = _RemotingConfiguration.GetRemoteObjectUrl(serverUrl, m.Value);
                T      instance  = (T)Activator.GetObject(typeof(T), objectUrl);

                string key = string.Format("{0}${1}${2}", host.Name, serverUrl, m.Key);
                _RemoteObjects[key] = instance;
            }
        }
示例#2
0
        void CheckRemotingHost(RemotingHost host)
        {
            string         objectUrl       = string.Empty;
            RemotingServer defaultServer   = host.Servers[host.DefaultServer];
            string         usableServerUrl = this.GetUsableServerUrl(host);
            bool           flag            = false; //是否需要重设当前可用服务器标志

            host.IsChecking = true;

            //首先检查当前可用服务器
            try
            {
                objectUrl = cfg.GetRemoteObjectUrl(usableServerUrl, "RemotingTest");
                IRemotingTest t = (IRemotingTest)Activator.GetObject(typeof(RemotingTest), objectUrl);
                t.GetDate();
                WriteLog(host.Name, usableServerUrl, true, "ok");
            }
            catch (Exception ex)
            {
                flag = true;    //需要重设当前可用服务器标志
                WriteLog(host.Name, usableServerUrl, false, ex.Message);
            }

            //若当前可用服务器不是默认服务器,则再检查默认服务器,若其可用,则还原
            if (defaultServer.ServerUrl != usableServerUrl)
            {
                try
                {
                    objectUrl = cfg.GetRemoteObjectUrl(defaultServer.ServerUrl, "RemotingTest");
                    IRemotingTest t = (IRemotingTest)Activator.GetObject(typeof(RemotingTest), objectUrl);
                    t.GetDate();

                    AppDomain.CurrentDomain.SetData(host.Name, defaultServer.ServerUrl);
                    WriteLog(host.Name, defaultServer.ServerUrl, true, "ok");
                }
                catch (Exception ex)
                {
                    WriteLog(host.Name, defaultServer.ServerUrl, false, ex.Message);
                }
            }

            string serverUrl = string.Empty;

            //遍历其他服务器,检查其状态
            foreach (KeyValuePair <string, RemotingServer> kvp in host.Servers)
            {
                serverUrl = kvp.Value.ServerUrl;

                if (serverUrl == usableServerUrl)
                {
                    continue;
                }
                if (serverUrl == defaultServer.ServerUrl)
                {
                    continue;
                }

                objectUrl = cfg.GetRemoteObjectUrl(serverUrl, "RemotingTest");

                try
                {
                    IRemotingTest t = (IRemotingTest)Activator.GetObject(typeof(RemotingTest), objectUrl);
                    t.GetDate();

                    if (flag)
                    {
                        AppDomain.CurrentDomain.SetData(host.Name, serverUrl);  //重设当前可用服务器
                        flag = false;
                        WriteLog(host.Name, serverUrl, true, "ok");
                    }

                    WriteLog(host.Name, serverUrl, false, "ok");
                }
                catch (Exception ex)
                {
                    WriteLog(host.Name, serverUrl, false, ex.Message);
                }
            }

            host.IsChecking = false;
        }