void wc_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) { if (_mode != 0 || e.BytesReceived > 100 * 1024) { DownloadProgressChanged?.Invoke(this, e); } }
public override void Start() { if (State != DownloadState.Prepared && State != DownloadState.Pause) { return; } State = DownloadState.Downloading; //每次重新开始 Message.TempFilePath = ApplicationData.Current.LocalCacheFolder.Path + @"\" + StorageTools.StorageManager.GetTemporaryName() + ".tmp"; speedHelper = new SpeedCalculator(); speedHelper.IsEnabled = true; client = new WebClient(); client.Credentials = CredentialCache.DefaultCredentials; client.DownloadFileCompleted += Client_DownloadFileCompleted; client.DownloadProgressChanged += (o, e) => { if (o != client) { return; } speedHelper.CurrentValue = e.BytesReceived; _prog_.Speed = speedHelper.Speed; _prog_.AverageSpeed = speedHelper.AverageSpeed; _prog_.TargetValue = null; _prog_.CurrentValue = speedHelper.CurrentValue; DownloadProgressChanged?.Invoke(_prog_); }; client.DownloadFileAsync(new Uri(Message.URL), Message.TempFilePath); }
private void Client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) { if (DownloadProgressChanged != null) { m_syncContext.Send(@this => DownloadProgressChanged.Invoke(@this, e), this); } }
/// <summary> /// Downloads the specified subtitle from subscene. /// </summary> /// <param name="url">The URL of the subtitle page.</param> /// <param name="target">The target location.</param> /// <param name="token">The user token.</param> private void InternalDownload(string url, string target, string token) { // get the info page var info = Utils.GetHTML(url); DownloadProgressChanged.Fire(this, 25); // extract the download link var dllink = "http://simple.podnapisi.net" + info.DocumentNode.GetNodeAttributeValue("//img[@title='Download']/..", "href"); if (dllink == "http://simple.podnapisi.net") { DownloadFileCompleted.Fire(this, null, null, null); return; } // pass the rest of the work to HTTPDownloader _dl = new HTTPDownloader(); _dl.DownloadProgressChanged += (s, e) => DownloadProgressChanged.Fire(this, e.Data); _dl.DownloadFileCompleted += (s, e) => DownloadFileCompleted.Fire(this, e.First, e.Second, e.Third); _dl.Download(dllink, target, token); }
public void Download(Version version) { if (!m_blnIsDownloading) { m_blnIsDownloading = true; string strVersionString = version.ToString(3); //Required for SSL connections ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls; using (m_webClient = new WebClient()) { m_webClient.DownloadProgressChanged += (s, e) => DownloadProgressChanged?.Invoke(this, e); m_webClient.DownloadDataCompleted += (s, e) => { if (!e.Cancelled) { DownloadCompleted?.Invoke(this, e); s_logger.Trace("Download completed"); } else { s_logger.Trace("User canceled download"); } m_blnIsDownloading = false; }; m_webClient.DownloadDataAsync(GetDownloadUri(version)); } } }
void wc_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) { if (DownloadProgressChanged != null) { DownloadProgressChanged.Invoke(this, e); } }
/// <summary> /// Asynchronously downloads the specified link. /// </summary> /// <param name="link"> /// The object containing the link. /// This can be an URL in a string or a <c>Link</c>/<c>Subtitle</c> object. /// </param> /// <param name="target">The target location.</param> /// <param name="token">The user token.</param> public void Download(object link, string target, string token = null) { string url; if (link is string) { url = link as string; } else if (link is Link) { url = (link as Link).FileURL; } else if (link is Subtitle) { url = (link as Subtitle).FileURL; } else { throw new Exception("The link object is an unsupported type."); } // we need to check if the URL is really an HTTP link. // if we don't do this, the software could be exploited into running any command if (!Regex.IsMatch(url, @"(https?|ftp)://", RegexOptions.IgnoreCase)) { throw new Exception("The specified URL doesn't look like a HTTP/FTP link."); } DownloadProgressChanged.Fire(this, 50); Utils.Run(url); DownloadProgressChanged.Fire(this, 100); DownloadFileCompleted.Fire(this, null, null, "LaunchedBrowser"); }
/// <summary> /// Downloads the specified subtitle from subscene. /// </summary> /// <param name="url">The URL of the subtitle page.</param> /// <param name="target">The target location.</param> /// <param name="token">The user token.</param> private void InternalDownload(string url, string target, string token) { // get the info page var info = Utils.GetJSON("http://aliensubtitles.com/?d=" + Regex.Match(url, "/download#([0-9a-z]+)").Groups[1].Value + "&a=3a2677106d44d238f13ba200dd9ff53454af87a6"); DownloadProgressChanged.Fire(this, 25); // check download link if (info["url"] == null) { DownloadFileCompleted.Fire(this, null, null, null); return; } // pass the rest of the work to HTTPDownloader _dl = new HTTPDownloader(); _dl.DownloadProgressChanged += (s, e) => DownloadProgressChanged.Fire(this, e.Data); _dl.DownloadFileCompleted += (s, e) => DownloadFileCompleted.Fire(this, e.First, e.Second, e.Third); _dl.Download((string)info["url"], target, token); }
private void OnDownloadProgressChanged() { double persentage = 100 * ((double)BytesDownloaded) / ContentLength.Value; int rounded = Convert.ToInt32(Math.Round(persentage)); DownloadProgressChanged?.Invoke(this, new DownloadProgressChangedEventArgs(rounded)); }
// Note that this event is invoked on a background thread, so we cannot access the UI directly. private void DownloadProgress(DownloadOperation download) { Debug.WriteLine(String.Format(CultureInfo.CurrentCulture, "Progress: {0}, Status: {1}", download.Guid, download.Progress.Status)); double percent = 100; if (download.Progress.TotalBytesToReceive > 0) { percent = download.Progress.BytesReceived * 100 / download.Progress.TotalBytesToReceive; } Debug.WriteLine(String.Format(CultureInfo.CurrentCulture, " - Transfered bytes: {0} of {1}, {2}%", download.Progress.BytesReceived, download.Progress.TotalBytesToReceive, percent)); DownloadProgressChanged?.Invoke(download.Guid.ToString(), percent); if (download.Progress.HasRestarted) { Debug.WriteLine(" - Download restarted"); } if (download.Progress.HasResponseChanged) { // We've received new response headers from the server. Debug.WriteLine(" - Response updated; Header count: " + download.GetResponseInformation().Headers.Count); // If you want to stream the response data this is a good time to start. // download.GetResultStreamAt(0); } }
private static ResourceResult DownloadResource() { try { using (var wc = new WebClientEx()) { wc.DownloadProgressChanged += (ls, le) => DownloadProgressChanged?.Invoke(le.ProgressPercentage); wc.DownloadFileAsync(new Uri(ResourceUrl), ResourcePath); while (wc.IsBusy) { Thread.Sleep(100); } } return(ResourceResult.Success); } catch (WebException ex) { Sentry.Error(ex); return(ResourceResult.NetworkError); } catch (Exception ex) { Sentry.Error(ex); return(ResourceResult.UnknownError); } }
public static void Download(Version version) { string strVersionString = version.ToString(3); if (version < NewVersionFormat) { strVersionString = version.ToString(2); } else { } using (m_webClient = new WebClient()) { m_webClient.DownloadProgressChanged += (s, e) => DownloadProgressChanged?.Invoke(s, e); m_webClient.DownloadDataCompleted += (s, e) => { if (!e.Cancelled) { DownloadCompleted?.Invoke(s, e); } else { Log.WriteLine("Download canceled", LogType.Debug); } }; m_webClient.DownloadDataAsync(new Uri($"{BaseUrl}/download/{strVersionString}/Spawn.HDT.DustUtility.zip")); } }
/// <summary> /// Triggers when the WebClient Download Progress Change happens. /// </summary> private void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) { //Set the percent to the progress of the download. Percent = e.ProgressPercentage; //Invoke the DownloadProgressChanged event DownloadProgressChanged?.Invoke(this, new EventArgs()); }
protected void Downloader_ProgressChanged(object sender, EventArgs e) { CurrentDownloadItem.Progress.BytesDownloaded = downloader.Progress; CurrentDownloadItem.Progress.BytesTotal = downloader.Size; CurrentDownloadItem.Progress.SpeedTracker.SetProgress(downloader.Progress); DownloadProgressChanged?.Invoke(this, new DownloadEventArgs(CurrentDownloadItem)); }
public Download(Queue queue) { _webClient = new WebClient(); _webClient.DownloadProgressChanged += (sender, args) => DownloadProgressChanged?.Invoke(sender, args); _webClient.DownloadFileCompleted += DownloadCompleted; Queue = queue; State = DownloadState.Scheduled; }
public void OnDownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) { var args = new DownloadProgressEventArgs() { TotalFileSize = e.TotalBytesToReceive, TotalBytesDownloaded = e.BytesReceived, ProgressPercentage = e.ProgressPercentage, Filename = _updateInfo.DownloadFileName }; DownloadProgressChanged?.Invoke(this, args); }
private void DownloadServiceOnDownloadProgressChanged(object sender, MyDownloadEventArgs myDownloadEventArgs) { DownloadTracker.SetProgress(myDownloadEventArgs.CurrentFileSize, myDownloadEventArgs.TotalFileSize); DownloadSpeed = DownloadTracker.GetBytesPerSecond(); DownloadSpeedAsString = DownloadTracker.GetBytesPerSecondString(); CurrentProgress = DownloadTracker.GetProgress(); DownloadProgressChanged?.Invoke(sender, myDownloadEventArgs); }
public void OnDownloadProgressChanged(MyProgress value) { var args = new MyDownloadEventArgs() { TotalFileSize = value.TotalFileSize, CurrentFileSize = value.CurrentFileSize }; DownloadProgressChanged?.Invoke(this, args); }
void OnProgressChanged(int percent) { if (DownloadProgressChanged != null) { DownloadProgressChanged.Invoke(this, new DownloadEventArgs { Percentage = percent }); } }
private void TriggerProgressChanged(string sourceFileUrl, string targetFilePath, long?totalDownloadSize, long totalBytesRead) { double?progressPercentage = null; if (totalDownloadSize.HasValue) { progressPercentage = Math.Round((double)totalBytesRead / totalDownloadSize.Value * 100, 2); } DownloadProgressChanged?.Invoke(this, new DownloadProgressChangedEventArgs(sourceFileUrl, targetFilePath, totalDownloadSize, totalBytesRead, progressPercentage)); }
private void Download() { Uri uri = new Uri(string.Format(uriFormat, version)); using (var client = new WebClient()) { client.DownloadProgressChanged += (sender, args) => DownloadProgressChanged?.Invoke(sender, args); client.DownloadFileCompleted += Unzip; client.DownloadFileCompleted += (sender, args) => DownloadCompleted?.Invoke(sender, args); client.DownloadFileAsync(uri, ZipFilePath); } }
public WebFile(Uri fileUri, string filePath) { if (fileUri == null || filePath == null) { throw new ArgumentNullException(); } FileUri = fileUri; FilePath = filePath; m_WebClient.DownloadFileCompleted += WebClientOnDownloadFileCompleted; m_WebClient.DownloadProgressChanged += (sender, args) => DownloadProgressChanged.Handle(h => h(sender, args)); }
/// <summary> /// Downloads the specified subtitle from subscene. /// </summary> /// <param name="url">The URL of the subtitle page.</param> /// <param name="target">The target location.</param> /// <param name="token">The user token.</param> private void InternalDownload(string url, string target, string token) { var parts = url.Split(';'); var nzb = Utils.GetURL(parts[0], parts[1], encoding: new Utils.Base64Encoding()); DownloadProgressChanged.Fire(this, 75); File.WriteAllBytes(target, Convert.FromBase64String(nzb)); DownloadProgressChanged.Fire(this, 100); DownloadFileCompleted.Fire(this, target, parts[2], token ?? string.Empty); }
public WebFile(Uri fileUri, string filePath) { if (fileUri == null || filePath == null) { throw new ArgumentNullException(); } FileUri = fileUri; FilePath = filePath; _webClient.DownloadFileCompleted += WebClientOnDownloadFileCompleted; _webClient.DownloadProgressChanged += (sender, args) => DownloadProgressChanged?.Invoke(this, args); }
/// <summary> /// Method to cancel the async layer /// </summary> public void Cancel() { //lock (_currentDownloads) //{ var cts = _cancellationTokenSource; cts?.Cancel(); //_currentDownloads.Clear(); _numPendingDownloads = 0; DownloadProgressChanged?.Invoke(_numPendingDownloads); //} }
private async Task Start(long range) { var request = (HttpWebRequest)WebRequest.Create(_source); request.Method = "GET"; request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:53.0) Gecko/20100101 Firefox/53.0"; request.Referer = @"http://reseton.pl/static/player/v612/jwplayer.flash.swf"; request.AddRange(range); try { using (var response = await request.GetResponseAsync()) { CurrentResponse = response; ContentLength = response.ContentLength; using (var responseStream = response.GetResponseStream()) { bool isDone = false; using (var fs = new FileStream(_destination, FileMode.Append, FileAccess.Write, FileShare.ReadWrite)) { while (_allowedToRun) { var buffer = new byte[_chunkSize]; var bytesRead = await responseStream.ReadAsync(buffer, 0, buffer.Length); if (bytesRead == 0) { isDone = true; break; } await fs.WriteAsync(buffer, 0, bytesRead); BytesWritten += bytesRead; DownloadProgressChanged?.Invoke(this, null); } await fs.FlushAsync(); } if (isDone) { DownloadCompleted?.Invoke(this, null); } } } } catch (Exception e) { Debug.Write("Download file exceptions: " + e.ToString()); ContentLength = -1; } }
private void OnChunkDownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) { Package.BytesReceived += e.ProgressedByteSize; CalculateDownloadSpeed(); ChunkDownloadProgressChanged?.Invoke(this, e); DownloadProgressChanged?.Invoke(this, new DownloadProgressChangedEventArgs(nameof(DownloadService)) { TotalBytesToReceive = Package.TotalFileSize, BytesReceived = Package.BytesReceived, BytesPerSecondSpeed = DownloadSpeed }); }
private void OnDownloadProgressChanged(object sender, DownloadFileProgressChangedArgs args) { if (this.BytesReceived < args.BytesReceived) { ////bytes growing? we have connection! this.attemptNumber = 1; } this.BytesReceived = args.BytesReceived; this.TotalBytesToReceive = args.TotalBytesToReceive; DownloadProgressChanged.SafeInvoke(sender, args); }
private void RaiseDownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) { ReceivedBytes = e.BytesReceived; TotalSize = e.TotalBytesToReceive; DownloadProgressChangedArgs args = new DownloadProgressChangedArgs(); args.ReceivedBytes = ReceivedBytes; args.ProgressPercentage = e.ProgressPercentage; args.TotalBytesToBeRecieved = TotalSize; args.DownloadSpeed = string.Format("{0} kB/s", (e.BytesReceived / 1024d / _culcDownloadSpeedStopwatch.Elapsed.TotalSeconds).ToString("0.00")); DownloadProgressChanged?.Invoke(this, args, UserToken); }
public static void GetFile(string key, string filename, string url) { var req = new WebClient(); req.DownloadFileCompleted += (sender, e) => { DownloadCompleted.Invoke(sender, e); }; req.DownloadProgressChanged += (sender, e) => { DownloadProgressChanged.Invoke(sender, e); }; downloading = true; req.DownloadFileAsync(new Uri(string.Format("{0}{1}", url, key)), filename); //var resp = req.GetResponse(); //var str = resp.GetResponseStream(); //var sr = new BinaryReader(str); //var retVal = new System.IO.MemoryStream(sr.ReadBytes((int)resp.ContentLength)); //return retVal; }
private Task<bool> RunSyncItem(Manifest.SyncItem f, bool verify, bool simulate, DownloadProgressChanged dpc, DownloadEnd de, DownloadMessage dm, CancellationTokenSource cts, string overrideDestination = null) { switch (f.type) { case "rsync": RSyncDownloader dd = new RSyncDownloader(this); dd.appPath = AppPath; dd.tmpPath = TmpPath; dd.VerifyChecksums = verify; dd.Simulate = simulate; return dd.Download(LatestManifest.rsyncUrl + "/" + f.name, f, RootPath, dpc, de, dm, cts, overrideDestination); case "delete": return Task<bool>.Run(() => { if (f.name.EndsWith("/") && Directory.Exists(RootPath + "/" + f.name)) { dm.Invoke("Deleting directory " + f.name); Directory.Delete(RootPath + "/" + f.name, true); } else if (File.Exists(RootPath + "/" + f.name)) { dm.Invoke("Deleting file " + f.name); File.Delete(RootPath + "/" + f.name); } return true; }); default: return null; } }