Skip to content

Commit

Permalink
feat: Update to net8.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
HavenDV committed Dec 21, 2023
1 parent 4f8546d commit 8b04f80
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 25 deletions.
10 changes: 6 additions & 4 deletions src/libs/H.Engine.IO/EngineIoClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ public sealed partial class EngineIoClient : IDisposable

#region Properties

private JsonSerializerOptions _jsonSerializerOptions = new()
{
PropertyNameCaseInsensitive = true,
};

/// <summary>
/// Internal WebSocket Client
/// </summary>
Expand Down Expand Up @@ -140,10 +145,7 @@ private void WebSocketClient_OnTextReceived(object? sender, WebSocketClient.Text
switch (packet.Prefix)
{
case EngineIoPacket.OpenPrefix:
OpenMessage = JsonSerializer.Deserialize<EngineIoOpenMessage>(packet.Value, new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true,
});
OpenMessage = JsonSerializer.Deserialize<EngineIoOpenMessage>(packet.Value, _jsonSerializerOptions);
IsOpened = true;

Timer.Interval = OpenMessage?.PingInterval ?? 25000;
Expand Down
2 changes: 1 addition & 1 deletion src/libs/H.Engine.IO/H.Engine.IO.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.1;netstandard2.0;net4.6.2;net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>netstandard2.1;netstandard2.0;net4.6.2;net6.0;net7.0;net8.0</TargetFrameworks>
<NoWarn>$(NoWarn);CA1031;CS3016</NoWarn>
</PropertyGroup>

Expand Down
4 changes: 2 additions & 2 deletions src/libs/H.Socket.IO/H.Socket.IO.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.1;netstandard2.0;net4.6.2;net6.0;net7.0</TargetFrameworks>
<NoWarn>$(NoWarn);CA1031;CS3016</NoWarn>
<TargetFrameworks>netstandard2.1;netstandard2.0;net4.6.2;net6.0;net7.0;net8.0</TargetFrameworks>
<NoWarn>$(NoWarn);CA1031;CS3016;CA1867</NoWarn>
</PropertyGroup>

<PropertyGroup Label="NuGet">
Expand Down
30 changes: 18 additions & 12 deletions src/libs/H.Socket.IO/SocketIoClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -285,16 +285,19 @@ public async Task<bool> ConnectAsync(Uri uri, CancellationToken cancellationToke
/// <param name="namespaces"></param>
/// <exception cref="ObjectDisposedException"></exception>
/// <returns></returns>
public async Task<bool> ConnectToNamespacesAsync(CancellationToken cancellationToken = default, params string[] namespaces)
public async Task<bool> ConnectToNamespacesAsync(
CancellationToken cancellationToken = default,
params string[] namespaces)
{
EngineIoClient = EngineIoClient ?? throw new ObjectDisposedException(nameof(EngineIoClient));

namespaces = namespaces ?? throw new ArgumentNullException(nameof(namespaces));

if (!EngineIoClient.IsOpened)
{
return false;
}

if (!namespaces.Any())
if (namespaces.Length == 0)
{
return true;
}
Expand Down Expand Up @@ -488,12 +491,13 @@ public void On<T>(string name, Action<T, string> action, string? customNamespace
action = action ?? throw new ArgumentNullException(nameof(action));

var key = GetOnKey(name, customNamespace);
if (!JsonDeserializeActions.ContainsKey(key))
if (!JsonDeserializeActions.TryGetValue(key, out var value))
{
JsonDeserializeActions[key] = new List<(Action<object, string> Action, Type Type)>();
value = new List<(Action<object, string> Action, Type Type)>();
JsonDeserializeActions[key] = value;
}

JsonDeserializeActions[key].Add(((obj, text) => action((T)obj, text), typeof(T)));
value.Add(((obj, text) => action((T)obj, text), typeof(T)));
}

/// <summary>
Expand Down Expand Up @@ -527,12 +531,13 @@ public void On(string name, Action<string> action, string? customNamespace = nul
action = action ?? throw new ArgumentNullException(nameof(action));

var key = GetOnKey(name, customNamespace);
if (!TextActions.ContainsKey(key))
if (!TextActions.TryGetValue(key, out var value))
{
TextActions[key] = new List<Action<string>>();
value = new List<Action<string>>();
TextActions[key] = value;
}

TextActions[key].Add(action);
value.Add(action);
}

/// <summary>
Expand All @@ -548,12 +553,13 @@ public void On(string name, Action action, string? customNamespace = null)
action = action ?? throw new ArgumentNullException(nameof(action));

var key = GetOnKey(name, customNamespace);
if (!Actions.ContainsKey(key))
if (!Actions.TryGetValue(key, out var value))
{
Actions[key] = new List<Action>();
value = new List<Action>();
Actions[key] = value;
}

Actions[key].Add(action);
value.Add(action);
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/libs/H.WebSockets/H.WebSockets.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1;net4.5.1;net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;netstandard2.1;net4.5.1;net6.0;net7.0;net8.0</TargetFrameworks>
<NoWarn>$(NoWarn);CA1031;CS3016</NoWarn>
</PropertyGroup>

Expand Down
4 changes: 4 additions & 0 deletions src/libs/H.WebSockets/Utilities/EventExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,11 @@ public static async Task<Dictionary<string, T>> WaitAnyEventAsync<T>(this object

await Task.WhenAny(tasks).ConfigureAwait(false);

#if NET8_0_OR_GREATER
await cts.CancelAsync().ConfigureAwait(false);
#else
cts.Cancel();
#endif
}
catch (OperationCanceledException)
{
Expand Down
4 changes: 4 additions & 0 deletions src/libs/H.WebSockets/Utilities/TaskWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,11 @@ public async ValueTask DisposeAsync()

if (Task != Task.CompletedTask)
{
#if NET8_0_OR_GREATER
await CancellationTokenSource.CancelAsync().ConfigureAwait(false);
#else
CancellationTokenSource.Cancel();
#endif

try
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net4.8</TargetFrameworks>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup Label="GlobalUsings">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net4.8</TargetFrameworks>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup Label="GlobalUsings">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net4.8</TargetFrameworks>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup Label="GlobalUsings">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net4.8</TargetFrameworks>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup Label="GlobalUsings">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net4.8</TargetFrameworks>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup Label="GlobalUsings">
Expand Down

0 comments on commit 8b04f80

Please sign in to comment.