bool DispatchAnnouncements() { bool ret = false; var grouped = _queuedAnnouncements.GroupBy(announce => announce.RepoName); foreach (var repoAnnouncements in grouped) { var announceLi = repoAnnouncements.ToList(); announceLi.Sort((a1, a2) => a1.TimeStamp.CompareTo(a2.TimeStamp)); //cull any announcements that were made in the past RepoAnnounceHistory announceHistory; try{ announceHistory = _repoAnnounceHistory.Single(d => d.RepoName.Equals(announceLi[0].RepoName)); } catch { announceHistory = new RepoAnnounceHistory(); announceHistory.AnnouncedPushes = new List <string>(); announceHistory.RepoName = announceLi[0].RepoName; _repoAnnounceHistory.Add(announceHistory); } for (int i = 0; i < announceLi.Count; i++) { var identifier = announceLi[i].CommitHashStart + announceLi[i].CommitHashEnd; if (announceHistory.AnnouncedPushes.Contains(identifier)) { announceLi.RemoveAt(i); i--; } } if (announceLi.Count == 0) { continue; } int numCommits = announceLi.Sum(announce => announce.CommitCount); string beginCommit = announceLi[0].CommitHashStart; string endCommit = announceLi.Last().CommitHashEnd; string finalLink = announceLi[0].Link + beginCommit + "..." + endCommit; var channels = IrcInterface.Client.GetChannels(); string plural = ""; if (numCommits > 1) { plural = "s"; } foreach (var channel in channels) { var msg = numCommits + " commit" + plural + " pushed to " + announceLi[0].RepoName + " by " + announceLi[0].Author + " " + finalLink; IrcInterface.Client.SendMessage(SendType.Message, channel, msg); } //add the newly made announcements to the announcement history foreach (var announcement in announceLi) { var identifier = announcement.CommitHashStart + announcement.CommitHashEnd; announceHistory.AnnouncedPushes.Add(identifier); ret = true; } SaveAnnouncementHistory(); } return(ret); }
bool DispatchAnnouncements() { bool ret = false; var grouped = _queuedAnnouncements.GroupBy(announce => announce.RepoName); foreach (var repoAnnouncements in grouped){ var announceLi = repoAnnouncements.ToList(); announceLi.Sort((a1, a2) => a1.TimeStamp.CompareTo(a2.TimeStamp)); //cull any announcements that were made in the past RepoAnnounceHistory announceHistory; try{ announceHistory = _repoAnnounceHistory.Single(d => d.RepoName.Equals(announceLi[0].RepoName)); } catch{ announceHistory = new RepoAnnounceHistory(); announceHistory.AnnouncedPushes = new List<string>(); announceHistory.RepoName = announceLi[0].RepoName; _repoAnnounceHistory.Add(announceHistory); } for (int i = 0; i < announceLi.Count; i++){ var identifier = announceLi[i].CommitHashStart + announceLi[i].CommitHashEnd; if (announceHistory.AnnouncedPushes.Contains(identifier)){ announceLi.RemoveAt(i); i--; } } if (announceLi.Count == 0){ continue; } int numCommits = announceLi.Sum(announce => announce.CommitCount); string beginCommit = announceLi[0].CommitHashStart; string endCommit = announceLi.Last().CommitHashEnd; string finalLink = announceLi[0].Link + beginCommit + "..." + endCommit; var channels = IrcInterface.Client.GetChannels(); string plural = ""; if (numCommits > 1){ plural = "s"; } foreach (var channel in channels){ var msg = numCommits + " commit" + plural + " pushed to " + announceLi[0].RepoName + " by " + announceLi[0].Author + " " + finalLink; IrcInterface.Client.SendMessage(SendType.Message, channel, msg); } //add the newly made announcements to the announcement history foreach (var announcement in announceLi){ var identifier = announcement.CommitHashStart + announcement.CommitHashEnd; announceHistory.AnnouncedPushes.Add(identifier); ret = true; } SaveAnnouncementHistory(); } return ret; }