/// <summary>
        /// Execute example
        /// </summary>
        /// <param name="cancellationToken">The cancellation token</param>
        /// <returns>The task</returns>
        public async Task Execute(CancellationToken cancellationToken)
        {
            var request = new ListIntegrationExportQueuedForMeV1Request
            {
                PageNumber = 1,
                PageSize   = 10,
            };

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

            Require.NotNull(response, nameof(response));
        }
Beispiel #2
0
        /// <summary>
        /// Execute download integration export hangfire job
        /// </summary>
        /// <param name="cancellationToken">The cancellation token</param>
        /// <returns>The response</returns>
        public async Task Execute(CancellationToken cancellationToken)
        {
            int totalCount  = PageSize;
            int loopCounter = 0;

            var exceptions = new List <Exception>(4);

            var configuration = _configuration.Value;

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

            if (configuration.Enabled != true)
            {
                return;
            }

            while (totalCount > 0)
            {
                if (exceptions.Count >= MaxExceptionCount)
                {
                    break;
                }

                loopCounter++;

                if (loopCounter > MaxLoops)
                {
                    //break;
                    throw new InvalidOperationException("Maximum number of iteration in while loop reached.");
                }

                cancellationToken.ThrowIfCancellationRequested();

                var request = new ListIntegrationExportQueuedForMeV1Request
                {
                    PageNumber = 1,
                    PageSize   = PageSize,
                };

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

                if (response.Headers.TotalCount.HasValue)
                {
                    totalCount = response.Headers.TotalCount.Value - PageSize;
                }
                else
                {
                    break;
                }

                foreach (var export in response.Model.Exports)
                {
                    try
                    {
                        var command = new DownloadIntegrationExportCommand
                        {
                            IntegrationExportId = export.IntegrationExportId,
                            IntegrationId       = export.IntegrationId,
                            FileName            = export.FileName,

                            // Injected by decorator
                            IntegrationExportLogId = null,

                            Configuration = null,

                            Accept = null,
                        };

                        var commandResult = await _commandHandler
                                            .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
                    {
                        exceptions.Add(ex);
                    }

                    if (exceptions.Count >= MaxExceptionCount)
                    {
                        break;
                    }
                }
            }

            if (exceptions.Count > 0)
            {
                throw new AggregateException(ExceptionResource.AggregateJobException, exceptions);
            }
        }