private IHub CreateHub(IRequest request, HubDescriptor descriptor, string connectionId, StateChangeTracker tracker = null, bool throwIfFailedToCreate = false) { try { var hub = _manager.ResolveHub(descriptor.Name); if (hub != null) { tracker = tracker ?? new StateChangeTracker(); hub.Context = new HubCallerContext(request, connectionId); hub.Clients = new HubConnectionContext(_pipelineInvoker, Connection, descriptor.Name, connectionId, tracker); hub.Groups = new GroupManager(Connection, PrefixHelper.GetHubGroupName(descriptor.Name)); } return(hub); } catch (Exception ex) { Trace.TraceInformation("Error creating Hub {0}. " + ex.Message, descriptor.Name); if (throwIfFailedToCreate) { throw; } return(null); } }
public void TestHubGroupMessage(string input, string hub) { var hubs = new List <string> { "hub1", "hub.hub1", "hub.hub1.h.hub2" }; var parser = new SignalRMessageParser(hubs, _resolver); var groupName = GenerateRandomName(); var fullName = PrefixHelper.GetHubGroupName(hub + "." + groupName); var message = SignalRMessageUtility.CreateMessage(fullName, input); var excludedConnectionIds = new string[] { GenerateRandomName(), GenerateRandomName() }; message.Filter = GetFilter(excludedConnectionIds.Select(s => PrefixHelper.GetConnectionId(s)).ToList()); var msgs = parser.GetMessages(message).ToList(); Assert.Single(msgs); var msg = msgs[0].Message as GroupBroadcastDataMessage; Assert.NotNull(msg); // For group message, it is the full name as the group, e.g. hg-hub.hub1.h.hub2.abcde Assert.Equal(fullName, msg.GroupName); Assert.Equal <string>(excludedConnectionIds, msg.ExcludedList); Assert.Equal(input, msg.Payloads["json"].GetSingleFramePayload()); }
private IHub CreateHub(HttpRequest request, HubDescriptor descriptor, string connectionId, bool throwIfFailedToCreate = false) { try { var hub = _manager.ResolveHub(descriptor.Name); if (hub != null) { hub.Context = new HubCallerContext(request, connectionId); hub.Clients = new HubConnectionContext(_pipelineInvoker, Connection, descriptor.Name, connectionId); hub.Groups = new GroupManager(Connection, PrefixHelper.GetHubGroupName(descriptor.Name)); } return(hub); } catch (Exception ex) { Logger.LogInformation(String.Format("Error creating Hub {0}. {1}", descriptor.Name, ex.Message)); if (throwIfFailedToCreate) { throw; } return(null); } }
public HubContext(IConnection connection, IHubPipelineInvoker invoker, string hubName) { Clients = new HubConnectionContextBase(connection, invoker, hubName); Groups = new GroupManager(connection, PrefixHelper.GetHubGroupName(hubName)); }
public HubContext(Func <string, ClientHubInvocation, IList <string>, Task> send, string hubName, IConnection connection) { Clients = new ExternalHubConnectionContext(send, hubName); Groups = new GroupManager(connection, PrefixHelper.GetHubGroupName(hubName)); }