Exemple #1
0
        /// <summary>
        /// Add a Downloader to Downloaders.
        /// </summary>
        /// <param name="downloader">The Downloader which is going to be added</param>
        /// <param name="handler">Handler for DownloadSucceeded event</param>
        /// <returns></returns>
        public static bool AddDownloader(Downloader downloader, DownloadCompletedEventHandler handler)
        {
            DownloadersMutex.WaitOne();
            // Clean up finished downloader
            int removedCount = Downloaders.RemoveAll(p => p.IsFinished);

            // Add downloader
            foreach (Downloader d in Downloaders)
            {
                if (d.To == downloader.To)
                {
                    d.DownloadSucceeded += handler;
                    DownloadersMutex.ReleaseMutex();
                    return(false);
                }
            }
            downloader.DownloadCompleted += new DownloadCompletedEventHandler(() =>
            {
                RemoveDownloader(downloader);
            });
            downloader.DownloadSucceeded += handler;
            // Add to downloaders
            Downloaders.Add(downloader);
            DownloadersMutex.ReleaseMutex();
            // Start downloading if no limit
            if (MaxDownload == 0)
            {
                downloader.DownloadAsync();
            }
            // Check downloaders
            CheckDownloaders();
            return(true);
        }
Exemple #2
0
 public abstract void Download(
     string id,
     string filePath,
     Uri url,
     IEnumerable <KeyValuePair <string, string> > cookies,
     bool disableTracking,
     DownloadChangedEventHandler downloadChanged     = null,
     DownloadCompletedEventHandler downloadCompleted = null);
Exemple #3
0
 public DownloadItem(string downloaderName, string file, Uri url, IEnumerable <KeyValuePair <string, string> > cookies,
                     DownloadChangedEventHandler downloadChanged     = null,
                     DownloadCompletedEventHandler downloadCompleted = null)
 {
     DownloaderName    = downloaderName;
     File              = file;
     Url               = url;
     Cookies           = cookies;
     DownloadChanged   = downloadChanged;
     DownloadCompleted = downloadCompleted;
     DownloadStatus    = new DownloadInfo(file, url);
 }
Exemple #4
0
        protected virtual void OnDownloadCompleted(DownloadInfo dif)
        {
            DownloadCompletedEventHandler handler = DownloadCompleted;

            lock (syncRoot)
            {
                UpdateProgress();
            }

            OnStatusUpdated();

            if (handler != null)
            {
                handler(this, new DownloadCompletedEventArgs(dif, new Uri(dif.LocalPath)));
            }
        }
 public CurlDownloadInfo(
     string id,
     string outputFile,
     Uri url,
     IEnumerable <KeyValuePair <string, string> > cookies = null,
     bool disableTracking = false,
     DownloadChangedEventHandler downloadChanged     = null,
     DownloadCompletedEventHandler downloadCompleted = null)
 {
     Id                = id;
     OutputFile        = outputFile;
     Url               = url;
     Cookies           = cookies;
     DisableTracking   = disableTracking;
     DownloadChanged   = downloadChanged;
     DownloadCompleted = downloadCompleted;
 }
Exemple #6
0
        public override void Download(
            string id,
            string filePath,
            Uri url,
            IEnumerable <KeyValuePair <string, string> > cookies,
            bool disableTracking,
            DownloadChangedEventHandler downloadChanged     = null,
            DownloadCompletedEventHandler downloadCompleted = null)
        {
            var outputFilePath = filePath.ToSafePath();

            var downloadInfo = new CurlDownloadInfo(id, outputFilePath, url, cookies, disableTracking, downloadChanged, downloadCompleted);

            PrepareOutputDirectory(outputFilePath);

            Sys.RunProcess(
                _curlBin,
                downloadInfo.GetCommadArguments(),
                true,
                (data) => HandleDownloadFeedback(data, downloadInfo),
                HandleDownloadError,
                (exitCode) => HandleDownloadCompleted(exitCode, downloadInfo));
        }
 private void onDownloadCompleted(object sender, EventArgs e)
 {
     DownloadCompletedEventHandler?.Invoke(sender, e);
 }