/// <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 <DownloadIntegrationExportCommandResult> Handle(
            DownloadIntegrationExportCommand command,
            CancellationToken cancellationToken)
        {
            DownloadIntegrationExportCommandResult 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 DownloadIntegrationExportCommandResult
                {
                    Success   = false,
                    Message   = "Error executing integration export",
                    Exception = ex,
                };
            }

            return(commandResult);
        }
Esempio n. 2
0
        private async Task <DownloadIntegrationExportCommandResult> Reject(
            DownloadIntegrationExportCommand command,
            CancellationToken cancellationToken)
        {
            var request = new RejectIntegrationExportV1Request
            {
                IntegrationExportId = command.IntegrationExportId,
                Message             = "Not configured for this integration",
            };

            _ = await _apiClient
                .Execute(request, cancellationToken)
                .ThrowIfFailed()
                .ConfigureAwait(Await.Default);

            var commandResult = new DownloadIntegrationExportCommandResult
            {
                Success   = false,
                Message   = request.Message,
                Exception = null,
            };

            return(commandResult);
        }
        /// <summary>
        /// Handle command
        /// </summary>
        /// <param name="command">The command</param>
        /// <param name="cancellationToken">The cancellation token</param>
        /// <returns>The response</returns>
        public async Task <DownloadIntegrationExportCommandResult> Handle(
            DownloadIntegrationExportCommand command,
            CancellationToken cancellationToken)
        {
            Argument.NotNull(command, nameof(command));

            DownloadIntegrationExportCommandResult commandResult;

            var request = new AcceptIntegrationExportV1Request
            {
                IntegrationExportId = command.IntegrationExportId,
            };

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

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

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

            return(commandResult);
        }
        /// <summary>
        /// Handles downloading the integration export
        /// </summary>
        /// <param name="command">The command</param>
        /// <param name="cancellationToken">The cancellation token</param>
        /// <returns>The response</returns>
        public async Task <DownloadIntegrationExportCommandResult> Handle(
            DownloadIntegrationExportCommand command,
            CancellationToken cancellationToken)
        {
            Argument.NotNull(command, nameof(command));

            var commandResult = new DownloadIntegrationExportCommandResult();

            var configuration = command.Configuration;

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

            var request = new DownloadIntegrationExportV1Request
            {
                IntegrationExportId = command.IntegrationExportId,
            };

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

            if (response.IsSuccessful)
            {
                using (var model = response.Model)
                {
                    var saveCommand = new SaveIntegrationExportFileCommand
                    {
                        IntegrationExportId = command.IntegrationExportId,
                        File              = model.File,
                        FileName          = model.FileName,
                        FileSize          = model.Size,
                        DestinationFolder = configuration.Folder,
                        BackupFolder      = configuration.BackupFolder,
                        Overwrite         = configuration.Overwrite,
                    };

                    var saveCommandResult = await _handler
                                            .Handle(saveCommand, cancellationToken)
                                            .ConfigureAwait(Await.Default);

                    switch (saveCommandResult.Result)
                    {
                    case SaveIntegrationExportFileCommandResultKind.Success:
                        commandResult.Success = true;   // TODO: ??
                        commandResult.Message = "";     // TODO: add backup file name and size
                        break;

                    case SaveIntegrationExportFileCommandResultKind.Failed:
                        commandResult.Success = false;
                        commandResult.Message = "";     // TODO:
                        break;

                    default:
                        throw UnexpectedEnumValueException.Create(saveCommandResult.Result);
                    }
                }
            }
            else
            {
                commandResult.Success = false;
                commandResult.Message = "Error downloading integration export";
            }

            return(commandResult);
        }