public Task HandleAsync(ItemDownloaded broadcasted)
        {
            logger.LogInformation("[HandleAsync] handling DownloadItemDownloaded event for: " + broadcasted.DownloadItemId);
            var item = repository.Find(broadcasted.DownloadItemId);

            // mark item as processing
            item = repository.Find(item.Id);
            item.DownloadedAt = DateTime.Now;
            item.State        = DownloadState.Processing;
            repository.Update(item);

            logger.LogInformation($"[Processing] [{item.Name}]");
            var movedFiles = new List <MediaItem>();

            try
            {
                movedFiles = mediaLibraryMover.ProcessDownloadItem(item);
            }
            catch (System.Exception e)
            {
                logger.LogError("ProcessDownloadItem Failed to process download items");
                logger.LogError(e.Message);
            }

            // mark item as completed
            item             = repository.Find(item.Id);
            item.MovedFiles  = movedFiles;
            item.CompletedAt = DateTime.Now;
            item.State       = DownloadState.Completed;
            repository.Update(item);
            return(Task.CompletedTask);
        }
Exemplo n.º 2
0
        public ObjectResult Get([Required] string token)
        {
            var item = repository.Find(token);

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

            service.ComputeDownloadProgress(item);
            return(Ok(item));
        }
Exemplo n.º 3
0
        public Task HandleAsync(ItemDownloaded broadcasted)
        {
            logger.LogInformation("SendItemCompletedEmail START");
            var item = downloadItemRepository.Find(broadcasted.DownloadItemId);

            if (tvShowSubscriptionRepository.IsSubscriptionDownload(item, out var subscribedUsersEmails))
            {
                logger.LogInformation("Item was downloaded by a subscription");
                logger.LogInformation($"Sending email to [{string.Join(",", subscribedUsersEmails)}]");
                NotifySubscribedUsers(item, subscribedUsersEmails);
            }
            else
            {
                logger.LogInformation($"Item was manually downloaded by {item.Owner.Email}");
                NotifyOwner(item);
            }
            logger.LogInformation("SendItemCompletedEmail END");
            return(Task.CompletedTask);
        }