private void CheckAndPublish() { if (!_informationEntriesQueue.Any() || _publishingInProgress) { return; } _publishingInProgress = true; var nextEntry = _informationEntriesQueue.Dequeue(); _subscriptionService.OnInformationReceived(nextEntry); if (nextEntry.DisplayLengthInSeconds.HasValue) { Task.Run( async() => { await Task.Delay(nextEntry.DisplayLengthInSeconds.Value * 1000); var emptyInfo = _viewDataAdapter.Adapt(InformationEntry.CreateEmpty()); _subscriptionService.OnInformationReceived(emptyInfo); _publishingInProgress = false; CheckAndPublish(); }); } else { _publishingInProgress = false; } }
public void Handle(Exception exception) { _loggingService.LogException(exception); var mostInnerException = exception.GetMostInnerException(); _informationPublisher.Publish(InformationEntry.CreateError(mostInnerException)); }
private void CheckAndPublish() { if (!_informationEntriesQueue.Any() || _publishingInProgress) { return; } _publishingInProgress = true; var nextEntry = _informationEntriesQueue.Dequeue(); _configurationService.Subscribers.ForEach(subs => subs.Invoke(nextEntry)); if (nextEntry.LengthInSeconds.HasValue) { Task.Run( async() => { await Task.Delay(nextEntry.LengthInSeconds.Value * 1000); var emptyInfo = InformationEntry.CreateEmpty(); _configurationService.Subscribers.ForEach(subs => subs.Invoke(emptyInfo)); _publishingInProgress = false; CheckAndPublish(); }); } else { _publishingInProgress = false; } }
public void Publish(InformationEntry infoEntry) { var viewData = _viewDataAdapter.Adapt(infoEntry); _informationEntriesQueue.Enqueue(viewData); CheckAndPublish(); }
private async Task DeleteIndividualAsync() { _informationPublisher.Publish(InformationEntry.CreateInfo($"Deleting Individual {_context.SelectedIndividual.FormattedName}..", true)); await _overviewService.DeleteIndividualAsync(_context.SelectedIndividual.Id); _context.Individuals.Remove(_context.SelectedIndividual); _informationPublisher.Publish(InformationEntry.CreateSuccess("Individual deleted", false, 5)); }
public InformationEntryViewData Adapt(InformationEntry infoEntry) { var brush = AdaptBrush(infoEntry.EntryType); return(new InformationEntryViewData( infoEntry.Message, infoEntry.ShowBusy, brush, infoEntry.DisplayLengthInSeconds)); }
public void CreatingEmpty_CreatesEmptyInfoEntry() { // Act var actualInfoEntry = InformationEntry.CreateEmpty(); // Assert Assert.AreEqual(false, actualInfoEntry.ShowBusy); Assert.AreEqual(string.Empty, actualInfoEntry.Message); Assert.IsNull(actualInfoEntry.DisplayLengthInSeconds); Assert.AreEqual(InformationEntryType.Info, actualInfoEntry.EntryType); }
public async Task StartAppAsync(WpfAppConfiguration config, Action <IServiceLocator> afterInitializedCallback) { _exceptionInitializationService.HookGlobalExceptions(); _viewModelMappingInitService.Initialize(config.WpfAssembly); await _viewModelContainer.InitializeAsync(); _infoPublisher.Publish(InformationEntry.CreateInfo("Here could be your text..", false)); afterInitializedCallback?.Invoke(_serviceLocator); ShowApp(config); }
public void CreatingExeption_CreatesErrorEntry_WithExceptionMessage_AsMessage() { // Arrange const string Message = "Hello Exception"; var exception = new ArgumentException(Message); // Act var actualInfoEntry = InformationEntry.CreateError(exception); // Assert Assert.AreEqual(false, actualInfoEntry.ShowBusy); Assert.AreEqual(Message, actualInfoEntry.Message); Assert.IsNull(actualInfoEntry.DisplayLengthInSeconds); Assert.AreEqual(InformationEntryType.Error, actualInfoEntry.EntryType); }
public void CreatingSuccess_CreatesSuccessEntry_WithPassedParameters() { // Arrange const bool ShowBusy = true; const string Message = "Hello"; // Act var actualInfoEntry = InformationEntry.CreateSuccess(Message, ShowBusy); // Assert Assert.AreEqual(ShowBusy, actualInfoEntry.ShowBusy); Assert.AreEqual(Message, actualInfoEntry.Message); Assert.IsNull(actualInfoEntry.DisplayLengthInSeconds); Assert.AreEqual(InformationEntryType.Success, actualInfoEntry.EntryType); }
public void CreatingInfo_CreatesInfoEntry_WithPassedParameters() { // Arrange const bool ShowBusy = true; const string Message = "Hello"; const int DisplayLengthInSeconds = 4; // Act var actualInfoEntry = InformationEntry.CreateInfo(Message, ShowBusy, DisplayLengthInSeconds); // Assert Assert.AreEqual(ShowBusy, actualInfoEntry.ShowBusy); Assert.AreEqual(Message, actualInfoEntry.Message); Assert.AreEqual(DisplayLengthInSeconds, actualInfoEntry.DisplayLengthInSeconds); Assert.AreEqual(InformationEntryType.Info, actualInfoEntry.EntryType); }
public void HandlingException_PublishesErrorOnce_WithExceptionMessageAsText() { // Arrange const string ExcpetionText = "Hello Tra"; var exception = new Exception(ExcpetionText); InformationEntry actualInfoEntry = null; _informationPublisherMock.Setup(f => f.Publish(It.IsAny <InformationEntry>())).Callback <InformationEntry>(e => actualInfoEntry = e); // Act _sut.Handle(exception); // Assert Assert.IsNotNull(actualInfoEntry); Assert.AreEqual(ExcpetionText, actualInfoEntry.Message); Assert.AreEqual(InformationEntryType.Error, actualInfoEntry.EntryType); }
public void RepositoryInsertsInformationWithActiveFlagAndResetsActiveFlagsOfOlderVersionsWhenInformationDoesAlreadyExist() { var existingEntries = new[] { new InformationEntry { InformationId = "234-BCD", IsActive = false, DiscoveryTimestamp = new DateTime(2017, 2, 3) }, new InformationEntry { InformationId = "234-BCD", IsActive = true, DiscoveryTimestamp = new DateTime(2017, 10, 4) } }; var informationCollection = new MongoCollectionReturnsSpecificDocumentsStub(existingEntries); var database = new MongoDatabaseSpy(new Dictionary <string, IMongoCollection <InformationEntry> > { { "information", informationCollection } }); var id = "234-BCD"; var repository = new StoreInformationMongoDatabaseRepository(database); repository.StoreInformation(new InformationEntity { Id = id, Properties = new[] { new InformationPropertyEntity { Name = "titles", Values = new[] { "title A" } } } }); var expectedEntry = new InformationEntry { InformationId = id, IsActive = true, DiscoveryTimestamp = MongoCollectionReturnsSpecificDocumentsStub.DiscoveryTimestamp, Properties = new[] { new InformationPropertyEntry { Name = "titles", Values = new BsonValue[] { "title A" } } } }; Assert.Equal( JsonConvert.SerializeObject(expectedEntry), JsonConvert.SerializeObject(informationCollection.LastInsertedEntry) ); existingEntries[1].IsActive = false; Assert.Equal( JsonConvert.SerializeObject(existingEntries), JsonConvert.SerializeObject(informationCollection.ReplacedEntries) ); }
public void GetEntry_ParsesEachColumn() { var provider = CreateProvider(); var row = CreateDataRow(); row["QueryName"] = "Title"; row["QueryText"] = "Text"; var entry = provider.GetEntry(row); var expected = new InformationEntry { Title = "Title", Text = "Text" }; var printer = new Stateprinter(); Assert.AreEqual(printer.PrintObject(expected), printer.PrintObject(entry)); }
public void RepositoryInsertsInformationWithActiveFlagAndDiscoveryTimestampWhenInformationDoesNotAlreadyExist() { var informationCollection = new MongoCollectionReturnsSpecificDocumentsStub(new List <InformationEntry>()); var database = new MongoDatabaseSpy(new Dictionary <string, IMongoCollection <InformationEntry> > { { "information", informationCollection } }); var id = "123-ABC"; var repository = new StoreInformationMongoDatabaseRepository(database); repository.StoreInformation(new InformationEntity { Id = id }); var expectedEntry = new InformationEntry { InformationId = id, IsActive = true, DiscoveryTimestamp = MongoCollectionReturnsSpecificDocumentsStub.DiscoveryTimestamp }; Assert.Equal( JsonConvert.SerializeObject(expectedEntry), JsonConvert.SerializeObject(informationCollection.LastInsertedEntry) ); }
public void RepositoryInsertsInformationAsNewRecord() { var informationCollection = new MongoCollectionSpy(); var database = new MongoDatabaseSpy(new Dictionary <string, IMongoCollection <InformationEntry> > { { "information", informationCollection } }); var repository = new StoreInformationMongoDatabaseRepository(database); repository.StoreInformation(new InformationEntity { Properties = new[] { new InformationPropertyEntity { Name = "title", Values = new object[] { "sweet shoes" } }, new InformationPropertyEntity { Name = "color", Values = new object[] { "red" } }, new InformationPropertyEntity { Name = "price", Values = new object[] { (decimal)12.45 } }, new InformationPropertyEntity { Name = "currency", Values = new object[] { "€" } }, new InformationPropertyEntity { Name = "size", Values = new object[] { 43 } } } }); var insertedEntry = informationCollection.LastInsertedEntry; var expectedEntry = new InformationEntry { IsActive = true, Properties = new[] { new InformationPropertyEntry { Name = "color", Values = new BsonString[] { "red" } }, new InformationPropertyEntry { Name = "currency", Values = new BsonString[] { "€" } }, new InformationPropertyEntry { Name = "price", Values = new BsonDecimal128[] { new BsonDecimal128((decimal)12.45) } }, new InformationPropertyEntry { Name = "size", Values = new BsonValue[] { new BsonInt32(43) } }, new InformationPropertyEntry { Name = "title", Values = new BsonString[] { "sweet shoes" } } }, DiscoveryTimestamp = MongoCollectionSpy.DiscoveryTimestamp }; Assert.Equal( JsonConvert.SerializeObject(expectedEntry), JsonConvert.SerializeObject(insertedEntry) ); }
private void InformationReceived(InformationEntry obj) { var viewData = new InformationEntryViewData(obj.Message, obj.IsBusy); _subscribers.ForEach(subs => subs(viewData)); }
public void Publish(InformationEntry informationEntry) { _informationEntriesQueue.Enqueue(informationEntry); CheckAndPublish(); }