public void SetupHere() { var chatAuthenticationService = new Mock <IChatAuthenticationService>(); chatAuthenticationService.Setup(m => m.GetUser(It.IsAny <string>())) .ReturnsAsync(new ChatUser("peter#123", "AB", new ProfilePicture())); _chatAuthenticationService = chatAuthenticationService.Object; _banRepository = new Mock <IBanRepository>().Object; _connectionMapping = new ConnectionMapping(); _chatHistory = new ChatHistory(); _settingsRepository = new SettingsRepository(MongoClient); _chatHub = new ChatHub(_chatAuthenticationService, _banRepository, _settingsRepository, _connectionMapping, _chatHistory, null, null); var clients = new Mock <IHubCallerClients>(); clients.Setup(c => c.Group(It.IsAny <string>())).Returns(new Mock <IClientProxy>().Object); clients.Setup(c => c.Caller).Returns(new Mock <IClientProxy>().Object); _chatHub.Clients = clients.Object; var context = new Mock <HubCallerContext>(); context.Setup(c => c.ConnectionId).Returns("TestId"); _chatHub.Context = context.Object; _chatHub.Groups = new Mock <IGroupManager>().Object; }
public static void MapAlertsHub(IEndpointRouteBuilder endpoints) { endpoints.MapHub <AlertsHub>("/api/alertshub"); Connections = new ConnectionMapping <Lite <IUserEntity> >(); AlertsHub = (IHubContext <AlertsHub, IAlertsClient>)endpoints.ServiceProvider.GetService(typeof(IHubContext <AlertsHub, IAlertsClient>)) !; var alertEvents = Schema.Current.EntityEvents <AlertEntity>(); alertEvents.Saved += AlertEvents_Saved; alertEvents.PreUnsafeDelete += AlertEvents_PreUnsafeDelete; alertEvents.PreUnsafeUpdate += AlertEvents_PreUnsafeUpdate; alertEvents.PreUnsafeInsert += AlertEvents_PreUnsafeInsert; CacheLogic.BroadcastReceivers.Add("AlertForReceiver", args => { if (args == "*") { NotifySignalRClients(null); } else { var users = args.Split("/").Select(a => (Lite <IUserEntity>)Lite.ParsePrimaryKey <UserEntity>(a)).ToHashSet(); NotifySignalRClients(users); } }); }
public override Task OnConnected() { string name = Context.QueryString["username"]; ConnectionMapping <string> .Add(name, Context.ConnectionId); Clients.All.userJoinOrLeave(ConnectionMapping <string> .GetConnections()); return(base.OnConnected()); }
public override Task OnDisconnected(bool stopCalled) { string name = Context.QueryString["username"]; ConnectionMapping <string> .Remove(name, Context.ConnectionId); Clients.All.userJoinOrLeave(ConnectionMapping <string> .GetConnections()); return(base.OnDisconnected(stopCalled)); }
public IntakeService(IArticleRepository articleRepository, ILocationRepository locationRepository, IHubContext <DeviceHub> intakeDeviceHubContext, IHubContext <IntakeDashboardHub> intakeDashboardHubContext, ConnectionMapping connectionMapping) { _articleRepository = articleRepository; _locationRepository = locationRepository; _intakeDeviceHubContext = intakeDeviceHubContext; _intakeDashboardHubContext = intakeDashboardHubContext; _connectionMapping = connectionMapping; }
public void ConnectionMappingAddSingleTest() { ConnectionMapping <string> groups = new ConnectionMapping <string>(); string group = "group_1"; CodeEditorUser user = new CodeEditorUser("g1_connection_1"); groups.Add(group, user); Assert.True(groups.Count == 1); Assert.Single(groups.GetConnections(group)); Assert.Equal(user, groups.GetConnections(group).ElementAtOrDefault(0)); return; }
public void Send(string from, string to, string message, string datetime) { _messages.Add(new Message { Body = message, From = from, To = to, DateTimeStr = datetime }); var connectionIds = ConnectionMapping <string> .GetConnections(to).ToList(); connectionIds.AddRange(ConnectionMapping <string> .GetConnections(from)); foreach (var connectionId in connectionIds) { Clients.Client(connectionId).newMessage(from, message, datetime); } }
public void OnCallback(string input) { var jobNameIndex = input.IndexOf('$'); var jobName = input.Substring(0, jobNameIndex); if (Enum.TryParse(jobName, true, out JobEnum job)) { var bodyInput = input.Substring(jobNameIndex + 1); var context = GlobalHost.ConnectionManager.GetConnectionContext <LogConnection>(); ConnectionMapping.GetConnections(job).ToList().ForEach(conn => context.Connection.Send(conn, bodyInput)); Console.WriteLine(bodyInput); return; } Console.WriteLine(input); }
public void Test() { SignalXTester.Run( (signalx, assert) => { SignalXTester.ScriptDownLoadFunction = ScriptSource.ScriptDownLoadFunction; signalx.SetUpClientErrorMessageHandler((error, request) => { }); signalx.SetUpClientDebugMessageHandler((error, request) => { }); SignalX mySignalX = SignalX.Instance; signalx.OnException((message, exception) => { }); signalx.OnWarning((message, exception) => { }); signalx.OnConnectionEvent((message, exception) => { }); signalx.AllowDynamicServer = false; signalx.Settings.RequireAuthorizationForPersistentConnections = false; signalx.Settings.ManageUserConnections = true; ConnectionMapping <string> Connections = signalx.Connections; bool HasOneOrMoreConnections = signalx.Settings.HasOneOrMoreConnections; HubConfiguration HubConfiguration = signalx.Settings.HubConfiguration; bool LogAgentMessagesOnClient = signalx.Settings.LogAgentMessagesOnClient; // ISignalXClientReceiver Receiver = signalx.Settings.Receiver; bool RequireAuthorizationForAllHandlers = signalx.Settings.RequireAuthorizationForAllHandlers; signalx.AuthenticationHandler(request => Task.FromResult(true)); signalx.DisableAllClients(); signalx.DisableClient("test"); signalx.EnableAllClients(); signalx.EnableClient("test"); signalx.GetInComingMessageSpeedAsync(TimeSpan.FromSeconds(10)); signalx.GetOutGoingMessageSpeedAsync(TimeSpan.FromSeconds(10)); signalx.SetGlobalDefaultMessageBufferSize(1000); signalx.AuthenticationHandler(r => Task.FromResult(true)); SignalXTester.ScriptDownLoadFunction = ScriptSource.ScriptDownLoadFunction; SignalXTester.EmbedeLibraryScripts = true; return(new SignalXTestDefinition("") { OnAppStarted = () => { signalx.Server(SignalXExtensions.GenerateUniqueNameId().Replace("-", ""), request => { }); signalx.Server(ServerType.Authorized, SignalXExtensions.GenerateUniqueNameId().Replace("-", ""), request => { }); signalx.Server(ServerType.AuthorizedSingleAccess, SignalXExtensions.GenerateUniqueNameId().Replace("-", ""), request => { }); signalx.Server(ServerType.SingleAccess, SignalXExtensions.GenerateUniqueNameId().Replace("-", ""), request => { }); }, TestEvents = new TestEventHandler( () => { assert.AreEqual(1, (int)signalx.ConnectionCount); }) }); }); }
public void ConnectionMappingAddMultipleTest() { ConnectionMapping <string> groups = new ConnectionMapping <string>(); string firstGroup = "group_1"; CodeEditorUser g1FirstUser = new CodeEditorUser("g1_connection_1"); CodeEditorUser g1SecondUser = new CodeEditorUser("g1_connection_2"); string secondGroup = "group_2"; CodeEditorUser g2FirstUser = new CodeEditorUser("g2_connection_1"); groups.Add(firstGroup, g1FirstUser); groups.Add(firstGroup, g1SecondUser); groups.Add(secondGroup, g2FirstUser); Assert.True(groups.Count == 2); Assert.Equal(2, groups.GetConnections(firstGroup).ToList <CodeEditorUser>().Count); Assert.Equal(g1FirstUser, groups.GetConnections(firstGroup).ElementAtOrDefault(0)); Assert.Equal(g1SecondUser, groups.GetConnections(firstGroup).ElementAtOrDefault(1)); Assert.Equal(g2FirstUser, groups.GetConnections(secondGroup).ElementAtOrDefault(0)); return; }
public void ConnectionMappingRemoveTest() { ConnectionMapping <string> groups = new ConnectionMapping <string>(); string firstGroup = "group_1"; CodeEditorUser g1FirstUser = new CodeEditorUser("g1_connection_1"); CodeEditorUser g1SecondUser = new CodeEditorUser("g1_connection2"); groups.Add(firstGroup, g1FirstUser); groups.Add(firstGroup, g1SecondUser); Assert.True(groups.Count == 1); Assert.Equal(2, groups.GetConnections(firstGroup).ToList <CodeEditorUser>().Count); Assert.Equal(g1FirstUser, groups.GetConnections(firstGroup).ElementAtOrDefault(0)); Assert.Equal(g1SecondUser, groups.GetConnections(firstGroup).ElementAtOrDefault(1)); groups.Remove(firstGroup, "g1_connection_1"); Assert.True(groups.Count == 1); Assert.Single(groups.GetConnections(firstGroup).ToList <CodeEditorUser>()); Assert.Equal(g1SecondUser, groups.GetConnections(firstGroup).ElementAtOrDefault(0)); return; }
public void ConnectionMappingFindKeysTest() { ConnectionMapping <string> groups = new ConnectionMapping <string>(); string firstGroup = "group_1"; CodeEditorUser g1FirstUser = new CodeEditorUser("g1_connection_1"); g1FirstUser.GroupName = firstGroup; CodeEditorUser g1SecondUser = new CodeEditorUser("g1_connection_2"); g1SecondUser.GroupName = firstGroup; string secondGroup = "group_2"; CodeEditorUser g2FirstUser = new CodeEditorUser("g2_connection_1"); g2FirstUser.GroupName = secondGroup; groups.Add(firstGroup, g1FirstUser); groups.Add(firstGroup, g1SecondUser); groups.Add(secondGroup, g2FirstUser); Assert.Equal(firstGroup, groups.FindKeys("g1_connection_1").ElementAtOrDefault(0)); Assert.Equal(firstGroup, groups.FindKeys("g1_connection_2").ElementAtOrDefault(0)); Assert.Equal(secondGroup, groups.FindKeys("g2_connection_1").ElementAtOrDefault(0)); return; }
static VoipHub() { Log = LogManager.GetLogger("ASC.Voip"); Phones = new ListPhones(Log); Connections = new ConnectionMapping(); }
public Notification(IHubContext <Notification> hub) { _connectionMapping = new ConnectionMapping(hub); }
public AbstractHub(ConnectionMapping <TConnectionKey> connections) { _connections = connections; }
public MessagesHub(IMessageService ms, ConnectionMapping <string> connections) { _ms = ms; _connections = connections; }
public ConnectionMappingTest() { _connnectionMapping = new ConnectionMapping(); }
public MessagesController(IMessageService ms, ConnectionMapping <string> connections) { _ms = new MessagesService(Db); _connections = connections; }
public NotificationHub() { _connections = ConnectionMapping.GetInstance(); }
static UserContext() { DefaultConnectionStringName = "DeusMaster"; SignalRConnectionMapping = new ConnectionMapping(); }
public ClientConnectionHandler(IHubContext hubContext) { Connections = new ConnectionMapping(hubContext); Endpoints = new Dictionary <string, EndpointConnectionInfo>(); }
public async Task <ServiceResponse <object> > GetUsersForChat() { List <ChatUserForListDto> Users = new List <ChatUserForListDto>(); if (!string.IsNullOrEmpty(_LoggedIn_UserRole)) { if (_LoggedIn_UserRole == Enumm.UserType.Admin.ToString()) { Users = (from u in _context.Users join csU in _context.ClassSectionUsers on u.Id equals csU.UserId join cs in _context.ClassSections on csU.ClassSectionId equals cs.Id where u.UserTypeId == (int)Enumm.UserType.Teacher && u.SchoolBranchId == _LoggedIn_BranchID select new ChatUserForListDto { UserIds = new List <int>() { u.Id }, Names = u.FullName, UserName = u.Username, IsOnline = ConnectionMapping <string> .GetConnections(u.Username).Any(), Description = cs.Class.Name + " " + cs.Section.SectionName, Photos = _context.Photos.Where(m => m.UserId == u.Id && m.IsPrimary == true).OrderByDescending(m => m.Id).Select(x => new PhotoDto { Id = x.Id, Name = x.Name, Url = _fileRepo.AppendImagePath(x.Name) }).ToList(), }).Distinct().ToList(); Users.AddRange((from u in _context.Users where u.UserTypeId == (int)Enumm.UserType.Admin && u.SchoolBranchId == _LoggedIn_BranchID && u.Id != _LoggedIn_UserID select new ChatUserForListDto { UserIds = new List <int>() { u.Id }, Names = u.FullName, UserName = u.Username, IsOnline = ConnectionMapping <string> .GetConnections(u.Username).Any(), Description = "", Photos = _context.Photos.Where(m => m.UserId == u.Id && m.IsPrimary == true).OrderByDescending(m => m.Id).Select(x => new PhotoDto { Id = x.Id, Name = x.Name, Url = _fileRepo.AppendImagePath(x.Name) }).ToList(), }).Distinct().ToList()); } else if (_LoggedIn_UserRole == Enumm.UserType.Teacher.ToString()) { var ClassSections = await(from csU in _context.ClassSectionUsers join cs in _context.ClassSections on csU.ClassSectionId equals cs.Id join u in _context.Users on csU.UserId equals u.Id where csU.UserId == _LoggedIn_UserID && u.Role == Enumm.UserType.Teacher.ToString() select new ClassSectionForResultListDto { ClassSectionId = cs.Id, Classs = cs.Class.Name, Section = cs.Section.SectionName }).Distinct().ToListAsync(); //var ClassSections = await (from cla in _context.ClassLectureAssignment // join cs in _context.ClassSections // on cla.ClassSectionId equals cs.Id // where cla.TeacherId == _LoggedIn_UserID // select new ClassSectionForResultListDto // { // ClassSectionId = cs.Id, // Classs = cs.Class.Name, // Section = cs.Section.SectionName // }).Distinct().ToListAsync(); Users = await(from u in _context.Users join csU in _context.ClassSectionUsers on u.Id equals csU.UserId join cs in _context.ClassSections on csU.ClassSectionId equals cs.Id let c1 = ClassSections.Select(m => m.ClassSectionId).Contains(csU.ClassSectionId) where u.UserTypeId == (int)Enumm.UserType.Student && c1 select new ChatUserForListDto { UserIds = new List <int>() { u.Id }, Names = u.FullName, UserName = u.Username, IsOnline = ConnectionMapping <string> .GetConnections(u.Username).Any(), Description = cs.Class.Name + " " + cs.Section.SectionName, Photos = _context.Photos.Where(m => m.UserId == u.Id && m.IsPrimary == true).OrderByDescending(m => m.Id).Select(x => new PhotoDto { Id = x.Id, Name = x.Name, Url = _fileRepo.AppendImagePath(x.Name) }).ToList(), }).Distinct().ToListAsync(); Users.AddRange((from u in _context.Users join csU in _context.ClassSectionUsers on u.Id equals csU.UserId join cs in _context.ClassSections on csU.ClassSectionId equals cs.Id let c1 = ClassSections.Select(m => m.ClassSectionId).Contains(csU.ClassSectionId) where u.UserTypeId == (int)Enumm.UserType.Teacher && u.SchoolBranchId == _LoggedIn_BranchID && c1 && u.Id != _LoggedIn_UserID select new ChatUserForListDto { UserIds = new List <int>() { u.Id }, Names = u.FullName, UserName = u.Username, IsOnline = ConnectionMapping <string> .GetConnections(u.Username).Any(), Description = cs.Class.Name + " " + cs.Section.SectionName, Photos = _context.Photos.Where(m => m.UserId == u.Id && m.IsPrimary == true).OrderByDescending(m => m.Id).Select(x => new PhotoDto { Id = x.Id, Name = x.Name, Url = _fileRepo.AppendImagePath(x.Name) }).ToList(), }).Distinct().ToList()); Users.AddRange((from u in _context.Users where u.UserTypeId == (int)Enumm.UserType.Admin && u.SchoolBranchId == _LoggedIn_BranchID select new ChatUserForListDto { UserIds = new List <int>() { u.Id }, Names = u.FullName, UserName = u.Username, IsOnline = ConnectionMapping <string> .GetConnections(u.Username).Any(), Description = "", Photos = _context.Photos.Where(m => m.UserId == u.Id && m.IsPrimary == true).OrderByDescending(m => m.Id).Select(x => new PhotoDto { Id = x.Id, Name = x.Name, Url = _fileRepo.AppendImagePath(x.Name) }).ToList(), }).Distinct().ToList()); } else if (_LoggedIn_UserRole == Enumm.UserType.Student.ToString()) { var ClassSections = await(from u in _context.Users join csU in _context.ClassSectionUsers on u.Id equals csU.UserId join cs in _context.ClassSections on csU.ClassSectionId equals cs.Id where csU.UserId == _LoggedIn_UserID select new ClassSectionForResultListDto { ClassSectionId = cs.Id, Classs = cs.Class.Name, Section = cs.Section.SectionName }).Distinct().ToListAsync(); Users = (from u in _context.Users join csU in _context.ClassSectionUsers on u.Id equals csU.UserId join cs in _context.ClassSections on csU.ClassSectionId equals cs.Id let c1 = ClassSections.Select(m => m.ClassSectionId).Contains(csU.ClassSectionId) where u.UserTypeId == (int)Enumm.UserType.Teacher && u.SchoolBranchId == _LoggedIn_BranchID && c1 select new ChatUserForListDto { UserIds = new List <int>() { u.Id }, Names = u.FullName, UserName = u.Username, IsOnline = ConnectionMapping <string> .GetConnections(u.Username).Any(), Description = cs.Class.Name + " " + cs.Section.SectionName, Photos = _context.Photos.Where(m => m.UserId == u.Id && m.IsPrimary == true).OrderByDescending(m => m.Id).Select(x => new PhotoDto { Id = x.Id, Name = x.Name, Url = _fileRepo.AppendImagePath(x.Name) }).ToList(), }).Distinct().ToList(); Users.AddRange((from u in _context.Users join csU in _context.ClassSectionUsers on u.Id equals csU.UserId join cs in _context.ClassSections on csU.ClassSectionId equals cs.Id let c1 = ClassSections.Select(m => m.ClassSectionId).Contains(csU.ClassSectionId) where u.UserTypeId == (int)Enumm.UserType.Student && u.SchoolBranchId == _LoggedIn_BranchID && u.Id != _LoggedIn_UserID && c1 select new ChatUserForListDto { UserIds = new List <int>() { u.Id }, UserName = u.Username, IsOnline = ConnectionMapping <string> .GetConnections(u.Username).Any(), Names = u.FullName, Description = cs.Class.Name + " " + cs.Section.SectionName, Photos = _context.Photos.Where(m => m.UserId == u.Id && m.IsPrimary == true).OrderByDescending(m => m.Id).Select(x => new PhotoDto { Id = x.Id, Name = x.Name, Url = _fileRepo.AppendImagePath(x.Name) }).ToList(), }).Distinct().ToList()); //Users = (from u in _context.Users // join cla in _context.ClassLectureAssignment // on u.Id equals cla.TeacherId // join cs in _context.ClassSections // on cla.ClassSectionId equals cs.Id // where u.UserTypeId == (int)Enumm.UserType.Teacher // && ClassSections.Select(m => m.ClassSectionId).Contains(cla.ClassSectionId) // && u.SchoolBranchId == _LoggedIn_BranchID // select new ChatUserForListDto // { // UserIds = new List<int>() { u.Id }, // Names = u.FullName, // UserName = u.Username, // IsOnline = ConnectionMapping<string>.GetConnections(u.Username).Any(), // Description = cs.Class.Name + " " + cs.Section.SectionName, // Photos = _context.Photos.Where(m => m.UserId == u.Id && m.IsPrimary == true).OrderByDescending(m => m.Id).Select(x => new PhotoDto // { // Id = x.Id, // Name = x.Name, // Url = _fileRepo.AppendImagePath(x.Name) // }).ToList(), // }).Distinct().ToList(); //Users.AddRange((from u in _context.Users // join cla in _context.ClassLectureAssignment // on u.Id equals cla.TeacherId // join cs in _context.ClassSections // on cla.ClassSectionId equals cs.Id // where u.UserTypeId == (int)Enumm.UserType.Student // && ClassSections.Select(m => m.ClassSectionId).Contains(cla.ClassSectionId) // && u.SchoolBranchId == _LoggedIn_BranchID // && u.Id != _LoggedIn_UserID // select new ChatUserForListDto // { // UserIds = new List<int>() { u.Id }, // UserName = u.Username, // IsOnline = ConnectionMapping<string>.GetConnections(u.Username).Any(), // Names = u.FullName, // Description = cs.Class.Name + " " + cs.Section.SectionName, // Photos = _context.Photos.Where(m => m.UserId == u.Id && m.IsPrimary == true).OrderByDescending(m => m.Id).Select(x => new PhotoDto // { // Id = x.Id, // Name = x.Name, // Url = _fileRepo.AppendImagePath(x.Name) // }).ToList(), // }).Distinct().ToList()); } } else { _serviceResponse.Success = false; _serviceResponse.Message = CustomMessage.UserNotLoggedIn; return(_serviceResponse); } _serviceResponse.Success = true; _serviceResponse.Data = Users; return(_serviceResponse); }