Skip to content

Commit

Permalink
0.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
osexpert committed Sep 5, 2024
1 parent b8eecab commit cc86ca3
Show file tree
Hide file tree
Showing 17 changed files with 112 additions and 80 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
## 0.0.3 (next)
## 0.0.3
* Use nuget stakx.DynamicProxy.AsyncInterceptor instead of copying the code
* Use nuget AsyncReaderWriterLockSlim instead of copying the code
* Remove change detect logic from CallContext again
* Fix some messages/warnings
* Update some nugets to latest version
* Change to use MinimalJsonEncoder to make the json smallest possible

## 0.0.2
* Not compatible with 0.0.1, not in code and not on the wire. So breaking.
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<Company>osexpert</Company>
<PackageReleaseNotes>See https://github.com/osexpert/GoreRemoting/blob/master/CHANGELOG.md for details</PackageReleaseNotes>

<VersionPrefix>0.0.2</VersionPrefix>
<VersionPrefix>0.0.3</VersionPrefix>
<PackageTags>remoting rpc grpc dotnet-remoting</PackageTags>
<Description>Grpc Remoting library for migration from .NET Remoting</Description>

Expand Down
33 changes: 17 additions & 16 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<ItemGroup>
<PackageVersion Include="AsyncReaderWriterLockSlim" Version="1.0.0" />
<PackageVersion Include="Castle.Core" Version="5.1.1" />
<PackageVersion Include="Grpc.Net.ClientFactory" Version="2.62.0" />
<PackageVersion Include="Microsoft.Bcl.AsyncInterfaces" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.1" />
<PackageVersion Include="Nerdbank.Streams" Version="2.10.72" />
Expand All @@ -18,29 +17,31 @@
<PackageVersion Include="System.Reflection.Emit.Lightweight" Version="4.7.0" />
<!-- <PackageReference Include="System.Runtime.Serialization.Formatters" Version="4.3.0" /> -->
<PackageVersion Include="System.Threading.Channels" Version="8.0.0" />
<PackageVersion Include="Grpc.AspNetCore.Server" Version="2.62.0" />
<PackageVersion Include="Grpc.AspNetCore.Server" Version="2.65.0" />
<PackageVersion Include="Grpc.Core" Version="2.46.6" />
<PackageVersion Include="Grpc.Net.Client" Version="2.62.0" />
<PackageVersion Include="Grpc.Net.Common" Version="2.62.0" />
<PackageVersion Include="Open.ChannelExtensions" Version="8.0.2" />
<PackageVersion Include="Grpc.Net.Client" Version="2.65.0" />
<PackageVersion Include="Grpc.Net.Common" Version="2.65.0" />
<PackageVersion Include="Grpc.Net.ClientFactory" Version="2.65.0" />
<!-- <PackageVersion Include="Open.ChannelExtensions" Version="8.0.2" /> -->
<PackageVersion Include="System.Security.Principal.Windows" Version="5.0.0" />
<PackageVersion Include="System.Text.Json" Version="8.0.3" />
<PackageVersion Include="System.Text.Json" Version="8.0.4" />
<PackageVersion Include="TupleAsJsonArray.Redux" Version="1.1.0" />
<PackageVersion Include="Microsoft.IO.RecyclableMemoryStream" Version="3.0.0" />
<PackageVersion Include="MessagePack" Version="2.5.140" />
<PackageVersion Include="Microsoft.Data.SqlClient" Version="5.2.0" />
<!-- <PackageVersion Include="Microsoft.IO.RecyclableMemoryStream" Version="3.0.0" /> -->
<PackageVersion Include="MessagePack" Version="2.5.172" />
<PackageVersion Include="Microsoft.Data.SqlClient" Version="5.2.2" />
<!-- <PackageVersion Include="Newtonsoft.Json" Version="13.0.3" /> -->
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageVersion Include="xunit" Version="2.7.0" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.5.7" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.11.0" />
<!-- <PackageVersion Include="xunit" Version="2.7.0" />-->
<!-- <PackageVersion Include="xunit.runner.visualstudio" Version="2.5.7" />-->
<PackageVersion Include="coverlet.collector" Version="6.0.2" />
<PackageVersion Include="K4os.Compression.LZ4.Streams" Version="1.3.8" />
<PackageVersion Include="MemoryPack" Version="1.21.1" />
<PackageVersion Include="Nullable " Version="1.3.1" />
<PackageVersion Include="MSTest.TestAdapter" Version="2.2.10" />
<PackageVersion Include="MSTest.TestFramework" Version="2.2.10" />
<PackageVersion Include="MSTest.TestAdapter" Version="3.5.2" />
<PackageVersion Include="MSTest.TestFramework" Version="3.5.2" />
<PackageVersion Include="System.Threading.Tasks.Extensions" Version="4.5.4" />
<PackageVersion Include="Portable.System.DateTimeOnly" Version="8.0.0" />

<PackageVersion Include="Portable.System.DateTimeOnly" Version="8.0.1" />
<PackageVersion Include="ExtremeJsonEncoders" Version="0.0.1" />

</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion Examples/GrpcCoreServerNet48/GrpcCoreServerNet48.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<ItemGroup>
<PackageReference Include="Grpc.Core" />
<PackageReference Include="Open.ChannelExtensions" />
<!-- <PackageReference Include="Open.ChannelExtensions" /> -->
<PackageReference Include="System.Security.Principal.Windows" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion Examples/GrpcCoreServerNet60/GrpcCoreServerNet60.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<ItemGroup>
<PackageReference Include="Grpc.Core" />
<PackageReference Include="Open.ChannelExtensions" />
<!-- <PackageReference Include="Open.ChannelExtensions" /> -->
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public class BinaryFormatterAdapter : ISerializerAdapter, IExceptionAdapter
/// <summary>
/// Creates a new instance of the BinarySerializerAdapter class.
/// </summary>
[SuppressMessage("ReSharper", "UnusedMember.Global")]
#if NETSTANDARD2_1_OR_GREATER
public BinaryFormatterAdapter(bool netCore = true)
#else
Expand Down Expand Up @@ -255,14 +254,9 @@ public Type ExceptionType
//}
}

public class BinarySerializerOptions
public class BinarySerializerOptions(bool netCore)
{
public bool NetCore { get; }

public BinarySerializerOptions(bool netCore)
{
NetCore = netCore;
}
public bool NetCore { get; } = netCore;

public BinarySerializerConfig? Config { get; set; } = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

<ItemGroup>
<PackageReference Include="System.Text.Json" />
<PackageReference Include="ExtremeJsonEncoders" />
<PackageReference Include="TupleAsJsonArray.Redux" Condition="'$(TargetFramework)' == 'net6.0'" />
</ItemGroup>

Expand Down
3 changes: 2 additions & 1 deletion GoreRemoting.Serialization.Json/JsonAdapter.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Text.Encodings.Web;
using System.Text.Json;
using System.Text.Json.Serialization;
using ExtremeJsonEncoders;
using GoreRemoting.Serialization.Json.ArgTypes;
#if NET6_0_OR_GREATER
using TupleAsJsonArray;
Expand Down Expand Up @@ -28,7 +29,7 @@ private static JsonSerializerOptions CreateDefaultOptions()
new TupleConverterFactory()
#endif
},
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
Encoder = MinimalJsonEncoder.Shared
};
}

Expand Down
8 changes: 4 additions & 4 deletions GoreRemoting.Serialization.MemoryPack/MemoryPackAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ public void Serialize(Stream stream, object?[] graph, Type[] types)
var args = (IArgs)Activator.CreateInstance(t);
args.Set(graph);
object o = args;
MemoryPackSerializer.SerializeAsync(t, stream, o, Options).GetAwaiter().GetResult();
MemoryPackSerializer.SerializeAsync(t, stream, o, Options).GetResult();
}
else
{
MemoryPackSerializer.SerializeAsync(types[0], stream, graph[0], Options).GetAwaiter().GetResult();
MemoryPackSerializer.SerializeAsync(types[0], stream, graph[0], Options).GetResult();
}
}

Expand All @@ -30,12 +30,12 @@ public void Serialize(Stream stream, object?[] graph, Type[] types)
if (types.Length > 1)
{
var t = GetArgsType(types);
var res = (IArgs)MemoryPackSerializer.DeserializeAsync(t, stream, Options).GetAwaiter().GetResult()!;
var res = (IArgs)MemoryPackSerializer.DeserializeAsync(t, stream, Options).GetResult()!;
return res.Get();
}
else
{
return new[] { MemoryPackSerializer.DeserializeAsync(types[0], stream, Options).GetAwaiter().GetResult() };
return new[] { MemoryPackSerializer.DeserializeAsync(types[0], stream, Options).GetResult() };
}
}

Expand Down
22 changes: 8 additions & 14 deletions GoreRemoting.Tests/AsyncTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ public async Task ExceptionTests(enSerializer ser)
AssertLines(e, new string[]
{
"System.Threading.Tasks.TaskCanceledException: A task was canceled.",
" at Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ThrowsException[T](Action action, String message, Object[] parameters)"
" at Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ThrowsException[T](Action action, String message, Object[] parameters) in /_/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs:line 180"
});
}
else
Expand All @@ -332,7 +332,7 @@ public async Task ExceptionTests(enSerializer ser)
"System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.",
" ---> System.Runtime.Serialization.SerializationException: Member 'Test' was not found.",
" --- End of inner exception stack trace ---",
" at Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ThrowsException[T](Action action, String message, Object[] parameters)"
" at Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ThrowsException[T](Action action, String message, Object[] parameters) in /_/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs:line 180"
});
}

Expand All @@ -347,7 +347,7 @@ public async Task ExceptionTests(enSerializer ser)
AssertLines(e, new string[]
{
"System.Threading.Tasks.TaskCanceledException: A task was canceled.",
" at Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ThrowsException[T](Action action, String message, Object[] parameters)"
" at Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ThrowsException[T](Action action, String message, Object[] parameters) in /_/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs:line 180"
});
}
else
Expand All @@ -361,7 +361,7 @@ public async Task ExceptionTests(enSerializer ser)
"System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.",
" ---> System.Runtime.Serialization.SerializationException: Member 'Test' was not found.",
" --- End of inner exception stack trace ---",
" at Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ThrowsException[T](Action action, String message, Object[] parameters)"
" at Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ThrowsException[T](Action action, String message, Object[] parameters) in /_/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs:line 180"
});
}

Expand All @@ -374,7 +374,7 @@ public async Task ExceptionTests(enSerializer ser)
{
"GoreRemoting.Tests.AsyncTests+SerExOk: The mess",
"--- End of stack trace from previous location ---",
" at Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ThrowsException[T](Action action, String message, Object[] parameters)"
" at Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ThrowsException[T](Action action, String message, Object[] parameters) in /_/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs:line 180"
});
}

Expand Down Expand Up @@ -415,7 +415,7 @@ public async Task ExceptionTests_InnerEx(enSerializer ser)
" ---> System.ArgumentException: Format of the initialization string does not conform to specification starting at index 0.",
" --- End of inner exception stack trace ---",
"--- End of stack trace from previous location ---",
" at Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ThrowsException[T](Action action, String message, Object[] parameters)",
" at Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ThrowsException[T](Action action, String message, Object[] parameters) in /_/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs:line 180",
});
}

Expand Down Expand Up @@ -492,15 +492,15 @@ public async Task ExceptionTests_SqlException(enSerializer ser)
"Microsoft.Data.SqlClient.SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)",
" ---> System.ComponentModel.Win32Exception (53): The network path was not found.",
"--- End of stack trace from previous location ---",
" at Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ThrowsException[T](Action action, String message, Object[] parameters)"
" at Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ThrowsException[T](Action action, String message, Object[] parameters) in /_/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs:line 180"
});
#else
AssertLines(e4, new string[]
{
"Microsoft.Data.SqlClient.SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)",
" ---> System.ComponentModel.Win32Exception (0x80004005): The network path was not found", // no dot
"--- End of stack trace from previous location ---",
" at Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ThrowsException[T](Action action, String message, Object[] parameters)"
" at Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ThrowsException[T](Action action, String message, Object[] parameters) in /_/src/TestFramework/TestFramework/Assertions/Assert.ThrowsException.cs:line 180"
});
#endif

Expand Down Expand Up @@ -536,11 +536,5 @@ public static ISerializerAdapter GetSerializer(enSerializer ser)
_ => throw new NotImplementedException(),
};
}






}
}
12 changes: 6 additions & 6 deletions GoreRemoting/Exception/ExceptionConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace GoreRemoting
{
static class ExceptionConverter
{
static JsonSerializerOptions _options = new JsonSerializerOptions
static readonly JsonSerializerOptions _options = new()
{
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
};
Expand Down Expand Up @@ -44,7 +44,7 @@ public static Exception ToException(Dictionary<string, string> dict)

private static SerializationInfo GetInfo(Dictionary<string, string> dict)
{
SerializationInfo? info = new SerializationInfo(typeof(Exception), new JsonFormatterConverter(_options));
SerializationInfo? info = new(typeof(Exception), new JsonFormatterConverter(_options));

var fullStackTrace = new StringBuilder();

Expand Down Expand Up @@ -109,9 +109,9 @@ private static SerializationInfo GetInfo(Dictionary<string, string> dict)

public static Dictionary<string, string> ToDict(Exception value)
{
Dictionary<string, string> dict = new Dictionary<string, string>();
Dictionary<string, string> dict = new();

SerializationInfo info = new SerializationInfo(value.GetType(), new JsonFormatterConverter(_options));
SerializationInfo info = new(value.GetType(), new JsonFormatterConverter(_options));

Serialize(value, info);

Expand All @@ -137,10 +137,9 @@ public static Dictionary<string, string> ToDict(Exception value)
return dict;
}


private static readonly Type[] DeserializingConstructorParameterTypes = new Type[] { typeof(SerializationInfo), typeof(StreamingContext) };

private static StreamingContext Context => new StreamingContext(StreamingContextStates.Remoting);
private static StreamingContext Context => new(StreamingContextStates.Remoting);

internal static Exception Deserialize(SerializationInfo info)
{
Expand Down Expand Up @@ -185,6 +184,7 @@ internal static Exception Deserialize(SerializationInfo info)
#else
var res = (Exception)FormatterServices.GetUninitializedObject(runtimeType);
#endif
// TODO: Support a derived exception that crash in its deserializing exception? And/or ignore that invoke fails?
ctor.Invoke(res, new object[] { info, Context });
return res;
}
Expand Down
14 changes: 4 additions & 10 deletions GoreRemoting/RemoteDelegates/DelegateProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace GoreRemoting.RemoteDelegates
public sealed class DelegateProxy : AsyncInterceptor
{
private Func<MethodInfo, object?[], object?> _callInterceptionHandler;
private Func<MethodInfo, object?[], Task<object?>> _callInterceptionAsyncHandler;
private readonly Func<MethodInfo, object?[], Task<object?>> _callInterceptionAsyncHandler;

static readonly MethodInfo _interceptMethod = typeof(DelegateProxy ).GetMethod(
name: nameof(DelegateProxy.DelegateTarget),
Expand Down Expand Up @@ -70,16 +70,10 @@ protected override async ValueTask InterceptAsync(IAsyncInvocation invocation)
return sin.ReturnValue;
}

class Invocation : IInvocation
class Invocation(MethodInfo method, object?[] args) : IInvocation
{
MethodInfo _method;
object?[] _args;

public Invocation(MethodInfo method, object?[] args)
{
_method = method;
_args = args;
}
readonly MethodInfo _method = method;
readonly object?[] _args = args;

public object?[] Arguments => _args;
public MethodInfo Method => _method;
Expand Down
8 changes: 4 additions & 4 deletions GoreRemoting/RemotingClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ namespace GoreRemoting

public class RemotingClient : IRemotingParty
{
internal ClientConfig _config;
CallInvoker _callInvoker;
internal readonly ClientConfig _config;
readonly CallInvoker _callInvoker;
ConcurrentDictionary<(MethodInfo, MessageType, int), Type[]> IRemotingParty.TypesCache { get; } = new ConcurrentDictionary<(MethodInfo, MessageType, int), Type[]>();

internal ConcurrentDictionary<(string, string), MethodInfo> _serviceMethodLookup = new ConcurrentDictionary<(string, string), MethodInfo>();
internal ConcurrentDictionary<(string, string), MethodInfo> _serviceMethodLookup = new();


public RemotingClient(CallInvoker callInvoker, ClientConfig config)
Expand Down Expand Up @@ -106,7 +106,7 @@ private MethodInfo GetServiceMethod(string serviceName, string methodName)
public Method<GoreRequestMessage, GoreResponseMessage> DuplexCallDescriptor { get; }


private static readonly Castle.DynamicProxy.ProxyGenerator ProxyGenerator = new Castle.DynamicProxy.ProxyGenerator();
private static readonly Castle.DynamicProxy.ProxyGenerator ProxyGenerator = new();

public T CreateProxy<T>()
{
Expand Down
8 changes: 4 additions & 4 deletions GoreRemoting/RemotingServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ namespace GoreRemoting
public class RemotingServer : IRemotingParty
{

MethodCallMessageBuilder MethodCallMessageBuilder = new();
readonly MethodCallMessageBuilder MethodCallMessageBuilder = new();

//private ConcurrentDictionary<(Type, int), DelegateProxy> _delegateProxyCache = new();
ConcurrentDictionary<string, Type> _services = new();
readonly ConcurrentDictionary<string, Type> _services = new();

ConcurrentDictionary<(MethodInfo, MessageType, int), Type[]> IRemotingParty.TypesCache { get; } = new ConcurrentDictionary<(MethodInfo, MessageType, int), Type[]>();

ConcurrentDictionary<(string, string), MethodInfo> _serviceMethodCache = new ConcurrentDictionary<(string, string), MethodInfo>();
readonly ConcurrentDictionary<(string, string), MethodInfo> _serviceMethodCache = new();

ServerConfig _config;
readonly ServerConfig _config;

public RemotingServer(ServerConfig config)
{
Expand Down
Loading

0 comments on commit cc86ca3

Please sign in to comment.