void wc_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) { if (DownloadProgressChanged != null) { DownloadProgressChanged.Invoke(this, e); } }
void wc_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) { if (_mode != 0 || e.BytesReceived > 100 * 1024) { DownloadProgressChanged?.Invoke(this, e); } }
private void Client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) { if (DownloadProgressChanged != null) { m_syncContext.Send(@this => DownloadProgressChanged.Invoke(@this, e), this); } }
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)); }
/// <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()); }
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); }
public Download(Queue queue) { _webClient = new WebClient(); _webClient.DownloadProgressChanged += (sender, args) => DownloadProgressChanged?.Invoke(sender, args); _webClient.DownloadFileCompleted += DownloadCompleted; Queue = queue; State = DownloadState.Scheduled; }
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)); }
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 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); } }
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 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); }
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 }); }
public Task Download(string path) { using (var webClient = new WebClient { Proxy = null }) { webClient.DownloadProgressChanged += (sender, args) => DownloadProgressChanged?.Invoke(this, new DownloadProgressChangedEventArgs(args.BytesReceived, args.TotalBytesToReceive)); return(webClient.DownloadFileTaskAsync(_downloadUrl, path)); } }
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; }
/// <summary> /// Faz download de um arquivo de áudio. /// </summary> /// <param name="item"></param> public WebClient Download(Item item) { WebClient client = new WebClient(); client.DownloadFileAsync(new Uri(item.AudioUrl), $"./Podcasts/{SanitizeFileName (item.Title)}.mp3"); client.DownloadProgressChanged += (sender, e) => { DownloadProgressChanged?.Invoke(e.ProgressPercentage); Console.WriteLine($"Download '{item.Title}': {e.ProgressPercentage}%"); }; client.DownloadFileCompleted += (sender, e) => { DownloadAudioCompleted?.Invoke(); Console.WriteLine($"Download '{item.Title}' concluído!"); }; Console.WriteLine($"Download '{item.Title}' iniciado!"); return(client); }
private void OnChunkDownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) { Package.AddReceivedBytes(e.ProgressedByteSize); _bandwidth.CalculateSpeed(e.ProgressedByteSize); ChunkDownloadProgressChanged?.Invoke(this, e); DownloadProgressChanged?.Invoke(this, new DownloadProgressChangedEventArgs(nameof(DownloadService)) { TotalBytesToReceive = Package.TotalFileSize, ReceivedBytesSize = Package.ReceivedBytesSize, BytesPerSecondSpeed = _bandwidth.Speed, AverageBytesPerSecondSpeed = _bandwidth.AverageSpeed, ReceivedBytes = e.ReceivedBytes }); }
private void OnChunkDownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) { _bandwidth.CalculateSpeed(e.ProgressedByteSize); var totalProgressArg = new DownloadProgressChangedEventArgs(nameof(DownloadService)) { TotalBytesToReceive = Package.TotalFileSize, ReceivedBytesSize = Package.ReceivedBytesSize, BytesPerSecondSpeed = _bandwidth.Speed, AverageBytesPerSecondSpeed = _bandwidth.AverageSpeed, ProgressedByteSize = e.ProgressedByteSize, ReceivedBytes = e.ReceivedBytes }; Package.SaveProgress = totalProgressArg.ProgressPercentage; ChunkDownloadProgressChanged?.Invoke(this, e); DownloadProgressChanged?.Invoke(this, totalProgressArg); }
public async Task DownloadAsync(string?remoteUrl, string?filePath) { if (string.IsNullOrEmpty(remoteUrl)) { throw new ArgumentNullException(nameof(remoteUrl)); } if (string.IsNullOrEmpty(filePath)) { throw new ArgumentNullException(nameof(filePath)); } var fileDirectory = Path.GetDirectoryName(filePath); if (!Directory.Exists(fileDirectory)) { Directory.CreateDirectory(fileDirectory !); } if (File.Exists(filePath)) { File.Delete(filePath !); } using var webClient = new WebClient(); var downloadStartTime = DateTime.Now; webClient.DownloadProgressChanged += (_, args) => { if (DownloadProgressChanged == null) { return; } var elapsedTime = DateTime.Now - downloadStartTime; var progress = args.BytesReceived / (double)args.TotalBytesToReceive; var bytesPerSecond = args.BytesReceived / elapsedTime.TotalSeconds; var estimatedRemainingTime = TimeSpan.FromSeconds((args.TotalBytesToReceive - args.BytesReceived) / bytesPerSecond); DownloadProgressChanged.Invoke(this, new DownloadProgressEventArguments(progress, bytesPerSecond / (1024.0d * 1024.0d), estimatedRemainingTime)); }; await webClient.DownloadFileTaskAsync(remoteUrl !, filePath !); }
private Task DownloadStart() { var client = new WebClient(); client.Headers[HttpRequestHeader.UserAgent] = "Awesome-Octocat-App-TqoonDevTeam"; client.Headers[HttpRequestHeader.Accept] = "application/octet-stream"; client.DownloadProgressChanged += (s, e) => { if (DownloadProgressChanged != null) { DownloadProgressChanged.Invoke(this, new AssertDownloadEventArgs { FilePath = _downloadPath, ProgressPercentage = e.ProgressPercentage }); } client.Dispose(); }; return(client.DownloadFileTaskAsync(_Url, _downloadPath)); }
private void Download() { this.logger.WriteLine(Strings.Daemon_Downloading); 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) => { this.logger.WriteLine(Strings.Daemon_Downloaded); DownloadCompleted?.Invoke(sender, args); }; client.DownloadFileAsync(uri, ZipFilePath); } }
//################################################################################## private bool WriteFile(HttpWebResponse response) { long received = 0; try { byte[] buffer = new byte[1024]; using (Stream input = response.GetResponseStream()) { long total = response.ContentLength; var test = new Java.IO.File(_filePath); //TODO: Check, ob File bereits existiert & gleiche Größe, wie der Stream hat >> SKIP FileStream fileStream = File.OpenWrite(_filePath); int size = input.Read(buffer, 0, buffer.Length); while (size > 0) { fileStream.Write(buffer, 0, size); received += size; int perc = (int)(received / total) * 100; if (perc < 0) { perc = 0; } if (perc > 100) { perc = 100; } DownloadProgressChanged?.Invoke(this, perc); size = input.Read(buffer, 0, buffer.Length); } fileStream.Flush(); fileStream.Close(); } return(System.IO.File.Exists(_filePath)); } catch (Exception) { } return(false); }
protected async Task <string> PerformDownloadAsync(string proposedDownloadFilePath, Func <Progress <DownloadProgress>, Task <string> > func) { var progress = new Progress <DownloadProgress>(); progress.ProgressChanged += (_, e) => DownloadProgressChanged?.Invoke(this, e); DownloadBegin?.Invoke(this, proposedDownloadFilePath); try { var result = await func(progress); StatusUpdate?.Invoke(this, result); return(result); } finally { DownloadCompleted?.Invoke(this, proposedDownloadFilePath); } }
public void Start() { if (State == DownloadState.Cancelled) { return; } if (_webClient.IsBusy) { State = DownloadState.Restart; } if (State == DownloadState.Restart) { return; } State = DownloadState.InProgress; _webClient.DownloadFileAsync(SourcePath, DestinationalFile); DownloadProgressChanged?.Invoke(this, null); }
public async Task <string> PerformDownloadFileAsync(string downloadUrl, string proposedDownloadFilePath) { var client = new HttpClient(); var progress = new Progress <DownloadProgress>(); progress.ProgressChanged += (_, e) => DownloadProgressChanged?.Invoke(this, e); DownloadBegin?.Invoke(this, proposedDownloadFilePath); try { var actualDownloadedFilePath = await client.DownloadFileAsync(downloadUrl, proposedDownloadFilePath, progress); return(actualDownloadedFilePath); } finally { DownloadCompleted?.Invoke(this, proposedDownloadFilePath); } }
internal static void GetSourceJarAsync(Side side) { string currentPath = Environment.CurrentDirectory; if (!Directory.Exists(currentPath + @"\jar")) { Directory.CreateDirectory(currentPath + @"\jar"); } FileDownloadervar = new FileDownloader(); FileDownloadervar.DownloadProgressChanged += (sender, e) => { DownloadProgressChanged.Invoke(sender, e); Debug.WriteLine(e.ProgressPercentage); }; FileDownloadervar.DownloadFileCompleted += (sender, e) => { if (e.State == CompletedState.Succeeded) { Debug.WriteLine("download mapping success"); DownloadCompleted.Invoke(sender, e); } else { Debug.WriteLine("download mapping failed"); } }; VersionInfo versioninfo = MappingService.VersioninfoCache; if (side == Side.Client) { FileDownloadervar.DownloadFileAsync(versioninfo.Downloads.Client.url, currentPath + @"\jar\source.jar"); } else { FileDownloadervar.DownloadFileAsync(versioninfo.Downloads.Server.url, currentPath + @"\jar\source.jar"); } }