示例#1
0
        /// <summary>
        /// Set error in result
        /// </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)
        {
            UploadIntegrationImportCommandResult commandResult;

            try
            {
                commandResult = await _handler
                                .Handle(command, cancellationToken)
                                .ConfigureAwait(Await.Default);
            }
#pragma warning disable CA1031 // Do not catch general exception types
            catch (Exception ex)
#pragma warning restore CA1031 // Do not catch general exception types
            {
                commandResult = new UploadIntegrationImportCommandResult
                {
                    Success   = false,
                    Message   = "Error executing integration import",
                    Exception = ex,
                };
            }

            return(commandResult);
        }
        /// <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>
        /// Start an integration import upload
        /// </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));

            UploadIntegrationImportCommandResult commandResult;

            var integrationImport = command.Item;

            Require.NotNull(integrationImport, nameof(integrationImport));

            var fileInfo = _fileInfoFactory.FromFileName(integrationImport.File);

            var remoteImportId = integrationImport.FileVersionId;

            var request = new StartIntegrationImportV1Request
            {
                IntegrationId = integrationImport.IntegrationId,
                FileName      = fileInfo.Name,
                FileDate      = integrationImport.FileDate,
                FileSize      = fileInfo.Length,
                FileVersionId = remoteImportId
            };

            var response = await _client
                           .Execute(request, cancellationToken)
                           .ConfigureAwait(Await.Default);

            if (response.IsSuccessful)
            {
                command.IntegrationImportId = response.Model.IntegrationImportId;

                commandResult = await _handler
                                .Handle(command, cancellationToken)
                                .ConfigureAwait(Await.Default);
            }
            else
            {
                commandResult = new UploadIntegrationImportCommandResult
                {
                    Success = false,
                    Message = "Error starting integration import",
                };
            }

            return(commandResult);
        }