private IEnumerable<MergeResult> HandleMerge(string projectUrl, Merge merge, ReadOnlyCollection<Merge> merges) { while (!_threadManager.TryStartThread()) { Thread.Sleep(1000); } var result = MergeIndividualMerge(projectUrl, merge); var childMerges = merges.Where(m => merge.Child == m.Parent); var results = childMerges .AsParallel() .Select(m => HandleMerge(projectUrl, m, merges)) .SelectMany(t => t); return new List<MergeResult> { result }.Concat(results); }
public void SendIndividualMergeEmail(Merge merge, MergeResult result) { if (!_sendEmails || merge.EmailSettings == null) { return; } if (merge.EmailSettings.FromAddress == null && (_settings == null || !_settings.FromAddress.InheritInMergeEmails)) { throw new InvalidOperationException("No from email address could be configured or inherited"); } using (var client = new SmtpClient()) using (var message = new MailMessage()) { message.From = new MailAddress( merge.EmailSettings.FromAddress != null ? merge.EmailSettings.FromAddress.Value : _settings.FromAddress.Value); AddEmailsToCollection(message.To, merge.EmailSettings.ToAddresses); AddEmailsToCollection(message.CC, merge.EmailSettings.CcAddresses); AddEmailsToCollection(message.Bcc, merge.EmailSettings.BccAddresses); if (_settings != null) { AddEmailsToCollection(message.To, _settings.ToAddresses.Where(a => a.InheritInMergeEmails)); AddEmailsToCollection(message.CC, _settings.CcAddresses.Where(a => a.InheritInMergeEmails)); AddEmailsToCollection(message.Bcc, _settings.BccAddresses.Where(a => a.InheritInMergeEmails)); } message.Subject = string.Format( "{0} merge {1} to {2} - {3}", result.Success ? "Successful" : "Failed", merge.Parent, merge.Child, DateTime.Now.ToString("yyyy-MM-dd HH:mm")); message.Body = result.Message; client.Send(message); } }
public MergeResult MergeIndividualMerge(string projectUrl, Merge merge) { var result = _merger.Merge(projectUrl, merge.Parent, merge.Child); try { _emailSender.SendIndividualMergeEmail(merge, result); } catch (Exception e) { result = new MergeResult( merge.Parent, merge.Child, false, string.Format("{0} - {1}", result.Message, e.Message), e); } return result; }