private void ProcessBlobEmails(List <Models.EmailMetric> emailMetrics, CloudBlob emailBlob) { using (var reader = new StreamReader(emailBlob.OpenRead())) { string line; while ((line = reader.ReadLine()) != null) { var jsonObj = JObject.Parse(line); // extract sender var sender = jsonObj.SelectToken("Sender.EmailAddress.Address")?.ToString(); // extract and count up recipients var totalRecipients = 0; totalRecipients += jsonObj.SelectToken("ToRecipients").Children().Count(); totalRecipients += jsonObj.SelectToken("CcRecipients").Children().Count(); totalRecipients += jsonObj.SelectToken("BccRecipients").Children().Count(); var emailMetric = new Models.EmailMetric(); emailMetric.Email = sender; emailMetric.RecipientsToEmail = totalRecipients; // if already have this sender... var existingMetric = emailMetrics.FirstOrDefault(metric => metric.Email == emailMetric.Email); if (existingMetric != null) { existingMetric.RecipientsToEmail += emailMetric.RecipientsToEmail; } else { emailMetrics.Add(emailMetric); } } } }
private Models.EmailMetric ProcessEmail(CloudBlob emailBlob) { var emailMetric = new Models.EmailMetric(); using (var reader = new StreamReader(emailBlob.OpenRead())) { string line; while ((line = reader.ReadLine()) != null) { var jsonObj = JObject.Parse(line); // extract sender var sender = jsonObj.SelectToken("Sender.EmailAddress.Address")?.ToString(); // extract and count up recipients var totalRecipients = 0; totalRecipients += jsonObj.SelectToken("ToRecipients").Children().Count(); totalRecipients += jsonObj.SelectToken("CcRecipients").Children().Count(); totalRecipients += jsonObj.SelectToken("BccRecipients").Children().Count(); emailMetric.Email = sender; emailMetric.RecipientsToEmail = totalRecipients; } } return(emailMetric); }