OLD | NEW |
(Empty) | |
| 1 #region Copyright notice and license |
| 2 // Copyright 2015, Google Inc. |
| 3 // All rights reserved. |
| 4 // |
| 5 // Redistribution and use in source and binary forms, with or without |
| 6 // modification, are permitted provided that the following conditions are |
| 7 // met: |
| 8 // |
| 9 // * Redistributions of source code must retain the above copyright |
| 10 // notice, this list of conditions and the following disclaimer. |
| 11 // * Redistributions in binary form must reproduce the above |
| 12 // copyright notice, this list of conditions and the following disclaimer |
| 13 // in the documentation and/or other materials provided with the |
| 14 // distribution. |
| 15 // * Neither the name of Google Inc. nor the names of its |
| 16 // contributors may be used to endorse or promote products derived from |
| 17 // this software without specific prior written permission. |
| 18 // |
| 19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 20 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 #endregion |
| 31 |
| 32 using System; |
| 33 using System.Collections.Generic; |
| 34 using System.Threading.Tasks; |
| 35 using Grpc.Core.Utils; |
| 36 |
| 37 namespace Math |
| 38 { |
| 39 public static class MathExamples |
| 40 { |
| 41 public static void DivExample(Math.IMathClient client) |
| 42 { |
| 43 DivReply result = client.Div(new DivArgs { Dividend = 10, Divisor =
3 }); |
| 44 Console.WriteLine("Div Result: " + result); |
| 45 } |
| 46 |
| 47 public static async Task DivAsyncExample(Math.IMathClient client) |
| 48 { |
| 49 DivReply result = await client.DivAsync(new DivArgs { Dividend = 4,
Divisor = 5 }); |
| 50 Console.WriteLine("DivAsync Result: " + result); |
| 51 } |
| 52 |
| 53 public static async Task FibExample(Math.IMathClient client) |
| 54 { |
| 55 using (var call = client.Fib(new FibArgs { Limit = 5 })) |
| 56 { |
| 57 List<Num> result = await call.ResponseStream.ToListAsync(); |
| 58 Console.WriteLine("Fib Result: " + string.Join("|", result)); |
| 59 } |
| 60 } |
| 61 |
| 62 public static async Task SumExample(Math.IMathClient client) |
| 63 { |
| 64 var numbers = new List<Num> |
| 65 { |
| 66 new Num { Num_ = 1 }, |
| 67 new Num { Num_ = 2 }, |
| 68 new Num { Num_ = 3 } |
| 69 }; |
| 70 |
| 71 using (var call = client.Sum()) |
| 72 { |
| 73 await call.RequestStream.WriteAllAsync(numbers); |
| 74 Console.WriteLine("Sum Result: " + await call.ResponseAsync); |
| 75 } |
| 76 } |
| 77 |
| 78 public static async Task DivManyExample(Math.IMathClient client) |
| 79 { |
| 80 var divArgsList = new List<DivArgs> |
| 81 { |
| 82 new DivArgs { Dividend = 10, Divisor = 3 }, |
| 83 new DivArgs { Dividend = 100, Divisor = 21 }, |
| 84 new DivArgs { Dividend = 7, Divisor = 2 } |
| 85 }; |
| 86 using (var call = client.DivMany()) |
| 87 { |
| 88 await call.RequestStream.WriteAllAsync(divArgsList); |
| 89 Console.WriteLine("DivMany Result: " + string.Join("|", await ca
ll.ResponseStream.ToListAsync())); |
| 90 } |
| 91 } |
| 92 |
| 93 public static async Task DependendRequestsExample(Math.IMathClient clien
t) |
| 94 { |
| 95 var numbers = new List<Num> |
| 96 { |
| 97 new Num { Num_ = 1 }, |
| 98 new Num { Num_ = 2 }, |
| 99 new Num { Num_ = 3 } |
| 100 }; |
| 101 |
| 102 Num sum; |
| 103 using (var sumCall = client.Sum()) |
| 104 { |
| 105 await sumCall.RequestStream.WriteAllAsync(numbers); |
| 106 sum = await sumCall.ResponseAsync; |
| 107 } |
| 108 |
| 109 DivReply result = await client.DivAsync(new DivArgs { Dividend = sum
.Num_, Divisor = numbers.Count }); |
| 110 Console.WriteLine("Avg Result: " + result); |
| 111 } |
| 112 } |
| 113 } |
OLD | NEW |