コード例 #1
0
ファイル: NodeClientBuilder.cs プロジェクト: mengtest/XNode
        private void BuildConfig()
        {
            CheckIsBuild();

            if (connectionInfos == null)
            {
                throw new InvalidOperationException("Connections is not config.");
            }

            if (serializer == null)
            {
                throw new InvalidOperationException("Serializer is not config.");
            }

            if (communicationFactory == null)
            {
                throw new InvalidOperationException("CommunicationFactory is not config.");
            }

            if (protocolStackFactory == null)
            {
                protocolStackFactory = new DefaultProtocolStackFactory();
            }

            if (loginHandler == null)
            {
                loginHandler = new DefaultLoginHandler(null, serializer, LoggerManager.ClientLoggerFactory);
            }

            if (passiveClosedStrategy == null)
            {
                passiveClosedStrategy = new DefaultPassiveClosedStrategy(new DefaultPassiveClosedStrategyConfig(), LoggerManager.ClientLoggerFactory);
            }
        }
コード例 #2
0
ファイル: NodeClientBuilder.cs プロジェクト: mengtest/XNode
        /// <summary>
        /// 配置协议工厂
        /// </summary>
        /// <param name="protocolStackFactory">协议工厂</param>
        /// <returns></returns>
        public INodeClientBuilder ConfigProtocolStackFactory(IProtocolStackFactory protocolStackFactory)
        {
            CheckIsBuild();

            this.protocolStackFactory = protocolStackFactory;

            return(this);
        }
コード例 #3
0
ファイル: NodeServerBuilder.cs プロジェクト: mengtest/XNode
        /// <summary>
        /// 配置协议栈工厂
        /// </summary>
        /// <param name="factory"></param>
        /// <returns></returns>
        public INodeServerBuilder ConfigProtocolStackFactory(IProtocolStackFactory factory)
        {
            CheckIsBuild();

            config.ProtocolStackFactory = factory;

            return(this);
        }
コード例 #4
0
ファイル: DefaultNodeServer.cs プロジェクト: mengtest/XNode
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="config">NodeServer配置</param>
 public DefaultNodeServer(NodeServerConfig config)
 {
     ValidateConfig(config);
     logger = LoggerManager.ServerLoggerFactory.CreateLogger <DefaultNodeServer>();
     server = config.Communication;
     protocolStackFactory = config.ProtocolStackFactory;
     serviceProvider      = config.ServiceProvider;
     RouteManager         = config.RouteFactory.CreateRouteManager();
     routeDescriptor      = config.RouteFactory.CreateRouteDescriptor();
     if (config.ServiceConfigs != null)
     {
         routeDescriptor.SetServiceConfig(config.ServiceConfigs);
     }
     serializer       = config.Serializer;
     serviceInvoker   = config.ServiceInvoker;
     serviceProcessor = config.ServiceProcessor;
     loginValidator   = config.LoginValidator;
     this.config      = config ?? throw new InvalidOperationException("Argument config is null.");
 }
コード例 #5
0
        /// <summary>
        /// 创建NodeClientParameters实例
        /// </summary>
        /// <param name="connectionInfoList">连接信息</param>
        /// <param name="serializer">序列化器实例</param>
        /// <param name="communicationFactory">底层客户端通信组件工厂</param>
        /// <param name="loginHandler">登录处理器</param>
        /// <param name="protocolStackFactory">协议栈工厂实例</param>
        /// <param name="passiveClosedStrategy">客户端被动关闭处理策略</param>
        /// <returns></returns>
        public static IList <NodeClientParameters> Create(IList <ConnectionInfo> connectionInfoList, ISerializer serializer, Func <ConnectionInfo, IClient> communicationFactory, ILoginHandler loginHandler = null, IProtocolStackFactory protocolStackFactory = null, IPassiveClosedStrategy passiveClosedStrategy = null)
        {
            var list = new List <NodeClientParameters>();

            foreach (var connectionInfo in connectionInfoList)
            {
                var item = new NodeClientParameters()
                {
                    Host                  = connectionInfo.Host,
                    Port                  = connectionInfo.Port,
                    LocalHost             = connectionInfo.LocalHost,
                    LocalPort             = connectionInfo.LocalPort,
                    Serializer            = serializer,
                    ProtocolStackFactory  = protocolStackFactory,
                    LoginHandler          = loginHandler,
                    PassiveClosedStrategy = passiveClosedStrategy,
                    Communication         = communicationFactory(connectionInfo)
                };
                list.Add(item);
            }
            return(list);
        }
コード例 #6
0
        /// <summary>
        /// 创建异常ServiceProcessResult
        /// </summary>
        /// <param name="exceptionId">异常Id</param>
        /// <param name="exceptionMessage">异常信息</param>
        /// <param name="protocolStackFactory">协议栈工厂</param>
        /// <returns></returns>
        public static ServiceProcessResult CreateExceptionResult(int exceptionId, string exceptionMessage, IProtocolStackFactory protocolStackFactory)
        {
            var response = protocolStackFactory.CreateServiceResponse();
            var result   = new ServiceProcessResult()
            {
                ServiceResponse = response
            };

            response.HasException     = true;
            response.ExceptionId      = exceptionId;
            response.ExceptionMessage = exceptionMessage;
            return(result);
        }
コード例 #7
0
 /// <summary>
 /// 创建异常ServiceProcessResult
 /// </summary>
 /// <param name="exceptionId">异常Id</param>
 /// <param name="protocolStackFactory">协议栈工厂</param>
 /// <returns></returns>
 public static ServiceProcessResult CreateSystemExceptionResult(int exceptionId, IProtocolStackFactory protocolStackFactory)
 {
     return(CreateExceptionResult(exceptionId, ExceptionMap.SystemExceptions[exceptionId], protocolStackFactory));
 }