Exemplo n.º 1
0
 public void StopDownloads(IEnumerable <Guid> downloadItemIds)
 {
     lock (downloadQueueLock)
     {
         foreach (Guid downloadItemId in downloadItemIds)
         {
             DownloadItem downloadItem = downloadQueue.FirstOrDefault(item => item.Id == downloadItemId);
             if (downloadItem == null)
             {
                 Logger.Debug($"Download item with ID = {downloadItemId} not found.");
                 return;
             }
             Logger.Debug($"Stop download requested for download ID = {downloadItemId}.");
             if (downloadItem.Status == DownloadItemStatus.QUEUED || downloadItem.Status == DownloadItemStatus.DOWNLOADING ||
                 downloadItem.Status == DownloadItemStatus.RETRY_DELAY)
             {
                 downloadItem.CancelDownload();
                 ReportStatusChange(downloadItem, DownloadItemStatus.STOPPED, DownloadItemLogLineType.INFORMATIONAL, localization.LogLineStopped);
             }
             else
             {
                 Logger.Debug($"Incorrect download item status = {downloadItem.Status} to stop it.");
             }
         }
         SaveDownloadQueue();
     }
 }
Exemplo n.º 2
0
 public void RemoveDownloads(IEnumerable <Guid> downloadItemIds)
 {
     lock (downloadQueueLock)
     {
         foreach (Guid downloadItemId in downloadItemIds)
         {
             DownloadItem downloadItem = downloadQueue.FirstOrDefault(item => item.Id == downloadItemId);
             if (downloadItem == null)
             {
                 Logger.Debug($"Download item with ID = {downloadItemId} not found.");
                 return;
             }
             Logger.Debug($"Remove download requested for download ID = {downloadItemId}.");
             downloadItem.CancelDownload();
             downloadQueue.Remove(downloadItem);
             downloadItem.Status = DownloadItemStatus.REMOVED;
             eventQueue.Add(new DownloadItemRemovedEventArgs(downloadItem));
             if (downloadItem.FileCreated && !downloadItem.FileHandleOpened)
             {
                 string filePath = Path.Combine(downloadItem.DownloadDirectory, downloadItem.FileName);
                 if (downloadItem.Status != DownloadItemStatus.COMPLETED)
                 {
                     filePath += ".part";
                 }
                 try
                 {
                     File.Delete(filePath);
                 }
                 catch (Exception exception)
                 {
                     Logger.Exception(exception);
                 }
             }
         }
         SaveDownloadQueue();
     }
 }