Example #1
0
   public void Send(string data)
   {
       // Form a message
       var newMessage = new Message { Data = data, Initiator = this, TimeStamp = DateTime.Now };
       _history.Add(newMessage);
 
       // YOUR CODE GOES HERE 
   }
Example #2
0
        protected void ButtonSendMessage_Click(object sender, EventArgs e)
        {
            if (!IsValid)
            {
                return;
            }

            string contents = this.TextBoxContents.Text.Trim();
            string author = this.TextBoxAuthor.Text.Trim();

            if (contents.Length > 250)
            {
                this.LabelErrorMessage.Text = "The contents must be at most 250 characters long.";
                return;
            }

            if (author.Length > 50)
            {
                this.LabelErrorMessage.Text = "The author name must be at most 50 characters long.";
                return;
            }

            var context = new SimpleChatEntities();

            var message = new Message
            {
                Contents = this.TextBoxContents.Text,
                Author = this.TextBoxAuthor.Text,
                Timestamp = DateTime.Now
            };

            context.Messages.Add(message);
            context.SaveChanges();

            this.TextBoxContents.Text = string.Empty;
            this.TextBoxAuthor.Text = string.Empty;
        }
 private void MessageReceived(Message message)
 {
     VisualizeNewMessage(message.Data, message.Initiator.Username);
 }
Example #4
0
        public void Receive(Message message)
        {
            _history.Add(message);

            // YOUR CODE GOES HERE 
        }