Пример #1
0
    public void Download(string[] urls, string destinationFolder, ManualResetEvent cancelEvent)
    {
      this.cancelEvent = cancelEvent;
      this.downloadCount = 0;
      this.totalDownloads = urls.Length;

      foreach (string url in urls)
      {
        // break out if a cancellation has occurred
        if (HasUserCancelled())
          break;

        // create the destination path using the destination folder and the url
        string fileName = Path.GetFileName(url);
        string destPath = Path.Combine(destinationFolder, Path.GetFileName(url));

        // send the new filename back to the owner class
        if (FileChanged != null)
          FileChanged(this, new DownloadEventArgs(fileName));

        // download the file
        using (var dL = new FileDownloader())
        {
          dL.StateChanged += dL_StateChanged;
          dL.ProgressChanged += dL_ProgressChanged;
          dL.Download(url, destPath, this.cancelEvent);
        }

        this.downloadCount++;
      }

      // send a 100% complete message if the user hasn't cancelled
      if (!HasUserCancelled())
        dL_ProgressChanged(this, new DownloadEventArgs(100));
    }
Пример #2
0
        private void SingleDownload(object data)
        {
            //this.Invoke(this.activeStateChanger, new object[]{true, true});

            try
            {
                DownloadInstructions instructions = (DownloadInstructions) data;
                //GetFileSize(url, out progressKnown);
                //this.Invoke(this.fileNameChanger, new object[]{Path.GetFileName(instructions.Destination)});

                using(FileDownloader dL = new FileDownloader())
                {

                    dL.ProgressChanged += new DownloadProgressHandler(this.SingleProgressChanged);
                    dL.StateChanged += new DownloadProgressHandler(this.StateChanged);
                    dL.Download(instructions.URLs, instructions.Destination, this.cancelEvent);

                }

            }
            catch(Exception exp)
            {
                WebMeeting.Client.ClientUI.getInstance().ShowExceptionMessage("Managecontents==>frmDownloader.cs 354",exp,null,false);

            }

            //this.Invoke(this.activeStateChanger, new object[]{false, true});
        }