aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/csharp/Grpc.Examples
diff options
context:
space:
mode:
authorGravatar Craig Tiller <craig.tiller@gmail.com>2015-05-24 15:58:14 -0700
committerGravatar Craig Tiller <craig.tiller@gmail.com>2015-05-24 15:58:14 -0700
commit8b5276c02ec7aebdf749bfd95d140406e6ea2226 (patch)
tree8389493193029a3cb5c80b11f595bc9d4d5035d7 /src/csharp/Grpc.Examples
parent24d115654056aa2be3d548d80ea97937eb15b2a1 (diff)
parent031dea1df4b6213b9f9779a824fccc6d348b8648 (diff)
Merge github.com:grpc/grpc into we-dont-need-no-backup
Conflicts: src/core/surface/call.c test/core/end2end/dualstack_socket_test.c test/core/end2end/tests/early_server_shutdown_finishes_inflight_calls.c test/core/end2end/tests/early_server_shutdown_finishes_tags.c test/core/end2end/tests/graceful_server_shutdown.c test/core/end2end/tests/invoke_large_request.c test/core/end2end/tests/max_concurrent_streams.c test/core/end2end/tests/max_message_length.c test/core/end2end/tests/request_response_with_binary_metadata_and_payload.c test/core/end2end/tests/request_response_with_metadata_and_payload.c test/core/end2end/tests/request_response_with_payload.c test/core/end2end/tests/request_response_with_payload_and_call_creds.c test/core/end2end/tests/request_response_with_trailing_metadata_and_payload.c test/core/end2end/tests/request_with_large_metadata.c test/core/end2end/tests/request_with_payload.c test/core/httpcli/httpcli_test.c tools/run_tests/run_tests.py
Diffstat (limited to 'src/csharp/Grpc.Examples')
-rw-r--r--src/csharp/Grpc.Examples/Grpc.Examples.csproj3
-rw-r--r--src/csharp/Grpc.Examples/MathExamples.cs40
-rw-r--r--src/csharp/Grpc.Examples/MathGrpc.cs44
-rw-r--r--src/csharp/Grpc.Examples/MathServiceImpl.cs4
-rw-r--r--src/csharp/Grpc.Examples/packages.config1
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