Ejemplo n.º 1
0
        /// <summary>
        /// Login
        /// Logins the user and registers the callback into a dictionary of
        /// logged in users.
        /// Sends a messgae that the user has logged on...
        /// </summary>
        /// <param name="userName">user name from the client (string)</param>
        public void Login(string userName)
        {
            // Trim the Username to 15 Characters
            if (userName.Length > 15)
            {
                userName = userName.Substring(0, 15);
            }

            // This is the caller and registers the callback for the service to
            // communicate the new messages
            IChatServiceCallback callback = OperationContext.Current.GetCallbackChannel <IChatServiceCallback>();

            // Validates the User is Not Already Logged In
            if (!loggedInUsers.ContainsKey(userName))
            {
                // Add to the List of Logged on Users
                loggedInUsers.Add(userName, callback);

                // Send a Message that the new user is Logged In
                SendMessage("Admin", $"User {userName} logged in...");

                // Write to Console
                Console.WriteLine($"User {userName} logged in...");
            } // end of if

            // Duplicate User Fault - User Logged In Already
            else
            {
                DuplicateUserFault fault = new DuplicateUserFault()
                {
                    Reason = "User '" + userName + "' already logged in!"
                };
                throw new FaultException <DuplicateUserFault>(fault);
            } // end of else
        }     // end of method
Ejemplo n.º 2
0
        public bool AddMeToServer(string userName)
        {
            if (userName.Length > 15)
            {
                userName = userName.Substring(0, 15);
            }


            IOneToOneChatCallback callback = OperationContext.Current.GetCallbackChannel <IOneToOneChatCallback>();

            if (!loggedInUsers.ContainsKey(userName))
            {
                loggedInUsers.Add(userName, callback);

                Console.WriteLine($"User {userName} logged in...");

                // Notify all the online users about newly joined user
                NotifyAllOnlineUsersAboutNewlyJoinedUser(userName);

                return(true);
            } // end of if

            else
            {
                DuplicateUserFault fault = new DuplicateUserFault()
                {
                    Reason = "User '" + userName + "' already logged in!"
                };
                throw new FaultException <DuplicateUserFault>(fault);
            } // end of else
        }
        public bool AddMeToServer(string userName)
        {
            if (userName.Length > 15)
            {
                userName = userName.Substring(0, 15);
            }


            IChatServiceCallback callback = OperationContext.Current.GetCallbackChannel <IChatServiceCallback>();

            if (!loggedInUsers.ContainsKey(userName))
            {
                loggedInUsers.Add(userName, callback);

                SendMessage("Admin", $"User {userName} logged in...");

                Console.WriteLine($"User {userName} logged in...");

                return(true);
            } // end of if

            else
            {
                DuplicateUserFault fault = new DuplicateUserFault()
                {
                    Reason = "User '" + userName + "' already logged in!"
                };
                throw new FaultException <DuplicateUserFault>(fault);
            } // end of else
        }     // end of method