Ejemplo n.º 1
0
 public Message AddMessage(
     User sender, User reciever,
     string content, DateTime userDatelLocal,
     bool isUnread = true)
 {
     try
     {
         var message = new Message
         {
             SenderId      = sender.Id,
             ReceiverId    = reciever.Id,
             SenderEmail   = sender.Email,
             ReceiverEmail = reciever.Email,
             Content       = content,
             ServerDateUtc = DateTime.UtcNow,
             UserDateLocal = userDatelLocal,
             IsUnread      = isUnread
         };
         _applicationContext.Messages.Add(message);
         _applicationContext.SaveChanges();
         OnMessageAdded?.Invoke(message);
         if (isUnread)
         {
             OnHaveUnread?.Invoke(reciever, sender);
         }
         return(message);
     }
     catch (Exception)
     {
         return(null);
     }
 }
Ejemplo n.º 2
0
        public static void Write(string message, int level = INFO)
        {
            if (Form.logVisualizer.InvokeRequired)
            {
                if (!Form.IsHandleCreated)
                {
                    return;
                }
                Form.Invoke(new MethodInvoker(() => { Write(message, level); }));
            }
            else
            {
                switch (level)
                {
                case INFO: InfoCount++;
                    break;

                case WARNING: WarningCount++;
                    break;

                case ERROR: ErrorCount++;
                    break;
                }
                var item = new LogItem(DateTime.Now, level, message);
                log.Add(item);
                var text = item.ToString();
                Form.logVisualizer.AppendText(text);
                Form.logVisualizer.SelectionStart  = Form.logVisualizer.TextLength - text.Length + 1;
                Form.logVisualizer.SelectionLength = text.Length;
                Form.logVisualizer.SelectionColor  = item.GetColor();
                Form.logVisualizer.HideSelection   = true;
                OnMessageAdded?.Invoke(item);
            }
        }
Ejemplo n.º 3
0
 public void AddMessage(IMessage msg)
 {
     if (msg == null)
     {
         return;
     }
     ListMessages.Clear();
     ListMessages.Add(msg);
     OnMessageAdded?.Invoke(this, new MessageAddedEventArgs(msg));
 }
Ejemplo n.º 4
0
        public void ReceiveChatMessage(ChatMessage chatMessage)
        {
            Console.WriteLine("ChatMessage");

            ClientChannel channel;

            if (Channels.TryGetValue(chatMessage.channelID, out channel))
            {
                ClientMessage newMessage = channel.AddMessage(chatMessage.message);
                OnMessageAdded?.Invoke(newMessage);
            }
            else
            {
                Console.WriteLine("Warning: Server sent chat message to a channel that doesn't exist");
            }
        }
Ejemplo n.º 5
0
        public void ReceiveGetChatHistory(GetChatHistory getChatHistory)
        {
            Console.WriteLine("GetChatHistory");

            ClientChannel channel;

            if (Channels.TryGetValue(getChatHistory.channelID, out channel))
            {
                foreach (Packets.Types.Data.MessageData message in getChatHistory.messages)
                {
                    ClientMessage newMessage = channel.AddMessage(message);
                    OnMessageAdded?.Invoke(newMessage);
                }
            }
            else
            {
                Console.WriteLine("Warning: Server sent chat history for a channel that doesn't exist");
            }
        }
Ejemplo n.º 6
0
 public void ChannelMessageAdded(TwilioIPMessagingClient client, Channel channel, Message message)
 {
     OnMessageAdded?.Invoke(message);
 }
Ejemplo n.º 7
0
 public static void AddMessage(TextMessage message)
 {
     Messages.Add(message);
     OnMessageAdded?.Invoke();
 }