private void InvokeNewNewsItem(NewNewsItemEventArgs args, bool newsIsBothLocalAndNew) { var newNewsItem = NewNewsItem; if (newsIsBothLocalAndNew) SosDb.ExportNewNewsItem(args); if (newNewsItem != null) newNewsItem(this, args); }
public void SerializeThenDeserialize() { SirenOfShameSettingsFake settings = new SirenOfShameSettingsFake(); var person = settings.FindAddPerson("Bob"); NewNewsItemEventArgs args = new NewNewsItemEventArgs { EventDate = new DateTime(2010, 1, 2, 3, 4, 5, 6), Person = person, Title = "Hello world", NewsItemType = NewsItemTypeEnum.BuildFailed, BuildDefinitionId = "Project 1", ReputationChange = -1, BuildId = "5", }; var asCommaSeparated = args.AsCommaSeparated(); var result = NewNewsItemEventArgs.FromCommaSeparated(asCommaSeparated, settings); Assert.IsNotNull(result); Assert.AreEqual("Bob", result.Person.RawName); Assert.AreEqual("Hello world", result.Title); Assert.AreEqual(new DateTime(2010, 1, 2, 3, 4, 5, 6), result.EventDate); Assert.AreEqual(NewsItemTypeEnum.BuildFailed, result.NewsItemType); Assert.AreEqual(-1, result.ReputationChange); Assert.AreEqual("Project 1", result.BuildDefinitionId); Assert.AreEqual("5", result.BuildId); }
public void AddNewsItem(NewNewsItemEventArgs args) { if (args == null || args.Person == null) return; if (!IncludeInFilter(args)) return; if (args.ShouldUpdateOldInProgressNewsItem) TryToFindAndUpdateOldInProgressNewsItem(args); else AddNewsItemToPanel(args); }
private void InvokeNewNewsItem(NewNewsItemEventArgs args, bool newsIsBothLocalAndNew) { var newNewsItem = NewNewsItem; if (newsIsBothLocalAndNew) { SosDb.ExportNewNewsItem(args); } if (newNewsItem != null) { newNewsItem(this, args); } }
public void SerializeThenDeserialize_CommaSeparatedTitle() { SirenOfShameSettingsFake settings = new SirenOfShameSettingsFake(); var person = settings.FindAddPerson("Bob"); NewNewsItemEventArgs args = new NewNewsItemEventArgs { EventDate = new DateTime(2010, 1, 2, 3, 4, 5, 6), Person = person, NewsItemType = NewsItemTypeEnum.BuildFailed, Title = ",Hello, world,", BuildDefinitionId = "Project 1" }; var asCommaSeparated = args.AsCommaSeparated(); var result = NewNewsItemEventArgs.FromCommaSeparated(asCommaSeparated, settings); Assert.IsNotNull(result); Assert.AreEqual(",Hello, world,", result.Title); }
public void ExportNewNewsItem(NewNewsItemEventArgs args) { var location = GetEventsLocation(); string asCommaSeparated = args.AsCommaSeparated(); if (!string.IsNullOrEmpty(asCommaSeparated)) { string contents = asCommaSeparated + "\r\n"; try { FileAdapter.AppendAllText(location, contents); } catch (IOException ex) { _log.Error("Unable to export news item: " + contents, ex); } } }
public void ExportNewNewsItem(NewNewsItemEventArgs args) { var location = GetEventsLocation(); string asCommaSeparated = args.AsCommaSeparated(); if (!string.IsNullOrEmpty(asCommaSeparated)) { string contents = asCommaSeparated + "\r\n"; try { FileAdapter.AppendAllText(location, contents); } catch (IOException ex) { _log.Error("Unable to export news item: " + contents, ex); } } }
private void TryToFindAndUpdateOldInProgressNewsItem(NewNewsItemEventArgs args) { var oldBuild = GetNewsItemControls().FirstOrDefault(i => i.BuildId == args.BuildId); if (oldBuild != null) oldBuild.UpdateState(args); else AddNewsItemToPanel(args); }
private bool IncludeInFilter(NewNewsItemEventArgs i) { return IncludeInFilter(i, _filterPerson, _filterBuildDefinitionId); }
private void AddNewsItemToPanel(NewNewsItemEventArgs args) { var newsItem = AddNewsItemToPanel(); newsItem.Initialize(args); _newsItemsPanel.Controls.SetChildIndex(newsItem, 0); newsItem.Height = 1; _newsItemsToOpen.Add(newsItem); _newsItemHeightAnimator.Start(); }
public void GetMostRecentNewsItems(SirenOfShameSettings settings, Action <IList <NewNewsItemEventArgs> > onGetNewsItems) { var location = GetEventsLocation(); if (!FileAdapter.Exists(location)) { onGetNewsItems(new List <NewNewsItemEventArgs>()); } var context = TaskScheduler.FromCurrentSynchronizationContext(); var newsItemGetter = new Task <List <NewNewsItemEventArgs> >(() => FileAdapter.ReadAllLines(location) .Select(i => NewNewsItemEventArgs.FromCommaSeparated(i, settings)) .Where(i => i != null) .Reverse() .ToList()); newsItemGetter.ContinueWith(result => onGetNewsItems(result.Result), new CancellationToken(), TaskContinuationOptions.OnlyOnRanToCompletion, context); newsItemGetter.ContinueWith(t => { if (t.Exception != null) { var exception = t.Exception.InnerExceptions.First(); if (!(exception is FileNotFoundException)) { _log.Error(exception); } } onGetNewsItems(new List <NewNewsItemEventArgs>()); }, new CancellationToken(), TaskContinuationOptions.OnlyOnFaulted, context); newsItemGetter.Start(); }
private void RulesEngineNewNewsItem(object sender, NewNewsItemEventArgs args) { Invoke(() => { args.AvatarImageList = _avatarImageList; _newsFeed1.AddNewsItem(args); }); }
private void SosOnlineServiceOnNewSosOnlineNotification(object sender, NewSosOnlineNotificationArgs args) { // this may result in a web request to retrieve the person's image, so keep it on some other thread SosOnlinePerson sosOnlinePerson = _sosOnlineService.CreateSosOnlinePersonFromSosOnlineNotification(args, _avatarImageList); Invoke(() => { NewNewsItemEventArgs newNewsItemEventArgs = new NewNewsItemEventArgs { EventDate = DateTime.Now, Person = sosOnlinePerson, Title = args.Message, AvatarImageList = _avatarImageList, NewsItemType = NewsItemTypeEnum.SosOnlineComment }; _newsFeed1.AddNewsItem(newNewsItemEventArgs); }); }
private void InitializeMetroColors(NewNewsItemEventArgs args) { Color backColor = GetBackgroundColorForEventType(args.NewsItemType); _leftPanel.BackColor = backColor; _project.BackColor = backColor; _userName.BackColor = backColor; _when.BackColor = backColor; _reputationChange.BackColor = backColor; }
public void Initialize(NewNewsItemEventArgs args) { _rawUserName = args.Person.RawName; BuildId = args.BuildId; EventDate = args.EventDate; InitializeUserNameLabel(args); InitializeReputationChangeLabel(args.ReputationChange); WriteProject(args); WriteTitle(args); WriteDate(args.EventDate); InitializeAvatar(args); InitializeMetroColors(args); }
public void UpdateState(NewNewsItemEventArgs args) { InitializeReputationChangeLabel(args.ReputationChange); InitializeMetroColors(args); }
private void WriteTitle(NewNewsItemEventArgs args) { string title = args.NewsItemType == NewsItemTypeEnum.SosOnlineComment ? "\"" + args.Title + "\"" : args.Title; _title.Text = title; }
private void WriteProject(NewNewsItemEventArgs args) { _project.Visible = !string.IsNullOrEmpty(args.BuildDefinitionId); if (args.BuildDefinitionId == null) return; _project.Text = args.BuildDefinitionId.ToUpperInvariant(); }
private void InitializeUserNameLabel(NewNewsItemEventArgs args) { DisplayName = args.Person.DisplayName; }
public static bool IncludeInFilter(NewNewsItemEventArgs newsItem, string filterPerson, string filterBuildDefinitionId) { if (filterPerson == null && filterBuildDefinitionId == null) return true; if (filterPerson != null) return newsItem.Person.RawName == filterPerson; return newsItem.IsSosOnlineEvent || newsItem.BuildDefinitionId == filterBuildDefinitionId; }
private void SosOnlineServiceOnOnNewSosOnlineNotification(object sender, NewSosOnlineNotificationArgs args) { NewsItemTypeEnum newItemType = (NewsItemTypeEnum)args.EventTypeId; bool currentUserAuthoredEvent = args.UserName == _settings.SosOnlineUsername; bool reputationChangeOrAchievement = newItemType == NewsItemTypeEnum.SosOnlineReputationChange || newItemType == NewsItemTypeEnum.SosOnlineNewAchievement; if (currentUserAuthoredEvent && reputationChangeOrAchievement) return; // this may result in a web request to retrieve the person's image, so keep it on some other thread SosOnlinePerson sosOnlinePerson = _sosOnlineService.CreateSosOnlinePersonFromSosOnlineNotification(args, _avatarImageList); Invoke(() => { NewNewsItemEventArgs newNewsItemEventArgs = new NewNewsItemEventArgs { EventDate = DateTime.Now, Person = sosOnlinePerson, Title = args.Message, AvatarImageList = _avatarImageList, NewsItemType = newItemType }; _newsFeed1.AddNewsItem(newNewsItemEventArgs); }); }
private void InitializeAvatar(NewNewsItemEventArgs args) { avatar1.SetImage(args.Person, args.AvatarImageList); avatar1.Cursor = args.Person.Clickable ? Cursors.Hand : Cursors.Default; }