Ejemplo n.º 1
0
        protected WcfServerChannel(string host, int port, ProtocolCode protocol)
            : this(protocol)
        {
            Assertions.NotNullOrEmpty(host, "host");
            if (port <= 1024 || port >= 65535)
            {
                throw new ArgumentException("port is only 1025 to 65534", "port");
            }

            _remoteAddress = string.Format("net.tcp://{0}:{1}/{2}", host, port, protocol.ToString().ToLower());
        }
Ejemplo n.º 2
0
        public IChannel GetChannel(string configurationNameOrIpAddress, ProtocolCode protocol)
        {
            if (Regex.IsMatch(configurationNameOrIpAddress, IpRegular))
            {
                var remoteUrl = string.Format("net.tcp://{0}/{1}", configurationNameOrIpAddress,
                                              protocol.ToString().ToLower());
                return(channelFactoryDict.AddOrUpdate(remoteUrl, CreateChannelFactoryByAddress, (url, original) =>
                {
                    if (original == null || original.State != CommunicationState.Opened)
                    {
                        CloseChannelFactory(original);
                        if (LogManager.Default.IsInfoEnabled)
                        {
                            LogManager.Default.InfoFormat(
                                "reconnect the disconnected channel factory, remotingAddress: {0}.", url);
                        }
                        return CreateChannelFactoryByAddress(url);
                    }
                    return original;
                }).CreateChannel());
            }

            return(channelFactoryDict.AddOrUpdate(configurationNameOrIpAddress, CreateChannelFactoryByConfig,
                                                  (name, original) =>
            {
                if (original == null || original.State != CommunicationState.Opened)
                {
                    CloseChannelFactory(original);
                    if (LogManager.Default.IsInfoEnabled)
                    {
                        LogManager.Default.InfoFormat(
                            "reconnect the disconnected channel factory, configurationName: {0}.", name);
                    }
                    return CreateChannelFactoryByConfig(name);
                }
                return original;
            }).CreateChannel());
        }
Ejemplo n.º 3
0
        //TODO: Thread safety
        /// <inheritdoc />
        public async Task RouteMessage(NetworkIncomingMessage <TPayloadType> message)
        {
            //Check the protocol coming in on the message
            ProtocolCode code = message.Payload.GetProtocol();

            if (!RoutingMap.ContainsKey(code))
            {
                throw new InvalidOperationException($"{GetType().FullName} does not contain a registered routing strategy for Protocol: {code.ToString()}.");
            }

            await RoutingMap[code].RouteMessage(message);
        }