public PackageBase[] GetPackages() { string ToOrderedString(IEnumerable <string> a) => string.Join(",", a.OrderBy(c => c).ToArray()); return((from rule in Rules from build in JiraService.GetBuilds(rule.ProjectCode) where rule.IsMatch(build) group new { build, rule } by new { To = ToOrderedString(rule.HowToNotify !.MetaAddressers), Cc = ToOrderedString(rule.HowToNotify.MetaCarbonCopy), rule.HowToNotify.Subject } into ag select new Package <BenderSendsLetter, Build> { Items = ag.Select(a => a.build).ToArray(), Reaction = new BenderSendsLetter { Addressees = new Addressees { To = ag.Key.To.Split(','), Cc = ag.Key.Cc.Split(',') }, Subject = ag.Key.Subject, Recommendations = ag.First().rule.HowToNotify !.Recommendations } })
public virtual PackageBase[] GetPackages() { var uncategorizedSet = ( from rule in Rules let issues = ( from issue in GetIssues(rule) where string.IsNullOrWhiteSpace(rule.AdditionalPredicateName) || IsIssueInAccordanceWithPredicate(rule.AdditionalPredicateName, issue) select issue ).ToArray() where issues.Any() select new { rule, issues } ).ToArray(); var notificationPackages = ( from set in uncategorizedSet from issue in set.issues where set.rule.HowToNotify != null group new { issue, set.rule } by new { To = ReplaceMarkersByRealAddresses(set.rule.HowToNotify !.MetaAddressers, issue.Staff), Cc = ReplaceMarkersByRealAddresses(set.rule.HowToNotify.MetaCarbonCopy, issue.Staff), set.rule.HowToNotify.Subject } into ag let basePackage = new Package <BenderSendsLetter, Issue> { Items = ag.Select(a => a.issue).ToArray(), Reaction = new BenderSendsLetter { Addressees = new Addressees { To = ag.Key.To.Split(','), Cc = ag.Key.Cc.Split(',') }, Subject = ag.Key.Subject, Recommendations = ag.First().rule.HowToNotify !.Recommendations } } select Enrich(basePackage, ag.First().rule) ) .ToArray(); var actionPackages = ( from set in uncategorizedSet from updateAction in set.rule.HowToUpdate let package = new Package <BenderMakesUpdateHimself, Issue> { Reaction = new BenderMakesUpdateHimself { BodyPattern = updateAction.BodyPattern, UrlPattern = updateAction.UrlPattern, Verb = updateAction.Verb }, Items = set.issues } select package ) .Cast <PackageBase>() .ToArray(); return(notificationPackages.Union(actionPackages).ToArray()); }