├── samples ├── Server │ ├── appsettings.Development.json │ ├── appsettings.json │ ├── Program.cs │ ├── Hubs │ │ └── Chat.cs │ ├── Server.csproj │ └── Properties │ │ └── launchSettings.json └── Client │ ├── Client.csproj │ └── Program.cs ├── src └── Microsoft.AspNetCore.SignalR.Orleans │ ├── DependencyInjectionExtensions.cs │ ├── Microsoft.AspNetCore.SignalR.Orleans.csproj │ ├── IHubLifetimeManagerGrainObserver.cs │ ├── IHubLifetimeManagerGrain.cs │ ├── HubLifetimeManagerGrain.cs │ └── OrleansHubLifetimeManager.cs ├── Microsoft.AspNetCore.SignalR.Orleans.sln └── .gitignore /samples/Server/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /samples/Server/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | }, 8 | "AllowedHosts": "*" 9 | } 10 | -------------------------------------------------------------------------------- /samples/Server/Program.cs: -------------------------------------------------------------------------------- 1 | using Orleans; 2 | using Orleans.Hosting; 3 | using Server.Hubs; 4 | 5 | var builder = WebApplication.CreateBuilder(args); 6 | 7 | builder.Host.UseOrleans(builder => builder.UseLocalhostClustering().AddMemoryGrainStorageAsDefault()); 8 | 9 | builder.Services.AddSignalR().AddOrleans(); 10 | 11 | var app = builder.Build(); 12 | 13 | app.MapHub("/chat"); 14 | 15 | app.Run(); 16 | -------------------------------------------------------------------------------- /samples/Server/Hubs/Chat.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.SignalR; 2 | 3 | namespace Server.Hubs; 4 | 5 | public class Chat : Hub 6 | { 7 | public async Task Send(string message) 8 | { 9 | await Groups.AddToGroupAsync(Context.ConnectionId, "g1"); 10 | 11 | await Clients.All.SendAsync("Send", message); 12 | 13 | await Clients.Group("g1").SendAsync("Send", "To the group!"); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /samples/Client/Client.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net7.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.SignalR.Orleans/DependencyInjectionExtensions.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.SignalR; 2 | 3 | namespace Microsoft.Extensions.DependencyInjection; 4 | 5 | public static class DependencyInjectionExtensions 6 | { 7 | public static ISignalRServerBuilder AddOrleans(this ISignalRServerBuilder signalRServerBuilder) 8 | { 9 | signalRServerBuilder.Services.AddSingleton(typeof(HubLifetimeManager<>), typeof(OrleansHubLifetimeManager<>)); 10 | return signalRServerBuilder; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.SignalR.Orleans/Microsoft.AspNetCore.SignalR.Orleans.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net7.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | all 13 | runtime; build; native; contentfiles; analyzers 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /samples/Server/Server.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net7.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | all 13 | runtime; build; native; contentfiles; analyzers 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /samples/Client/Program.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.SignalR.Client; 2 | using Microsoft.Extensions.Logging; 3 | 4 | var connection = new HubConnectionBuilder() 5 | .WithUrl("https://localhost:7181/chat") 6 | .ConfigureLogging(logging => 7 | { 8 | logging.SetMinimumLevel(LogLevel.Information); 9 | logging.AddConsole(); 10 | }) 11 | .Build(); 12 | 13 | await Task.Delay(1000); 14 | 15 | connection.On("Send", (string name) => 16 | { 17 | Console.WriteLine($"Server: {name}"); 18 | }); 19 | 20 | await connection.StartAsync(); 21 | 22 | 23 | while (true) 24 | { 25 | Console.Write("> "); 26 | var message = Console.ReadLine(); 27 | await connection.InvokeAsync("Send", message); 28 | } -------------------------------------------------------------------------------- /samples/Server/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:40039", 7 | "sslPort": 44359 8 | } 9 | }, 10 | "profiles": { 11 | "WebApplication33": { 12 | "commandName": "Project", 13 | "dotnetRunMessages": true, 14 | "launchBrowser": false, 15 | "applicationUrl": "https://localhost:7181;http://localhost:5181", 16 | "environmentVariables": { 17 | "ASPNETCORE_ENVIRONMENT": "Development" 18 | } 19 | }, 20 | "IIS Express": { 21 | "commandName": "IISExpress", 22 | "launchBrowser": true, 23 | "environmentVariables": { 24 | "ASPNETCORE_ENVIRONMENT": "Development" 25 | } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.SignalR.Orleans/IHubLifetimeManagerGrainObserver.cs: -------------------------------------------------------------------------------- 1 | using Orleans; 2 | 3 | namespace Microsoft.AspNetCore.SignalR; 4 | 5 | internal interface IHubLifetimeManagerGrainObserver : IGrainObserver 6 | { 7 | Task SendAllAsync(string methodName, object?[] args); 8 | Task SendAllExceptAsync(string methodName, object?[] args, IReadOnlyList excludedConnectionIds); 9 | Task SendConnectionAsync(string connectionId, string methodName, object?[] args); 10 | Task SendGroupAsync(string groupName, string methodName, object?[] args); 11 | Task SendGroupExceptAsync(string groupName, string methodName, object?[] args, IReadOnlyList excludedConnectionIds); 12 | Task SendUserAsync(string userId, string methodName, object?[] args); 13 | Task AddToGroupAsync(string connectionId, string groupName); 14 | Task RemoveFromGroupAsync(string connectionId, string groupName); 15 | } -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.SignalR.Orleans/IHubLifetimeManagerGrain.cs: -------------------------------------------------------------------------------- 1 | using Orleans; 2 | 3 | namespace Microsoft.AspNetCore.SignalR; 4 | 5 | internal interface IHubLifetimeManagerGrain : IGrainWithStringKey 6 | { 7 | Task SendAllAsync(string methodName, object?[] args); 8 | Task SendAllExceptAsync(string methodName, object?[] args, IReadOnlyList excludedConnectionIds); 9 | Task SendConnectionAsync(string connectionId, string methodName, object?[] args); 10 | Task SendGroupAsync(string groupName, string methodName, object?[] args); 11 | Task SendGroupExceptAsync(string groupName, string methodName, object?[] args, IReadOnlyList excludedConnectionIds); 12 | Task SendUserAsync(string userId, string methodName, object?[] args); 13 | Task AddToGroupAsync(string connectionId, string groupName); 14 | Task RemoveFromGroupAsync(string connectionId, string groupName); 15 | Task SubscribeAsync(IHubLifetimeManagerGrainObserver observer); 16 | Task UnsubscribeAsync(IHubLifetimeManagerGrainObserver observer); 17 | } 18 | -------------------------------------------------------------------------------- /Microsoft.AspNetCore.SignalR.Orleans.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.3.32525.520 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{7D9D4FEB-9CB5-44DE-BEA2-7D9671E13E2E}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Client", "samples\Client\Client.csproj", "{86A5A7DC-E681-43F1-8974-61B431C88436}" 9 | EndProject 10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Server", "samples\Server\Server.csproj", "{384C3827-4082-44B8-990B-33D2C9DB79D6}" 11 | EndProject 12 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{0259A6B9-DF7C-43E3-9D55-0B5B1D184F7D}" 13 | EndProject 14 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.SignalR.Orleans", "src\Microsoft.AspNetCore.SignalR.Orleans\Microsoft.AspNetCore.SignalR.Orleans.csproj", "{EA43BA3A-457F-4194-B4FF-F4B00BCCB6EB}" 15 | EndProject 16 | Global 17 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 18 | Debug|Any CPU = Debug|Any CPU 19 | Release|Any CPU = Release|Any CPU 20 | EndGlobalSection 21 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 22 | {86A5A7DC-E681-43F1-8974-61B431C88436}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 23 | {86A5A7DC-E681-43F1-8974-61B431C88436}.Debug|Any CPU.Build.0 = Debug|Any CPU 24 | {86A5A7DC-E681-43F1-8974-61B431C88436}.Release|Any CPU.ActiveCfg = Release|Any CPU 25 | {86A5A7DC-E681-43F1-8974-61B431C88436}.Release|Any CPU.Build.0 = Release|Any CPU 26 | {384C3827-4082-44B8-990B-33D2C9DB79D6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 27 | {384C3827-4082-44B8-990B-33D2C9DB79D6}.Debug|Any CPU.Build.0 = Debug|Any CPU 28 | {384C3827-4082-44B8-990B-33D2C9DB79D6}.Release|Any CPU.ActiveCfg = Release|Any CPU 29 | {384C3827-4082-44B8-990B-33D2C9DB79D6}.Release|Any CPU.Build.0 = Release|Any CPU 30 | {EA43BA3A-457F-4194-B4FF-F4B00BCCB6EB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 31 | {EA43BA3A-457F-4194-B4FF-F4B00BCCB6EB}.Debug|Any CPU.Build.0 = Debug|Any CPU 32 | {EA43BA3A-457F-4194-B4FF-F4B00BCCB6EB}.Release|Any CPU.ActiveCfg = Release|Any CPU 33 | {EA43BA3A-457F-4194-B4FF-F4B00BCCB6EB}.Release|Any CPU.Build.0 = Release|Any CPU 34 | EndGlobalSection 35 | GlobalSection(SolutionProperties) = preSolution 36 | HideSolutionNode = FALSE 37 | EndGlobalSection 38 | GlobalSection(NestedProjects) = preSolution 39 | {86A5A7DC-E681-43F1-8974-61B431C88436} = {7D9D4FEB-9CB5-44DE-BEA2-7D9671E13E2E} 40 | {384C3827-4082-44B8-990B-33D2C9DB79D6} = {7D9D4FEB-9CB5-44DE-BEA2-7D9671E13E2E} 41 | {EA43BA3A-457F-4194-B4FF-F4B00BCCB6EB} = {0259A6B9-DF7C-43E3-9D55-0B5B1D184F7D} 42 | EndGlobalSection 43 | GlobalSection(ExtensibilityGlobals) = postSolution 44 | SolutionGuid = {4297AAFE-5828-48D9-855F-E29B86205358} 45 | EndGlobalSection 46 | EndGlobal 47 | -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.SignalR.Orleans/HubLifetimeManagerGrain.cs: -------------------------------------------------------------------------------- 1 | using Orleans; 2 | using Orleans.Runtime; 3 | 4 | namespace Microsoft.AspNetCore.SignalR; 5 | 6 | internal class HubLifetimeManagerGrain : Grain, IHubLifetimeManagerGrain 7 | { 8 | public Task AddToGroupAsync(string connectionId, string groupName) 9 | { 10 | return DoAction(static (s, state) => 11 | { 12 | var (connectionId, groupName) = state; 13 | 14 | return s.AddToGroupAsync(connectionId, groupName); 15 | 16 | }, (connectionId, groupName)); 17 | } 18 | 19 | public Task RemoveFromGroupAsync(string connectionId, string groupName) 20 | { 21 | return DoAction(static (s, state) => 22 | { 23 | var (connectionId, groupName) = state; 24 | 25 | return s.RemoveFromGroupAsync(connectionId, groupName); 26 | 27 | }, (connectionId, groupName)); 28 | } 29 | 30 | public Task SendAllAsync(string methodName, object?[] args) 31 | { 32 | return DoAction(static (s, state) => 33 | { 34 | var (methodName, args) = state; 35 | 36 | return s.SendAllAsync(methodName, args); 37 | 38 | }, (methodName, args)); 39 | } 40 | 41 | public Task SendAllExceptAsync(string methodName, object?[] args, IReadOnlyList excludedConnectionIds) 42 | { 43 | return DoAction(static (s, state) => 44 | { 45 | var (methodName, args, excludedConnectionIds) = state; 46 | 47 | return s.SendAllExceptAsync(methodName, args, excludedConnectionIds); 48 | 49 | }, (methodName, args, excludedConnectionIds)); 50 | } 51 | 52 | public Task SendConnectionAsync(string connectionId, string methodName, object?[] args) 53 | { 54 | return DoAction(static (s, state) => 55 | { 56 | var (connectionId, methodName, args) = state; 57 | 58 | return s.SendConnectionAsync(connectionId, methodName, args); 59 | 60 | }, (connectionId, methodName, args)); 61 | } 62 | 63 | public Task SendGroupAsync(string groupName, string methodName, object?[] args) 64 | { 65 | return DoAction(static (s, state) => 66 | { 67 | var (groupName, methodName, args) = state; 68 | 69 | return s.SendGroupAsync(groupName, methodName, args); 70 | 71 | }, (groupName, methodName, args)); 72 | } 73 | 74 | public Task SendGroupExceptAsync(string groupName, string methodName, object?[] args, IReadOnlyList excludedConnectionIds) 75 | { 76 | return DoAction(static (s, state) => 77 | { 78 | var (groupName, methodName, args, excludedConnectionIds) = state; 79 | 80 | return s.SendGroupExceptAsync(groupName, methodName, args, excludedConnectionIds); 81 | 82 | }, (groupName, methodName, args, excludedConnectionIds)); 83 | } 84 | 85 | public Task SendUserAsync(string userId, string methodName, object?[] args) 86 | { 87 | return DoAction(static (s, state) => 88 | { 89 | var (userId, methodName, args) = state; 90 | 91 | return s.SendUserAsync(userId, methodName, args); 92 | 93 | }, (userId, methodName, args)); 94 | } 95 | 96 | public Task SubscribeAsync(IHubLifetimeManagerGrainObserver observer) 97 | { 98 | State.Subscriptions.Add(observer); 99 | return WriteStateAsync(); 100 | } 101 | 102 | public Task UnsubscribeAsync(IHubLifetimeManagerGrainObserver observer) 103 | { 104 | State.Subscriptions.Remove(observer); 105 | return WriteStateAsync(); 106 | } 107 | 108 | private async Task DoAction(Func callback, TState state) 109 | { 110 | List? clientsToRemove = null; 111 | 112 | foreach (var s in State.Subscriptions) 113 | { 114 | try 115 | { 116 | await callback(s, state); 117 | } 118 | catch (Exception ex) when (ex is ClientNotAvailableException or OrleansMessageRejectionException) 119 | { 120 | clientsToRemove ??= new(); 121 | clientsToRemove.Add(s); 122 | } 123 | } 124 | 125 | if (clientsToRemove is not null) 126 | { 127 | foreach (var s in clientsToRemove) 128 | { 129 | State.Subscriptions.Remove(s); 130 | } 131 | 132 | await WriteStateAsync(); 133 | } 134 | } 135 | } 136 | 137 | internal class SubscriptionState 138 | { 139 | public HashSet Subscriptions { get; } = new(); 140 | } -------------------------------------------------------------------------------- /src/Microsoft.AspNetCore.SignalR.Orleans/OrleansHubLifetimeManager.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.Logging; 2 | using Orleans; 3 | 4 | namespace Microsoft.AspNetCore.SignalR; 5 | 6 | internal class OrleansHubLifetimeManager : HubLifetimeManager, IHubLifetimeManagerGrainObserver, IAsyncDisposable where THub : Hub 7 | { 8 | private readonly DefaultHubLifetimeManager _thisManager; 9 | private readonly IGrainFactory _grainFactory; 10 | private readonly IHubLifetimeManagerGrain _hubGrain; 11 | private readonly SemaphoreSlim _initialLock = new(1, 1); 12 | private IHubLifetimeManagerGrainObserver? _thisObserver; 13 | 14 | public OrleansHubLifetimeManager(IGrainFactory grainFactory, ILogger> logger) 15 | { 16 | _grainFactory = grainFactory; 17 | _thisManager = new(logger); 18 | 19 | _hubGrain = _grainFactory.GetGrain>(typeof(THub).FullName); 20 | } 21 | 22 | public override async Task AddToGroupAsync(string connectionId, string groupName, CancellationToken cancellationToken = default) 23 | { 24 | var group = _grainFactory.GetGrain>(groupName); 25 | 26 | await group.SubscribeAsync(_thisObserver!); 27 | 28 | await group.AddToGroupAsync(connectionId, groupName); 29 | } 30 | 31 | public override async Task OnConnectedAsync(HubConnectionContext connection) 32 | { 33 | await EnsureObserverAsync(); 34 | 35 | var connectionGrain = _grainFactory.GetGrain>(connection.ConnectionId); 36 | 37 | await connectionGrain.SubscribeAsync(_thisObserver!); 38 | 39 | if (connection.UserIdentifier is not null) 40 | { 41 | var userGrain = _grainFactory.GetGrain>(connection.UserIdentifier); 42 | 43 | await userGrain.SubscribeAsync(_thisObserver!); 44 | 45 | // await userGrain.AddToUserAsync(connection.ConnectionId, connection.UserIdentifier); 46 | } 47 | 48 | await _thisManager.OnConnectedAsync(connection); 49 | } 50 | 51 | public override async Task OnDisconnectedAsync(HubConnectionContext connection) 52 | { 53 | var connectionGrain = _grainFactory.GetGrain>(connection.ConnectionId); 54 | 55 | await connectionGrain.UnsubscribeAsync(_thisObserver!); 56 | 57 | if (connection.UserIdentifier is not null) 58 | { 59 | // var userGrain = _grainFactory.GetGrain>(connection.UserIdentifier); 60 | 61 | // TODO: Handle removal of users 62 | // await userGrain.RemoveFromUserAsync(connection.ConnectionId, connection.UserIdentifier); 63 | } 64 | 65 | await _thisManager.OnDisconnectedAsync(connection); 66 | } 67 | 68 | public override async Task RemoveFromGroupAsync(string connectionId, string groupName, CancellationToken cancellationToken = default) 69 | { 70 | var groupGrain = _grainFactory.GetGrain>(groupName); 71 | 72 | await groupGrain.RemoveFromGroupAsync(connectionId, groupName); 73 | 74 | await groupGrain.UnsubscribeAsync(_thisObserver!); 75 | } 76 | 77 | public override async Task SendAllAsync(string methodName, object?[] args, CancellationToken cancellationToken = default) 78 | { 79 | await _hubGrain.SendAllAsync(methodName, args); 80 | } 81 | 82 | public override Task SendAllExceptAsync(string methodName, object?[] args, IReadOnlyList excludedConnectionIds, CancellationToken cancellationToken = default) 83 | { 84 | return _hubGrain.SendAllExceptAsync(methodName, args, excludedConnectionIds); 85 | } 86 | 87 | public override Task SendConnectionAsync(string connectionId, string methodName, object?[] args, CancellationToken cancellationToken = default) 88 | { 89 | var connectionGrain = _grainFactory.GetGrain>(connectionId); 90 | 91 | return connectionGrain.SendConnectionAsync(connectionId, methodName, args); 92 | } 93 | 94 | public override Task SendConnectionsAsync(IReadOnlyList connectionIds, string methodName, object?[] args, CancellationToken cancellationToken = default) 95 | { 96 | var tasks = new Task[connectionIds.Count]; 97 | var i = 0; 98 | 99 | foreach (var id in connectionIds) 100 | { 101 | tasks[i++] = SendConnectionAsync(id, methodName, args, cancellationToken); 102 | } 103 | return Task.WhenAll(tasks); 104 | } 105 | 106 | public override Task SendGroupAsync(string groupName, string methodName, object?[] args, CancellationToken cancellationToken = default) 107 | { 108 | var group = _grainFactory.GetGrain>(groupName); 109 | 110 | return group.SendGroupAsync(groupName, methodName, args); 111 | } 112 | 113 | public override Task SendGroupExceptAsync(string groupName, string methodName, object?[] args, IReadOnlyList excludedConnectionIds, CancellationToken cancellationToken = default) 114 | { 115 | var group = _grainFactory.GetGrain>(groupName); 116 | 117 | return group.SendGroupExceptAsync(groupName, methodName, args, excludedConnectionIds); 118 | } 119 | 120 | public override Task SendGroupsAsync(IReadOnlyList groupNames, string methodName, object?[] args, CancellationToken cancellationToken = default) 121 | { 122 | var tasks = new Task[groupNames.Count]; 123 | var i = 0; 124 | 125 | foreach (var group in groupNames) 126 | { 127 | tasks[i++] = SendGroupAsync(group, methodName, args, cancellationToken); 128 | } 129 | 130 | return Task.WhenAll(tasks); 131 | } 132 | 133 | public override Task SendUserAsync(string userId, string methodName, object?[] args, CancellationToken cancellationToken = default) 134 | { 135 | var userGrain = _grainFactory.GetGrain>(userId); 136 | 137 | return userGrain.SendUserAsync(userId, methodName, args); 138 | } 139 | 140 | public override Task SendUsersAsync(IReadOnlyList userIds, string methodName, object?[] args, CancellationToken cancellationToken = default) 141 | { 142 | var tasks = new Task[userIds.Count]; 143 | var i = 0; 144 | 145 | foreach (var userId in userIds) 146 | { 147 | tasks[i++] = SendUserAsync(userId, methodName, args, cancellationToken); 148 | } 149 | 150 | return Task.WhenAll(tasks); 151 | } 152 | 153 | Task IHubLifetimeManagerGrainObserver.SendAllAsync(string methodName, object?[] args) 154 | { 155 | return _thisManager.SendAllAsync(methodName, args); 156 | } 157 | 158 | Task IHubLifetimeManagerGrainObserver.SendAllExceptAsync(string methodName, object?[] args, IReadOnlyList excludedConnectionIds) 159 | { 160 | return _thisManager.SendAllExceptAsync(methodName, args, excludedConnectionIds); 161 | } 162 | 163 | Task IHubLifetimeManagerGrainObserver.SendConnectionAsync(string connectionId, string methodName, object?[] args) 164 | { 165 | return _thisManager.SendConnectionAsync(connectionId, methodName, args); 166 | } 167 | 168 | Task IHubLifetimeManagerGrainObserver.SendGroupAsync(string groupName, string methodName, object?[] args) 169 | { 170 | return _thisManager.SendGroupAsync(groupName, methodName, args); 171 | } 172 | 173 | Task IHubLifetimeManagerGrainObserver.SendGroupExceptAsync(string groupName, string methodName, object?[] args, IReadOnlyList excludedConnectionIds) 174 | { 175 | return _thisManager.SendGroupExceptAsync(groupName, methodName, args, excludedConnectionIds); 176 | } 177 | 178 | Task IHubLifetimeManagerGrainObserver.AddToGroupAsync(string connectionId, string groupName) 179 | { 180 | // This will noop if the connection isn't on this node 181 | return _thisManager.AddToGroupAsync(connectionId, groupName); 182 | } 183 | 184 | Task IHubLifetimeManagerGrainObserver.RemoveFromGroupAsync(string connectionId, string groupName) 185 | { 186 | // This will noop if the connection isn't on this node 187 | _thisManager.RemoveFromGroupAsync(connectionId, groupName); 188 | 189 | // REVIEW: We need to track group -> connection count on this node 190 | return Task.FromResult(true); 191 | } 192 | 193 | Task IHubLifetimeManagerGrainObserver.SendUserAsync(string userId, string methodName, object?[] args) 194 | { 195 | return _thisManager.SendUserAsync(userId, methodName, args); 196 | } 197 | 198 | private async Task EnsureObserverAsync() 199 | { 200 | if (_thisObserver is null) 201 | { 202 | await _initialLock.WaitAsync(); 203 | 204 | try 205 | { 206 | if (_thisObserver is not null) 207 | { 208 | // Somebody else set the observer 209 | return; 210 | } 211 | 212 | _thisObserver = await _grainFactory.CreateObjectReference(this); 213 | 214 | await _hubGrain.SubscribeAsync(_thisObserver); 215 | } 216 | finally 217 | { 218 | _initialLock.Release(); 219 | } 220 | } 221 | } 222 | 223 | public async ValueTask DisposeAsync() 224 | { 225 | if (_thisObserver is not null) 226 | { 227 | await _hubGrain.UnsubscribeAsync(_thisObserver); 228 | } 229 | } 230 | } 231 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Ww][Ii][Nn]32/ 27 | [Aa][Rr][Mm]/ 28 | [Aa][Rr][Mm]64/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Ll]og/ 33 | [Ll]ogs/ 34 | 35 | # Visual Studio 2015/2017 cache/options directory 36 | .vs/ 37 | # Uncomment if you have tasks that create the project's static files in wwwroot 38 | #wwwroot/ 39 | 40 | # Visual Studio 2017 auto generated files 41 | Generated\ Files/ 42 | 43 | # MSTest test Results 44 | [Tt]est[Rr]esult*/ 45 | [Bb]uild[Ll]og.* 46 | 47 | # NUnit 48 | *.VisualState.xml 49 | TestResult.xml 50 | nunit-*.xml 51 | 52 | # Build Results of an ATL Project 53 | [Dd]ebugPS/ 54 | [Rr]eleasePS/ 55 | dlldata.c 56 | 57 | # Benchmark Results 58 | BenchmarkDotNet.Artifacts/ 59 | 60 | # .NET 61 | project.lock.json 62 | project.fragment.lock.json 63 | artifacts/ 64 | 65 | # Tye 66 | .tye/ 67 | 68 | # ASP.NET Scaffolding 69 | ScaffoldingReadMe.txt 70 | 71 | # StyleCop 72 | StyleCopReport.xml 73 | 74 | # Files built by Visual Studio 75 | *_i.c 76 | *_p.c 77 | *_h.h 78 | *.ilk 79 | *.meta 80 | *.obj 81 | *.iobj 82 | *.pch 83 | *.pdb 84 | *.ipdb 85 | *.pgc 86 | *.pgd 87 | *.rsp 88 | *.sbr 89 | *.tlb 90 | *.tli 91 | *.tlh 92 | *.tmp 93 | *.tmp_proj 94 | *_wpftmp.csproj 95 | *.log 96 | *.tlog 97 | *.vspscc 98 | *.vssscc 99 | .builds 100 | *.pidb 101 | *.svclog 102 | *.scc 103 | 104 | # Chutzpah Test files 105 | _Chutzpah* 106 | 107 | # Visual C++ cache files 108 | ipch/ 109 | *.aps 110 | *.ncb 111 | *.opendb 112 | *.opensdf 113 | *.sdf 114 | *.cachefile 115 | *.VC.db 116 | *.VC.VC.opendb 117 | 118 | # Visual Studio profiler 119 | *.psess 120 | *.vsp 121 | *.vspx 122 | *.sap 123 | 124 | # Visual Studio Trace Files 125 | *.e2e 126 | 127 | # TFS 2012 Local Workspace 128 | $tf/ 129 | 130 | # Guidance Automation Toolkit 131 | *.gpState 132 | 133 | # ReSharper is a .NET coding add-in 134 | _ReSharper*/ 135 | *.[Rr]e[Ss]harper 136 | *.DotSettings.user 137 | 138 | # TeamCity is a build add-in 139 | _TeamCity* 140 | 141 | # DotCover is a Code Coverage Tool 142 | *.dotCover 143 | 144 | # AxoCover is a Code Coverage Tool 145 | .axoCover/* 146 | !.axoCover/settings.json 147 | 148 | # Coverlet is a free, cross platform Code Coverage Tool 149 | coverage*.json 150 | coverage*.xml 151 | coverage*.info 152 | 153 | # Visual Studio code coverage results 154 | *.coverage 155 | *.coveragexml 156 | 157 | # NCrunch 158 | _NCrunch_* 159 | .*crunch*.local.xml 160 | nCrunchTemp_* 161 | 162 | # MightyMoose 163 | *.mm.* 164 | AutoTest.Net/ 165 | 166 | # Web workbench (sass) 167 | .sass-cache/ 168 | 169 | # Installshield output folder 170 | [Ee]xpress/ 171 | 172 | # DocProject is a documentation generator add-in 173 | DocProject/buildhelp/ 174 | DocProject/Help/*.HxT 175 | DocProject/Help/*.HxC 176 | DocProject/Help/*.hhc 177 | DocProject/Help/*.hhk 178 | DocProject/Help/*.hhp 179 | DocProject/Help/Html2 180 | DocProject/Help/html 181 | 182 | # Click-Once directory 183 | publish/ 184 | 185 | # Publish Web Output 186 | *.[Pp]ublish.xml 187 | *.azurePubxml 188 | # Note: Comment the next line if you want to checkin your web deploy settings, 189 | # but database connection strings (with potential passwords) will be unencrypted 190 | *.pubxml 191 | *.publishproj 192 | 193 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 194 | # checkin your Azure Web App publish settings, but sensitive information contained 195 | # in these scripts will be unencrypted 196 | PublishScripts/ 197 | 198 | # NuGet Packages 199 | *.nupkg 200 | # NuGet Symbol Packages 201 | *.snupkg 202 | # The packages folder can be ignored because of Package Restore 203 | **/[Pp]ackages/* 204 | # except build/, which is used as an MSBuild target. 205 | !**/[Pp]ackages/build/ 206 | # Uncomment if necessary however generally it will be regenerated when needed 207 | #!**/[Pp]ackages/repositories.config 208 | # NuGet v3's project.json files produces more ignorable files 209 | *.nuget.props 210 | *.nuget.targets 211 | 212 | # Microsoft Azure Build Output 213 | csx/ 214 | *.build.csdef 215 | 216 | # Microsoft Azure Emulator 217 | ecf/ 218 | rcf/ 219 | 220 | # Windows Store app package directories and files 221 | AppPackages/ 222 | BundleArtifacts/ 223 | Package.StoreAssociation.xml 224 | _pkginfo.txt 225 | *.appx 226 | *.appxbundle 227 | *.appxupload 228 | 229 | # Visual Studio cache files 230 | # files ending in .cache can be ignored 231 | *.[Cc]ache 232 | # but keep track of directories ending in .cache 233 | !?*.[Cc]ache/ 234 | 235 | # Others 236 | ClientBin/ 237 | ~$* 238 | *~ 239 | *.dbmdl 240 | *.dbproj.schemaview 241 | *.jfm 242 | *.pfx 243 | *.publishsettings 244 | orleans.codegen.cs 245 | 246 | # Including strong name files can present a security risk 247 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 248 | #*.snk 249 | 250 | # Since there are multiple workflows, uncomment next line to ignore bower_components 251 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 252 | #bower_components/ 253 | 254 | # RIA/Silverlight projects 255 | Generated_Code/ 256 | 257 | # Backup & report files from converting an old project file 258 | # to a newer Visual Studio version. Backup files are not needed, 259 | # because we have git ;-) 260 | _UpgradeReport_Files/ 261 | Backup*/ 262 | UpgradeLog*.XML 263 | UpgradeLog*.htm 264 | ServiceFabricBackup/ 265 | *.rptproj.bak 266 | 267 | # SQL Server files 268 | *.mdf 269 | *.ldf 270 | *.ndf 271 | 272 | # Business Intelligence projects 273 | *.rdl.data 274 | *.bim.layout 275 | *.bim_*.settings 276 | *.rptproj.rsuser 277 | *- [Bb]ackup.rdl 278 | *- [Bb]ackup ([0-9]).rdl 279 | *- [Bb]ackup ([0-9][0-9]).rdl 280 | 281 | # Microsoft Fakes 282 | FakesAssemblies/ 283 | 284 | # GhostDoc plugin setting file 285 | *.GhostDoc.xml 286 | 287 | # Node.js Tools for Visual Studio 288 | .ntvs_analysis.dat 289 | node_modules/ 290 | 291 | # Visual Studio 6 build log 292 | *.plg 293 | 294 | # Visual Studio 6 workspace options file 295 | *.opt 296 | 297 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 298 | *.vbw 299 | 300 | # Visual Studio 6 auto-generated project file (contains which files were open etc.) 301 | *.vbp 302 | 303 | # Visual Studio 6 workspace and project file (working project files containing files to include in project) 304 | *.dsw 305 | *.dsp 306 | 307 | # Visual Studio 6 technical files 308 | *.ncb 309 | *.aps 310 | 311 | # Visual Studio LightSwitch build output 312 | **/*.HTMLClient/GeneratedArtifacts 313 | **/*.DesktopClient/GeneratedArtifacts 314 | **/*.DesktopClient/ModelManifest.xml 315 | **/*.Server/GeneratedArtifacts 316 | **/*.Server/ModelManifest.xml 317 | _Pvt_Extensions 318 | 319 | # Paket dependency manager 320 | .paket/paket.exe 321 | paket-files/ 322 | 323 | # FAKE - F# Make 324 | .fake/ 325 | 326 | # CodeRush personal settings 327 | .cr/personal 328 | 329 | # Python Tools for Visual Studio (PTVS) 330 | __pycache__/ 331 | *.pyc 332 | 333 | # Cake - Uncomment if you are using it 334 | # tools/** 335 | # !tools/packages.config 336 | 337 | # Tabs Studio 338 | *.tss 339 | 340 | # Telerik's JustMock configuration file 341 | *.jmconfig 342 | 343 | # BizTalk build output 344 | *.btp.cs 345 | *.btm.cs 346 | *.odx.cs 347 | *.xsd.cs 348 | 349 | # OpenCover UI analysis results 350 | OpenCover/ 351 | 352 | # Azure Stream Analytics local run output 353 | ASALocalRun/ 354 | 355 | # MSBuild Binary and Structured Log 356 | *.binlog 357 | 358 | # NVidia Nsight GPU debugger configuration file 359 | *.nvuser 360 | 361 | # MFractors (Xamarin productivity tool) working folder 362 | .mfractor/ 363 | 364 | # Local History for Visual Studio 365 | .localhistory/ 366 | 367 | # Visual Studio History (VSHistory) files 368 | .vshistory/ 369 | 370 | # BeatPulse healthcheck temp database 371 | healthchecksdb 372 | 373 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 374 | MigrationBackup/ 375 | 376 | # Ionide (cross platform F# VS Code tools) working folder 377 | .ionide/ 378 | 379 | # Fody - auto-generated XML schema 380 | FodyWeavers.xsd 381 | 382 | # VS Code files for those working on multiple tools 383 | .vscode/* 384 | !.vscode/settings.json 385 | !.vscode/tasks.json 386 | !.vscode/launch.json 387 | !.vscode/extensions.json 388 | *.code-workspace 389 | 390 | # Local History for Visual Studio Code 391 | .history/ 392 | 393 | # Windows Installer files from build outputs 394 | *.cab 395 | *.msi 396 | *.msix 397 | *.msm 398 | *.msp 399 | 400 | # JetBrains Rider 401 | *.sln.iml 402 | 403 | ## 404 | ## Visual studio for Mac 405 | ## 406 | 407 | 408 | # globs 409 | Makefile.in 410 | *.userprefs 411 | *.usertasks 412 | config.make 413 | config.status 414 | aclocal.m4 415 | install-sh 416 | autom4te.cache/ 417 | *.tar.gz 418 | tarballs/ 419 | test-results/ 420 | 421 | # Mac bundle stuff 422 | *.dmg 423 | *.app 424 | 425 | # content below from: https://github.com/github/gitignore/blob/master/Global/macOS.gitignore 426 | # General 427 | .DS_Store 428 | .AppleDouble 429 | .LSOverride 430 | 431 | # Icon must end with two \r 432 | Icon 433 | 434 | 435 | # Thumbnails 436 | ._* 437 | 438 | # Files that might appear in the root of a volume 439 | .DocumentRevisions-V100 440 | .fseventsd 441 | .Spotlight-V100 442 | .TemporaryItems 443 | .Trashes 444 | .VolumeIcon.icns 445 | .com.apple.timemachine.donotpresent 446 | 447 | # Directories potentially created on remote AFP share 448 | .AppleDB 449 | .AppleDesktop 450 | Network Trash Folder 451 | Temporary Items 452 | .apdisk 453 | 454 | # content below from: https://github.com/github/gitignore/blob/master/Global/Windows.gitignore 455 | # Windows thumbnail cache files 456 | Thumbs.db 457 | ehthumbs.db 458 | ehthumbs_vista.db 459 | 460 | # Dump file 461 | *.stackdump 462 | 463 | # Folder config file 464 | [Dd]esktop.ini 465 | 466 | # Recycle Bin used on file shares 467 | $RECYCLE.BIN/ 468 | 469 | # Windows Installer files 470 | *.cab 471 | *.msi 472 | *.msix 473 | *.msm 474 | *.msp 475 | 476 | # Windows shortcuts 477 | *.lnk 478 | --------------------------------------------------------------------------------