Ejemplo n.º 1
0
        public static CRoom GetRoom(string hashRoom)
        {
            try
            {
                changeLock.WaitOne();
            }
            catch (AbandonedMutexException)
            {
                changeLock.ReleaseMutex();
                changeLock.WaitOne();
            }
            CRoom answer = null;
            var   rooms  = HttpContext.Current.Application["OnlineRooms"];

            if (rooms != null)
            {
                var onlineRooms = (Dictionary <string, CRoom>)rooms;
                if (onlineRooms.ContainsKey(hashRoom))
                {
                    answer = onlineRooms[hashRoom];
                }
            }
            changeLock.ReleaseMutex();
            return(answer);
        }
Ejemplo n.º 2
0
        public bool AddRoom(CRoom room)
        {
            try
            {
                changeLock.WaitOne();
            }
            catch (AbandonedMutexException)
            {
                changeLock.ReleaseMutex();
                changeLock.WaitOne();
            }
            bool answer = true;

            var online = HttpContext.Current.Application["OnlineRooms"];

            if (online == null)
            {
                online = new Dictionary <string, CRoom>();
            }

            var OnlineRooms = (Dictionary <string, CRoom>)online;

            if (!OnlineRooms.ContainsKey(roomHash))
            {
                OnlineRooms.Add(roomHash, room);
                HttpContext.Current.Application["OnlineRooms"] = OnlineRooms;
            }
            else
            {
                answer = false;
            }
            changeLock.ReleaseMutex();
            return(answer);
        }