Beispiel #1
0
        public DefaultProxyChannel(IClient client, IServerChannel srvChannel)
        {
            if (client == null)
            {
                throw new ArgumentNullException("client");
            }
            if (srvChannel == null)
            {
                throw new ArgumentNullException("srvChannel");
            }
            clientHandlers = new IChannelExtensions.ChannelHandlers
            {
                ErrorOccured     = errorOccuredHandler,
                ChannelClosed    = channelClosedHandler,
                ChannelReplaced  = client_ChannelReplaced,
                RequestSent      = client_RequestSent,
                ResponseReceived = client_ResponseReceived,
            };

            serverHandlers = new IChannelExtensions.ChannelHandlers
            {
                ErrorOccured    = errorOccuredHandler,
                ChannelClosed   = channelClosedHandler,
                ChannelReplaced = server_ChannelReplaced,
                RequestReceived = server_RequestReceived,
                ResponseSent    = server_ResponseSent,
            };
            Exception clientException        = null;
            EventHandler <Exception> handler = delegate(object sender, Exception e)
            {
                clientException = e;
            };

            client.ErrorOccured += handler;
            clientChannel        = client.Start();
            client.ErrorOccured -= handler;
            if (clientChannel != null)
            {
                clientChannel.BindAllEvents(clientHandlers);
                serverChannel = srvChannel;
                serverChannel.BindAllEvents(serverHandlers);
            }
            else
            {
                srvChannel.Close();
                if (clientException != null)
                {
                    throw clientException;
                }
                throw new DefaultProxyException("Unable to start a client channel.");
            }
        }