Exemplo n.º 1
0
        public void SendMessage(Message message)
        {
            foreach (var user in _registeredUsers)
            {
                if (user.Equals(message.Receiver))
                {
                    try
                    {
                        _storageHandler.AddChatContact(message.Receiver, message.Sender);
                        _storageHandler.AddMessageToHistory(message.Sender, message.Receiver, message);
                        _storageHandler.AddMessageToHistory(message.Receiver, message.Sender, message);
                    }
                    catch (Exception)
                    {
                    }
                }
            }

            var onlineUser = _onlineUsersList.FirstOrDefault(u => u.Id == message.Receiver.Id);

            if (onlineUser != null)
            {
                onlineUser.OperationContext.GetCallbackChannel <IChatServerCallback>().MessageCallback(message);
            }
        }