public void Process(CaseReportReceived @event) { var transaction = _commandContextManager.EstablishForCommand( new Dolittle.Runtime.Commands.CommandRequest( Guid.NewGuid(), Guid.NewGuid(), 1, new Dictionary <string, object>())); var root = _caseReportAggregateRootRepository.Get(@event.CaseReportId); var data = new CaseReportData { CaseReportId = @event.CaseReportId, DataCollectorId = @event.DataCollectorId, HealthRiskId = @event.HealthRiskId, Latitude = @event.Latitude, Longitude = @event.Longitude, Timestamp = @event.Timestamp, NumberOfMalesUnder5 = @event.NumberOfMalesUnder5, NumberOfMalesAged5AndOlder = @event.NumberOfMalesAged5AndOlder, NumberOfFemalesUnder5 = @event.NumberOfFemalesUnder5, NumberOfFemalesAged5AndOlder = @event.NumberOfFemalesAged5AndOlder, Message = @event.Message, PhoneNumber = @event.Origin }; root.ProcessReport(data); transaction.Commit(); }
public void Changed(Report updatedItem) { //TODO if there's open alert with same Health risk, we should just add the case to that alert. var alertRules = _alertRuleRunnerFactory.GetRelevantAlertRules(updatedItem.HealthRiskNumber); foreach (IAlertRuleRunner alertRunner in alertRules) { AlertRuleRunResult result = alertRunner.RunAlertRule(_reportsRepository); if (result.Triggered) { var alertId = Guid.NewGuid(); var transaction = _commandContextManager.EstablishForCommand( new Dolittle.Runtime.Commands.CommandRequest( Guid.NewGuid(), Guid.NewGuid(), 1, new Dictionary <string, object>())); var alertRuleAggrRoot = _aggregateRootRepository.Get(alertId); alertRuleAggrRoot.OpenAlert( alertId, result.AlertRuleId, result.Cases ); transaction.Commit(); } } }
public IDeviceRequest Begin() { var transactionCorrelationId = TransactionCorrelationId.New(); var commandRequest = new CommandRequest(transactionCorrelationId, _nullCommandIdentifier, new Dictionary <string, object>()); var commandContext = _commandContextManager.EstablishForCommand(commandRequest); var deviceRequest = new DeviceRequest(commandContext); return(deviceRequest); }
void ApplyEventsFor(ImprovementContext context, IEnumerable <IEvent> events) { var request = new CommandRequest(_executionContextManager.Current.CorrelationId, _nullCommandArtifactId, ArtifactGeneration.First, new Dictionary <string, object>()); using (var commandContext = _commandContextManager.EstablishForCommand(request)) { var improvement = _repository.Get(context.Improvement.Id); events.ForEach(_ => improvement.Apply(_)); } }
void SetImprovmentResult(ImprovementId id, bool succeeded) { var request = new CommandRequest(_executionContextManager.Current.CorrelationId, _nullCommandArtifactId, ArtifactGeneration.First, new Dictionary <string, object>()); using (var commandContext = _commandContextManager.EstablishForCommand(request)) { var improvement = _repository.Get(id); if (succeeded) { improvement.Complete(); } else { improvement.Fail(); } } }
public void Process(ReportRegistered @event) { var transaction = _commandContextManager.EstablishForCommand( new Dolittle.Runtime.Commands.CommandRequest( Guid.NewGuid(), Guid.NewGuid(), 1, new Dictionary <string, object>())); var root = _alertsAggregateRootRepository.Get(@event.CaseReportId); var item = _reportRepository.GetById(@event.ReportId); var relevantAlertRules = GetRelevantAlertRules(item.HealthRiskNumber); foreach (var alertRule in relevantAlertRules) { TriggerAlerts(alertRule, root); } transaction.Commit(); }
public void Process(TrainingReportConvertedToLive notification, EventSourceId caseReportId) { var transaction = _commandContextManager.EstablishForCommand(new Dolittle.Runtime.Commands.CommandRequest(Guid.NewGuid(), Guid.Empty, 0, new Dictionary <string, object>())); var report = _trainingReports.GetById((CaseReportId)caseReportId.Value); var aggregateRoot = _caseReportingRepository.Get(caseReportId); var reportFromKnownDataCollector = report.DataCollectorId != null && report.DataCollectorId != CaseReportId.NotSet; var validReport = report.HealthRiskId != null && report.HealthRiskId != HealthRiskId.NotSet; if (reportFromKnownDataCollector && validReport) { aggregateRoot.Report( report.DataCollectorId.Value, report.HealthRiskId.Value, report.Origin, report.NumberOfMalesUnder5, report.NumberOfMalesAged5AndOlder, report.NumberOfFemalesUnder5, report.NumberOfFemalesAged5AndOlder, report.Location.Longitude, report.Location.Latitude, report.Timestamp, report.Message ); } else if (reportFromKnownDataCollector && !validReport) { aggregateRoot.ReportInvalidReport( report.DataCollectorId.Value, report.Origin, report.Message, report.Location.Longitude, report.Location.Latitude, report.ParsingErrorMessage, report.Timestamp ); } else if (!reportFromKnownDataCollector && validReport) { aggregateRoot.ReportFromUnknownDataCollector( report.Origin, report.HealthRiskId.Value, report.NumberOfMalesUnder5, report.NumberOfMalesAged5AndOlder, report.NumberOfFemalesUnder5, report.NumberOfFemalesAged5AndOlder, report.Timestamp, report.Message ); } else if (!reportFromKnownDataCollector && !validReport) { aggregateRoot.ReportInvalidReportFromUnknownDataCollector( report.Origin, report.Message, report.ParsingErrorMessage, report.Timestamp ); } transaction.Commit(); }
public void Process(TextMessage message) { var commandContext = _commandContextManager.EstablishForCommand( new CommandRequest( TransactionCorrelationId.New(), null, new Dictionary <string, object>()) ); _processors.ForEach(processor => { try { processor.Process(message); } catch (Exception ex) { _logger.Error(ex, "Problems processing message"); } }); commandContext.Commit(); }
public void AggregateRoot <T>(Action <IAggregateOf <T> > callback) where T : class, IAggregateRoot { var thread = new Thread(() => { Thread.Sleep(500); var commandRequest = new CommandRequest( _executionContextManager.Current.CorrelationId, Artifact, ArtifactGeneration.First, new Dictionary <string, object>() ); using (_commandContextManager.EstablishForCommand(commandRequest)) { var aggregate = _container.Get <IAggregateOf <T> >(); callback(aggregate); } }); thread.Start(); }
/// <inheritdoc/> public CommandResult Handle(ICommand command) { return(Handle(_commandContextManager.EstablishForCommand(command), command)); }
public void Process(TextMessageReceived notification) { var transaction = _commandContextManager.EstablishForCommand(new Dolittle.Runtime.Commands.CommandRequest(Guid.NewGuid(), Guid.NewGuid(), 1, new Dictionary <string, object>())); var parsingResult = _textMessageParser.Parse(notification); // var filter = Builders<DataCollector>.Filter.AnyEq(c => c.PhoneNumbers, (PhoneNumber)phoneNumber); var isTextMessageFormatValid = parsingResult.IsValid; var dataCollector = _dataCollectors.Query.Where(_ => _.PhoneNumbers.Contains(new Concepts.DataCollectors.PhoneNumber() { Value = notification.Sender })).FirstOrDefault(); var unknownDataCollector = dataCollector == null; var caseReportId = Guid.NewGuid(); var caseReporting = _caseReportingRepository.Get(caseReportId); if (!isTextMessageFormatValid && unknownDataCollector) { caseReporting.ReportInvalidReportFromUnknownDataCollector( notification.Sender, notification.Text, parsingResult.ErrorMessages, notification.Received); transaction.Commit(); return; } if (!isTextMessageFormatValid && !unknownDataCollector) { caseReporting.ReportInvalidReport( dataCollector.Id, notification.Sender, notification.Text, dataCollector.Location.Longitude, dataCollector.Location.Latitude, parsingResult.ErrorMessages, notification.Received); transaction.Commit(); return; } var healthRiskReadableId = parsingResult.HealthRiskReadableId; var healthRiskId = _healthRisks.Query.Where(i => i.ReadableId == healthRiskReadableId).FirstOrDefault()?.Id; if (healthRiskId == null || healthRiskId == HealthRiskId.NotSet) { var errorMessages = new List <string> { $"Unable to find health risk, since there are no health risks with a readable id of {healthRiskReadableId}" }; if (unknownDataCollector) { caseReporting.ReportInvalidReportFromUnknownDataCollector( notification.Sender, notification.Text, errorMessages, notification.Received); transaction.Commit(); return; } caseReporting.ReportInvalidReport( dataCollector.Id, notification.Sender, notification.Text, dataCollector.Location.Longitude, dataCollector.Location.Latitude, errorMessages, notification.Received); transaction.Commit(); return; } if (unknownDataCollector) { caseReporting.ReportFromUnknownDataCollector( notification.Sender, healthRiskId.Value, parsingResult.MalesUnder5, parsingResult.MalesAged5AndOlder, parsingResult.FemalesUnder5, parsingResult.FemalesAged5AndOlder, notification.Received, notification.Text ); transaction.Commit(); return; } caseReporting.Report( dataCollector.Id, healthRiskId.Value, notification.Sender, parsingResult.MalesUnder5, parsingResult.MalesAged5AndOlder, parsingResult.FemalesUnder5, parsingResult.FemalesAged5AndOlder, dataCollector.Location.Longitude, dataCollector.Location.Latitude, notification.Received, notification.Text ); transaction.Commit(); }