public override async Task Execute(RecipeService.RecipeServiceClient client, IPrinter printer) { printer.PrintLine("which recipe would you like to see?"); var recipeSlug = _inputter.Read().ToLower(); var reply = await client.RequestRecipeAsync(new RecipeRequest { Slug = recipeSlug }); if (reply != null) { printer.PrintRecipe(reply); } else { printer.PrintLine($"recipe with name {recipeSlug} not found."); } }
public override async Task Execute(RecipeService.RecipeServiceClient client, IPrinter printer) { var cts = new CancellationTokenSource(TimeSpan.FromSeconds(10)); using var streamingCall = client.RequestAllRecipes(new Empty(), cancellationToken: cts.Token); try { await foreach (var recipe in streamingCall.ResponseStream.ReadAllAsync(cancellationToken: cts.Token)) { printer.PrintRecipe(recipe); } } catch (RpcException ex) when(ex.StatusCode == StatusCode.Cancelled) { printer.PrintLine("Stream cancelled."); } }
static async Task Main(string[] args) { InitializeApplication(); // The server address must match the address of the gRPC server. using var channel = GrpcChannel.ForAddress(_config["ServerAddress"]); var client = new RecipeService.RecipeServiceClient(channel); var exiting = false; while (!exiting) { _printer.PrintWelcomeNote(); var index = ReadUserInput(ref exiting); var requestHandlerStrategy = PickStrategy(index); await requestHandlerStrategy.Execute(client, _printer); } }
public virtual Task Execute(RecipeService.RecipeServiceClient client, IPrinter printer) { return(Task.CompletedTask); }