diff --git a/src/csharp/Grpc.Core/Calls.cs b/src/csharp/Grpc.Core/Calls.cs index 5409ce32bcf..cc1d67afcae 100644 --- a/src/csharp/Grpc.Core/Calls.cs +++ b/src/csharp/Grpc.Core/Calls.cs @@ -38,8 +38,6 @@ using Grpc.Core.Internal; namespace Grpc.Core { - // NOTE: this class is work-in-progress - /// /// Helper methods for generated stubs to make RPC calls. /// diff --git a/src/csharp/Grpc.Core/Channel.cs b/src/csharp/Grpc.Core/Channel.cs index 5a479619971..3a42dac1d7a 100644 --- a/src/csharp/Grpc.Core/Channel.cs +++ b/src/csharp/Grpc.Core/Channel.cs @@ -36,6 +36,9 @@ using Grpc.Core.Internal; namespace Grpc.Core { + /// + /// gRPC Channel + /// public class Channel : IDisposable { readonly ChannelSafeHandle handle; diff --git a/src/csharp/Grpc.Core/ChannelArgs.cs b/src/csharp/Grpc.Core/ChannelArgs.cs index 2d560c07b82..74ab310e44e 100644 --- a/src/csharp/Grpc.Core/ChannelArgs.cs +++ b/src/csharp/Grpc.Core/ChannelArgs.cs @@ -30,6 +30,7 @@ #endregion using System; using System.Collections.Generic; +using System.Collections.Immutable; using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; @@ -37,33 +38,18 @@ using Grpc.Core.Internal; namespace Grpc.Core { - // TODO: should we be using the builder pattern? + /// + /// gRPC channel options. + /// public class ChannelArgs { public const string SslTargetNameOverrideKey = "grpc.ssl_target_name_override"; - public class Builder - { - Dictionary stringArgs = new Dictionary(); - // TODO: AddInteger not supported yet. - public Builder AddString(string key, string value) - { - stringArgs.Add(key, value); - return this; - } + readonly ImmutableDictionary stringArgs; - public ChannelArgs Build() - { - return new ChannelArgs(stringArgs); - } - } - - Dictionary stringArgs; - - private ChannelArgs(Dictionary stringArgs) + private ChannelArgs(ImmutableDictionary stringArgs) { - // TODO: use immutable dict? - this.stringArgs = new Dictionary(stringArgs); + this.stringArgs = stringArgs; } public string GetSslTargetNameOverride() @@ -76,11 +62,28 @@ namespace Grpc.Core return null; } - public static Builder NewBuilder() + public static Builder CreateBuilder() { return new Builder(); } + public class Builder + { + readonly Dictionary stringArgs = new Dictionary(); + + // TODO: AddInteger not supported yet. + public Builder AddString(string key, string value) + { + stringArgs.Add(key, value); + return this; + } + + public ChannelArgs Build() + { + return new ChannelArgs(stringArgs.ToImmutableDictionary()); + } + } + /// /// Creates native object for the channel arguments. /// diff --git a/src/csharp/Grpc.Core/Credentials.cs b/src/csharp/Grpc.Core/Credentials.cs index ddf9d6dcd33..15dd3ef3216 100644 --- a/src/csharp/Grpc.Core/Credentials.cs +++ b/src/csharp/Grpc.Core/Credentials.cs @@ -36,6 +36,9 @@ using Grpc.Core.Internal; namespace Grpc.Core { + /// + /// Client-side credentials. + /// public abstract class Credentials { /// diff --git a/src/csharp/Grpc.Core/Grpc.Core.csproj b/src/csharp/Grpc.Core/Grpc.Core.csproj index c4b12b1cab0..29f1a0604a2 100644 --- a/src/csharp/Grpc.Core/Grpc.Core.csproj +++ b/src/csharp/Grpc.Core/Grpc.Core.csproj @@ -31,6 +31,9 @@ + + ..\packages\System.Collections.Immutable.1.1.34-rc\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll + @@ -54,7 +57,7 @@ - + @@ -77,6 +80,9 @@ + + + diff --git a/src/csharp/Grpc.Core/ServerCallHandler.cs b/src/csharp/Grpc.Core/Internal/ServerCallHandler.cs similarity index 99% rename from src/csharp/Grpc.Core/ServerCallHandler.cs rename to src/csharp/Grpc.Core/Internal/ServerCallHandler.cs index c5598e5e994..25fd4fab8f7 100644 --- a/src/csharp/Grpc.Core/ServerCallHandler.cs +++ b/src/csharp/Grpc.Core/Internal/ServerCallHandler.cs @@ -36,7 +36,7 @@ using System.Linq; using Grpc.Core.Internal; using Grpc.Core.Utils; -namespace Grpc.Core +namespace Grpc.Core.Internal { internal interface IServerCallHandler { diff --git a/src/csharp/Grpc.Core/Marshaller.cs b/src/csharp/Grpc.Core/Marshaller.cs index 9c9dfa4bc9b..e73e7b762ef 100644 --- a/src/csharp/Grpc.Core/Marshaller.cs +++ b/src/csharp/Grpc.Core/Marshaller.cs @@ -66,6 +66,9 @@ namespace Grpc.Core } } + /// + /// Utilities for creating marshallers. + /// public static class Marshallers { public static Marshaller Create(Func serializer, Func deserializer) diff --git a/src/csharp/Grpc.Core/RpcException.cs b/src/csharp/Grpc.Core/RpcException.cs index 0356bf7b4a9..433d87215ee 100644 --- a/src/csharp/Grpc.Core/RpcException.cs +++ b/src/csharp/Grpc.Core/RpcException.cs @@ -35,6 +35,9 @@ using System; namespace Grpc.Core { + /// + /// Thrown when remote procedure call fails. + /// public class RpcException : Exception { private readonly Status status; diff --git a/src/csharp/Grpc.Core/ServerCalls.cs b/src/csharp/Grpc.Core/ServerCalls.cs index b2dcdf24f6b..dcae99446fe 100644 --- a/src/csharp/Grpc.Core/ServerCalls.cs +++ b/src/csharp/Grpc.Core/ServerCalls.cs @@ -32,6 +32,7 @@ #endregion using System; +using Grpc.Core.Internal; namespace Grpc.Core { diff --git a/src/csharp/Grpc.Core/ServerCredentials.cs b/src/csharp/Grpc.Core/ServerCredentials.cs index 59c341ef51f..ab7d0b49143 100644 --- a/src/csharp/Grpc.Core/ServerCredentials.cs +++ b/src/csharp/Grpc.Core/ServerCredentials.cs @@ -33,10 +33,14 @@ using System; using System.Collections.Generic; +using System.Collections.Immutable; using Grpc.Core.Internal; namespace Grpc.Core { + /// + /// Server side credentials. + /// public abstract class ServerCredentials { /// @@ -51,8 +55,8 @@ namespace Grpc.Core /// public class KeyCertificatePair { - string certChain; - string privateKey; + readonly string certChain; + readonly string privateKey; public KeyCertificatePair(string certChain, string privateKey) { @@ -82,10 +86,9 @@ namespace Grpc.Core /// public class SslServerCredentials : ServerCredentials { - // TODO: immutable list... - List keyCertPairs; + ImmutableList keyCertPairs; - public SslServerCredentials(List keyCertPairs) + public SslServerCredentials(ImmutableList keyCertPairs) { this.keyCertPairs = keyCertPairs; } diff --git a/src/csharp/Grpc.Core/ServerServiceDefinition.cs b/src/csharp/Grpc.Core/ServerServiceDefinition.cs index d7f69f3c9f3..004415477ca 100644 --- a/src/csharp/Grpc.Core/ServerServiceDefinition.cs +++ b/src/csharp/Grpc.Core/ServerServiceDefinition.cs @@ -33,22 +33,26 @@ using System; using System.Collections.Generic; +using System.Collections.Immutable; +using Grpc.Core.Internal; namespace Grpc.Core { + /// + /// Mapping of method names to server call handlers. + /// public class ServerServiceDefinition { readonly string serviceName; - // TODO: we would need an immutable dictionary here... - readonly Dictionary callHandlers; + readonly ImmutableDictionary callHandlers; - private ServerServiceDefinition(string serviceName, Dictionary callHandlers) + private ServerServiceDefinition(string serviceName, ImmutableDictionary callHandlers) { this.serviceName = serviceName; - this.callHandlers = new Dictionary(callHandlers); + this.callHandlers = callHandlers; } - internal Dictionary CallHandlers + internal ImmutableDictionary CallHandlers { get { @@ -89,7 +93,7 @@ namespace Grpc.Core public ServerServiceDefinition Build() { - return new ServerServiceDefinition(serviceName, callHandlers); + return new ServerServiceDefinition(serviceName, callHandlers.ToImmutableDictionary()); } } } diff --git a/src/csharp/Grpc.Core/StatusCode.cs b/src/csharp/Grpc.Core/StatusCode.cs index 111863a2a9c..a9696fa4690 100644 --- a/src/csharp/Grpc.Core/StatusCode.cs +++ b/src/csharp/Grpc.Core/StatusCode.cs @@ -35,9 +35,9 @@ using System; namespace Grpc.Core { - // TODO: element names should changed to comply with C# naming conventions. /// - /// based on grpc_status_code from grpc/status.h + /// Result of a remote procedure call. + /// Based on grpc_status_code from grpc/status.h /// public enum StatusCode { diff --git a/src/csharp/Grpc.Core/packages.config b/src/csharp/Grpc.Core/packages.config new file mode 100644 index 00000000000..cf711ac3622 --- /dev/null +++ b/src/csharp/Grpc.Core/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/src/csharp/Grpc.IntegrationTesting/Grpc.IntegrationTesting.csproj b/src/csharp/Grpc.IntegrationTesting/Grpc.IntegrationTesting.csproj index 438bf9e95de..cfb258711ad 100644 --- a/src/csharp/Grpc.IntegrationTesting/Grpc.IntegrationTesting.csproj +++ b/src/csharp/Grpc.IntegrationTesting/Grpc.IntegrationTesting.csproj @@ -39,6 +39,10 @@ ..\packages\Google.ProtocolBuffers.2.4.1.521\lib\net40\Google.ProtocolBuffers.dll + + False + ..\packages\System.Collections.Immutable.1.1.34-rc\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll + @@ -76,8 +80,5 @@ PreserveNewest - - - - - + + \ No newline at end of file diff --git a/src/csharp/Grpc.IntegrationTesting/InteropClient.cs b/src/csharp/Grpc.IntegrationTesting/InteropClient.cs index 56760ecdabc..6b92d3c660f 100644 --- a/src/csharp/Grpc.IntegrationTesting/InteropClient.cs +++ b/src/csharp/Grpc.IntegrationTesting/InteropClient.cs @@ -109,7 +109,7 @@ namespace Grpc.IntegrationTesting ChannelArgs channelArgs = null; if (!string.IsNullOrEmpty(options.serverHostOverride)) { - channelArgs = ChannelArgs.NewBuilder() + channelArgs = ChannelArgs.CreateBuilder() .AddString(ChannelArgs.SslTargetNameOverrideKey, options.serverHostOverride).Build(); } diff --git a/src/csharp/Grpc.IntegrationTesting/InteropClientServerTest.cs b/src/csharp/Grpc.IntegrationTesting/InteropClientServerTest.cs index 36c784e28f1..814f6311f23 100644 --- a/src/csharp/Grpc.IntegrationTesting/InteropClientServerTest.cs +++ b/src/csharp/Grpc.IntegrationTesting/InteropClientServerTest.cs @@ -62,7 +62,7 @@ namespace Grpc.IntegrationTesting int port = server.AddPort(host + ":0", TestCredentials.CreateTestServerCredentials()); server.Start(); - var channelArgs = ChannelArgs.NewBuilder() + var channelArgs = ChannelArgs.CreateBuilder() .AddString(ChannelArgs.SslTargetNameOverrideKey, TestCredentials.DefaultHostOverride).Build(); channel = new Channel(host + ":" + port, TestCredentials.CreateTestClientCredentials(true), channelArgs); diff --git a/src/csharp/Grpc.IntegrationTesting/TestCredentials.cs b/src/csharp/Grpc.IntegrationTesting/TestCredentials.cs index 10df704f1dd..401c50b1aea 100644 --- a/src/csharp/Grpc.IntegrationTesting/TestCredentials.cs +++ b/src/csharp/Grpc.IntegrationTesting/TestCredentials.cs @@ -33,6 +33,7 @@ using System; using System.Collections.Generic; +using System.Collections.Immutable; using System.Diagnostics; using System.IO; using System.Text.RegularExpressions; @@ -77,7 +78,7 @@ namespace Grpc.IntegrationTesting var keyCertPair = new KeyCertificatePair( File.ReadAllText(ServerCertChainPath), File.ReadAllText(ServerPrivateKeyPath)); - return new SslServerCredentials(new List { keyCertPair }); + return new SslServerCredentials(ImmutableList.Create(keyCertPair)); } } } diff --git a/src/csharp/Grpc.IntegrationTesting/packages.config b/src/csharp/Grpc.IntegrationTesting/packages.config index 51c17bcd5e7..157c264eac0 100644 --- a/src/csharp/Grpc.IntegrationTesting/packages.config +++ b/src/csharp/Grpc.IntegrationTesting/packages.config @@ -2,4 +2,5 @@ + \ No newline at end of file