public async Task <bool> Add(ImportCommand importCommand, Stream attachment) { var accountId = importCommand.AccountId; await EnsureRefLogStructureIsClean(accountId); var importCommands = await GetAll(accountId); if (importCommands.Any(i => i.Id == importCommand.Id)) { return(false); } importCommands.Add(importCommand); await PersistReflog(accountId, importCommands); string attachmentsPath = GetCommandAttachmentFilePath(importCommand); using (var sTarget = Fs.FileCreate(attachmentsPath)) { await attachment.CopyToAsync(sTarget); } return(true); }
public async Task<bool> RequestImportExecution(ImportCommand importCommand, Stream sourceData) { bool result = false; try { if (!sourceData.CanSeek) { var seekableStream = new MemoryStream(); await sourceData.CopyToAsync(seekableStream); sourceData = seekableStream; sourceData.Seek(0, SeekOrigin.Begin); } await _accountCommandRepository.Add(importCommand, sourceData); sourceData.Seek(0, SeekOrigin.Begin); var executionImportResult = await _operationsManager.ExecuteImport(importCommand, sourceData); result = await _accountCommandRepository.AddExecutionImpact(importCommand.AccountId, executionImportResult); } catch (Exception exn) { _logger.Error("import failed", exn); } if (result) { await GetCacheEntry(importCommand.AccountId).DeleteAsync(); } return result; }
public async Task <Stream> OpenAttachment(ImportCommand importCommand) { string attachmentsPath = GetCommandAttachmentFilePath(importCommand); await EnsureRefLogStructureIsClean(importCommand.AccountId); return(Fs.FileOpenRead(attachmentsPath)); }
public async Task <bool> Replace(ImportCommand importCommand) { var accountId = importCommand.AccountId; await EnsureRefLogStructureIsClean(accountId); var importCommands = await GetAll(accountId); var position = importCommands.FindIndex(i => i.Id == importCommand.Id); if (position < 0) { return(false); } importCommands.RemoveAt(position); importCommands.Insert(position, importCommand); await PersistReflog(accountId, importCommands); return(true); }
private string GetCommandAttachmentFilePath(ImportCommand command) { return(GetCommandAttachmentFilePath(command.AccountId, command.Id)); }