private void _workerProgressChanged(object sender, ProgressChangedEventArgs e) { if (e.ProgressPercentage == 100) { OnDownloadComplete?.Invoke(this); } OnProgressChanged?.Invoke(this, e.ProgressPercentage); }
private void _workerCompleted(object sender, RunWorkerCompletedEventArgs e) { if (e.Error != null) { OnError?.Invoke(this, e.Error.Message); return; } OnDownloadComplete?.Invoke(this); }
private void M_ftp2_DownloadDataCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e) { try { OnDownloadComplete?.Invoke(sender, e); } catch (Exception ex) { Log.OutputBox(ex); Log.ShowError(m_ftp.ErrorMsg); } }
public void Download(string label) { var index = GetLabelIndex(label); if (AsyncOpExists(listOps[index])) { Debug.Log("Download is allready in progress"); return; } listOps[index] = Addressables.DownloadDependenciesAsync(listLabels[index]); listOps[index].Completed += (x) => { OnDownloadComplete?.Invoke(GetLabel(index)); }; StartCoroutine(CRTDownload(index)); }
public void QueueDownload(UriString url, string targetDirectory, string filename = null, int retryCount = 0) { var download = new DownloadTask(TaskManager, url, targetDirectory, filename, retryCount, Token); download.OnStart += t => OnDownloadStart?.Invoke(((DownloadTask)t).Url); download.OnEnd += (t, res, s, ex) => { if (s) { OnDownloadComplete?.Invoke(((DownloadTask)t).Url, res); } else { OnDownloadFailed?.Invoke(((DownloadTask)t).Url, ex); } }; // queue after hooking up events so OnDownload* gets called first Queue(download); }
public void QueueDownload(UriString url, NPath targetDirectory) { var download = new DownloadTask(Token, fileSystem, url, targetDirectory); download.OnStart += t => OnDownloadStart?.Invoke(((DownloadTask)t).Url); download.OnEnd += (t, res, s, ex) => { if (s) { OnDownloadComplete?.Invoke(((DownloadTask)t).Url, res); } else { OnDownloadFailed?.Invoke(((DownloadTask)t).Url, ex); } }; // queue after hooking up events so OnDownload* gets called first Queue(download); }
/// <summary> /// Translate event to high level /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e) { OnDownloadComplete?.Invoke(this, e); }
/// <summary> /// From a provided REST API endpoint download a mod. /// </summary> public async Task DownloadMod(string url) { Downloading = true; string modZipPath; string modImagePath; string modExtractPath; string modString = string.Empty; using (WebClient wc = new WebClient()) { dynamic Data = new OnDownloadCompleteArgs(); OnDownloadStart?.Invoke(this, Data); wc.DownloadProgressChanged += WCDownloadPercentChanged; try { modString = await wc.DownloadStringTaskAsync(url); } catch (WebException ex) { Data.ErrorMessage = ex.Message; OnDownloadComplete?.Invoke(this, Data); return; } JsonObject json = JsonObject.Parse(modString); // Let's make sure the slug doesn't have weird stuff. json["slug"] = string.Join(" ", json["slug"].Split(Path.GetInvalidFileNameChars().Concat(Path.GetInvalidPathChars()).ToArray())); if (json["compatible"] != "Yes") { Data.ErrorMessage = Helpers._("Error.NotCompatible"); OnDownloadComplete?.Invoke(this, Data); return; } m = new Mod( json["id"], json.ArrayObjects("title") [0]["rendered"], DateTime.ParseExact(json["modified"].Replace("T", " "), "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture), json.ArrayObjects("content") [0]["rendered"], json["author_name"], url, json["File"], json["slug"], json["slug"] + ".jpg" ); modZipPath = zipPath + m.Slug + ".zip"; modExtractPath = Mod.InstallPath + m.Slug + "\\"; modImagePath = Mod.ImagePath + m.Thumbnail; // Cleanup previous versions and files. Delete(m.Slug); if (File.Exists(modZipPath)) { File.Delete(modZipPath); } if (Directory.Exists(modExtractPath)) { Directory.Delete(modExtractPath, true); } if (File.Exists(modImagePath)) { File.Delete(modImagePath); } // And start downloading stuff. try { await wc.DownloadFileTaskAsync(new System.Uri(json["image"]), modImagePath); } catch (WebException we) { Data.ErrorMessage = we.Message; OnDownloadComplete?.Invoke(this, Data); return; } try { await wc.DownloadFileTaskAsync(new System.Uri(m.File), modZipPath); } catch (WebException we) { Data.ErrorMessage = we.Message; OnDownloadComplete?.Invoke(this, Data); return; } UnpackMod(modZipPath, modExtractPath); AvailableMods.Add(m); Data.Success = true; OnDownloadComplete?.Invoke(this, Data); UpdateSettings(); } Downloading = false; }
void client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e) { OnDownloadComplete?.Invoke(tempFile); }
private async void DownloadWithUrl(string _url) { var _filePath = new Uri(_url).AbsolutePath; var _name = Path.GetFileName(_filePath); var _dir = $"./downloads/{Path.GetDirectoryName(_filePath)}"; var _path = $"{_dir}/{_name}"; if (!Directory.Exists(_dir)) { Directory.CreateDirectory(_dir); } if (File.Exists(_path)) { OnDownloadComplete?.Invoke(this, new DownloadResultEventArg { FileName = _name, Success = true, Url = _url, Contains = true }); } else { try { OnDownloadStart?.Invoke(this, new DownloadResultEventArg { FileName = _name, Success = true, Url = _url }); HttpWebRequest webRequest = WebRequest.CreateHttp(_url); webRequest.UserAgent = "Half-Life 2"; webRequest.Referer = "hl2://31.186.251.23:27016"; using (WebResponse _request = webRequest.GetResponse()) using (Stream _stream = _request.GetResponseStream()) using (FileStream _file = File.Create(_path)) await _stream.CopyToAsync(_file); OnDownloadComplete?.Invoke(this, new DownloadResultEventArg { FileName = _name, Success = true, Url = _url }); } catch (Exception ex) { //WebException _ex = ex as WebException; if (_retryCount++ < 3) { File.Delete(_path); DownloadWithUrl(_url); } else { _retryCount = 0; OnDownloadComplete?.Invoke(this, new DownloadResultEventArg { FileName = _name, Success = false, Url = _url, Exception = ex }); } } } }