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); }