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); }
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); }
private void deattachServer() { if (channel != null) { channel.ShutdownAsync(); } }
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(); }
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); } }
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(); } }
public override async Task TeardownAsync(WorkloadContext context) { await client.DisposeAsync(); await channel.ShutdownAsync(); channel.Dispose(); }
static void Main(string[] args) { channel = GrpcChannel.ForAddress("https://localhost:5001"); client = new StarSignService.StarSignServiceClient(channel); RunZodiacMenu(); channel.ShutdownAsync(); }
public async ValueTask DisposeAsync() { await notifyClient.DisposeAsync(); await channel.ShutdownAsync(); channel.Dispose(); }
public async void Dispose() { _client = null; await _channel.ShutdownAsync(); _channel = null; _runningJobs?.Clear(); _runningJobs = default; }
public void Dispose() { _holdingLineRequest?.Dispose(); _channel?.ShutdownAsync().Wait(TimeSpan.FromSeconds(5)); _channel?.Dispose(); StartStreamCallback = default; StopStreamCallback = default; CloseApplicationCallback = default; }
internal void DropRef() { lock (this) { refs--; if (refs == 0) { channel.ShutdownAsync().Wait(); } } }
public void Dispose() { if (_channel is null) { return; } try { _channel.ShutdownAsync().GetAwaiter().GetResult(); } catch { // Ignored } }
public async Task ShutdowmAsync() { try { await GrpcChannel.ShutdownAsync(); } catch (Exception e) { _logger.Debug($"Grpc channel shutdown fail. {e.Message}"); } finally { State = GrpcConnectionState.Shutdown; } }
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; } }
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); }
public void Dispose() { _channel.ShutdownAsync().ConfigureAwait(false).GetAwaiter().GetResult(); }
public async Task CloseAsync() { _logger.LogInformation("Closing gRPC channel..."); await _channel.ShutdownAsync(); }
public void Dispose() { _grpcChannel.ShutdownAsync(); _grpcChannel.Dispose(); }
/// <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); }
private async void OnStopping() { _timer?.Change(Timeout.Infinite, 0); await _channel?.ShutdownAsync(); }
public Task Stop() { _cts?.Cancel(); return(channel.ShutdownAsync()); }
public void Dispose() { channel.ShutdownAsync().Wait(); channel.Dispose(); }