示例#1
0
        private void addBtn_Click(object sender, EventArgs e)
        {
            string uriName = urlInput.Text;
            Uri    uriResult;
            bool   result = Uri.TryCreate(uriName, UriKind.Absolute, out uriResult) && uriResult.Scheme == Uri.UriSchemeHttp;

            if (result)
            {
                if (!Directory.Exists(downloadDirectory))
                {
                    Directory.CreateDirectory(downloadDirectory);
                }
                string outfileName = GetAvailableOutputName(downloadDirectory + Path.DirectorySeparatorChar + Path.GetFileName(uriResult.LocalPath));
                Console.WriteLine("outfile " + outfileName);

                DownloadTask downloadTask = new DownloadTask(uriName, outfileName);
                downloadTasks.Add(downloadTask);


                DownloadListItem downloadListItem = new DownloadListItem(downloadTask);
                downloadListItem.Text = Path.GetFileName(outfileName);
                downloadListItem.DownloadItemRemoved += downloadListItem_DownloadItemRemoved;
                flowLayoutPanel1.Controls.Add(downloadListItem);
                downloadTask.StartDownload();
            }
            else
            {
                MessageBox.Show("Invalid Url");
            }
            urlInput.Text = "";
        }
示例#2
0
        private void addBtn_Click(object sender, EventArgs e)
        {
            string uriName = urlInput.Text;
            Uri uriResult;
            bool result = Uri.TryCreate(uriName, UriKind.Absolute, out uriResult) && uriResult.Scheme == Uri.UriSchemeHttp;
            if (result)
            {
                if(!Directory.Exists(downloadDirectory))
                {
                    Directory.CreateDirectory(downloadDirectory);
                }
                string outfileName = GetAvailableOutputName(downloadDirectory + Path.DirectorySeparatorChar + Path.GetFileName(uriResult.LocalPath));
                Console.WriteLine("outfile " + outfileName);

                DownloadTask downloadTask = new DownloadTask(uriName, outfileName);
                downloadTasks.Add(downloadTask);

                DownloadListItem downloadListItem = new DownloadListItem(downloadTask);
                downloadListItem.Text = Path.GetFileName(outfileName);
                downloadListItem.DownloadItemRemoved += downloadListItem_DownloadItemRemoved;
                flowLayoutPanel1.Controls.Add(downloadListItem);
                downloadTask.StartDownload();
            }
            else
            {
                MessageBox.Show("Invalid Url");
            }
            urlInput.Text = "";
        }
示例#3
0
 private void DownloadProgressChanged(object sender, DownloadEventArgs e)
 {
     if (sender is DownloadTask)
     {
         DownloadTask     currentDownloadTask = sender as DownloadTask;
         int              index            = downloadTasks.FindIndex(downloadTask => downloadTask.Url.Equals(currentDownloadTask.OutFilename, StringComparison.Ordinal));
         DownloadListItem downloadListItem = flowLayoutPanel1.Controls[index] as DownloadListItem;
         downloadListItem.SetProgress(e.Progress);
     }
 }
示例#4
0
 private void DownloadStatusChanged(object sender, DownloadEventArgs e)
 {
     if (sender is DownloadTask)
     {
         DownloadTask     currentDownloadTask = sender as DownloadTask;
         int              index            = downloadTasks.FindIndex(downloadTask => downloadTask.Url.Equals(currentDownloadTask.OutFilename, StringComparison.Ordinal));
         DownloadListItem downloadListItem = flowLayoutPanel1.Controls[index] as DownloadListItem;
         if (e.Status == DownloadStatus.Completed)
         {
             downloadListItem.Done();
         }
     }
 }