Exemplo n.º 1
0
        internal void UpdateRoomWordle(string roomID, bool publishGlobaly)
        {
            using (SagletModel db = new SagletModel())
            {
                Room room = db.Rooms.Find(Convert.ToInt32(roomID));
                ICollection <VMsg> msgs = room.RoomGroup.Msgs;
                if (msgs.Count > 0)
                {
                    List <string>            sentences  = msgs.Where(m => m.UserID != "server").Select(m => m.Text).ToList();
                    string                   joined     = String.Join(",", sentences);
                    string[]                 words      = Regex.Split(joined, @"\W+");
                    Dictionary <string, int> dictionary = words.GroupBy(str => str)
                                                          .OrderByDescending(group => group.Count())
                                                          .ToDictionary(group => group.Key, group => group.Count());

                    if (publishGlobaly)
                    {
                        context.Clients.Group(roomID).updateWordle(roomID, dictionary);                    //publish globally
                    }
                    else
                    {
                        context.Clients.Client(Context.ConnectionId).updateWordle(roomID, dictionary);      //public locally
                    }
                }
            }
        }
Exemplo n.º 2
0
        private UserData ExtractUserData(int roomID, string userID, bool isOnline)
        {
            UserData data;

            using (SagletModel db = new SagletModel())
            {
                Room room = db.Rooms.Find(roomID);
                User user = db.Users.Find(userID);
                bool isMod = room.ModeratorsAllowed.Any(m => m.Username == userID);
                int  msgs = 0, acts = 0, sentiment = 50;
                if (user != null)
                {
                    msgs      = user.Msgs.Count(m => m.GroupID == roomID);
                    acts      = user.Actions.Count(a => a.Tab.GroupID == roomID);
                    sentiment = 50;
                    if (msgs > 0)
                    {
                        Convert.ToInt32(user.Msgs.Average(m => m.Sentiment));            // TODO fix here for user msgs in the room only
                    }
                }

                data = new UserData(userID, isMod, isOnline, msgs, acts, sentiment);
            }
            return(data);
        }
Exemplo n.º 3
0
        internal void UpdateRoomSTR(string roomID, bool publishGlobaly)
        {
            using (SagletModel db = new SagletModel())
            {
                Room room = db.Rooms.Find(Convert.ToInt32(roomID));
                if (room == null)
                {
                    UpdateError(roomID, String.Format("room {0} not found on server", roomID));
                    return;
                }
                List <string> roomMods      = room.ModeratorsAllowed.Select(m => m.Username).ToList();
                double        usersMsgCount = room.RoomGroup.Msgs.Count(m => !roomMods.Contains(m.UserID));
                double        modsMsgCount  = room.RoomGroup.Msgs.Count(m => roomMods.Contains(m.UserID));
                double        str           = usersMsgCount / Math.Max(modsMsgCount, 1);
                str = Math.Min(str, 3); //3 is max value

                if (publishGlobaly)
                {
                    context.Clients.Group(roomID).updateStr(roomID, str);                    //publish globally
                }
                else
                {
                    context.Clients.Client(Context.ConnectionId).updateStr(roomID, str);     //public locally
                }
            }
        }
Exemplo n.º 4
0
 internal void UpdateRoomAtmosphere(string roomID, bool publishGlobaly)
 {
     using (SagletModel db = new SagletModel())
     {
         Room room = db.Rooms.Find(Convert.ToInt32(roomID));
         if (room == null)
         {
             UpdateError(roomID, String.Format("room {0} not found on server", roomID));
             return;
         }
         int avg = 50;
         if (room.RoomGroup.Msgs.Count > 0)
         {
             avg = (int)room.RoomGroup.Msgs.Average(m => m.Sentiment);
         }
         if (publishGlobaly)
         {
             context.Clients.Group(roomID).updateAtmosphere(roomID, avg);                    //publish globally
         }
         else
         {
             context.Clients.Client(Context.ConnectionId).updateAtmosphere(roomID, avg);     //public locally
         }
     }
 }
Exemplo n.º 5
0
 public void ResetState()
 {
     lock (dbLock)
     {
         db = new SagletModel();
     }
     hubDetails = new RoomDetailsHub();
     hubIndex   = new RoomIndexHub();
 }
Exemplo n.º 6
0
        /// Assaf
        public void JoinGroup(string roomsFromClient)
        {
            using (SagletModel db = new SagletModel())
            {
                string user = AppHelper.GetVmtUser();
                ctrl.addSagletUserToRoom(roomsFromClient, user);

                Groups.Add(Context.ConnectionId, roomsFromClient.ToString());
                context.Clients.Client(Context.ConnectionId).registeredComplete("Registered succesfully to rooms: " + roomsFromClient);
            }
        }
Exemplo n.º 7
0
        /* CP injections */

        public void LoadCpmModal(string roomID, string msgID)
        {
            int  i_roomID = Convert.ToInt32(roomID);
            int  i_msgID  = Convert.ToInt32(msgID);
            VMsg msg      = null;

            string[] enums = Enum.GetNames(new CriticalPointTypes().GetType());
            using (SagletModel db = new SagletModel())
            {
                msg = db.Msgs.Find(i_msgID, i_roomID);
                context.Clients.Client(Context.ConnectionId).updateCpmData(roomID, msg, msg.CriticalPoints, enums);
            }
        }
Exemplo n.º 8
0
        public void UpdateRoomIndex(string roomID)
        {
            using (SagletModel db = new SagletModel())
            {
                Room   room    = db.Rooms.Find(Convert.ToInt32(roomID));
                string date    = room.LastUpdate.ToString();
                int    mods    = room.ModeratorsAllowed.Count;
                int    msgs    = room.RoomGroup.Msgs.Count(m => m.UserID != "server");
                int    actions = room.RoomGroup.Tabs.Sum(x => x.Actions.Count);
                int    users   = room.RoomGroup.GetUsersFromString().Count;

                context.Clients.Group(roomID).updateRoomIndex(room);
            }
        }
Exemplo n.º 9
0
        private List <int> RegisterToToolBarGroups()
        {
            string     user     = AppHelper.GetVmtUser();
            List <int> roomsIDs = null;

            using (SagletModel db = new SagletModel())
            {
                roomsIDs = db.Moderators.Find(user).RoomsAllowed.Select(x => x.ID).ToList();
                foreach (int roomID in roomsIDs)
                {
                    context.Groups.Add(Context.ConnectionId, roomID + toolbarStr);
                }
            }
            return(roomsIDs);
        }
Exemplo n.º 10
0
        public static string GetVmtUser()
        {
            if (!HttpContext.Current.User.Identity.IsAuthenticated)
            {
                return(null);
            }

            string aspUserID = GetAspUserID();
            string userName  = null;

            using (SagletModel db = new SagletModel()){
                userName = db.Moderators.Where(m => m.AspUserID.Equals(aspUserID)).Select(x => x.Username).FirstOrDefault();
            }

            return(userName);
        }
Exemplo n.º 11
0
        public void InjectCPM(string action, string roomID, string msgID, CriticalPointTypes type, string priority)
        {
            int i_roomID = Convert.ToInt32(roomID);
            int i_msgID  = Convert.ToInt32(msgID);

            using (SagletModel db = new SagletModel())
            {
                CriticalMsgPoints cpm = null;

                try
                {
                    switch (action)
                    {
                    case "add":
                        VMsg msg = db.Msgs.Find(i_msgID, i_roomID);
                        cpm          = new CriticalMsgPoints();
                        cpm.Type     = type;
                        cpm.Priority = priority;
                        msg.CriticalPoints.Add(cpm);
                        // save
                        db.SaveChanges();
                        // update clients
                        UpdateNewCP(roomID, cpm);
                        break;

                    case "remove":      // TODO - not supported yet -> need to inform modal and inform all clients on toolbar(remove from table and update numbers and colors)
                        cpm = db.CriticalMsgPoints.Find(i_msgID, i_roomID, type);
                        db.CriticalMsgPoints.Remove(cpm);
                        // save
                        db.SaveChanges();
                        // update clients
                        UpdateRemovedCP(roomID, cpm);
                        break;
                    }

                    UpdateCPModal(roomID, msgID, action, type, priority);
                    UpdateCPOutSiteModal(roomID, msgID);
                }
                catch (Exception e)
                {
                    throw e;
                }
            }
        }
Exemplo n.º 12
0
        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);
        }
Exemplo n.º 13
0
        private void UpdateCPOutSiteModal(string roomID, string msgID)
        {
            int i_roomID = Convert.ToInt32(roomID);
            int i_msgID  = Convert.ToInt32(msgID);
            Dictionary <CriticalPointTypes, string> cpData = new Dictionary <CriticalPointTypes, string>();

            using (SagletModel db = new SagletModel())
            {
                VMsg msg = db.Msgs.Find(i_msgID, i_roomID);
                foreach (CriticalMsgPoints cpm in msg.CriticalPoints)
                {
                    cpData.Add(cpm.Type, cpm.Priority);
                }
                //msg = db.Msgs.Include("CriticalPoints")
                //    .Where(m => m.ID == i_msgID && m.GroupID == i_roomID)
                //    .FirstOrDefault();
                //msg = db.Msgs.Where(m => m.ID == i_msgID && m.GroupID == i_roomID).Include;
                //IQueryable<VMsg> query = db.Msgs.Include(msg.CriticalPoints)
            }
            context.Clients.Group(roomID).UpdateCPOutSiteModal(roomID, msgID, cpData);
        }
Exemplo n.º 14
0
        public void UpdateLike(int idOne, int idTwo, string type, CriticalPointTypes idLabel, string like)
        {
            int roomID = -1;

            using (SagletModel db = new SagletModel())
            {
                try
                {
                    switch (type)
                    {
                    case "msg":
                    {
                        roomID = idTwo;
                        CriticalMsgPoints cmp = db.CriticalMsgPoints.Find(idOne, idTwo, idLabel);
                        cmp.Like = (like == "like") ? true : false;
                        break;
                    }

                    case "act":
                    {
                        CriticalActionPoints cap = db.CriticalActionPoints.Find(idOne, idTwo, idLabel);
                        cap.Like = (like == "like") ? true : false;
                        roomID   = cap.Action.Tab.GroupID;
                        break;
                    }
                    }
                    // save
                    db.SaveChanges();
                    // update clients
                    UpdateLike(roomID.ToString(), type, idOne, idTwo, idLabel.ToString(), like);
                }
                catch (Exception e)
                {
                    throw e;
                }
            }
        }
Exemplo n.º 15
0
        //get rooms details for the home room index
        public void GetRooms()
        {
            using (SagletModel db = new SagletModel())
            {
                String user = AppHelper.GetVmtUser();

                List <Room> roomsList = new List <Room>();
                List <int>  roomsIds  = db.Moderators.Find(user).RoomsAllowed.Select(r => r.ID).ToList();

                foreach (int roomId in roomsIds)
                {
                    Room room     = db.Rooms.Find(Convert.ToInt32(roomId));
                    Room thisRoom = new Room
                    {
                        LastUpdate = room.LastUpdate,
                        ID         = room.ID,
                        Name       = room.Name,
                        Sync       = room.Sync
                    };
                    roomsList.Add(thisRoom);
                }
                context.Clients.Client(Context.ConnectionId).getRooms(roomsList);
            }
        }