/// <summary> /// Handles uploading the integration import /// </summary> /// <param name="command">The command</param> /// <param name="cancellationToken">The cancellation token</param> /// <returns>The response</returns> public async Task <UploadIntegrationImportCommandResult> Handle( UploadIntegrationImportCommand command, CancellationToken cancellationToken) { Argument.NotNull(command, nameof(command)); var commandResult = new UploadIntegrationImportCommandResult(); var integrationImport = command.Item; Require.NotNull(integrationImport, nameof(integrationImport)); var query = new CreateStreamFromPathQuery { Path = integrationImport.File }; using (var queryResult = await _queryHandler .Handle(query, cancellationToken) .ConfigureAwait(Await.Default)) { var uploadRequest = new UploadIntegrationImportV1Request { IntegrationImportId = command.IntegrationImportId, File = queryResult.File, FileName = integrationImport.FileName, Size = queryResult.Size, }; var response = await _client .Execute(uploadRequest, cancellationToken) .ConfigureAwait(Await.Default); if (response.IsSuccessful) { commandResult.Success = true; commandResult.Message = ""; uploadRequest.Dispose(); } else { commandResult.Success = false; commandResult.Message = "Error uploading integration import"; uploadRequest.Dispose(); } } return(commandResult); }
/// <summary> /// Handles creating the create stream from path query and uploading the datasource file /// </summary> /// <param name="command">The command</param> /// <param name="cancellationToken">The cancellation token</param> /// <returns>The response</returns> public async Task <UploadDataSourceFileCommandResult> Handle( UploadDataSourceFileCommand command, CancellationToken cancellationToken) { Argument.NotNull(command, nameof(command)); var commandResult = new UploadDataSourceFileCommandResult(); var query = new CreateStreamFromPathQuery { Path = command.Path }; using (var queryResult = await _queryHandler .Handle(query, cancellationToken) .ConfigureAwait(Await.Default)) { var uploadCommand = new DataSourceFileUploadCommand { DataSourceId = command.DataSourceId, File = queryResult.File, FileName = queryResult.FileName, Path = queryResult.Path, Size = queryResult.Size, CreationTimeUtc = queryResult.CreationTimeUtc, LastWriteTimeUtc = queryResult.LastWriteTimeUtc, }; _ = await _uploader .Upload(uploadCommand, cancellationToken) .ConfigureAwait(Await.Default); } commandResult.Result = UploadDataSourceFileCommandResultKind.Success; return(commandResult); }