public async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, HttpMethods.Delete, Route = "category/{id:guid}")] HttpRequest req, [NotificationSubscriber] string subscriber, string id, ILogger log) { var correlationId = _guidProvider.GenerateGuid(); _correlationInitializer.Initialize(correlationId); log.LogProgress(OperationStatus.Started, "Deleting category process started", correlationId); var categoryDeletedEvent = new DeleteCategoryProcessStartedEvent(id, correlationId); await _subscriber.Register(correlationId, subscriber); var saveEventResult = await _eventStore.AppendEvent(id, categoryDeletedEvent); if (!saveEventResult.Success) { log.LogFailedOperation(OperationStatus.Failed, "Deleting category process failed", saveEventResult.Errors, correlationId); return(new BadRequestResult()); } log.LogProgress(OperationStatus.InProgress, "Request accepted to further processing.", correlationId); await _eventPublisher.PublishEvent(categoryDeletedEvent); log.LogProgress(OperationStatus.InProgress, $"{nameof(DeleteCategoryProcessStartedEvent)} published", correlationId); return(new AcceptedWithCorrelationIdHeaderResult(correlationId)); }
public async Task Run( [ActivityTrigger] IDurableActivityContext context) { _correlationInitializer.Initialize(context.InstanceId); var status = context.GetInput <string>(); var applicationFailedEvent = new CreatingApplicationFailedEvent(context.InstanceId, status, context.InstanceId); await _eventStore.AppendEvent(context.InstanceId, applicationFailedEvent); await _eventPublisher.PublishEvent(applicationFailedEvent); }
public async Task SaveAsync(TAggregate aggregate) { foreach (var evnt in aggregate.GetUncommittedEvents()) { await eventStore.AppendEvent(evnt); await domainEventPublisher.Publish((dynamic)evnt); } aggregate.ClearUncommittedEvents(); }
public async Task Handle(CreateApplicationProcessStartedEvent createApplicationProcessStartedEvent) { _logger.LogProgress(OperationStatus.InProgress, "Indexing started", createApplicationProcessStartedEvent.CorrelationId); var applicationDto = _mapper.Map <CreateApplicationProcessStartedEvent, ApplicationDto>(createApplicationProcessStartedEvent); await _searchableApplicationIndexer.Index(applicationDto); var applicationCreatedEvent = new ApplicationCreatedEvent(createApplicationProcessStartedEvent); await _eventStore.AppendEvent(applicationCreatedEvent.Id, applicationCreatedEvent); await _eventPublisher.PublishEvent(applicationCreatedEvent); _logger.LogProgress(OperationStatus.Finished, string.Empty, createApplicationProcessStartedEvent.CorrelationId); }
public async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, HttpMethods.Put, Route = "category/{id:guid}")] UpdateCategoryHttpRequest updateCategoryRequest, string id, [NotificationSubscriber] string subscriber, ILogger log) { var correlationId = _guidProvider.GenerateGuid(); _correlationInitializer.Initialize(correlationId); var validationResult = await _updateCommandValidator.ValidateAsync(new UpdateCategoryCommand(id, updateCategoryRequest)); log.LogProgress(OperationStatus.Started, "Updating category process started", correlationId); if (!validationResult.IsValid) { log.LogProgress(OperationStatus.Failed, "Validation failed", correlationId); return(new BadRequestObjectResult(validationResult.Errors)); } await _subscriber.Register(correlationId, subscriber); var categoryChangedEvent = new UpdateCategoryProcessStartedEvent( id, updateCategoryRequest.Name, updateCategoryRequest.Description, updateCategoryRequest.SortOrder, correlationId); var saveEventResult = await _eventStore.AppendEvent(id, categoryChangedEvent); if (!saveEventResult.Success) { log.LogFailedOperation(OperationStatus.Failed, "Creating category process failed", saveEventResult.Errors, correlationId); return(new BadRequestResult()); } log.LogProgress(OperationStatus.InProgress, "Request accepted to further processing.", correlationId); await _eventPublisher.PublishEvent(categoryChangedEvent); log.LogProgress(OperationStatus.InProgress, $"{nameof(UpdateCategoryProcessStartedEvent)} published", correlationId); return(new AcceptedWithCorrelationIdHeaderResult(correlationId)); }
private async Task HandleSingleApplication( CategoryNameChangedEvent categoryNameChangedEvent, ApplicationDto applicationToChange) { var applicationCategoryNameChangedEvent = new ApplicationCategoryNameChangedEvent( applicationToChange.Id, categoryNameChangedEvent.NewName, categoryNameChangedEvent.CorrelationId); var saveEventResult = await _eventStore.AppendEvent(applicationToChange.Id, applicationCategoryNameChangedEvent); if (saveEventResult.Success) { await _eventPublisher.PublishEvent(applicationCategoryNameChangedEvent); } _logger.LogErrors( $"{nameof(CategoryNameChangedEvent)} for category {categoryNameChangedEvent.NewName} failed for:", saveEventResult.Errors); }
public async Task Run( [DurableClient] IDurableOrchestrationClient client, [ActivityTrigger] IDurableActivityContext context, ILogger log) { _correlationInitializer.Initialize(context.InstanceId); var command = context.GetInput <CreateApplicationCommand>(); var applicationCreatedEvent = _mapper.Map <CreateApplicationCommand, CreateApplicationProcessStartedEvent>(command); var result = await _eventStore.AppendEvent(applicationCreatedEvent.Id, applicationCreatedEvent); if (!result.Success) { var applicationSaveFailedEvent = new ApplicationSaveFailedInternalFunctionEvent(result.Errors); await client.RaiseEventAsync(context.InstanceId, nameof(ApplicationSaveFailedInternalFunctionEvent), applicationSaveFailedEvent); } log.LogProgress(OperationStatus.InProgress, "Application accepted", context.InstanceId); await _eventPublisher.PublishEvent(applicationCreatedEvent); var applicationSavedEvent = new ApplicationSavedInternalFunctionEvent(); await client.RaiseEventAsync(context.InstanceId, nameof(ApplicationSavedInternalFunctionEvent), applicationSavedEvent); }
protected async Task SaveAndDispatchEvent(string id, IEvent @event) { await _eventStore.AppendEvent(id, @event); await _eventPublisher.PublishEvent(@event); }