public CommonDownload(List <CloudFile> files, ProgressBar[] progressBars, Label[] progressLabels, CloudServiceType cloudServiceType, int overwriteMode = 3, NetworkCredential networkCredential = null, bool folderNewFiles = true) { progressbars = progressBars; progresslabels = progressLabels; downloads = new List <CommonFileDownload>(); OverwriteMode = overwriteMode; CloudService = cloudServiceType; if (folderNewFiles) { downloadFolderPath = MainForm.syncFolderPath + "/New Files " + DateTime.Now.Date.ToShortDateString(); } else { downloadFolderPath = MainForm.syncFolderPath; } //var logFileName = $"download-log-{DateTime.Now.ToString("MM-dd-yyyy")}.txt"; //string log = $"{DateTime.Now}\ndownloadFolderPath:{downloadFolderPath}\nlogin: {networkCredential.UserName}\npassword: {networkCredential.Password}\n"; //File.AppendAllText(logFileName, log); try { foreach (CloudFile file in files) { CommonFileDownload fileDownload = new CommonFileDownload(this, file, downloadFolderPath + file.Path, networkCredential); downloadQueue.Enqueue(fileDownload); downloads.Add(fileDownload); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public void Start() { System.Net.ServicePointManager.DefaultConnectionLimit = 4; progresslabels[progresslabels.Length - 1].Text = ""; progresslabels[progresslabels.Length - 1].Visible = true; lock (downloadQueue) { if (downloadQueue.Count > 0) { for (int i = 0; i < progressbars.Length; i++) { if (progressbars[i].Tag == null) { CommonFileDownload dd = downloadQueue.Dequeue(); dd.ProgressBar = progressbars[i]; dd.ProgressLabel = progresslabels[i]; dd.StartDownload(); if (downloadQueue.Count == 0) { break; } } } } } }
public void UpdateQueue(CommonFileDownload d) { lock (downloadQueue) { d.Finished = true; d.ProgressBar.Tag = null; d.ProgressBar.Value = 0; d.ProgressLabel.Visible = false; if (downloadQueue.Count > 0 && !cancellationTokenSource.IsCancellationRequested) { CommonFileDownload newd = downloadQueue.Dequeue(); newd.ProgressBar = d.ProgressBar; newd.ProgressLabel = d.ProgressLabel; newd.StartDownload(); } } finishedDownloads++; progresslabels[progresslabels.Length - 1].Text = $"{finishedDownloads}/{downloads.Count} files finished"; if (finishedDownloads == downloads.Count && !cancellationTokenSource.IsCancellationRequested) { DownloadsFinishedForm downloadsFinishedForm = new DownloadsFinishedForm(downloadFolderPath, "All downloads are finished!"); downloadsFinishedForm.Show(); } }