Esempio n. 1
0
        public async Task RunSample()
        {
            int from, to;

            do
            {
                Console.WriteLine("Enter min number");
                from = MoreConsole.ReadInt();
                Console.WriteLine();
                Console.WriteLine("Enter max number");
                to = MoreConsole.ReadInt();
                Console.WriteLine();

                if (from > to)
                {
                    Console.WriteLine("Max number must be greater than min");
                    Console.WriteLine();
                }
            }while (from > to);

            Console.WriteLine("Asking server...");

            CountRequest request = new() { From = from, To = to };

            using AsyncServerStreamingCall <CountResponse> serverResponse = client.Count(request);

            Console.WriteLine("Server responded: ");
            IAsyncEnumerable <CountResponse> responses = serverResponse.ResponseStream.ReadAllAsync();

            await foreach (CountResponse countResponse in responses)
            {
                Console.WriteLine($"Count: {countResponse.Current}");
            }
        }
    }
Esempio n. 2
0
        public async Task RunSample()
        {
            Console.WriteLine("Enter first number");
            int lhs = MoreConsole.ReadInt();

            Console.WriteLine();
            Console.WriteLine("Enter second number");
            int rhs = MoreConsole.ReadInt();

            Console.WriteLine();

            Console.WriteLine("Asking server...");

            AddNumbersRequest  request  = new() { Lhs = lhs, Rhs = rhs };
            AddNumbersResponse response = await client.AddNumbersAsync(request);

            Console.WriteLine("Server responded: ");
            Console.WriteLine($"{lhs} + {rhs} = {response.Result}");
        }
    }