public void UpdateModule(String roomGuid, String userGuid, ModuleModel model) { if(CollaborationRooms.ContainsKey(roomGuid)){ for(int i = 0; i < CollaborationRooms[roomGuid].Modules.Count; i++) { if (model.ModuleId == CollaborationRooms[roomGuid].Modules[i].ModuleId) { CollaborationRooms[roomGuid].Modules[i] = model; Clients.Group(roomGuid,Context.ConnectionId).updateModule(model); //Clients.All.updateModule(model); break; } } } }
//A public chat detail collection //So make a model public CollaborationHub() { //Create a couple of demo rooms if nothing exists in context collection if (CollaborationRooms.Count == 0) { /*ModuleModel testMod1 = new ModuleModel(); testMod1.ModuleId = 1; testMod1.ModuleTypeId = Constants.MODULE_TYPE_CHAT; testMod1.ModuleWidth = 200; testMod1.ModuleHeight = 200; testMod1.ModuleX = 100; testMod1.ModuleY = 100; testMod1.ModuleContent = ""+ "{"+ " \"log\":[\"This is some test chat\", \"And this should come second\", \"Look at all of this chat\"]" + "}";*/ ModuleModel testMod2 = new ModuleModel(); testMod2.ModuleId = 2; testMod2.ModuleTypeId = Constants.MODULE_TYPE_CHAT; testMod2.ModuleWidth = 300; testMod2.ModuleHeight = 300; testMod2.ModuleX = 100; testMod2.ModuleY = 100; testMod2.ModuleContent = "" + "{" + " \"log\":[\"Welcome to the chat room\"]" + "}"; RoomModel room1 = new RoomModel(); room1.BannedUsers = new ConcurrentDictionary<String, RoomUserModel>(); room1.CurrentUsers = new ConcurrentDictionary<String, RoomUserModel>(); room1.RoomName = "General Chat"; room1.RoomGuid = Guid.NewGuid().ToString(); room1.RoomDescription = "Welcome to CollaboratR, from SignalR!"; room1.Modules = new List<ModuleModel>(); room1.Modules.Add(testMod2); RoomModel room2 = new RoomModel(); room2.BannedUsers = new ConcurrentDictionary<String, RoomUserModel>(); room2.CurrentUsers = new ConcurrentDictionary<String, RoomUserModel>(); room2.RoomName = "Private chat"; room2.RoomGuid = Guid.NewGuid().ToString(); room2.RoomDescription = "This is private chat"; room2.Password = "******"; RoomModel room3 = new RoomModel(); room3.BannedUsers = new ConcurrentDictionary<String, RoomUserModel>(); room3.CurrentUsers = new ConcurrentDictionary<String, RoomUserModel>(); room3.RoomName = "Current News"; room3.RoomGuid = Guid.NewGuid().ToString(); room3.RoomDescription = "Come discuss current news and events!"; if (!CollaborationRooms.ContainsKey(room1.RoomGuid)) { CollaborationRooms.TryAdd(room1.RoomGuid, room1); } if (!CollaborationRooms.ContainsKey(room2.RoomGuid)) { CollaborationRooms.TryAdd(room2.RoomGuid, room2); } if (!CollaborationRooms.ContainsKey(room3.RoomGuid)) { CollaborationRooms.TryAdd(room3.RoomGuid, room3); } } /////////////////////////////////////////////////// /////////////////////////////////////////////////// }