示例#1
0
        /// <summary>
        /// Used to login to BugTracker service.
        /// </summary>
        /// <param name="userInfo">User informations</param>
        public bool Login(UserInfo userInfo)
        {
            //Check nick if it is being used by another user
            if (FindClientByNick(userInfo.Username) != null)
            {
                throw new UsernameInUseException("The username '" + userInfo.Username + "' is being used by another user. Please select another one.");
            }
            if (checkLogin(userInfo))
            {
                //Get a reference to the current client that is calling this method
                var client = CurrentClient;
                //Get a proxy object to call methods of client when needed
                var clientProxy = client.GetClientProxy <IBugTrackerClient>();

                //Create a BugTrackerClient and store it in a collection
                var bugTrackerClient = new BugTrackerClient(client, clientProxy, userInfo);
                _clients[client.ClientId] = bugTrackerClient;

                //Register to Disconnected event to know when user connection is closed
                client.Disconnected += Client_Disconnected;
                //Start a new task to send user list to new user and to inform
                //all users that a new user joined to room
                Task.Factory.StartNew(
                    () =>
                {
                    OnUserListChanged();
                    //SendUserListToClient(bugTrackerClient);
                    //SendUserLoginInfoToAllClients(userInfo);
                });
                return(true);
            }
            return(false);
        }
示例#2
0
        /// <summary>
        /// This method is used to send list of all online users to a new joined user.
        /// </summary>
        /// <param name="client">New user that is joined to service</param>
        private void SendUserListToClient(BugTrackerClient client)
        {
            //Get all users except new user
            var userList = UserList.Where((user) => (user.Username != client.User.Username)).ToArray();

            //Do not send list if no user available (except the new user)
            if (userList.Length <= 0)
            {
                return;
            }

            client.ClientProxy.GetUserList(userList);
        }