forked from OrleansContrib/SignalR.Orleans
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/support for multiple hub types (OrleansContrib#9)
* refactor(OrleansHubLifetimeManager): refactor `if statement` in `ProcessAllMessage` * feat(user): implement user group * user: update `UserGroupPrefix` * refactor(User): extracted `GroupGrain` logic to `ConnectionGroupGrain`. `UserGrain` and `GroupGrain` inherits from `ConnectionGroupGrain`. * user: solutionfile * all: switch grain states as internal * fix(ConnectionGroup): `RemoveMember` wont throw an exception if the connection doesnt exists * test(InvokeConnectionAsync): added test to ensure an exception thrown if OnConnect is not called * test(InvokeConnectionAsync): fix failing test * removed unused code * feat(all): add support for multiple hubtypes + add `HubContext` * connectiongroup: fix subscription leak * refactor(all): `GetGrain` usages with extensions * chore(all): rename properties for readability purposes * docs(readme): update `Hub Context` section * readme: fixed paket command * fix(stream providers): fix stream issues between multiple servers * HubContext: renamed property * tests(OrleansHubLifetimeManager): added test for specific hub type messages + update test method names convention * chore(logging): added basic logging * feat(disconnected users): stream per connectionId * refactor(ConnectionGrain): rename `ConnectionGroupGrain` to `ConnectionGrain` * push minor change * removed serialization attribute * chore(serialization): removed all serialization
- Loading branch information
1 parent
8baec1f
commit 1306b2a
Showing
19 changed files
with
301 additions
and
177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
using Orleans; | ||
using System; | ||
using System.Threading.Tasks; | ||
using Orleans; | ||
|
||
namespace SignalR.Orleans.Clients | ||
{ | ||
public interface IClientGrain : IGrainWithStringKey | ||
{ | ||
Task SendMessage(object message); | ||
Task OnConnect(Guid serverId); | ||
Task OnConnect(Guid serverId, string hubName, string connectionId); | ||
Task OnDisconnect(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using Microsoft.AspNetCore.SignalR.Internal.Protocol; | ||
using SignalR.Orleans.Clients; | ||
using SignalR.Orleans.Core; | ||
using SignalR.Orleans.Groups; | ||
using SignalR.Orleans.Users; | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
// ReSharper disable once CheckNamespace | ||
namespace Orleans | ||
{ | ||
public static class GrainSignalRExtensions | ||
{ | ||
public static async Task SendSignalRMessage(this IConnectionGrain grain, string methodName, params object[] message) | ||
{ | ||
var invocationMessage = new InvocationMessage(Guid.NewGuid().ToString(), nonBlocking: true, target: methodName, arguments: message); | ||
await grain.SendMessage(invocationMessage); | ||
} | ||
} | ||
|
||
public static class GrainFactoryExtensions | ||
{ | ||
public static HubContext<THub> GetHub<THub>(this IGrainFactory grainFactory) | ||
{ | ||
return new HubContext<THub>(grainFactory); | ||
} | ||
|
||
internal static IClientGrain GetClientGrain(this IGrainFactory factory, string hubName, string connectionId) | ||
=> factory.GetGrain<IClientGrain>(Utils.BuildGrainId(hubName, connectionId)); | ||
|
||
internal static IGroupGrain GetGroupGrain(this IGrainFactory factory, string hubName, string groupName) | ||
=> factory.GetGrain<IGroupGrain>(Utils.BuildGrainId(hubName, groupName)); | ||
|
||
internal static IUserGrain GetUserGrain(this IGrainFactory factory, string hubName, string userId) | ||
=> factory.GetGrain<IUserGrain>(Utils.BuildGrainId(hubName, userId)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using Orleans; | ||
using SignalR.Orleans.Clients; | ||
using SignalR.Orleans.Groups; | ||
using SignalR.Orleans.Users; | ||
|
||
namespace SignalR.Orleans.Core | ||
{ | ||
public class HubContext<THub> | ||
{ | ||
private readonly IGrainFactory _grainFactory; | ||
private readonly string _hubName; | ||
|
||
public HubContext(IGrainFactory grainFactory) | ||
{ | ||
_grainFactory = grainFactory; | ||
var hubType = typeof(THub); | ||
_hubName = hubType.IsInterface && hubType.Name.StartsWith("I") | ||
? hubType.Name.Substring(1) | ||
: hubType.Name; | ||
} | ||
|
||
public IClientGrain Client(string connectionId) => _grainFactory.GetClientGrain(_hubName, connectionId); | ||
public IGroupGrain Group(string groupName) => _grainFactory.GetGroupGrain(_hubName, groupName); | ||
public IUserGrain User(string userId) => _grainFactory.GetUserGrain(_hubName, userId); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace SignalR.Orleans.Core | ||
{ | ||
internal static class Utils | ||
{ | ||
internal static string BuildGrainId(string hubName, string key) => $"{hubName}:{key}".ToLower(); | ||
|
||
internal static string BuildStreamHubName(string hubName) => $"registered-hub::{hubName}".ToLower(); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.