Пример #1
0
        /// <summary>
        /// Sends a public message to room.
        /// It will be seen all users in room.
        /// </summary>
        /// <param name="message">Message to be sent</param>
        public void SendMessageToRoom(ChatMessage message)
        {
            //Get ChatClient object
            var senderClient = _clients[CurrentClient.ClientId];
            if (senderClient == null)
            {
                throw new ApplicationException("Can not send message before login.");
            }

            //Send message to all online users
            Task.Factory.StartNew(
                () =>
                {
                    foreach (var chatClient in _clients.GetAllItems())
                    {
                        try
                        {
                            chatClient.ClientProxy.OnMessageToRoom(senderClient.User.Nick, message);
                        }
                        catch
                        {

                        }
                    }
                });
        }
Пример #2
0
        /// <summary>
        /// Sends a private message to a specific user.
        /// Message will be seen only by destination user.
        /// </summary>
        /// <param name="destinationNick">Nick of the destination user who will receive message</param>
        /// <param name="message">Message to be sent</param>
        public void SendPrivateMessage(string destinationNick, ChatMessage message)
        {
            //Get ChatClient object for sender user
            var senderClient = _clients[CurrentClient.ClientId];
            if (senderClient == null)
            {
                throw new ApplicationException("Can not send message before login.");
            }

            //Get ChatClient object for destination user
            var receiverClient = FindClientByNick(destinationNick);
            if (receiverClient == null)
            {
                throw new ApplicationException("There is no online user with nick " + destinationNick);
            }

            //Send message to destination user
            receiverClient.ClientProxy.OnPrivateMessage(senderClient.User.Nick, message);
        }
Пример #3
0
 /// <summary>
 /// Sends a public message to room.
 /// It will be seen by all users in room.
 /// </summary>
 /// <param name="message">Message to be sent</param>
 public void SendMessageToRoom(ChatMessage message)
 {
     _scsClient.ServiceProxy.SendMessageToRoom(message);
 }
        /// <summary>
        /// Adds a new message to message history.
        /// </summary>
        /// <param name="nick">Nick of sender</param>
        /// <param name="message">Message</param>
        public void MessageReceived(string nick, ChatMessage message)
        {
            //Create a new paragraph to write new message
            var messageParagraph = new Paragraph();

            //Set message as Bold if needed
            if (message.TextStyle.IsBold)
            {
                messageParagraph.FontWeight = FontWeights.Bold;
            }

            //Set message as Italic if needed
            if (message.TextStyle.IsItalic)
            {
                messageParagraph.FontStyle = FontStyles.Italic;
            }

            //Set message font if needed
            if (!string.IsNullOrEmpty(message.TextStyle.FontFamily))
            {
                try
                {
                    messageParagraph.FontFamily = new FontFamily(message.TextStyle.FontFamily);
                }
                catch
                {

                }
            }

            //Set message text size if needed
            if (message.TextStyle.TextSize > 0)
            {
                messageParagraph.FontSize = message.TextStyle.TextSize;
            }

            //Set message color if needed
            if (message.TextStyle.TextColor != null)
            {
                messageParagraph.Foreground =
                    new SolidColorBrush(
                        new Color
                        {
                            A = 255,
                            R = message.TextStyle.TextColor.Red,
                            G = message.TextStyle.TextColor.Green,
                            B = message.TextStyle.TextColor.Blue
                        });
            }

            //Add message to paragraph
            messageParagraph.Inlines.Add(new Run(nick + ": " + message.MessageText));

            //Add new parapraph to message history
            txtMessageHistory.Document.Blocks.Add(messageParagraph);

            if (txtMessageHistory.Document.Blocks.Count > 1000)
            {
                txtMessageHistory.Document.Blocks.Remove(txtMessageHistory.Document.Blocks.FirstBlock);
            }

            txtMessageHistory.ScrollToEnd();
        }
Пример #5
0
 /// <summary>
 /// This method is called when a private message is sent to the current user.
 /// </summary>
 /// <param name="nick">Nick of sender</param>
 /// <param name="message">The message</param>
 public void OnPrivateMessageReceived(string nick, ChatMessage message)
 {
     Dispatcher.Invoke(new Action(() => OnPrivateMessageReceivedInternal(nick, message)));
 }
Пример #6
0
 /// <summary>
 /// Sends a private message to a user.
 /// </summary>
 /// <param name="nick">Destination nick</param>
 /// <param name="message">Message</param>
 public void SendPrivateMessage(string nick, ChatMessage message)
 {
     _scsClient.ServiceProxy.SendPrivateMessage(nick, message);
 }
Пример #7
0
        /// <summary>
        /// This method is used to send private message to proper private messaging window.
        /// </summary>
        /// <param name="nick">Nick of sender</param>
        /// <param name="message">Message</param>
        private void OnPrivateMessageReceivedInternal(string nick, ChatMessage message)
        {
            var userCard = FindUserInList(nick);
            if (userCard == null)
            {
                return;
            }

            if (!_privateChatWindows.ContainsKey(nick))
            {
                //Create new private chat window
                _privateChatWindows[nick] = CreatePrivateChatWindow(userCard);

                //Set initial state as minimized
                _privateChatWindows[nick].WindowState = WindowState.Minimized;
                
                //Flash the window button on taskbar to inform user
                WindowsHelper.FlashWindow(new WindowInteropHelper(_privateChatWindows[nick]).Handle, WindowsHelper.FlashWindowFlags.FLASHW_ALL, 2, 1000);
            }

            _privateChatWindows[nick].MessageReceived(message);
        }
Пример #8
0
 /// <summary>
 /// This method is called when a message is sent to chat room.
 /// </summary>
 /// <param name="nick">Nick of sender</param>
 /// <param name="message">Message</param>
 public void OnMessageReceived(string nick, ChatMessage message)
 {
     Dispatcher.Invoke(new Action(() => messagingArea.MessageReceived(nick, message)));
 }
Пример #9
0
 /// <summary>
 /// Sends a message to the room.
 /// </summary>
 public void SendMessage(ChatMessage message)
 {
     _controller.SendMessageToRoom(message);
 }
Пример #10
0
 /// <summary>
 /// This method is called by MessagingAreaControl to send messages.
 /// </summary>
 /// <param name="message">Message to be sent</param>
 public void SendMessage(ChatMessage message)
 {
     _controller.SendPrivateMessage(RemoteUserNick, message);
     MessageHistory.MessageReceived(CurrentUserNick, message);
 }
Пример #11
0
 /// <summary>
 /// This method is used to add a new message to message history of that window.
 /// </summary>
 /// <param name="message">Message</param>
 public void MessageReceived(ChatMessage message)
 {
     MessageHistory.MessageReceived(_remoteUserNick, message);
     if (!IsActive)
     {
         //Flash taskbar button if this window is not active
         WindowsHelper.FlashWindow(_windowInteropHelper.Handle, WindowsHelper.FlashWindowFlags.FLASHW_TRAY, 1, 1000);
         ClientHelper.PlayIncomingMessageSound();
     }
 }
Пример #12
0
 /// <summary>
 /// This method is called from chat server to inform that a message
 /// is sent to the current used privately.
 /// </summary>
 /// <param name="nick">Nick of sender</param>
 /// <param name="message">Message</param>
 public void OnPrivateMessage(string nick, ChatMessage message)
 {
     _chatRoom.OnPrivateMessageReceived(nick, message);
 }
Пример #13
0
 /// <summary>
 /// This method is called from chat server to inform that a message
 /// is sent to chat room publicly.
 /// </summary>
 /// <param name="nick">Nick of sender</param>
 /// <param name="message">Message text</param>
 public void OnMessageToRoom(string nick, ChatMessage message)
 {
     _chatRoom.OnMessageReceived(nick, message);
 }