Example #1
0
        public Task Invoke()
        {
            logger.LogInformation("[ArchiveDownloadItemsJob] Start");
            var toArchive = repository.GetPassedItemsToArchive(ArchiveThresholdDays);

            logger.LogInformation($"[ArchiveDownloadItemsJob] {toArchive.Count} items to archive");
            toArchive.ForEach(item =>
            {
                service.ArchiveDownload(item);
                logger.LogInformation($"[ArchiveDownloadItemsJob] Archived {item.Token}");
            });

            logger.LogInformation($"[ArchiveDownloadItemsJob] Done");
            return(Task.CompletedTask);
        }
Example #2
0
        public ObjectResult Archive([FromBody] string token)
        {
            var downloadItem = repository.Find(token);

            if (downloadItem == null)
            {
                return(StatusCode(404, DownloadItemActionError.ItemNotFound));
            }

            var authorizationResult = authorizationService.AuthorizeAsync(User, downloadItem, DownloadItemPolicies.ArchivePolicy).Result;

            if (!authorizationResult.Succeeded)
            {
                var requirement = authorizationResult.Failure.FailedRequirements.First() as DownloadItemBaseRequirement;
                logger.LogWarning(requirement.Error.ToString());
                return(StatusCode(requirement.HttpCode, requirement.Error));
            }

            service.ArchiveDownload(downloadItem);

            return(StatusCode(200, null));
        }