private void AddNewMessageButtonClick() { if (CloseMessageButtonVisibility) // VALIDATE if there is already a message displayed { MessageBox.Show("Please close currently displayed message before adding a new one."); } else { var message = new RawMessage { Header = HeaderTextBox, Body = BodyTextBox }; if (message.IsValid()) { var newMsg = _messageService.AddNewMessage(message); if (newMsg != null) { // DISPLAY Newly Added Message ContentControlBinding = new DisplayMessageView(newMsg); OnChanged(nameof(ContentControlBinding)); CloseMessageButtonVisibility = true; OnChanged(nameof(CloseMessageButtonVisibility)); } } else { MessageBox.Show("Message has NOT been added!\n\nMessage body cannot be empty.\nMessage header has to be 10 characters long \nwith first letter indicating message type: \nS -> SMS, T -> Tweet, E -> Email,\nfollowed by 9 digits."); } } }
public Message AddNewMessage(RawMessage message) { if (message.IsValid()) { // New Message and Message Type Message newMessage = GetMessageWithType(message); if (newMessage != null) { // Id newMessage.Id = message.Header; // Sender and Content var(sender, content) = ExtractSenderAndContent(message.Body); newMessage.Sender = sender; newMessage.Content = content; // type-specific functions switch (newMessage.Type) { case MessageType.Email: Email email = (Email)newMessage; email.SetSubjectContentAndSIRflag(); // remaining Email properties var quarantinedUrls = email.SterilizeContentFromUrls(); _statisticsService.AddQuarantinedUrls(quarantinedUrls); if (email.IsSIR) { SIR sir = (SIR)newMessage; sir.SetSportCentreCodeAndNatureOfIncident(); // remaining SIR properties _statisticsService.AddSIRs(sir.IncidentDetails); } break; case MessageType.Sms: Sms sms = (Sms)newMessage; sms.SanitizeContent(_dataProvider.ImportAbbreviations()); break; case MessageType.Tweet: Tweet tweet = (Tweet)newMessage; tweet.SanitizeContent(_dataProvider.ImportAbbreviations()); tweet.CheckContentForHashtagsAndMentions(); if (tweet.Hashtags != null && tweet.Hashtags.Count > 0) { _statisticsService.AddHashtags(tweet.Hashtags); } if (tweet.Mentions != null && tweet.Mentions.Count > 0) { _statisticsService.AddMentions(tweet.Mentions); } break; } ; // export msg to a file if (_dataProvider.ExportMessage(newMessage)) { _statisticsService.UpdateStatistics(); // return fully-processed message to the ViewModel return(newMessage); } } } return(null); }