Пример #1
0
        /// <summary>
        ///     根据KAE网络资源来构建一个网络宿主信道
        /// </summary>
        /// <param name="resource">KAE网络资源</param>
        /// <returns>返回构建后的宿主信道</returns>
        /// <exception cref="NotSupportedException">不支持的网络类型</exception>
        public static IHostTransportChannel BuildHostChannel(KAENetworkResource resource)
        {
            IHostTransportChannel channel;

            switch (resource.NetworkUri.NetworkType)
            {
            case NetworkTypes.TCP:
                channel = new TcpHostTransportChannel((((TcpUri)resource.NetworkUri).IsUseDynamicResource ? GetDynamicTCPPort() : ((TcpUri)resource.NetworkUri).Port));
                break;

            default: throw new NotSupportedException("#Sadly, current network type wasn't supported yet! #Network Type: " + resource.NetworkUri.NetworkType);
            }
            return(channel);
        }
Пример #2
0
        internal static void ChannelCreated(object sender, LightSingleArgEventArgs <ITransportChannel> e)
        {
            IHostTransportChannel hostChannel = (IHostTransportChannel)sender;
            KAENetworkResource    tag         = (KAENetworkResource)hostChannel.Tag;

            if (tag.Protocol == ProtocolTypes.Metadata)
            {
                IMessageTransportChannel <MetadataContainer> msgChannel = new MessageTransportChannel <MetadataContainer>((IRawTransportChannel)e.Target, (IProtocolStack)NetworkHelper.GetProtocolStack(tag.Protocol));
                MetadataConnectionAgent agent = new MetadataConnectionAgent(msgChannel, (MetadataTransactionManager)NetworkHelper.GetTransactionManager(tag.Protocol));
                agent.Disconnected   += AgentDisconnected;
                agent.NewTransaction += MetadataNewTransactionHandler;
                agent.Tag             = tag;
            }
            else if (tag.Protocol == ProtocolTypes.Intellegence)
            {
                IMessageTransportChannel <BaseMessage> msgChannel = new MessageTransportChannel <BaseMessage>((IRawTransportChannel)e.Target, (IProtocolStack)NetworkHelper.GetProtocolStack(tag.Protocol));
                IntellectObjectConnectionAgent         agent      = new IntellectObjectConnectionAgent(msgChannel, (MessageTransactionManager)NetworkHelper.GetTransactionManager(tag.Protocol));
                agent.Disconnected   += AgentDisconnected;
                agent.NewTransaction += IntellegenceNewTransactionHandler;
                agent.Tag             = tag;
            }
        }