Ejemplo n.º 1
0
        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.");
            }
        }
Ejemplo n.º 2
0
        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.");
            }
        }
Ejemplo n.º 3
0
        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);
            }
        }
Ejemplo n.º 4
0
 public virtual Task Execute(RecipeService.RecipeServiceClient client, IPrinter printer)
 {
     return(Task.CompletedTask);
 }