diff options
Diffstat (limited to 'src/csharp/Grpc.Examples')
-rw-r--r-- | src/csharp/Grpc.Examples/Grpc.Examples.csproj | 3 | ||||
-rw-r--r-- | src/csharp/Grpc.Examples/MathExamples.cs | 40 | ||||
-rw-r--r-- | src/csharp/Grpc.Examples/MathGrpc.cs | 44 | ||||
-rw-r--r-- | src/csharp/Grpc.Examples/MathServiceImpl.cs | 4 | ||||
-rw-r--r-- | src/csharp/Grpc.Examples/packages.config | 1 |
5 files changed, 49 insertions, 43 deletions
diff --git a/src/csharp/Grpc.Examples/Grpc.Examples.csproj b/src/csharp/Grpc.Examples/Grpc.Examples.csproj index 2c5019c214..5ce490f403 100644 --- a/src/csharp/Grpc.Examples/Grpc.Examples.csproj +++ b/src/csharp/Grpc.Examples/Grpc.Examples.csproj @@ -35,6 +35,9 @@ <Reference Include="Google.ProtocolBuffers"> <HintPath>..\packages\Google.ProtocolBuffers.2.4.1.521\lib\net40\Google.ProtocolBuffers.dll</HintPath> </Reference> + <Reference Include="System.Interactive.Async"> + <HintPath>..\packages\Ix-Async.1.2.3\lib\net45\System.Interactive.Async.dll</HintPath> + </Reference> </ItemGroup> <ItemGroup> <Compile Include="Properties\AssemblyInfo.cs" /> diff --git a/src/csharp/Grpc.Examples/MathExamples.cs b/src/csharp/Grpc.Examples/MathExamples.cs index ab06a44c0d..d2cfbee18f 100644 --- a/src/csharp/Grpc.Examples/MathExamples.cs +++ b/src/csharp/Grpc.Examples/MathExamples.cs @@ -51,18 +51,13 @@ namespace math Console.WriteLine("DivAsync Result: " + result); } - 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); - } - 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)); + using (var call = stub.Fib(new FibArgs.Builder { Limit = 5 }.Build())) + { + List<Num> result = await call.ResponseStream.ToList(); + Console.WriteLine("Fib Result: " + string.Join("|", result)); + } } public static async Task SumExample(Math.IMathClient stub) @@ -74,9 +69,11 @@ namespace math new Num.Builder { Num_ = 3 }.Build() }; - var call = stub.Sum(); - await call.RequestStream.WriteAll(numbers); - Console.WriteLine("Sum Result: " + await call.Result); + using (var call = stub.Sum()) + { + await call.RequestStream.WriteAll(numbers); + Console.WriteLine("Sum Result: " + await call.Result); + } } public static async Task DivManyExample(Math.IMathClient stub) @@ -87,9 +84,11 @@ namespace math 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())); + using (var call = stub.DivMany()) + { + await call.RequestStream.WriteAll(divArgsList); + Console.WriteLine("DivMany Result: " + string.Join("|", await call.ResponseStream.ToList())); + } } public static async Task DependendRequestsExample(Math.IMathClient stub) @@ -101,9 +100,12 @@ namespace math new Num.Builder { Num_ = 3 }.Build() }; - var sumCall = stub.Sum(); - await sumCall.RequestStream.WriteAll(numbers); - Num sum = await sumCall.Result; + Num sum; + using (var sumCall = stub.Sum()) + { + await sumCall.RequestStream.WriteAll(numbers); + sum = await sumCall.Result; + } DivReply result = await stub.DivAsync(new DivArgs.Builder { Dividend = sum.Num_, Divisor = numbers.Count }.Build()); Console.WriteLine("Avg Result: " + result); diff --git a/src/csharp/Grpc.Examples/MathGrpc.cs b/src/csharp/Grpc.Examples/MathGrpc.cs index 2546fd220d..b9efc44e8c 100644 --- a/src/csharp/Grpc.Examples/MathGrpc.cs +++ b/src/csharp/Grpc.Examples/MathGrpc.cs @@ -12,30 +12,30 @@ namespace math { { static readonly string __ServiceName = "math.Math"; - static readonly Marshaller<DivArgs> __Marshaller_DivArgs = Marshallers.Create((arg) => arg.ToByteArray(), DivArgs.ParseFrom); - static readonly Marshaller<DivReply> __Marshaller_DivReply = Marshallers.Create((arg) => arg.ToByteArray(), DivReply.ParseFrom); - static readonly Marshaller<FibArgs> __Marshaller_FibArgs = Marshallers.Create((arg) => arg.ToByteArray(), FibArgs.ParseFrom); - static readonly Marshaller<Num> __Marshaller_Num = Marshallers.Create((arg) => arg.ToByteArray(), Num.ParseFrom); + static readonly Marshaller<global::math.DivArgs> __Marshaller_DivArgs = Marshallers.Create((arg) => arg.ToByteArray(), global::math.DivArgs.ParseFrom); + static readonly Marshaller<global::math.DivReply> __Marshaller_DivReply = Marshallers.Create((arg) => arg.ToByteArray(), global::math.DivReply.ParseFrom); + static readonly Marshaller<global::math.FibArgs> __Marshaller_FibArgs = Marshallers.Create((arg) => arg.ToByteArray(), global::math.FibArgs.ParseFrom); + static readonly Marshaller<global::math.Num> __Marshaller_Num = Marshallers.Create((arg) => arg.ToByteArray(), global::math.Num.ParseFrom); - static readonly Method<DivArgs, DivReply> __Method_Div = new Method<DivArgs, DivReply>( + static readonly Method<global::math.DivArgs, global::math.DivReply> __Method_Div = new Method<global::math.DivArgs, global::math.DivReply>( MethodType.Unary, "Div", __Marshaller_DivArgs, __Marshaller_DivReply); - static readonly Method<DivArgs, DivReply> __Method_DivMany = new Method<DivArgs, DivReply>( + static readonly Method<global::math.DivArgs, global::math.DivReply> __Method_DivMany = new Method<global::math.DivArgs, global::math.DivReply>( MethodType.DuplexStreaming, "DivMany", __Marshaller_DivArgs, __Marshaller_DivReply); - static readonly Method<FibArgs, Num> __Method_Fib = new Method<FibArgs, Num>( + static readonly Method<global::math.FibArgs, global::math.Num> __Method_Fib = new Method<global::math.FibArgs, global::math.Num>( MethodType.ServerStreaming, "Fib", __Marshaller_FibArgs, __Marshaller_Num); - static readonly Method<Num, Num> __Method_Sum = new Method<Num, Num>( + static readonly Method<global::math.Num, global::math.Num> __Method_Sum = new Method<global::math.Num, global::math.Num>( MethodType.ClientStreaming, "Sum", __Marshaller_Num, @@ -44,20 +44,20 @@ namespace math { // client-side stub interface public interface IMathClient { - DivReply Div(DivArgs request, CancellationToken token = default(CancellationToken)); - Task<DivReply> DivAsync(DivArgs request, CancellationToken token = default(CancellationToken)); - AsyncDuplexStreamingCall<DivArgs, DivReply> DivMany(CancellationToken token = default(CancellationToken)); - AsyncServerStreamingCall<Num> Fib(FibArgs request, CancellationToken token = default(CancellationToken)); - AsyncClientStreamingCall<Num, Num> Sum(CancellationToken token = default(CancellationToken)); + global::math.DivReply Div(global::math.DivArgs request, CancellationToken token = default(CancellationToken)); + Task<global::math.DivReply> DivAsync(global::math.DivArgs request, CancellationToken token = default(CancellationToken)); + AsyncDuplexStreamingCall<global::math.DivArgs, global::math.DivReply> DivMany(CancellationToken token = default(CancellationToken)); + AsyncServerStreamingCall<global::math.Num> Fib(global::math.FibArgs request, CancellationToken token = default(CancellationToken)); + AsyncClientStreamingCall<global::math.Num, global::math.Num> Sum(CancellationToken token = default(CancellationToken)); } // server-side interface public interface IMath { - Task<DivReply> Div(ServerCallContext context, DivArgs request); - Task DivMany(ServerCallContext context, IAsyncStreamReader<DivArgs> requestStream, IServerStreamWriter<DivReply> responseStream); - Task Fib(ServerCallContext context, FibArgs request, IServerStreamWriter<Num> responseStream); - Task<Num> Sum(ServerCallContext context, IAsyncStreamReader<Num> requestStream); + Task<global::math.DivReply> Div(ServerCallContext context, global::math.DivArgs request); + Task DivMany(ServerCallContext context, IAsyncStreamReader<global::math.DivArgs> requestStream, IServerStreamWriter<global::math.DivReply> responseStream); + Task Fib(ServerCallContext context, global::math.FibArgs request, IServerStreamWriter<global::math.Num> responseStream); + Task<global::math.Num> Sum(ServerCallContext context, IAsyncStreamReader<global::math.Num> requestStream); } // client stub @@ -69,27 +69,27 @@ namespace math { public MathClient(Channel channel, StubConfiguration config) : base(channel, config) { } - public DivReply Div(DivArgs request, CancellationToken token = default(CancellationToken)) + public global::math.DivReply Div(global::math.DivArgs request, CancellationToken token = default(CancellationToken)) { var call = CreateCall(__ServiceName, __Method_Div); return Calls.BlockingUnaryCall(call, request, token); } - public Task<DivReply> DivAsync(DivArgs request, CancellationToken token = default(CancellationToken)) + public Task<global::math.DivReply> DivAsync(global::math.DivArgs request, CancellationToken token = default(CancellationToken)) { var call = CreateCall(__ServiceName, __Method_Div); return Calls.AsyncUnaryCall(call, request, token); } - public AsyncDuplexStreamingCall<DivArgs, DivReply> DivMany(CancellationToken token = default(CancellationToken)) + public AsyncDuplexStreamingCall<global::math.DivArgs, global::math.DivReply> DivMany(CancellationToken token = default(CancellationToken)) { var call = CreateCall(__ServiceName, __Method_DivMany); return Calls.AsyncDuplexStreamingCall(call, token); } - public AsyncServerStreamingCall<Num> Fib(FibArgs request, CancellationToken token = default(CancellationToken)) + public AsyncServerStreamingCall<global::math.Num> Fib(global::math.FibArgs request, CancellationToken token = default(CancellationToken)) { var call = CreateCall(__ServiceName, __Method_Fib); return Calls.AsyncServerStreamingCall(call, request, token); } - public AsyncClientStreamingCall<Num, Num> Sum(CancellationToken token = default(CancellationToken)) + public AsyncClientStreamingCall<global::math.Num, global::math.Num> Sum(CancellationToken token = default(CancellationToken)) { var call = CreateCall(__ServiceName, __Method_Sum); return Calls.AsyncClientStreamingCall(call, token); diff --git a/src/csharp/Grpc.Examples/MathServiceImpl.cs b/src/csharp/Grpc.Examples/MathServiceImpl.cs index 3b33b09bbd..e247ac9d73 100644 --- a/src/csharp/Grpc.Examples/MathServiceImpl.cs +++ b/src/csharp/Grpc.Examples/MathServiceImpl.cs @@ -62,7 +62,7 @@ namespace math { foreach (var num in FibInternal(request.Limit)) { - await responseStream.Write(num); + await responseStream.WriteAsync(num); } } } @@ -81,7 +81,7 @@ namespace math { await requestStream.ForEach(async divArgs => { - await responseStream.Write(DivInternal(divArgs)); + await responseStream.WriteAsync(DivInternal(divArgs)); }); } diff --git a/src/csharp/Grpc.Examples/packages.config b/src/csharp/Grpc.Examples/packages.config index 51c17bcd5e..4c8d60fa62 100644 --- a/src/csharp/Grpc.Examples/packages.config +++ b/src/csharp/Grpc.Examples/packages.config @@ -1,5 +1,6 @@ <?xml version="1.0" encoding="utf-8"?> <packages> <package id="Google.ProtocolBuffers" version="2.4.1.521" targetFramework="net45" /> + <package id="Ix-Async" version="1.2.3" targetFramework="net45" /> <package id="NUnit" version="2.6.4" targetFramework="net45" /> </packages>
\ No newline at end of file |