public async Task <CommandHandlingResult> Handle(ExportClientHistoryCommand command, IEventPublisher publisher) { var result = new List <BaseHistoryModel>(); for (var i = 0; ; i++) { var response = await _historyClient.HistoryApi.GetHistoryByWalletAsync(Guid.Parse(command.ClientId), command.OperationTypes, command.AssetId, command.AssetPairId, i *PageSize, PageSize); if (!response.Any()) { break; } result.AddRange(response); } var history = result.Select(x => x.ToHistoryModel()).OrderByDescending(x => x.DateTime); var idForUri = await _fileMapper.MapAsync(command.ClientId, command.Id); var file = await _fileMaker.MakeAsync(history); var uri = await _fileUploader.UploadAsync(idForUri, FileType.Csv, file); await _expiryWatcher.AddAsync( new ExpiryEntry { ClientId = command.ClientId, RequestId = command.Id, ExpiryDateTime = DateTime.UtcNow + _ttl }); publisher.PublishEvent(new ClientHistoryExportedEvent { Id = command.Id, ClientId = command.ClientId, Uri = uri }); return(CommandHandlingResult.Ok()); }
public async Task Handle(ClientHistoryExpiredEvent evt) { var id = await _fileMapper.MapAsync(evt.ClientId, evt.Id); await _fileUploader.RemoveAsync(id, FileType.Csv); }