Skip to content

Commit

Permalink
Merge pull request #1017 from jtattermusch/csharp_codestyle
Browse files Browse the repository at this point in the history
Fixing C# codestyle
  • Loading branch information
murgatroid99 committed Mar 12, 2015
2 parents 01f8f11 + 075dde4 commit e7268b8
Show file tree
Hide file tree
Showing 58 changed files with 708 additions and 310 deletions.
8 changes: 5 additions & 3 deletions src/csharp/Grpc.Core.Tests/ClientServerTest.cs
Expand Up @@ -122,10 +122,13 @@ public void UnknownMethodHandler()
{
var call = new Call<string, string>(unaryEchoStringMethod, channel);

try {
try
{
Calls.BlockingUnaryCall(call, "ABC", default(CancellationToken));
Assert.Fail();
} catch(RpcException e) {
}
catch (RpcException e)
{
Assert.AreEqual(StatusCode.Unimplemented, e.Status.StatusCode);
}
}
Expand All @@ -140,4 +143,3 @@ private void HandleUnaryEchoString(string request, IObserver<string> responseObs
}
}
}

2 changes: 1 addition & 1 deletion src/csharp/Grpc.Core.Tests/GrpcEnvironmentTest.cs
Expand Up @@ -68,7 +68,7 @@ public void InitializeAfterShutdown()
var tp2 = GrpcEnvironment.ThreadPool;
GrpcEnvironment.Shutdown();

Assert.IsFalse(Object.ReferenceEquals(tp1, tp2));
Assert.IsFalse(object.ReferenceEquals(tp1, tp2));
}
}
}
35 changes: 17 additions & 18 deletions src/csharp/Grpc.Core.Tests/PInvokeTest.cs
Expand Up @@ -33,13 +33,13 @@

using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using Grpc.Core;
using Grpc.Core.Internal;
using Grpc.Core.Utils;
using NUnit.Framework;
using System.Runtime.InteropServices;

namespace Grpc.Core.Tests
{
Expand Down Expand Up @@ -73,14 +73,13 @@ public void CompletionQueueCreateDestroyBenchmark()
{
BenchmarkUtil.RunBenchmark(
100000, 1000000,
() => {
() =>
{
CompletionQueueSafeHandle cq = CompletionQueueSafeHandle.Create();
cq.Dispose();
}
);
});
}


/// <summary>
/// Approximate results:
/// (~80ns Mono Linux)
Expand All @@ -94,10 +93,10 @@ public void NativeCallbackBenchmark()
counter = 0;
BenchmarkUtil.RunBenchmark(
1000000, 10000000,
() => {
() =>
{
grpcsharp_test_callback(handler);
}
);
});
Assert.AreNotEqual(0, counter);
}

Expand All @@ -113,10 +112,10 @@ public void NewNativeCallbackBenchmark()
counter = 0;
BenchmarkUtil.RunBenchmark(
10000, 10000,
() => {
grpcsharp_test_callback(new CompletionCallbackDelegate(Handler));
}
);
() =>
{
grpcsharp_test_callback(new CompletionCallbackDelegate(Handler));
});
Assert.AreNotEqual(0, counter);
}

Expand All @@ -129,15 +128,15 @@ public void NopPInvokeBenchmark()
{
BenchmarkUtil.RunBenchmark(
1000000, 100000000,
() => {
() =>
{
grpcsharp_test_nop(IntPtr.Zero);
}
);
});
}

private void Handler(GRPCOpError op, IntPtr ptr) {
counter ++;
private void Handler(GRPCOpError op, IntPtr ptr)
{
counter++;
}
}
}

10 changes: 0 additions & 10 deletions src/csharp/Grpc.Core.Tests/Properties/AssemblyInfo.cs
@@ -1,8 +1,6 @@
using System.Reflection;
using System.Runtime.CompilerServices;

// Information about this assembly is defined by the following attributes.
// Change them to the values specific to your project.
[assembly: AssemblyTitle("Grpc.Core.Tests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
Expand All @@ -11,12 +9,4 @@
[assembly: AssemblyCopyright("Google Inc. All rights reserved.")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
[assembly: AssemblyVersion("0.1.*")]
// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.
//[assembly: AssemblyDelaySign(false)]
//[assembly: AssemblyKeyFile("")]

1 change: 0 additions & 1 deletion src/csharp/Grpc.Core.Tests/ServerTest.cs
Expand Up @@ -53,6 +53,5 @@ public void StartAndShutdownServer()

GrpcEnvironment.Shutdown();
}

}
}
1 change: 0 additions & 1 deletion src/csharp/Grpc.Core.Tests/TimespecTest.cs
Expand Up @@ -86,4 +86,3 @@ public void Add_NanosOverflow()
}
}
}

4 changes: 2 additions & 2 deletions src/csharp/Grpc.Core/Call.cs
Expand Up @@ -47,7 +47,8 @@ public class Call<TRequest, TResponse>
Func<TRequest, byte[]> requestSerializer,
Func<byte[], TResponse> responseDeserializer,
TimeSpan timeout,
Channel channel) {
Channel channel)
{
this.methodName = methodName;
this.requestSerializer = requestSerializer;
this.responseDeserializer = responseDeserializer;
Expand Down Expand Up @@ -95,4 +96,3 @@ public string MethodName
}
}
}

4 changes: 2 additions & 2 deletions src/csharp/Grpc.Core/Calls.cs
Expand Up @@ -89,9 +89,9 @@ public static class Calls
return new ClientStreamingInputObserver<TRequest, TResponse>(asyncCall);
}

private static CompletionQueueSafeHandle GetCompletionQueue() {
private static CompletionQueueSafeHandle GetCompletionQueue()
{
return GrpcEnvironment.ThreadPool.CompletionQueue;
}
}
}

2 changes: 1 addition & 1 deletion src/csharp/Grpc.Core/Channel.cs
Expand Up @@ -39,7 +39,7 @@ namespace Grpc.Core
public class Channel : IDisposable
{
readonly ChannelSafeHandle handle;
readonly String target;
readonly string target;

/// <summary>
/// Creates a channel.
Expand Down
4 changes: 2 additions & 2 deletions src/csharp/Grpc.Core/ChannelArgs.cs
Expand Up @@ -44,7 +44,7 @@ public class ChannelArgs

public class Builder
{
Dictionary<string,string> stringArgs = new Dictionary<string,string>();
Dictionary<string, string> stringArgs = new Dictionary<string, string>();
// TODO: AddInteger not supported yet.
public Builder AddString(string key, string value)
{
Expand All @@ -58,7 +58,7 @@ public ChannelArgs Build()
}
}

Dictionary<string,string> stringArgs;
Dictionary<string, string> stringArgs;

private ChannelArgs(Dictionary<string, string> stringArgs)
{
Expand Down
1 change: 0 additions & 1 deletion src/csharp/Grpc.Core/ClientStreamingAsyncResult.cs
Expand Up @@ -67,4 +67,3 @@ public IObserver<TRequest> Inputs
}
}
}

1 change: 0 additions & 1 deletion src/csharp/Grpc.Core/Credentials.cs
Expand Up @@ -74,4 +74,3 @@ internal override CredentialsSafeHandle ToNativeCredentials()
}
}
}

8 changes: 4 additions & 4 deletions src/csharp/Grpc.Core/GrpcEnvironment.cs
Expand Up @@ -63,8 +63,9 @@ public class GrpcEnvironment
/// lifetime (and call Shutdown once you're done), for the sake of easier testing it's
/// allowed to initialize the environment again after it has been successfully shutdown.
/// </summary>
public static void Initialize() {
lock(staticLock)
public static void Initialize()
{
lock (staticLock)
{
if (instance == null)
{
Expand All @@ -79,7 +80,7 @@ public class GrpcEnvironment
/// </summary>
public static void Shutdown()
{
lock(staticLock)
lock (staticLock)
{
if (instance != null)
{
Expand Down Expand Up @@ -133,4 +134,3 @@ private void Close()
}
}
}

14 changes: 6 additions & 8 deletions src/csharp/Grpc.Core/Internal/AsyncCall.cs
Expand Up @@ -54,7 +54,7 @@ internal class AsyncCall<TRequest, TResponse> : AsyncCallBase<TRequest, TRespons
TaskCompletionSource<TResponse> unaryResponseTcs;

// Set after status is received. Only used for streaming response calls.
Nullable<Status> finishedStatus;
Status? finishedStatus;

bool readObserverCompleted; // True if readObserver has already been completed.

Expand All @@ -64,7 +64,7 @@ public AsyncCall(Func<TRequest, byte[]> serializer, Func<byte[], TResponse> dese
this.finishedHandler = CreateBatchCompletionCallback(HandleFinished);
}

public void Initialize(Channel channel, CompletionQueueSafeHandle cq, String methodName)
public void Initialize(Channel channel, CompletionQueueSafeHandle cq, string methodName)
{
var call = CallSafeHandle.Create(channel.Handle, cq, methodName, channel.Target, Timespec.InfFuture);
InitializeInternal(call);
Expand All @@ -77,9 +77,9 @@ public void Initialize(Channel channel, CompletionQueueSafeHandle cq, String met
/// <summary>
/// Blocking unary request - unary response call.
/// </summary>
public TResponse UnaryCall(Channel channel, String methodName, TRequest msg)
public TResponse UnaryCall(Channel channel, string methodName, TRequest msg)
{
using(CompletionQueueSafeHandle cq = CompletionQueueSafeHandle.Create())
using (CompletionQueueSafeHandle cq = CompletionQueueSafeHandle.Create())
{
byte[] payload = UnsafeSerialize(msg);

Expand Down Expand Up @@ -254,7 +254,7 @@ protected override void CompleteReadObserver()
/// </summary>
private void HandleUnaryResponse(bool wasError, BatchContextSafeHandleNotOwned ctx)
{
lock(myLock)
lock (myLock)
{
finished = true;
halfclosed = true;
Expand All @@ -264,9 +264,7 @@ private void HandleUnaryResponse(bool wasError, BatchContextSafeHandleNotOwned c

if (wasError)
{
unaryResponseTcs.SetException(new RpcException(
new Status(StatusCode.Internal, "Internal error occured.")
));
unaryResponseTcs.SetException(new RpcException(new Status(StatusCode.Internal, "Internal error occured.")));
return;
}

Expand Down
18 changes: 9 additions & 9 deletions src/csharp/Grpc.Core/Internal/AsyncCallBase.cs
Expand Up @@ -225,7 +225,7 @@ protected bool TrySerialize(TWrite msg, out byte[] payload)
payload = serializer(msg);
return true;
}
catch(Exception)
catch (Exception)
{
Console.WriteLine("Exception occured while trying to serialize message");
payload = null;
Expand All @@ -240,7 +240,7 @@ protected bool TryDeserialize(byte[] payload, out TRead msg)
msg = deserializer(payload);
return true;
}
catch(Exception)
catch (Exception)
{
Console.WriteLine("Exception occured while trying to deserialize message");
msg = default(TRead);
Expand All @@ -254,7 +254,7 @@ protected void FireReadObserverOnNext(TRead value)
{
readObserver.OnNext(value);
}
catch(Exception e)
catch (Exception e)
{
Console.WriteLine("Exception occured while invoking readObserver.OnNext: " + e);
}
Expand All @@ -266,7 +266,7 @@ protected void FireReadObserverOnCompleted()
{
readObserver.OnCompleted();
}
catch(Exception e)
catch (Exception e)
{
Console.WriteLine("Exception occured while invoking readObserver.OnCompleted: " + e);
}
Expand All @@ -278,7 +278,7 @@ protected void FireReadObserverOnError(Exception error)
{
readObserver.OnError(error);
}
catch(Exception e)
catch (Exception e)
{
Console.WriteLine("Exception occured while invoking readObserver.OnError: " + e);
}
Expand All @@ -290,7 +290,7 @@ protected void FireCompletion(AsyncCompletionDelegate completionDelegate, Except
{
completionDelegate(error);
}
catch(Exception e)
catch (Exception e)
{
Console.WriteLine("Exception occured while invoking completion delegate: " + e);
}
Expand All @@ -302,14 +302,15 @@ protected void FireCompletion(AsyncCompletionDelegate completionDelegate, Except
/// </summary>
protected CompletionCallbackDelegate CreateBatchCompletionCallback(Action<bool, BatchContextSafeHandleNotOwned> handler)
{
return new CompletionCallbackDelegate( (error, batchContextPtr) => {
return new CompletionCallbackDelegate((error, batchContextPtr) =>
{
try
{
var ctx = new BatchContextSafeHandleNotOwned(batchContextPtr);
bool wasError = (error != GRPCOpError.GRPC_OP_OK);
handler(wasError, ctx);
}
catch(Exception e)
catch (Exception e)
{
Console.WriteLine("Caught exception in a native handler: " + e);
}
Expand Down Expand Up @@ -363,7 +364,6 @@ private void HandleHalfclosed(bool wasError, BatchContextSafeHandleNotOwned ctx)
{
FireCompletion(origCompletionDelegate, null);
}

}

/// <summary>
Expand Down
1 change: 0 additions & 1 deletion src/csharp/Grpc.Core/Internal/AsyncCompletion.cs
Expand Up @@ -91,5 +91,4 @@ private void HandleCompletion(Exception error)
tcs.SetException(error);
}
}

}
Expand Up @@ -80,16 +80,18 @@ public byte[] GetReceivedMessage()
{
return null;
}
byte[] data = new byte[(int) len];
byte[] data = new byte[(int)len];
grpcsharp_batch_context_recv_message_to_buffer(this, data, new UIntPtr((ulong)data.Length));
return data;
}

public CallSafeHandle GetServerRpcNewCall() {
public CallSafeHandle GetServerRpcNewCall()
{
return grpcsharp_batch_context_server_rpc_new_call(this);
}

public string GetServerRpcNewMethod() {
public string GetServerRpcNewMethod()
{
return Marshal.PtrToStringAnsi(grpcsharp_batch_context_server_rpc_new_method(this));
}
}
Expand Down

0 comments on commit e7268b8

Please sign in to comment.