Esempio n. 1
0
        private void Begin()
        {
            _webClient.DownloadFileCompleted += DownloadCompleted;

            if (!ValidateUri(DownloadUri))
            {
                throw new DownloadException("The specified url cannot be found");
            }

            if (!String.IsNullOrEmpty(SaveFileAs))
            {
                ValidateSaveAs(SaveFileAs);
            }

            if (!Headless)
            {
                Show();
                TopMost = true;
            }

            Text             = String.Format("0% of {0} Completed", Path.GetFileName(DownloadUri.ToString()));
            lblProgress.Text = "";
            lblFileName.Text = String.Format("{0} from {1}", Path.GetFileName(DownloadUri.ToString()), PathName);
            _webClient.DownloadProgressChanged += DownloadProgressChanged;
            _webClient.DownloadFileCompleted   -= DownloadComplete;
            _webClient.DownloadFileCompleted   += DownloadComplete;
            progressBar1.Value = 0;

            Log.Info("Download started");
            _timer.Interval  = 1000;
            _timer.Tick     += TimerTick;
            _webClient.Proxy = null;
            _webClient.DownloadFileAsync(DownloadUri, FileToSave, SaveFileAs);
            _timer.Start();
        }
Esempio n. 2
0
        public DownloadMessage(Uri uri, string targetPath, E_FileDisposition enumDisposition = E_FileDisposition.OverwriteAlways, int htmlDepth = 0)
        {
            ID          = unchecked (Interlocked.Increment(ref RequestID));
            DownloadUri = uri ?? throw new NullReferenceException("DownloadMessage requires non-null Uri"); // assume caller has lowercased strings
            Url         = DownloadUri.ToString();                                                           // set alternate format as 1-off
            var segs = uri.Segments;                                                                        // split the url (except querystring)

            TargetPath = (string.IsNullOrWhiteSpace(Path.GetFileNameWithoutExtension(targetPath)))
                ? Path.Combine(targetPath, segs[segs.Length - 1] + ".html") // default filename to final segment of Url
                : targetPath;
            EnumDisposition = enumDisposition;
            HtmlDepth       = htmlDepth;
        }
Esempio n. 3
0
        private void DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
        {
            DownloadStatus = Status.Downloading;
            DownloadSize   = e.TotalBytesToReceive;
            DataDownloaded = e.BytesReceived;

            Text = String.Format("{0}% of {1} Completed", e.ProgressPercentage, Path.GetFileName(DownloadUri.ToString()));
            progressBar1.Value = e.ProgressPercentage;

            DownloadProgress = String.Format("{0} of {1}", Utils.BitsToString(Convert.ToInt32(e.BytesReceived)), Utils.BitsToString(Convert.ToInt32(e.TotalBytesToReceive)));

            lblProgress.Text = String.Format("{0} at {1}", DownloadProgress, DownloadSpeedAsString);
            lblFileName.Text = String.Format("{0} from {1}", Path.GetFileName(DownloadUri.ToString()), PathName);
        }