public ActionResult Edit([Bind(Include = "ID,Sync,LastUpdate")] Room room, string[] ModsAllowedID) { if (ModelState.IsValid) { Room roomBefore = db.Rooms.Find(room.ID); // handle mods roomBefore.ModeratorsAllowed.Clear(); if (ModsAllowedID == null) { ModsAllowedID = new string[0]; } List <Moderator> newModeratorsAllowed = db.Moderators.Where(m => ModsAllowedID.Contains(m.Username)).ToList(); roomBefore.ModeratorsAllowed.Add(roomBefore.Moderator); foreach (Moderator m in newModeratorsAllowed) { roomBefore.ModeratorsAllowed.Add(m); } // handle sync if (room.Sync && !roomBefore.Sync) { //VmtDevAPIRegisterLiveChat(room.ID); VmtDevAPI.RegisterLiveActions(room.ID); } if (!room.Sync && roomBefore.Sync) { VmtDevAPI.CloseSocket(room.ID); } roomBefore.Sync = room.Sync; db.Entry(roomBefore).State = EntityState.Modified; // TODO check disable? db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ID = new SelectList(db.Groups, "RoomID", "UsernamesAsString", room.ID); return(View(room)); }
// GET: Rooms/SyncNewRooms public void SyncNewRooms(string followedRoomId = "None") { try { string user = AppHelper.GetVmtUser(); // make HTML request var client = new ExtendedWebClient(); client.Encoding = System.Text.Encoding.UTF8; string roomsData = client.DownloadString(VmtDevAPI.VMT_URL + "/rooms/"); // sync rooms (if followedRoomId is not 'None', then user is not a moderator) List <Room> newRooms; if (followedRoomId == "None") { newRooms = SyncUserRooms(user.ToLower(), roomsData); } else { newRooms = followNewRoom(user.ToLower(), followedRoomId, roomsData); } foreach (Room room in newRooms) { VmtDevAPI.RegisterLiveChat(room.ID); VmtDevAPI.RegisterLiveActions(room.ID); } } catch (Exception e) { throw e; } }
public void CheckIdleness(string rooms) { if (rooms.CompareTo("") == 0) { return; } List <int> roomList = rooms.Split(',').Select(Int32.Parse).ToList(); VmtDevAPI.HandleIdleness(roomList); }
//send what rooms were chosen, and add them to AlertAnalyzer public void StartIdleness(string rooms) { if (rooms.CompareTo("") == 0) { return; } List <int> roomList = rooms.Split(',').Select(Int32.Parse).ToList(); VmtDevAPI.OpenAnalyzeRooms(roomList); context.Clients.Client(Context.ConnectionId).updateIdlenessAlertFrequency(this.idlenessAlertFrequency); }
//open socket on chosen rooms public void RegisterLiveChatAndLiveActions(string roomsFromClient) { if (roomsFromClient.CompareTo("") == 0) { return; } List <String> roomsID = roomsFromClient.Split(',').ToList(); foreach (String id in roomsID) { VmtDevAPI.RegisterLiveChat(int.Parse(id)); VmtDevAPI.RegisterLiveActions(int.Parse(id)); } }
private List <UserData> ExtractUsersInRoom(int roomID) { List <UserData> usersData = new List <UserData>(); using (SagletModel db = new SagletModel()) { Room room = db.Rooms.Find(roomID); HashSet <string> usersIDs = new HashSet <string>(room.RoomGroup.GetUsersFromString(), StringComparer.OrdinalIgnoreCase); HashSet <string> usersOnline = new HashSet <string>(VmtDevAPI.GetUsersConnected(roomID), StringComparer.OrdinalIgnoreCase); foreach (string userID in usersIDs) { bool isOnline = usersOnline.Contains(userID, StringComparer.OrdinalIgnoreCase); UserData data = ExtractUserData(roomID, userID, isOnline); usersData.Add(data); } } return(usersData); }
public void IdlenessOpenRoom(int idleWindow, List <int> roomIDs) { foreach (int roomID in roomIDs) { bool wasAlreadyOpened = criticalPointAlerts.openRoom(roomID); if (wasAlreadyOpened && roomSagletUsers.ContainsKey(roomID.ToString())) // "refresh" saglet users in room { roomSagletUsers.Remove(roomID.ToString()); } List <string> users = VmtDevAPI.GetUsersConnected(roomID); foreach (string userID in users) { if (!isSagletUserInRoom(roomID.ToString(), userID)) { criticalPointAlerts.user_joined(roomID, userID); } } } }
private List <VAction> GetActionHistory(int tabID, int startIndex) { List <VAction> actions = new List <VAction>(); string json = VmtDevAPI.GetActionHistory(tabID, startIndex); if (json == null) { throw new TimeoutException(String.Format("TabID: {0} | TimeOut Exception | waiting time for actions from client API acceeded the timeout!", tabID)); } var results = JsonConvert.DeserializeObject <dynamic>(json); foreach (var item in results) { VAction action = VAction.ConvertHistoryActionJson(tabID, item); if (action != null) { actions.Add(action); } } return(actions); }
private List <VMsg> GetChatHistory(int roomID, int startIndex) { List <VMsg> msgs = new List <VMsg>(); string json = VmtDevAPI.GetChatHistory(roomID, startIndex); if (json == null) { throw new TimeoutException(String.Format("roomID: {0} | TimeOut Exception | waiting time for messeges from client API acceeded the timeout!", roomID)); } var results = JsonConvert.DeserializeObject <dynamic>(json); foreach (var item in results.chats) { VMsg msg = VMsg.ConvertHistoryMessageJson(roomID, item); if (msg != null) { msgs.Add(msg); } } return(msgs); }