示例#1
0
 public Client(INodeEndpointProtocolClient outerProtocol, ITranslatorProtocolHandlerFactory handlerFactory, TranslatorProtocolFactory factory)
     : base(factory)
 {
     this.clientHandler = handlerFactory.CreateClientHandler();
     SetOuterProtocol(outerProtocol);
     this.Handler = this.clientHandler;
     this.clientHandler.AttachClient(this);
 }
示例#2
0
 public void SetOuterProtocol(INodeEndpointProtocolClient protocol)
 {
     if (this.outerProtocol != null)
     {
         this.outerProtocol.OnInnerProtocolSet(null);
     }
     this.outerProtocol  = protocol;
     this.ParentProtocol = protocol;
     if (this.outerProtocol != null)
     {
         this.outerProtocol.OnInnerProtocolSet(this);
     }
 }
示例#3
0
 public void OnReceivedRequest(INodeEndpointProtocolRequest request)
 {
     if (!this.server.Connected)
     {
         if (this.client != null)
         {
             this.client.Disconnect();
         }
     }
     else
     {
         if (this.client == null)
         {
             string message = request.RequestMessage();
             if (message.StartsWith("[CONNECTENDPOINT]"))
             {
                 string endpointName = message.Substring(17);
                 INodeEndpointProtocolClient protocolClient = this.protocolFactory.CreateClient();
                 if (protocolClient.Connect("localhost/" + TcpShareProtocolFactory.GetInternalPipeAddress(port), endpointName, NodeEndpointProtocolFactoryExtension.DefaultTimeout))
                 {
                     this.client = protocolClient;
                     this.client.AddListener(new ResponseListener(this.server));
                     this.client.BeginListen();
                     request.Respond("[CONNECTED]");
                     return;
                 }
                 else
                 {
                     request.Respond("[CANNOTFINDENDPOINT]");
                 }
             }
             else
             {
                 request.Respond("[ENDPOINTNOTCONNECTED]");
             }
             this.server.Disconnect();
         }
         else if (this.client.Connected)
         {
             this.client.Send(request.Message);
         }
         else
         {
             this.server.Disconnect();
         }
     }
 }
示例#4
0
        private void ConnectionThreadProc(string address, string endpointName)
        {
            bool aborted = false;

            try
            {
                INodeEndpointProtocolClient client = this.Reflector.Factory.CreateClient();
                if (client.Connect(address, endpointName, 5000))
                {
                    this.protocolClient          = client;
                    this.clientProvider          = new ProtocolEnabledClientProvider();
                    this.clientProvider.Protocol = this.protocolClient;
                    this.protocolClient.BeginListen();
                }
            }
            catch (ThreadAbortException)
            {
                aborted = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Connecting Service");
            }

            if (!aborted)
            {
                this.Invoke(new MethodInvoker(() =>
                {
                    if (this.clientProvider == null)
                    {
                        labelConnectionState.Text = "Failed to connect.";
                        buttonConnect.Enabled     = true;
                    }
                    else
                    {
                        labelConnectionState.Text = "Connected to the service.";
                        buttonSend.Enabled        = true;
                    }
                    this.connectionThread = null;
                }));
            }
        }
        public static T WaitForClient <T>(
            this INodeEndpointProtocolFactory protocolFactory,
            string address,
            string endpointName,
            int timeout = DefaultTimeout
            )
            where T : INodeEndpointClient
        {
            INodeEndpointProtocolClient client = protocolFactory.CreateClient();

            if (client.Connect(address, endpointName, timeout))
            {
                INodeEndpointClientProvider provider = new ProtocolEnabledClientProvider();
                provider.Protocol = client;
                T endpointInterface = StrongTypedNodeEndpointClientBuilder.Create <T>(provider);
                client.BeginListen();
                return(endpointInterface);
            }
            else
            {
                return(default(T));
            }
        }
 public void AttachClient(INodeEndpointProtocolClient client)
 {
     this.client = client;
 }
示例#7
0
 public virtual void OnInnerProtocolSet(INodeEndpointProtocolClient protocol)
 {
     this.innerProtocol = protocol;
 }
示例#8
0
 public virtual void SetOuterProtocol(INodeEndpointProtocolClient protocol)
 {
     throw new InvalidOperationException("The protocol client cannot have a outer protocol.");
 }
示例#9
0
 public void AttachClient(INodeEndpointProtocolClient client)
 {
 }