From 5048d678ac127920e1ec634f4ceea9f46e1b1691 Mon Sep 17 00:00:00 2001 From: HavenDV Date: Mon, 27 Nov 2023 23:25:07 +0400 Subject: [PATCH] feat: Use MessagePackFormatter by default on net8.0. --- src/libs/H.Pipes/H.Pipes.csproj | 11 ++++++++++- src/libs/H.Pipes/PipeClient.cs | 4 ++-- src/libs/H.Pipes/PipeServer.cs | 4 ++-- src/libs/H.Pipes/SingleConnectionPipeClient.cs | 4 ++-- src/libs/H.Pipes/SingleConnectionPipeServer.cs | 4 ++-- src/tests/Directory.Build.props | 7 ++++++- src/tests/H.Pipes.Tests/BaseTests.cs | 8 ++++---- src/tests/H.Pipes.Tests/DataTests.cs | 6 ++++-- src/tests/H.Pipes.Tests/H.Pipes.Tests.csproj | 2 +- src/tests/H.Pipes.Tests/SerializableTests.cs | 12 +++++------- src/tests/H.Pipes.Tests/Tests.cs | 1 + 11 files changed, 39 insertions(+), 24 deletions(-) diff --git a/src/libs/H.Pipes/H.Pipes.csproj b/src/libs/H.Pipes/H.Pipes.csproj index 6ec5765..790ebce 100644 --- a/src/libs/H.Pipes/H.Pipes.csproj +++ b/src/libs/H.Pipes/H.Pipes.csproj @@ -21,6 +21,11 @@ - Supports `PipeAccessRule`'s(see `H.Pipes.AccessControl` nuget package) or more complex code to access using the `PipeServer.PipeStreamInitializeAction` property + + + + + @@ -30,10 +35,14 @@ - + + + + + all diff --git a/src/libs/H.Pipes/PipeClient.cs b/src/libs/H.Pipes/PipeClient.cs index 59d5158..202b756 100644 --- a/src/libs/H.Pipes/PipeClient.cs +++ b/src/libs/H.Pipes/PipeClient.cs @@ -108,7 +108,7 @@ private void OnExceptionOccurred(Exception exception) /// Name of the server's pipe /// the Name of the server, default is local machine /// Default reconnection interval - - /// Default formatter - + /// Default formatter - public PipeClient(string pipeName, string serverName = ".", TimeSpan? reconnectionInterval = default, IFormatter? formatter = default) { PipeName = pipeName; @@ -141,7 +141,7 @@ public PipeClient(string pipeName, string serverName = ".", TimeSpan? reconnecti } }; - Formatter = formatter ?? new BinaryFormatter(); + Formatter = formatter ?? new DefaultFormatter(); } #endregion diff --git a/src/libs/H.Pipes/PipeServer.cs b/src/libs/H.Pipes/PipeServer.cs index bd252a9..5162cd6 100644 --- a/src/libs/H.Pipes/PipeServer.cs +++ b/src/libs/H.Pipes/PipeServer.cs @@ -115,11 +115,11 @@ private void OnExceptionOccurred(Exception exception) /// Constructs a new NamedPipeServer object that listens for client connections on the given . /// /// Name of the pipe to listen on - /// Default formatter - + /// Default formatter - public PipeServer(string pipeName, IFormatter? formatter = default) { PipeName = pipeName; - Formatter = formatter ?? new BinaryFormatter(); + Formatter = formatter ?? new DefaultFormatter(); } #endregion diff --git a/src/libs/H.Pipes/SingleConnectionPipeClient.cs b/src/libs/H.Pipes/SingleConnectionPipeClient.cs index 1d26692..f2faa5e 100644 --- a/src/libs/H.Pipes/SingleConnectionPipeClient.cs +++ b/src/libs/H.Pipes/SingleConnectionPipeClient.cs @@ -107,7 +107,7 @@ private void OnExceptionOccurred(Exception exception) /// Name of the server's pipe /// the Name of the server, default is local machine /// Default reconnection interval - - /// Default formatter - + /// Default formatter - public SingleConnectionPipeClient(string pipeName, string serverName = ".", TimeSpan? reconnectionInterval = default, IFormatter? formatter = default) { PipeName = pipeName; @@ -141,7 +141,7 @@ public SingleConnectionPipeClient(string pipeName, string serverName = ".", Time } }; - Formatter = formatter ?? new BinaryFormatter(); + Formatter = formatter ?? new DefaultFormatter(); } #endregion diff --git a/src/libs/H.Pipes/SingleConnectionPipeServer.cs b/src/libs/H.Pipes/SingleConnectionPipeServer.cs index 0fef4ee..0a47e2d 100644 --- a/src/libs/H.Pipes/SingleConnectionPipeServer.cs +++ b/src/libs/H.Pipes/SingleConnectionPipeServer.cs @@ -106,11 +106,11 @@ private void OnExceptionOccurred(Exception exception) /// Constructs a new NamedPipeServer object that listens for client connections on the given . /// /// Name of the pipe to listen on - /// Default formatter - + /// Default formatter - public SingleConnectionPipeServer(string pipeName, IFormatter? formatter = default) { PipeName = pipeName; - Formatter = formatter ?? new BinaryFormatter(); + Formatter = formatter ?? new DefaultFormatter(); } #endregion diff --git a/src/tests/Directory.Build.props b/src/tests/Directory.Build.props index cc1e0df..1932e05 100644 --- a/src/tests/Directory.Build.props +++ b/src/tests/Directory.Build.props @@ -2,9 +2,14 @@ - + + + + + + diff --git a/src/tests/H.Pipes.Tests/BaseTests.cs b/src/tests/H.Pipes.Tests/BaseTests.cs index 7cd0721..71530da 100644 --- a/src/tests/H.Pipes.Tests/BaseTests.cs +++ b/src/tests/H.Pipes.Tests/BaseTests.cs @@ -106,14 +106,14 @@ public static async Task DataTestAsync(List values, Func? hash using var cancellationTokenSource = new CancellationTokenSource(timeout ?? TimeSpan.FromMinutes(1)); const string pipeName = "pipe"; - await using var server = new PipeServer(pipeName, formatter ?? new BinaryFormatter()) + await using var server = new PipeServer(pipeName, formatter ?? new DefaultFormatter()) { #if NET48 // https://github.com/HavenDV/H.Pipes/issues/6 WaitFreePipe = true, #endif }; - await using var client = new PipeClient(pipeName, formatter: formatter ?? new BinaryFormatter()); + await using var client = new PipeClient(pipeName, formatter: formatter ?? new DefaultFormatter()); await DataTestAsync(server, client, values, hashFunc, cancellationTokenSource.Token); } @@ -123,11 +123,11 @@ public static async Task DataSingleTestAsync(List values, Func using var cancellationTokenSource = new CancellationTokenSource(timeout ?? TimeSpan.FromMinutes(1)); const string pipeName = "pipe"; - await using var server = new SingleConnectionPipeServer(pipeName, formatter ?? new BinaryFormatter()) + await using var server = new SingleConnectionPipeServer(pipeName, formatter ?? new DefaultFormatter()) { WaitFreePipe = true }; - await using var client = new SingleConnectionPipeClient(pipeName, formatter: formatter ?? new BinaryFormatter()); + await using var client = new SingleConnectionPipeClient(pipeName, formatter: formatter ?? new DefaultFormatter()); await DataTestAsync(server, client, values, hashFunc, cancellationTokenSource.Token); } diff --git a/src/tests/H.Pipes.Tests/DataTests.cs b/src/tests/H.Pipes.Tests/DataTests.cs index 1d36918..10182eb 100644 --- a/src/tests/H.Pipes.Tests/DataTests.cs +++ b/src/tests/H.Pipes.Tests/DataTests.cs @@ -161,7 +161,8 @@ public async Task Single_TestMessageSize1Kx3_SystemTextJson() //{ // await BaseTests.BinaryDataSingleTestAsync(1025, 3, new CerasFormatter()); //} - + +#if !NET8_0_OR_GREATER [TestMethod] public async Task TypeTest() { @@ -170,7 +171,7 @@ public async Task TypeTest() using var registration = cancellationTokenSource.Token.Register(() => completionSource.TrySetCanceled()); const string pipeName = "pipe"; - var formatter = new BinaryFormatter(); + var formatter = new DefaultFormatter(); await using var server = new PipeServer(pipeName, formatter); await using var client = new PipeClient(pipeName, formatter: formatter); @@ -191,4 +192,5 @@ public async Task TypeTest() Assert.IsTrue(await completionSource.Task); } +#endif } diff --git a/src/tests/H.Pipes.Tests/H.Pipes.Tests.csproj b/src/tests/H.Pipes.Tests/H.Pipes.Tests.csproj index 5c26660..8c361cb 100644 --- a/src/tests/H.Pipes.Tests/H.Pipes.Tests.csproj +++ b/src/tests/H.Pipes.Tests/H.Pipes.Tests.csproj @@ -1,7 +1,7 @@ - net8.0 + net7.0;net8.0 $(TargetFrameworks);net4.8 false diff --git a/src/tests/H.Pipes.Tests/SerializableTests.cs b/src/tests/H.Pipes.Tests/SerializableTests.cs index cf9d47a..9fbad34 100644 --- a/src/tests/H.Pipes.Tests/SerializableTests.cs +++ b/src/tests/H.Pipes.Tests/SerializableTests.cs @@ -12,8 +12,6 @@ public class SerializableTests private PipeServer? _server; private PipeClient? _client; - private TestCollection? _expectedData; - private int _expectedHash; private TestCollection? _actualData; private int _actualHash; @@ -36,8 +34,6 @@ public async Task SetUp() _server = new PipeServer(PipeName); _client = new PipeClient(PipeName); - _expectedData = null; - _expectedHash = 0; _actualData = null; _actualHash = 0; @@ -97,16 +93,17 @@ private void ServerOnMessageReceived(object? sender, ConnectionMessageEventArgs< #region Tests +#if !NET8_0_OR_GREATER [TestMethod] public async Task TestCircularReferences() { - _expectedData = new TestCollection(); + var _expectedData = new TestCollection(); for (var i = 0; i < 10; i++) { var item = new TestItem(i, _expectedData, RandomEnum()); _expectedData.Add(item); } - _expectedHash = _expectedData.GetHashCode(); + var _expectedHash = _expectedData.GetHashCode(); if (_client != null) { @@ -135,7 +132,8 @@ public async Task TestCircularReferences() $"Item at index {i}'s Parent property should reference the item's parent collection"); } } - +#endif + private TestEnum RandomEnum() { var rand = new Random().NextDouble(); diff --git a/src/tests/H.Pipes.Tests/Tests.cs b/src/tests/H.Pipes.Tests/Tests.cs index 10eb246..45d0bce 100644 --- a/src/tests/H.Pipes.Tests/Tests.cs +++ b/src/tests/H.Pipes.Tests/Tests.cs @@ -10,6 +10,7 @@ namespace H.Pipes.Tests; [TestClass] public class Tests { + [Ignore] [TestMethod] public async Task Interrupted() {