Skip to content

Commit 2d9fb7b

Browse files
committed
tests and code style
1 parent 2222fbd commit 2d9fb7b

File tree

15 files changed

+72
-62
lines changed

15 files changed

+72
-62
lines changed

ManagedCode.Orleans.SignalR.Core/Helpers/Logs.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,58 +15,58 @@ public static partial class Logs
1515
public static partial void Ping(ILogger logger, string grainType, string grainId);
1616

1717
[LoggerMessage(
18-
Level = LogLevel.Information,
18+
Level = LogLevel.Debug,
1919
Message = "{grainType}:{grainId} AddConnection `{connectionId}`")]
2020
public static partial void AddConnection(ILogger logger, string grainType, string grainId, string connectionId);
2121

2222
[LoggerMessage(
23-
Level = LogLevel.Information,
23+
Level = LogLevel.Debug,
2424
Message = "{grainType}:{grainId} RemoveConnection `{connectionId}`")]
2525
public static partial void RemoveConnection(ILogger logger, string grainType, string grainId, string connectionId);
2626

2727
[LoggerMessage(
28-
Level = LogLevel.Information,
28+
Level = LogLevel.Debug,
2929
Message = "{grainType}:{grainId} SendToAll")]
3030
public static partial void SendToAll(ILogger logger, string grainType, string grainId);
3131

3232
[LoggerMessage(
33-
Level = LogLevel.Information,
33+
Level = LogLevel.Debug,
3434
Message = "{grainType}:{grainId} SendToAllExcept")]
3535
public static partial void SendToAllExcept(ILogger logger, string grainType, string grainId, string[] expectedConnectionIds);
3636

3737
[LoggerMessage(
38-
Level = LogLevel.Information,
38+
Level = LogLevel.Debug,
3939
Message = "{grainType}:{grainId} SendToConnection")]
4040
public static partial void SendToConnection(ILogger logger, string grainType, string grainId, string connectionId);
4141

4242
[LoggerMessage(
43-
Level = LogLevel.Information,
43+
Level = LogLevel.Debug,
4444
Message = "{grainType}:{grainId} SendToConnections")]
4545
public static partial void SendToConnections(ILogger logger, string grainType, string grainId, string[] expectedConnectionIds);
4646

4747

4848
[LoggerMessage(
49-
Level = LogLevel.Information,
49+
Level = LogLevel.Debug,
5050
Message = "{grainType}:{grainId} SendToGroup")]
5151
public static partial void SendToGroup(ILogger logger, string grainType, string grainId);
5252

5353
[LoggerMessage(
54-
Level = LogLevel.Information,
54+
Level = LogLevel.Debug,
5555
Message = "{grainType}:{grainId} SendToGroupExcept")]
5656
public static partial void SendToGroupExcept(ILogger logger, string grainType, string grainId, string[] expectedConnectionIds);
5757

5858
[LoggerMessage(
59-
Level = LogLevel.Information,
59+
Level = LogLevel.Debug,
6060
Message = "{grainType}:{grainId} TryCompleteResult")]
6161
public static partial void TryCompleteResult(ILogger logger, string grainType, string grainId, string connectionId);
6262

6363
[LoggerMessage(
64-
Level = LogLevel.Information,
64+
Level = LogLevel.Debug,
6565
Message = "{grainType}:{grainId} TryGetReturnType")]
6666
public static partial void TryGetReturnType(ILogger logger, string grainType, string grainId);
6767

6868
[LoggerMessage(
69-
Level = LogLevel.Information,
69+
Level = LogLevel.Debug,
7070
Message = "{grainType}:{grainId} AddInvocation")]
7171
public static partial void AddInvocation(ILogger logger, string grainType, string grainId, string invocationId, string connectionId);
7272

@@ -76,9 +76,9 @@ public static partial class Logs
7676
public static partial void RemoveInvocation(ILogger logger, string grainType, string grainId);
7777

7878
[LoggerMessage(
79-
Level = LogLevel.Information,
79+
Level = LogLevel.Debug,
8080
Message = "{grainType}:{grainId} SendToUser")]
8181
public static partial void SendToUser(ILogger logger, string grainType, string grainId);
8282

8383

84-
}
84+
}

ManagedCode.Orleans.SignalR.Core/HubContext/OrleansHubClients.cs

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,54 +3,47 @@
33

44
namespace ManagedCode.Orleans.SignalR.Core.HubContext;
55

6-
internal sealed class OrleansHubClients<T> : IHubClients<T>
6+
internal sealed class OrleansHubClients<T>(IHubClients hubClients) : IHubClients<T>
77
{
8-
private readonly IHubClients _hubClients;
9-
10-
public OrleansHubClients(IHubClients hubClients)
11-
{
12-
_hubClients = hubClients;
13-
}
14-
158
public T Client(string connectionId)
169
{
17-
return TypedClientBuilder<T>.Build(_hubClients.Client(connectionId));
10+
return TypedClientBuilder<T>.Build(hubClients.Client(connectionId));
1811
}
1912

20-
public T All => TypedClientBuilder<T>.Build(_hubClients.All);
13+
public T All => TypedClientBuilder<T>.Build(hubClients.All);
2114

2215
public T AllExcept(IReadOnlyList<string> excludedConnectionIds)
2316
{
24-
return TypedClientBuilder<T>.Build(_hubClients.AllExcept(excludedConnectionIds));
17+
return TypedClientBuilder<T>.Build(hubClients.AllExcept(excludedConnectionIds));
2518
}
2619

2720
public T Group(string groupName)
2821
{
29-
return TypedClientBuilder<T>.Build(_hubClients.Group(groupName));
22+
return TypedClientBuilder<T>.Build(hubClients.Group(groupName));
3023
}
3124

3225
public T GroupExcept(string groupName, IReadOnlyList<string> excludedConnectionIds)
3326
{
34-
return TypedClientBuilder<T>.Build(_hubClients.GroupExcept(groupName, excludedConnectionIds));
27+
return TypedClientBuilder<T>.Build(hubClients.GroupExcept(groupName, excludedConnectionIds));
3528
}
3629

3730
public T Clients(IReadOnlyList<string> connectionIds)
3831
{
39-
return TypedClientBuilder<T>.Build(_hubClients.Clients(connectionIds));
32+
return TypedClientBuilder<T>.Build(hubClients.Clients(connectionIds));
4033
}
4134

4235
public T Groups(IReadOnlyList<string> groupNames)
4336
{
44-
return TypedClientBuilder<T>.Build(_hubClients.Groups(groupNames));
37+
return TypedClientBuilder<T>.Build(hubClients.Groups(groupNames));
4538
}
4639

4740
public T User(string userId)
4841
{
49-
return TypedClientBuilder<T>.Build(_hubClients.User(userId));
42+
return TypedClientBuilder<T>.Build(hubClients.User(userId));
5043
}
5144

5245
public T Users(IReadOnlyList<string> userIds)
5346
{
54-
return TypedClientBuilder<T>.Build(_hubClients.Users(userIds));
47+
return TypedClientBuilder<T>.Build(hubClients.Users(userIds));
5548
}
5649
}

ManagedCode.Orleans.SignalR.Core/HubContext/OrleansHubContext.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,15 @@ namespace ManagedCode.Orleans.SignalR.Core.HubContext;
55
/// <summary>
66
/// A context abstraction for a hub.
77
/// </summary>
8-
public class OrleansHubContext<THub, TClient> : IOrleansHubContext<THub, TClient> where THub : Hub
8+
public class OrleansHubContext<THub, TClient>(IHubContext<THub> context) : IOrleansHubContext<THub, TClient> where THub : Hub
99
{
10-
public OrleansHubContext(IHubContext<THub> context)
11-
{
12-
Clients = new OrleansHubClients<TClient>(context.Clients);
13-
Groups = context.Groups;
14-
}
15-
1610
/// <summary>
1711
/// Gets a <see cref="IHubClients" /> that can be used to invoke methods on clients connected to the hub.
1812
/// </summary>
19-
public IHubClients<TClient> Clients { get; }
13+
public IHubClients<TClient> Clients { get; } = new OrleansHubClients<TClient>(context.Clients);
2014

2115
/// <summary>
2216
/// Gets a <see cref="IGroupManager" /> that can be used to add and remove connections to named groups.
2317
/// </summary>
24-
public IGroupManager Groups { get; }
18+
public IGroupManager Groups { get; } = context.Groups;
2519
}

ManagedCode.Orleans.SignalR.Core/HubContext/TypedClientBuilder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ internal static class TypedClientBuilder<T>
1414
private const string ClientModuleName = "Microsoft.AspNetCore.SignalR.TypedClientBuilder";
1515

1616
// There is one static instance of _builder per T
17-
private static readonly Lazy<Func<IClientProxy, T>> _builder = new(() => GenerateClientBuilder());
17+
private static readonly Lazy<Func<IClientProxy, T>> _builder = new(GenerateClientBuilder);
1818

1919
private static readonly PropertyInfo CancellationTokenNoneProperty =
2020
typeof(CancellationToken).GetProperty("None", BindingFlags.Public | BindingFlags.Static)!;
2121

2222
private static readonly ConstructorInfo ObjectConstructor = typeof(object).GetConstructors().Single();
2323

24-
private static readonly Type[] ParameterTypes = { typeof(IClientProxy) };
24+
private static readonly Type[] ParameterTypes = [typeof(IClientProxy)];
2525

2626
public static T Build(IClientProxy proxy)
2727
{

ManagedCode.Orleans.SignalR.Core/Interfaces/ISignalRConnectionCoordinatorGrain.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,6 @@ public interface ISignalRConnectionCoordinatorGrain : IGrainWithStringKey
2424
[OneWay]
2525
Task SendToConnections(HubMessage message, string[] connectionIds);
2626

27+
[OneWay]
2728
Task NotifyConnectionRemoved(string connectionId);
2829
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
using System.Threading.Tasks;
22
using ManagedCode.Orleans.SignalR.Core.Models;
33
using Orleans;
4+
using Orleans.Concurrency;
45

56
namespace ManagedCode.Orleans.SignalR.Core.Interfaces;
67

78
public interface ISignalRConnectionHeartbeatGrain : IGrainWithStringKey
89
{
910
Task Start(ConnectionHeartbeatRegistration registration);
11+
12+
[OneWay]
1013
Task Stop();
1114
}

ManagedCode.Orleans.SignalR.Core/Interfaces/ISignalRGroupCoordinatorGrain.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,12 @@ public interface ISignalRGroupCoordinatorGrain : IGrainWithStringKey
2222
[OneWay]
2323
Task SendToGroups(string[] groupNames, HubMessage message);
2424

25+
[OneWay]
2526
Task AddConnectionToGroup(string groupName, string connectionId, ISignalRObserver observer);
2627

28+
[OneWay]
2729
Task RemoveConnectionFromGroup(string groupName, string connectionId, ISignalRObserver observer);
2830

31+
[OneWay]
2932
Task NotifyGroupRemoved(string groupName);
3033
}

ManagedCode.Orleans.SignalR.Core/Interfaces/ISignalRGroupPartitionGrain.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@ public interface ISignalRGroupPartitionGrain : IGrainWithIntegerKey, IObserverCo
1313
[OneWay]
1414
Task SendToGroupsExcept(HubMessage message, string[] groupNames, string[] excludedConnectionIds);
1515

16+
[OneWay]
1617
Task AddConnectionToGroup(string groupName, string connectionId, ISignalRObserver observer);
1718

19+
[OneWay]
1820
Task RemoveConnectionFromGroup(string groupName, string connectionId, ISignalRObserver observer);
1921

2022
[ReadOnly]
2123
Task<bool> HasConnection(string connectionId);
2224

25+
[OneWay]
2326
Task EnsureInitialized(string hubKey);
2427
}

ManagedCode.Orleans.SignalR.Core/SignalR/NameHelperGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public static ISignalRConnectionHeartbeatGrain GetConnectionHeartbeatGrain(IGrai
9191

9292
public static string CleanString(string input)
9393
{
94-
var builder = new System.Text.StringBuilder();
94+
var builder = new StringBuilder();
9595
foreach (char c in input)
9696
{
9797
if (char.IsLetterOrDigit(c) || c == '-' || c == ':' || c == '.')

ManagedCode.Orleans.SignalR.Core/SignalR/Observers/SignalRObserver.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,9 @@
55

66
namespace ManagedCode.Orleans.SignalR.Core.SignalR.Observers;
77

8-
public class SignalRObserver : ISignalRObserver, IDisposable
8+
public class SignalRObserver(Func<HubMessage, Task> onNextAction) : ISignalRObserver, IDisposable
99
{
10-
private Func<HubMessage, Task>? _onNextAction;
11-
12-
public SignalRObserver(Func<HubMessage, Task> onNextAction)
13-
{
14-
_onNextAction = onNextAction;
15-
}
10+
private Func<HubMessage, Task>? _onNextAction = onNextAction;
1611

1712
public void Dispose()
1813
{

0 commit comments

Comments
 (0)