예제 #1
0
        public async Task <bool> Disconnect()
        {
            try
            {
                //start timmer for connect to server
                _timer.Enabled = false;
                if (_connectionStatus == ConnectionStatusEnum.Connected)
                {
                    var response = _coreComClient.ClientDisconnectFromServer(new DisconnectFromServerRequest
                    {
                        ClientId = _coreComOptions.ClientId
                    }, GetCallOptions(false));
                    //log disconnected
                    LogEventOccurred(new LogEvent {
                        ClientId = _coreComOptions.ClientId, Description = response.Response
                    });
                }

                _coreComClient = null;
                await _channel.ShutdownAsync();
            }
            catch (Exception ex)
            {
                LogErrorOccurred(ex, new CoreComMessageResponse {
                    ClientId = _coreComOptions.ClientId
                });
            }
            finally
            {
                ConnectionStatusChange(ConnectionStatusEnum.Disconnected);
            }

            return(true);
        }
예제 #2
0
        public Task StopAsync(CancellationToken stoppingToken)
        {
            _logger.LogInformation("Timed Hosted Service is stopping.");

            _timer?.Change(Timeout.Infinite, 0);
            _metricsUpdateChannel?.RequestStream.CompleteAsync().ConfigureAwait(false).GetAwaiter().GetResult();
            _heatbeatChannel?.RequestStream.CompleteAsync().ConfigureAwait(false).GetAwaiter().GetResult();
            _channel.ShutdownAsync().ConfigureAwait(false).GetAwaiter().GetResult();

            return(Task.CompletedTask);
        }
예제 #3
0
 private void deattachServer()
 {
     if (channel != null)
     {
         channel.ShutdownAsync();
     }
 }
예제 #4
0
        public void EstablishChannel(string serverId)
        {
            Console.ForegroundColor = ConsoleColor.DarkGray;

            if (serverId != this.ServerId)
            {
                try {
                    Console.Write($"Establishing channel with server {serverId}... ");
                    if (_channel != null)
                    {
                        _channel.ShutdownAsync().Wait();
                    }
                    _channel      = GrpcChannel.ForAddress(_servers[serverId]);
                    _client       = new Giga.GigaClient(_channel);
                    this.ServerId = serverId;
                    Console.WriteLine("Established.");
                }
                catch (Exception e) {
                    Console.WriteLine("Failed.");
                    Console.ResetColor();
                    throw e; // rethrow exception
                }
            }

            Console.ResetColor();
        }
예제 #5
0
    protected override async Task ExecuteAsync(CancellationToken stoppingToken)
    {
        while (!stoppingToken.IsCancellationRequested)
        {
            try
            {
                GrpcChannel channel = GrpcChannel.ForAddress("https://localhost:5001");
                OrdersManager.OrdersManagerClient client = new OrdersManager.OrdersManagerClient(channel);

                NewOrderReply result = await client.GetNewOrderAsync(new NewOrderRequest());

                if (result.OrderId != 0)
                {
                    logger.LogInformation($"Processing order id {result.OrderId}");
                    await client.UpdateOrderAsync(new UpdateOrderRequest
                    {
                        OrderId = result.OrderId,
                        Status  = "Processed by .NET"
                    });
                }
                else
                {
                    logger.LogInformation($"No pending orders at {DateTimeOffset.Now}");
                }

                await channel.ShutdownAsync();
            }
            catch (Exception ex)
            {
                logger.LogError($"{ex.Message}\n{ex.StackTrace}");
            }

            await Task.Delay(3000, stoppingToken);
        }
    }
예제 #6
0
        static void TestGrpc()
        {
            try
            {
                GrpcChannel channel = GrpcChannel.ForAddress("https://localhost:5001");

                var client = new AccountsService.AccountsServiceClient(channel);

                var reply = client.CreateAccountAsync(
                    new AccountModel
                {
                    FirstName = "Christian",
                    LastName  = "Di Costanzo"
                }).GetAwaiter().GetResult();

                Console.WriteLine("New Account: " + reply.AccountId);

                channel.ShutdownAsync().Wait();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                Console.ReadKey();
            }
        }
예제 #7
0
        public override async Task TeardownAsync(WorkloadContext context)
        {
            await client.DisposeAsync();

            await channel.ShutdownAsync();

            channel.Dispose();
        }
예제 #8
0
        static void Main(string[] args)
        {
            channel = GrpcChannel.ForAddress("https://localhost:5001");
            client  = new StarSignService.StarSignServiceClient(channel);
            RunZodiacMenu();

            channel.ShutdownAsync();
        }
예제 #9
0
파일: Class1.cs 프로젝트: ikihiki/TodoTree
        public async ValueTask DisposeAsync()
        {
            await notifyClient.DisposeAsync();

            await channel.ShutdownAsync();

            channel.Dispose();
        }
예제 #10
0
        public async void Dispose()
        {
            _client = null;
            await _channel.ShutdownAsync();

            _channel = null;
            _runningJobs?.Clear();
            _runningJobs = default;
        }
예제 #11
0
        public void Dispose()
        {
            _holdingLineRequest?.Dispose();
            _channel?.ShutdownAsync().Wait(TimeSpan.FromSeconds(5));
            _channel?.Dispose();

            StartStreamCallback      = default;
            StopStreamCallback       = default;
            CloseApplicationCallback = default;
        }
예제 #12
0
 internal void DropRef()
 {
     lock (this) {
         refs--;
         if (refs == 0)
         {
             channel.ShutdownAsync().Wait();
         }
     }
 }
예제 #13
0
 public void Dispose()
 {
     if (_channel is null)
     {
         return;
     }
     try
     {
         _channel.ShutdownAsync().GetAwaiter().GetResult();
     }
     catch
     {
         // Ignored
     }
 }
예제 #14
0
 public async Task ShutdowmAsync()
 {
     try
     {
         await GrpcChannel.ShutdownAsync();
     }
     catch (Exception e)
     {
         _logger.Debug($"Grpc channel shutdown fail. {e.Message}");
     }
     finally
     {
         State = GrpcConnectionState.Shutdown;
     }
 }
예제 #15
0
        public async Task ShutdownAsync()
        {
            try
            {
                await _channel?.ShutdownAsync();

                _logger.Information($"Shutdown connection[{_channel.Target}].");
            }
            catch (Exception e)
            {
                _logger.Error($"Shutdown connection fail.", e);
            }
            finally
            {
                _state = ConnectionState.Failure;
            }
        }
예제 #16
0
        public static async Task Main(string[] args)
        {
            GrpcChannel             channel = null;
            CancellationTokenSource cts     = new CancellationTokenSource();

            var builder = WebAssemblyHostBuilder.CreateDefault(args);

            builder.RootComponents.Add <App>("app");

            builder.Services.AddSingleton <IDialogService, DialogServiceImplementation>();
            builder.Services.AddSingleton <IDialogServiceExt>(services => services.GetService <IDialogService>() as DialogServiceImplementation);

            builder.Services.AddSingleton <IWebSocketHandler, ClientWebSocketHandler>();

            builder.Services.AddSingleton(services =>
            {
                var httpHandler = new GrpcWebHandler(GrpcWebMode.GrpcWebText, new HttpClientHandler());

                channel = GrpcChannel.ForAddress("http://localhost:50080/", new GrpcChannelOptions {
                    HttpHandler = httpHandler
                });

                return(new AdminAccess.AdminAccessClient(channel));
            });

            builder.Services.AddTransient <IMainViewModel, MainViewModel>();
            builder.Services.AddTransient <CreateUserViewModel>();
            builder.Services.AddTransient <UsersListViewModel>();
            builder.Services.AddTransient <QueueViewModel>();
            builder.Services.AddTransient <ItemsViewModel>();



            await using WebAssemblyHost host = builder.Build();

            _ = (host.Services.GetService <IWebSocketHandler>() as ClientWebSocketHandler).RunAsync(cts.Token);
            await host.RunAsync();

            await channel?.ShutdownAsync();

            cts.Cancel();
        }
        private void InitializeSensorsClient(string sensorsUrl, X509Certificate2 clientCertificate)
        {
            if (_channel != null)
            {
                _channel.ShutdownAsync();
                _channel.Dispose();
                _channel = null;
            }

            var handler = CreateHandler(sensorsUrl, clientCertificate);

            _channel = GrpcChannel.ForAddress(sensorsUrl, new GrpcChannelOptions()
            {
                HttpHandler           = handler,
                MaxReceiveMessageSize = 40 * 1024 * 1024,
                MaxSendMessageSize    = 40 * 1024 * 1024,
            });

            _sensorsClient = new Sensors.SensorsClient(_channel);
        }
예제 #18
0
 public void Dispose()
 {
     _channel.ShutdownAsync().ConfigureAwait(false).GetAwaiter().GetResult();
 }
예제 #19
0
 public async Task CloseAsync()
 {
     _logger.LogInformation("Closing gRPC channel...");
     await _channel.ShutdownAsync();
 }
예제 #20
0
 public void Dispose()
 {
     _grpcChannel.ShutdownAsync();
     _grpcChannel.Dispose();
 }
예제 #21
0
        /// <inheritdoc />
        public async void Dispose()
        {
            await m_channel.ShutdownAsync().ConfigureAwait(false);

            m_channel.Dispose();
        }
 public Task StopAsync(CancellationToken cancellationToken)
 {
     _channel?.ShutdownAsync();
     _timer?.Dispose();
     return(Task.CompletedTask);
 }
예제 #23
0
 private async void OnStopping()
 {
     _timer?.Change(Timeout.Infinite, 0);
     await _channel?.ShutdownAsync();
 }
 public Task Stop()
 {
     _cts?.Cancel();
     return(channel.ShutdownAsync());
 }
예제 #25
0
 public void Dispose()
 {
     channel.ShutdownAsync().Wait();
     channel.Dispose();
 }