Пример #1
0
        public async Task ExecuteAsync(DownloadMonitorCommand.Parameters parameters)
        {
            await this.ensureAuthenticated.ExecuteAsync();

            var inputFolder  = this.getCreatedOutputFolder.Execute(parameters.InputFolder);
            var outputFolder = this.getCreatedOutputFolder.Execute(parameters.OutputFolder);

            using var cts = CommandUtilities.CreateCommandCancellationTokenSource();

            var channel = Channel.CreateUnbounded <QueuedDownloadToken>();

            try
            {
                var monitorDownloadsTask = this.monitorDownloads.ExecuteAsync(
                    channel.Writer,
                    inputFolder,
                    cts.Token);

                await this.processDownloads.ExecuteAsync(
                    channel.Reader,
                    targetFolder : outputFolder,
                    generateCsv : parameters.GenerateCsv,
                    keepBinary : parameters.KeepBinary,
                    postProcessorPath : parameters.PostProcessor,
                    postProcessorArguments : parameters.PostProcessorArguments,
                    cancellationToken : cts.Token);

                await monitorDownloadsTask;
            }
            catch (Exception t) when(ExceptionUtilities.IsFromCancellation(t))
            {
                // Download monitoring was cancelled.
            }
        }
Пример #2
0
        public async Task ExecuteAsync(GetStudyCommand.Parameters parameters, CancellationToken cancellationToken)
        {
            try
            {
                var authenticatedUser = await this.ensureAuthenticated.ExecuteAsync();

                var outputFolder = this.getCreatedOutputFolder.Execute(parameters.OutputFolder);

                var tenantId = string.IsNullOrWhiteSpace(parameters.TenantId) ? authenticatedUser.TenantId : parameters.TenantId;
                var studyId  = parameters.StudyId;
                var jobIndex = parameters.JobIndex;

                await this.downloadStudy.ExecuteAsync(outputFolder, tenantId, studyId, jobIndex, cancellationToken);

                var generateCsvFiles = parameters.GenerateCsv;

                if (generateCsvFiles && !cancellationToken.IsCancellationRequested)
                {
                    var deleteProcessedFiles = !parameters.KeepBinary;
                    await this.processLocalStudyResults.ExecuteAsync(outputFolder, deleteProcessedFiles, cancellationToken);
                }
            }
            catch (Exception t) when(ExceptionUtilities.IsFromCancellation(t))
            {
                // Just return if the task was cancelled.
            }
        }
Пример #3
0
        public RetryPolicies(ILogger <RetryPolicies> logger)
        {
            this.logger = logger;

            this.FilePolicy = Policy
                              .Handle <IOException>()
                              .WaitAndRetryAsync(
                new[]
            {
                TimeSpan.FromSeconds(1),
                TimeSpan.FromSeconds(2),
                TimeSpan.FromSeconds(3)
            },
                (exception, timeSpan, context) =>
            {
                this.logger.LogInformation("Retrying file IO operation.");
            });

            this.DownloadPolicy = Policy
                                  .Handle <Exception>(v => !ExceptionUtilities.IsFromCancellation(v))
                                  .WaitAndRetryAsync(
                3,
                retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)),
                (exception, timeSpan, context) =>
            {
                this.logger.LogWarning(exception, "Retrying download.");
            });
        }
Пример #4
0
 public async Task <TransferStatus?> ExecuteAsync(
     CloudBlobDirectory blobDirectory,
     string outputDirectoryPath,
     DownloadDirectoryOptions options,
     DirectoryTransferContext context,
     CancellationToken cancellationToken)
 {
     try
     {
         return(await TransferManager.DownloadDirectoryAsync(
                    blobDirectory,
                    outputDirectoryPath,
                    options,
                    context,
                    cancellationToken));
     }
     catch (Exception t) when(ExceptionUtilities.IsFromCancellation(t))
     {
         return(null);
     }
 }