Exemplo n.º 1
0
        public void Build()
        {
            _builder.Initialize(_marshallerFactory.Object, _callOptionsFactory);

            var actual = _builder.Build(_callInvoker.Object);

            var mock = actual.ShouldBeOfType <ClientMock>();

            mock.CallInvoker.ShouldBe(_callInvoker.Object);
            mock.Contract.MarshallerFactory.ShouldBe(_marshallerFactory.Object);
            mock.DefaultCallOptionsFactory.ShouldBe(_callOptionsFactory);
        }
        public static IClusterClientEx Run(this IClientBuilder clientBuilder)
        {
            if (clientBuilder == null)
            {
                throw new ArgumentNullException(nameof(clientBuilder));
            }

            ClusterClientWapper clusterClientWapper = new ClusterClientWapper();

            clientBuilder
            .AddClientInvokeCallback(clusterClientWapper.Callback)
            .AddClusterConnectionLostHandler(clusterClientWapper.Handler);
            clusterClientWapper.ClusterClient = clientBuilder.Build();
            clusterClientWapper.ClusterClient.Connect().GetAwaiter().GetResult();
            return(clusterClientWapper);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Builds and connects the client.
        /// </summary>
        /// <param name="builder">The <see cref="IClientBuilder"/>.</param>
        /// <returns>The <see cref="IClusterClient"/>.</returns>
        public static IClusterClient BuildAndConnect([NotNull] this IClientBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            var clusterClient = builder.Build();

            clusterClient
            .Connect(CreateRetryFilter())
            .ConfigureAwait(false)
            .GetAwaiter()
            .GetResult();

            return(clusterClient);
        }
Exemplo n.º 4
0
        private void EstablishConnection(IConnectionStub <TMessage, TKey> stub)
        {
            var client = clientBuilder.Build(stub);

            if (null == client)
            {
                return;
            }
            clientLock.EnterWriteLock();
            try
            {
                if (connectedClients.ContainsKey(client.ClientId))
                {
                    client.Close();
                    return;
                }
                connectedClients.Add(client.ClientId, client);
                client.Disconnected += ClientOnDisconnected;
                OnClientConnected(client.ClientId);
            }
            finally { clientLock.ExitWriteLock(); }
        }
Exemplo n.º 5
0
        public ClusterClientHostedService(IClientBuilder clientBuilder)
        {
            Client = clientBuilder.Build();

            logger.Debug("client:" + Client);
        }
        private IClusterClient BuilderClient(string name)
        {
            IClientBuilder builder = this.serviceProvider.GetRequiredServiceByName <IClientBuilder>(name);

            return(builder.Build());
        }