public async Task HandleAsync(AddResource command) { if (await _repository.ExistsAsync(command.ResourceId)) { throw new ResourceAlreadyExistsException(command.ResourceId); } var resource = Resource.Create(command.ResourceId, command.Tags); await _repository.AddAsync(resource); await _eventProcessor.ProcessAsync(resource.Events); }
public async Task HandleAsync(AddResource command) { if (await _repository.ExistsAsync(command.ResourceId)) { throw new ResourceAlreadyExistsException(command.ResourceId); } var resource = Resource.Create(command.ResourceId); await _repository.AddAsync(resource); var events = _eventMapper.MapAll(resource.Events); await _messageBroker.PublishAsync(events.ToArray()); }
private async Task LoadAsync(Uri discoveryUrl, TimeSpan delay, CancellationToken cancellationToken) { while (!cancellationToken.IsCancellationRequested) { try { var endpoints = await fHttpService.DiscoveryAsync(discoveryUrl, cancellationToken); Console.WriteLine($"Discovered '${discoveryUrl}', found endpoints: '{string.Join(',', endpoints)}'"); foreach (var endpoint in endpoints) { await fResourcesRepository.AddAsync(new Uri(endpoint).AbsoluteUri, cancellationToken); } } catch (Exception ex) { Console.WriteLine($"Error while discovering endpoint '${discoveryUrl}'."); Console.WriteLine(ex); } await Task.Delay(delay, cancellationToken); } }