Пример #1
0
        public static async Task DependendRequestsExample(Math.IMathClient client)
        {
            var numbers = new List <Num>
            {
                new Num.Builder {
                    Num_ = 1
                }.Build(),
                new Num.Builder {
                    Num_ = 2
                }.Build(),
                new Num.Builder {
                    Num_ = 3
                }.Build()
            };

            Num sum;

            using (var sumCall = client.Sum())
            {
                await sumCall.RequestStream.WriteAll(numbers);

                sum = await sumCall.Result;
            }

            DivReply result = await client.DivAsync(new DivArgs.Builder { Dividend = sum.Num_, Divisor = numbers.Count }.Build());

            Console.WriteLine("Avg Result: " + result);
        }
Пример #2
0
        public static void DivExample(Math.IMathClient client)
        {
            DivReply result = client.Div(new DivArgs.Builder {
                Dividend = 10, Divisor = 3
            }.Build());

            Console.WriteLine("Div Result: " + result);
        }
Пример #3
0
        public static async Task DivAsyncExample(Math.IMathClient client)
        {
            Task <DivReply> resultTask = client.DivAsync(new DivArgs.Builder {
                Dividend = 4, Divisor = 5
            }.Build());
            DivReply result = await resultTask;

            Console.WriteLine("DivAsync Result: " + result);
        }
Пример #4
0
        public static async Task DivAsyncWithCancellationExample(Math.IMathClient stub)
        {
            Task <DivReply> resultTask = stub.DivAsync(new DivArgs.Builder {
                Dividend = 4, Divisor = 5
            }.Build());
            DivReply result = await resultTask;

            Console.WriteLine(result);
        }
Пример #5
0
        public static async Task FibExample(Math.IMathClient stub)
        {
            var call = stub.Fib(new FibArgs.Builder {
                Limit = 5
            }.Build());
            List <Num> result = await call.ResponseStream.ToList();

            Console.WriteLine("Fib Result: " + string.Join("|", result));
        }
Пример #6
0
        public static async Task FibExample(Math.IMathClient client)
        {
            using (var call = client.Fib(new FibArgs {
                Limit = 5
            }))
            {
                List <Num> result = await call.ResponseStream.ToListAsync();

                Console.WriteLine("Fib Result: " + string.Join("|", result));
            }
        }
Пример #7
0
        public static async Task DivManyExample(Math.IMathClient stub)
        {
            var divArgsList = new List <DivArgs>
            {
                new DivArgs.Builder {
                    Dividend = 10, Divisor = 3
                }.Build(),
                new DivArgs.Builder {
                    Dividend = 100, Divisor = 21
                }.Build(),
                new DivArgs.Builder {
                    Dividend = 7, Divisor = 2
                }.Build()
            };
            var call = stub.DivMany();
            await call.RequestStream.WriteAll(divArgsList);

            Console.WriteLine("DivMany Result: " + string.Join("|", await call.ResponseStream.ToList()));
        }
Пример #8
0
        public static async Task SumExample(Math.IMathClient stub)
        {
            var numbers = new List <Num>
            {
                new Num.Builder {
                    Num_ = 1
                }.Build(),
                new Num.Builder {
                    Num_ = 2
                }.Build(),
                new Num.Builder {
                    Num_ = 3
                }.Build()
            };

            var call = stub.Sum();
            await call.RequestStream.WriteAll(numbers);

            Console.WriteLine("Sum Result: " + await call.Result);
        }
Пример #9
0
        public void Init()
        {
            GrpcEnvironment.Initialize();

            server = new Server();
            server.AddServiceDefinition(Math.BindService(new MathServiceImpl()));
            int port = server.AddListeningPort(host, Server.PickUnusedPort);

            server.Start();
            channel = new Channel(host, port);

            // TODO(jtattermusch): get rid of the custom header here once we have dedicated tests
            // for header support.
            var stubConfig = new StubConfiguration((headerBuilder) =>
            {
                headerBuilder.Add(new Metadata.MetadataEntry("customHeader", "abcdef"));
            });

            client = Math.NewStub(channel, stubConfig);
        }
Пример #10
0
        public static async Task DivManyExample(Math.IMathClient client)
        {
            var divArgsList = new List <DivArgs>
            {
                new DivArgs {
                    Dividend = 10, Divisor = 3
                },
                new DivArgs {
                    Dividend = 100, Divisor = 21
                },
                new DivArgs {
                    Dividend = 7, Divisor = 2
                }
            };

            using (var call = client.DivMany())
            {
                await call.RequestStream.WriteAllAsync(divArgsList);

                Console.WriteLine("DivMany Result: " + string.Join("|", await call.ResponseStream.ToListAsync()));
            }
        }
Пример #11
0
        public static async Task SumExample(Math.IMathClient client)
        {
            var numbers = new List <Num>
            {
                new Num {
                    Num_ = 1
                },
                new Num {
                    Num_ = 2
                },
                new Num {
                    Num_ = 3
                }
            };

            using (var call = client.Sum())
            {
                await call.RequestStream.WriteAllAsync(numbers);

                Console.WriteLine("Sum Result: " + await call.ResponseAsync);
            }
        }
Пример #12
0
        public static async Task DivAsyncExample(Math.IMathClient client)
        {
            DivReply result = await client.DivAsync(new DivArgs { Dividend = 4, Divisor = 5 });

            Console.WriteLine("DivAsync Result: " + result);
        }
Пример #13
0
        public void Init()
        {
            GrpcEnvironment.Initialize();

            server = new Server();
            server.AddServiceDefinition(Math.BindService(new MathServiceImpl()));
            int port = server.AddListeningPort(host, Server.PickUnusedPort);
            server.Start();
            channel = new Channel(host + ":" + port);

            // TODO(jtattermusch): get rid of the custom header here once we have dedicated tests
            // for header support.
            var stubConfig = new StubConfiguration((headerBuilder) =>
            {
                headerBuilder.Add(new Metadata.MetadataEntry("customHeader", "abcdef"));
            });
            client = Math.NewStub(channel, stubConfig);
        }