Esempio n. 1
0
        /// <summary>
        /// 初始化服务器
        /// </summary>
        /// <param name="col"></param>
        private static string InitServer(ServerCollection col)
        {
            StringBuilder sb = new StringBuilder();
            bool          hasRegisterLocalServer = false;

            if (col != null && col.Count > 0)
            {
                IList <IServerInfo> serverList = ConfigHelper.GetServerInfoList(col);
                foreach (IServerInfo s in serverList)
                {
                    sb.Append(s);
                    ServerManager.Register(s);
                    //服务器如果是自己才注册通道和服务
                    if (IPHelper.IsLocalIP(s.Address))
                    {
                        if (s.IsProvideService)
                        {
                            ServerManager.RegisterServerChannel(s);
                            ServerManager.RegisterService(s);
                        }
                        else
                        {
                            ServerManager.RegisterClientChannel(s);
                        }
                        hasRegisterLocalServer = true;
                    }
                }
            }
            //如果没有注册本地服务,则在此注册
            if (!hasRegisterLocalServer)
            {
                ServerManager.RegisterClientChannel("tcp");
            }
            return(sb.ToString());
        }
Esempio n. 2
0
        public static IList <IServerInfo> GetServerInfoList(ServerCollection col)
        {
            IList <IServerInfo> list = null;

            if (col != null && col.Count > 0)
            {
                list = new List <IServerInfo>();
                foreach (ServerElement s in col)
                {
                    IServerInfo s3 = new ServerInfo(s.Code);
                    s3.Protocal             = s.Protocal;
                    s3.Address              = s.Address;
                    s3.Port                 = (short)s.Port;
                    s3.PerformanceValue     = (short)s.PerformanceValue;
                    s3.CreditValue          = (short)s.CreditValue;
                    s3.Timeout              = s.Timeout;
                    s3.ServerStatus         = (ServerStatus)Enum.Parse(typeof(ServerStatus), s.ServerStatus, false);
                    s3.IsProvideService     = s.IsProvideService == 1 ? true : false;
                    s3.IsDistributionServer = s.IsDistribution == 1 ? true : false;
                    list.Add(s3);
                }
            }
            return(list);
        }