예제 #1
0
        /// <summary>
        /// Remoting服务器测试
        /// </summary>
        /// <param name="serverUrl">Remoting服务器地址 (比如:tcp://127.0.0.1:8888)</param>
        /// <returns>Remoting服务器时间</returns>
        public string RemotingServerTest(string serverUrl)
        {
            IRemotingTest t = RemotingClientUtil <IRemotingTest> .Instance.GetWellKnownClientInstance(serverUrl.TrimEnd('/') + "/RemotingTest");

            return(t.GetDate());
        }
예제 #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;
        }