Пример #1
0
        /// <summary>
        /// Constructs the <see cref="IMessageTransport{T}"/> for a client
        /// </summary>
        /// <typeparam name="T"> The type of message to be transported </typeparam>
        /// <param name="clientId"> The client Id. </param>
        /// <returns> The message transport instance for the client </returns>
        public IMessageTransport <T> CreateClientTransport <T>(Guid clientId) where T : class
        {
            NamedPipeClient clientPipe;

            if (!this.clientPipes.TryGetValue(clientId, out clientPipe))
            {
                clientPipe = new NamedPipeClient(clientId.ToString(), this.dispatcher);
                this.clientPipes.Add(clientId, clientPipe);
                clientPipe.Start();
            }

            IDictionary <Type, object> cachedTransports;

            if (!this.clientTransports.TryGetValue(clientId, out cachedTransports))
            {
                cachedTransports = new Dictionary <Type, object>();
                this.clientTransports[clientId] = cachedTransports;
            }

            object cachedTransport;

            if (!cachedTransports.TryGetValue(typeof(T), out cachedTransport))
            {
                cachedTransport             = new ClientTransport <T>(clientPipe);
                cachedTransports[typeof(T)] = cachedTransport;
            }

            return((ClientTransport <T>)cachedTransport);
        }
Пример #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ClientTransport{T}"/> class.
 /// </summary>
 /// <param name="client"> The client. </param>
 public ClientTransport(NamedPipeClient client)
 {
     this.client = client;
     client.Router.AddMessageRouter <T>(this.HandleMessageReceived);
 }