Exemplo n.º 1
0
        /// <summary>
        /// Builds an <see cref="IBlipClient" /> with the configured parameters
        /// </summary>
        public IBlipClient Build()
        {
            var channelBuilder = ClientChannelBuilder
                                 .Create(() => _transportFactory.Create(EndPoint), EndPoint)
                                 .WithSendTimeout(SendTimeout)
                                 .WithEnvelopeBufferSize(100)
                                 .AddCommandModule(c => new ReplyPingChannelModule(c))
                                 .AddBuiltHandler(
                (c, t) =>
            {
                if (Throughput > 0)
                {
                    ThroughputControlChannelModule.CreateAndRegister(c, Throughput);
                }
                return(Task.CompletedTask);
            });

            var establishedClientChannelBuilder = new EstablishedClientChannelBuilder(channelBuilder)
                                                  .WithIdentity(Identity)
                                                  .WithAuthentication(GetAuthenticationScheme())
                                                  .WithCompression(Compression)
                                                  .WithEncryption(Encryption)
                                                  .AddEstablishedHandler(SetPresenceAsync)
                                                  .AddEstablishedHandler(SetReceiptAsync);

            if (Instance != null)
            {
                establishedClientChannelBuilder = establishedClientChannelBuilder.WithInstance(Instance);
            }

            var onDemandClientChannel = CreateOnDemandClientChannel(establishedClientChannelBuilder);

            return(new BlipClient(onDemandClientChannel, _logger));
        }
        /// <summary>
        /// Builds a <see cref="IMessagingHubConnection">connection</see> with the configured parameters
        /// </summary>
        /// <returns>An inactive connection with the Messaging Hub. Call <see cref="IMessagingHubConnection.ConnectAsync"/> to activate it</returns>
        public IMessagingHubConnection Build()
        {
            var channelBuilder = ClientChannelBuilder.Create(() => _transportFactory.Create(EndPoint), EndPoint)
                                 .WithSendTimeout(SendTimeout)
                                 .WithEnvelopeBufferSize(ChannelBuffer)
                                 .AddCommandModule(c => new ReplyPingChannelModule(c));

            channelBuilder =
                channelBuilder
                .AddBuiltHandler(
                    (c, t) =>
            {
                if (Throughput > 0)
                {
                    ThroughputControlChannelModule.CreateAndRegister(c, Throughput);
                }

                return(Task.CompletedTask);
            })
                .AddBuiltHandler(
                    (c, t) =>
            {
                if (ChannelCount > 1)
                {
                    FillEnvelopeRecipientsChannelModule.CreateAndRegister(c);
                }

                return(Task.CompletedTask);
            });


            var establishedClientChannelBuilder = new EstablishedClientChannelBuilder(channelBuilder)
                                                  .WithIdentity(Identity)
                                                  .WithAuthentication(GetAuthenticationScheme())
                                                  .WithCompression(Compression)
                                                  .AddEstablishedHandler(SetPresenceAsync)
                                                  .AddEstablishedHandler(SetReceiptAsync)
                                                  .WithEncryption(Encryption);

            if (Instance != null)
            {
                establishedClientChannelBuilder = establishedClientChannelBuilder.WithInstance(Instance);
            }

            var onDemandClientChannelFactory = new OnDemandClientChannelFactory(establishedClientChannelBuilder);

            return(new MessagingHubConnection(SendTimeout, MaxConnectionRetries, onDemandClientChannelFactory, ChannelCount));
        }