private void MCDownload(string link, Label label, ProgressBar progressBar, DownloadType type) { progressBar.Invoke(new MethodInvoker(delegate { progressBar.Visible = true; })); label.Invoke(new MethodInvoker(delegate { label.Visible = true; })); using (var client = new System.Net.WebClient()) { Thread thread = new Thread(() => { client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged); client.DownloadFileCompleted += new AsyncCompletedEventHandler(client_DownloadFileCompleted); client.DownloadFileAsync(new Uri(link), gamepath + "\\Archive.rar"); }); thread.Start(); } void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) { double MbytesIn = double.Parse(e.BytesReceived.ToString()) * 1024; double totalMBytes = double.Parse(e.TotalBytesToReceive.ToString()) * 1024; double percentage = MbytesIn / totalMBytes * 100; if (label.InvokeRequired && progressBar.InvokeRequired) { label.Invoke(new MethodInvoker(delegate { label.Text = "Type: " + char.ToUpper(type.ToString()[0]) + type.ToString().Substring(1) + " " + e.BytesReceived / (1024 * 1024) + "mb" + " / " + e.TotalBytesToReceive / (1024 * 1024) + "mb"; })); progressBar.Invoke(new MethodInvoker(delegate { progressBar.Value = int.Parse(Math.Truncate(percentage).ToString()); })); } } void client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e) { if (label.InvokeRequired) { label.Invoke(new MethodInvoker(delegate { label.Text = "Unraring..."; })); } UnArch(label, progressBar); } }
public async Task <FileDownloadDto> GetDownloadAsync(int urn, DownloadType format, IPrincipal principal) => (await _httpClient.GetAsync <FileDownloadDto>($"establishment/{urn}/download?format={format.ToString().ToLower()}", principal)).GetResponse();
public string GetDownloadTypeName(DownloadType type) { return(type.ToString()); }
public void downloadFile(Form attachedForm, FileType type, long fid, string title, DownloadType downloadType, Dictionary<string, string> paramKeyValues) { new Thread(delegate() { byte[] data; WebHeaderCollection headers; string url = getUrl(Action.downloadfile); url += "/" + type.ToString().ToLower() + "/" + downloadType.ToString(); url += "?fid=" + fid; if (paramKeyValues != null && paramKeyValues.Count > 0) { foreach (KeyValuePair<string, string> pair in paramKeyValues) { url += "&" + pair.Key + "=" + pair.Value; } } HttpStatusCode statusCode = HTTPRequest.MakeRequest(url, "GET", null, Constants.RAW_MIME, null, out data, out headers); if (statusCode == HttpStatusCode.OK) { if (onDownloadFileSuccessfully != null) attachedForm.BeginInvoke(onDownloadFileSuccessfully, type, fid, title, downloadType, data); } else { if (onDownloadFileFailed != null) attachedForm.BeginInvoke(onDownloadFileFailed, type, fid, title, downloadType, statusCode); } }).Start(); }