Пример #1
0
        public void LeaveRoom(string username, string roomName)
        {
            IMQDriver mqDriver = GetMQDriver();

            string command      = Config.GenerateCommand(Config.CMD.LEAVE_ROOM, Thread.CurrentThread.ManagedThreadId, username, roomName);
            bool   hasResponded = false;

            mqDriver.OnResponseRecieved += (cmd) =>
            {
                string[] cmdParts = cmd.Split(':');

                string cmdType = GetCmdType(Config.CMD.LEAVE_ROOM_RESPONSE);

                if (cmdParts[0].Equals(cmdType))
                {
                    if (cmdParts[1].Equals(Thread.CurrentThread.ManagedThreadId))
                    {
                        if (!cmdParts[2].ToUpper().Equals("OK"))
                        {
                            throw new FaultException(cmd);
                        }
                        else
                        {
                            hasResponded = true;
                        }
                    }
                }
            };

            mqDriver.SendCommand(command);
            Wait(ref hasResponded);
            mqDriver.ListenerOpen = false;
        }
Пример #2
0
        private void LockUsername(string username, IMQDriver mqDriver)
        {
            string command = Config.GenerateCommand(Config.CMD.VAL_USERNAME, Thread.CurrentThread.ManagedThreadId, username);

            bool usernameLocked = false;

            mqDriver.OnResponseRecieved += (cmd) =>
            {
                string   cmdType  = GetCmdType(Config.CMD.VAL_USERNAME_REPONSE);
                string[] cmdParts = cmd.Split(Config.SEPERATOR);

                if (cmdParts[0].Equals(cmdType))
                {
                    if (cmdParts[1].Equals(Thread.CurrentThread.ManagedThreadId))
                    {
                        if (cmdParts[2].ToUpper().Equals("OK"))
                        {
                            usernameLocked = true;
                        }
                        else
                        {
                            throw new FaultException(cmd);
                        }
                    }
                }
            };
            mqDriver.SendCommand(command);
            Wait(ref usernameLocked);
        }
Пример #3
0
        private void ReleaseUsername(string username, IMQDriver mqDriver)
        {
            string command = Config.GenerateCommand(Config.CMD.RELEASE_USERNAME, Thread.CurrentThread.ManagedThreadId, username);

            mqDriver.SendCommand(command);
            //mqDriver.CloseConnections();  //TODO: close connections?
        }
Пример #4
0
        public void JoinRoom(string username, string roomName)
        {
            IMQDriver mqDriver = GetMQDriver();

            string command      = Config.GenerateCommand(Config.CMD.JOIN_ROOM, Thread.CurrentThread.ManagedThreadId, username, roomName);
            bool   hasResponded = false;

            mqDriver.OnResponseRecieved += (cmd) => {
                string[] cmdParts = cmd.Split(Config.SEPERATOR);

                string cmdType = GetCmdType(Config.CMD.JOIN_ROOM_RESPONSE);

                if (cmdParts[0].Equals(cmdType))
                {
                    if (cmdParts[1].Equals(Thread.CurrentThread.ManagedThreadId))
                    {
                        if (!cmdParts[2].ToUpper().Equals("OK"))
                        {
                            throw new FaultException(cmd);
                        }
                        else
                        {
                            hasResponded = true;
                        }
                    }
                }
            };

            Wait(ref hasResponded);

            mqDriver.SendCommand(command);
            //mqDriver.CloseConnections();  //TODO: close connections?
        }
Пример #5
0
        public void SendMessage(string username, string roomName, string encryptedMessage)
        {
            IMQDriver mqDriver = GetMQDriver();

            string command = Config.GenerateCommand(Config.CMD.SEND_MESSAGE, Thread.CurrentThread.ManagedThreadId, username, roomName, encryptedMessage);

            mqDriver.SendCommand(command);
            mqDriver.ListenerOpen = false;
        }
Пример #6
0
        public void SendMessage(string username, string roomName, string encryptedMessage)
        {
            IMQDriver mqDriver = GetMQDriver();

            string command = Config.GenerateCommand(Config.CMD.SEND_MESSAGE, Thread.CurrentThread.ManagedThreadId, username, roomName, encryptedMessage);

            mqDriver.SendCommand(command);
            //mqDriver.CloseConnections();  //TODO: close connections?
        }
Пример #7
0
        public string[] GetRooms()
        {
            IMQDriver mqDriver = GetMQDriver();
            string    command  = Config.GenerateCommand(Config.CMD.REQUEST_ROOMS, Thread.CurrentThread.ManagedThreadId);

            List <string> rooms = new List <string>();
            bool          aServerHasResponded = false;

            mqDriver.OnResponseRecieved += (cmd) =>
            {
                if (!aServerHasResponded)
                {
                    string cmdType = GetCmdType(Config.CMD.REQUEST_ROOMS_RESPONSE);

                    string[] cmdParts = cmd.Split(':');

                    if (cmdParts[0].Equals(cmdType))
                    {
                        if (cmdParts[1].Equals(Thread.CurrentThread.ManagedThreadId))
                        {
                            for (int i = 2; i < cmdParts.Length; i++)
                            {
                                rooms.Add(cmdParts[i]);
                            }
                            aServerHasResponded = true;
                        }
                    }
                }
            };

            mqDriver.SendCommand(command);
            Wait(ref aServerHasResponded);
            mqDriver.ListenerOpen = false;

            return(rooms.ToArray());
        }
Пример #8
0
 private void ReleaseUsername(string username, IMQDriver mqDriver)
 {
     string command = Config.GenerateCommand(Config.CMD.RELEASE_USERNAME, Thread.CurrentThread.ManagedThreadId, username);
     mqDriver.SendCommand(command);
 }
Пример #9
0
        private void LockUsername(string username, IMQDriver mqDriver)
        {
            string command = Config.GenerateCommand(Config.CMD.VAL_USERNAME, Thread.CurrentThread.ManagedThreadId, username);

            bool usernameLocked = false;
            mqDriver.OnResponseRecieved += (cmd) =>
            {
                string cmdType = GetCmdType(Config.CMD.VAL_USERNAME_REPONSE);
                string[] cmdParts = cmd.Split(Config.SEPERATOR);

                if (cmdParts[0].Equals(cmdType))
                {
                    if (cmdParts[1].Equals(Thread.CurrentThread.ManagedThreadId))
                    {
                        if (cmdParts[2].ToUpper().Equals("OK"))
                        {
                            usernameLocked = true;
                        }
                        else
                        {
                            throw new FaultException(cmd);
                        }
                    }
                }
            };
            mqDriver.SendCommand(command);
            Wait(ref usernameLocked);
        }