Exemplo n.º 1
0
        public static void Main(string[] args)
        {
            Channel channel = new Channel("127.0.0.1:50051", ChannelCredentials.Insecure);

            var client = new Greeter.GreeterClient(channel);

            String user    = "******";
            var    request = new HelloRequest {
                Name = user
            };
            var reply = client.SayHello(request);


            //var factResult = client.Factorial(new NumberRequset { Number = 4 });

            var factArrayResult = client.FactorialSequence(new NumberRequset {
                Number = 4
            });

            using (var call = client.RPNCalc())
            {
                var responseReaderTask = Task.Run(async() =>
                {
                    while (await call.ResponseStream.MoveNext())
                    {
                        Console.WriteLine($"Result: {call.ResponseStream.Current.Number}");
                    }
                });

                var requsetWriterTask = Task.Run(async() =>
                {
                    await call.RequestStream.WriteAsync(new CalculatorRequest {
                        Operation = CalculatorRequest.Types.Operation.Push, Value = 7
                    });
                    await call.RequestStream.WriteAsync(new CalculatorRequest {
                        Operation = CalculatorRequest.Types.Operation.Push, Value = 3
                    });
                    await call.RequestStream.WriteAsync(new CalculatorRequest {
                        Operation = CalculatorRequest.Types.Operation.Push, Value = 3
                    });
                    await call.RequestStream.WriteAsync(new CalculatorRequest {
                        Operation = CalculatorRequest.Types.Operation.Add
                    });
                    await call.RequestStream.WriteAsync(new CalculatorRequest {
                        Operation = CalculatorRequest.Types.Operation.Multiply
                    });
                });

                requsetWriterTask.Wait();
                responseReaderTask.Wait();
            }

            channel.ShutdownAsync().Wait();
            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }