public void Process(PhoneNumberAddedToDataCollector @event, EventSourceId dataCollectorId) { var dataCollector = _dataCollectors.GetById(dataCollectorId.Value); dataCollector.PhoneNumbers.Add(@event.PhoneNumber); _dataCollectors.Update(dataCollector); }
public void Process(PhoneNumberRemovedFromDataCollector @event, EventSourceId dataCollectorId) { var dataCollector = _dataCollectors.GetById(dataCollectorId.Value); dataCollector.PhoneNumbers.Remove(@event.PhoneNumber); _dataCollectors.Update(dataCollector); }
/// <inheritdoc/> public T Get(EventSourceId id) { var commandContext = _commandContextManager.GetCurrent(); var type = typeof(T); var constructor = GetConstructorFor(type); ThrowIfConstructorIsInvalid(type, constructor); var aggregateRoot = GetInstanceFrom(id, constructor); if (null != aggregateRoot) { if (!aggregateRoot.IsStateless()) { ReApplyEvents(commandContext, aggregateRoot); } else { FastForward(commandContext, aggregateRoot); } } commandContext.RegisterForTracking(aggregateRoot); return(aggregateRoot); }
Task InsertEvent( IClientSessionHandle transaction, EventLogSequenceNumber version, DateTimeOffset occurred, EventSourceId eventSource, UncommittedEvent @event, AggregateMetadata aggregate, Execution.ExecutionContext executionContext, CancellationToken cancellationToken) { return(_streams.DefaultEventLog.InsertOneAsync( transaction, new Event( version, executionContext.ToStoreRepresentation(), new EventMetadata( occurred.UtcDateTime, eventSource, @event.Type.Id, @event.Type.Generation, @event.Public), aggregate, new EventHorizonMetadata(), BsonDocument.Parse(@event.Content)), cancellationToken: cancellationToken)); }
/// <inheritdoc/> public EventSourceVersion GetFor(Artifact eventSource, EventSourceId eventSourceId) { var version = EventSourceVersion.Zero; version = _eventStore.GetVersionFor(eventSource, eventSourceId); return(version); }
/// <inheritdoc/> public T Get(EventSourceId id) { _logger.Trace($"Get '{typeof(T).AssemblyQualifiedName}' with Id of '{id?.Value.ToString() ?? "<unknown id>"}'"); var commandContext = _commandContextManager.GetCurrent(); var type = typeof(T); var constructor = GetConstructorFor(type); ThrowIfConstructorIsInvalid(type, constructor); var aggregateRoot = GetInstanceFrom(id, constructor); if (null != aggregateRoot) { if (!aggregateRoot.IsStateless()) { ReApplyEvents(commandContext, aggregateRoot); } else { FastForward(commandContext, aggregateRoot); } } commandContext.RegisterForTracking(aggregateRoot); return(aggregateRoot); }
/// <summary> /// Initializes a new instance of the <see cref="Event"/> class. /// </summary> /// <param name="eventSourceId">The Events EventSourceId.</param> /// <param name="type">The <see cref="Artifact"/> representing the type of the Event.</param> /// <param name="isPublic">Whether the Event is public.</param> /// <param name="content">The content of the Event represented as a JSON-encoded <see cref="string"/>.</param> protected Event(EventSourceId eventSourceId, Artifact type, bool isPublic, string content) { EventSource = eventSourceId; Type = type; Public = isPublic; Content = content; }
/// <inheritdoc/> public IEnumerable <EventStoragePath> GetForContext(EventSourceId eventSourceId) { var context = _eventStorageContexts.GetCurrentFor(eventSourceId); var paths = _templates.All.Select(_ => (EventStoragePath)_.Function(context)); return(paths); }
/// <summary> /// Initializes a new instance of the <see cref="UncommittedAggregateEvents"/> class. /// </summary> /// <param name="eventSource">The <see cref="EventSourceId"/> that the Events were applied to.</param> /// <param name="aggregateRoot">The <see cref="Artifact"/> representing the type of the Aggregate Root that applied the Event to the Event Source.</param> /// <param name="expectedAggregateRootVersion">The <see cref="AggregateRootVersion"/> of the Aggregate Root that was used to apply the rules that resulted in the Events.</param> /// <param name="events">The <see cref="UncommittedEvent">events</see>.</param> public UncommittedAggregateEvents(EventSourceId eventSource, Artifact aggregateRoot, AggregateRootVersion expectedAggregateRootVersion, IReadOnlyList <UncommittedEvent> events) : base(events) { EventSource = eventSource; AggregateRoot = aggregateRoot; ExpectedAggregateRootVersion = expectedAggregateRootVersion; }
string GetPartitionKeyFilterFor(IApplicationResourceIdentifier eventSource, EventSourceId eventSourceId) { var partitionKey = GetPartitionKeyFor(eventSource, eventSourceId); var partitionKeyFilter = TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, partitionKey); return(partitionKeyFilter); }
string GetPartitionKeyFor(IApplicationResourceIdentifier identifier, EventSourceId id) { var identifierAsString = GetSanitizedApplicationResourceIdentifier(identifier); var partitionKey = $"{identifierAsString}-{id}"; return(partitionKey); }
public void Process(TrainingReportReceived @event, EventSourceId caseReportId) { var dataCollector = _dataCollectors.GetById(@event.DataCollectorId); var healthRisk = _healthRisks.GetById(@event.HealthRiskId); var report = new TrainingReport(caseReportId.Value) { Status = CaseReportStatus.Success, Message = @event.Message, DataCollectorId = dataCollector.Id, DataCollectorDisplayName = dataCollector.DisplayName, DataCollectorDistrict = dataCollector.District, DataCollectorRegion = dataCollector.Region, DataCollectorVillage = dataCollector.Village, Location = dataCollector.Location, Origin = @event.Origin, HealthRiskId = healthRisk.Id, HealthRisk = healthRisk.Name, NumberOfMalesUnder5 = @event.NumberOfMalesUnder5, NumberOfMalesAged5AndOlder = @event.NumberOfMalesAged5AndOlder, NumberOfFemalesUnder5 = @event.NumberOfFemalesUnder5, NumberOfFemalesAged5AndOlder = @event.NumberOfFemalesAged5AndOlder, Timestamp = @event.Timestamp, }; _trainingReports.Insert(report); }
public void Process(InvalidReportReceived @event, EventSourceId caseReportId) { var dataCollector = _dataCollectors.GetById(@event.DataCollectorId); var caseReport = new CaseReportForListing(caseReportId.Value) { Status = CaseReportStatus.TextMessageParsingError, DataCollectorDisplayName = dataCollector.DisplayName, DataCollectorId = dataCollector.Id, DataCollectorRegion = dataCollector.Region, DataCollectorDistrict = dataCollector.District, DataCollectorVillage = dataCollector.Village, HealthRiskId = null, HealthRisk = "Unknown", Location = dataCollector.Location, Message = @event.Message, Origin = @event.Origin, ParsingErrorMessage = @event.ErrorMessages, Timestamp = @event.Timestamp }; _caseReports.Insert(caseReport); }
/// <summary> /// Converts a <see cref="EventSourceId" /> into its <see cref="BsonDocument" /> representation /// </summary> /// <param name="eventSourceId">The <see cref="EventSourceId" /></param> /// <returns>A <see cref="BsonDocument" /> representation of the <see cref="EventSourceId" /></returns> public static BsonDocument AsBson(this EventSourceId eventSourceId) { return(new BsonDocument(new Dictionary <string, object> { { Constants.EVENTSOURCE_ID, eventSourceId.Value } })); }
public static EventSourceKey get_event_source_key(EventSourceId event_source_id = null, ArtifactId artifact_id = null) { var es = event_source_id ?? EventSourceId.New(); var a = artifact_id ?? ArtifactId.New(); return(new EventSourceKey(es, a)); }
public void IterationSetup() { var eventSource = new EventSourceId("46c4de33-9a60-4465-97ab-a2a7f5b7e6a3"); var aggregateRoot = new Artifact(new ArtifactId(Guid.NewGuid()), ArtifactGeneration.First); _eventsToCommit = new UncommittedAggregateEvents( eventSource, aggregateRoot, AggregateRootVersion.Initial + (ulong)PreExistingEvents, _eventsToCommit); if (PreExistingEvents > 0) { var events = new List <UncommittedEvent>(); for (var n = 0; n < PreExistingEvents; n++) { events.Add(new UncommittedEvent( new EventSourceId("46c4de33-9a60-4465-97ab-a2a7f5b7e6a3"), new Artifact(new ArtifactId(Guid.Parse("08db4b0a-3724-444f-9968-ada44922fb78")), ArtifactGeneration.First), false, "{ \"hello\": \"world\" }")); } var preExistingEvents = new UncommittedAggregateEvents( eventSource, aggregateRoot, AggregateRootVersion.Initial, events); _eventStore.Commit(preExistingEvents, _executionContext).GetAwaiter().GetResult(); } }
public void Process(LastActiveUpdated @event, EventSourceId dataCollectorId) { var dataCollector = _dataCollectors.GetById(dataCollectorId); dataCollector.LastActive = @event.LastActive; _dataCollectors.Update(dataCollector); }
public void Process(ImprovementInitiated @event, EventSourceId eventSourceId) { var recipe = new DotNetFramework(); var improvement = new Improvement { Id = eventSourceId.Value, Improvable = @event.ForImprovable, PullRequest = @event.PullRequest, Version = @event.Version }; var improvable = _improvableManager.GetById(@event.ForImprovable); var context = new ImprovementContext( _executionContextManager.Current.Tenant, improvement, improvable); var pod = _improvementPodFactory.BuildFrom(context, recipe); using (var client = _kubernetesClientFactory()) { client.CreateNamespacedPod(pod, pod.Metadata.NamespaceProperty); } }
/// <inheritdoc/> public Task <AggregateRoot> IncrementVersionFor( IClientSessionHandle transaction, EventSourceId eventSource, ArtifactId aggregateRoot, AggregateRootVersion expectedVersion, AggregateRootVersion nextVersion, CancellationToken cancellationToken) { _logger.IncrementingVersionForAggregate(aggregateRoot, eventSource); ThrowIfNextVersionIsNotGreaterThanExpectedVersion(eventSource, aggregateRoot, expectedVersion, nextVersion); if (expectedVersion == AggregateRootVersion.Initial) { return(WriteFirstAggregateRootDocument( transaction, eventSource, aggregateRoot, expectedVersion, nextVersion, cancellationToken)); } else { return(UpdateExistingAggregateRootDocument( transaction, eventSource, aggregateRoot, expectedVersion, nextVersion, cancellationToken)); } }
public void Process(CaseReportFromUnknownDataCollectorReceived @event, EventSourceId caseReportId) { var healthRisk = _healthRisks.GetById(@event.HealthRiskId); var caseReport = new CaseReportForListing(caseReportId.Value) { Status = CaseReportStatus.UnknownDataCollector, DataCollectorDisplayName = "Unknown", DataCollectorId = null, HealthRisk = healthRisk.Name, HealthRiskId = healthRisk.Id, Location = Location.NotSet, Message = @event.Message, Origin = @event.Origin, Timestamp = @event.Timestamp, DataCollectorDistrict = null, DataCollectorRegion = null, DataCollectorVillage = null }; _caseReports.Insert(caseReport); }
public void Process(DataCollectorVillageChanged @event, EventSourceId dataCollectorId) { var dataCollector = _dataCollectors.GetById(dataCollectorId.Value); dataCollector.Village = @event.Village; _dataCollectors.Update(dataCollector); }
public void Process(DataCollectorLocationChanged @event, EventSourceId dataCollectorId) { var dataCollector = _dataCollectors.GetById(dataCollectorId.Value); dataCollector.Location = new Location(@event.LocationLatitude, @event.LocationLongitude); _dataCollectors.Update(dataCollector); }
/// <inheritdoc/> public bool HasEventsFor(IApplicationResourceIdentifier eventSource, EventSourceId eventSourceId) { var eventSourceIdentifier = _applicationResourceIdentifierConverter.AsString(eventSource); var eventPath = GetPathFor(eventSourceIdentifier, eventSourceId); var files = _files.GetFilesIn(eventPath, "*.event"); return(files.Count() > 0); }
/// <summary> /// Initializes a new instance of the <see cref="AggregateRoot"/> class. /// </summary> /// <param name="eventSourceId">The <see cref="Events.EventSourceId"/> that the Aggregate Root will apply events on.</param> protected AggregateRoot(EventSourceId eventSourceId) { EventSourceId = eventSourceId; Version = AggregateRootVersion.Initial; _ruleSetEvaluations = new List <RuleSetEvaluation>(); _brokenRules = new List <BrokenRule>(); _uncommittedEvents = new NullFreeList <IEvent>(); }
public when_saving_a_new_event_source() : base() { //Bandaid for file system race. See issue #54 for full explanation Thread.Sleep(TimeSpan.FromSeconds(1)); _foldername = GetPath(); _filename = EventSourceId.ToString().Substring(2); }
public static UncommittedEventStream BuildUncommitted(this EventSourceId eventSourceId, ArtifactId eventSourceArtifact, DateTimeOffset?now = null, CorrelationId correlationId = null) { var committed = now ?? DateTimeOffset.Now; var events = BuildEvents(); VersionedEventSource versionedEventSource = eventSourceId.InitialVersion(eventSourceArtifact); return(BuildFrom(versionedEventSource, committed, correlationId ?? Guid.NewGuid(), events)); }
/// <summary> /// /// </summary> /// <param name="eventSourceId"></param> /// <param name="@event"></param> protected void Apply(EventSourceId eventSourceId, IEvent @event) { var transactionCorrelationId = TransactionCorrelationId.New(); var eventSource = GetEventSourceForThisController(eventSourceId); eventSource.Apply(@event); _uncommittedEventStreamCoordinator.Commit(transactionCorrelationId, eventSource.UncommittedEvents); }
public static CommittedEvent single(uint event_log_sequence_number) => new CommittedEvent( event_log_sequence_number, DateTimeOffset.UtcNow, EventSourceId.New(), execution_contexts.create(), new Artifact(ArtifactId.New(), ArtifactGeneration.First), false, "{\"something\":42}");
public static CommittedEvent single() => new CommittedEvent( EventLogSequenceNumber.Initial, DateTimeOffset.UtcNow, EventSourceId.New(), execution_contexts.create(), new Artifact(ArtifactId.New(), ArtifactGeneration.First), false, "{\"something\":42}");
public void Process(DataCollectorPreferredLanguageChanged @event, EventSourceId dataCollectorId) { var dataCollector = _dataCollectors.GetById(dataCollectorId.Value); dataCollector.PreferredLanguage = (Language)@event.Language; _dataCollectors.Update(dataCollector); }