public bool DownloadFile(string filePath, DownloadCompleteHandler completeHandler, Control control) { //foreach (DownloadInfo downloadInfo in _downloadList) //{ // if (downloadInfo._filePath == filePath) // { // return true; // } //} DownloadInfo newInfo = new DownloadInfo(); newInfo._filePath = filePath; newInfo._completeHandler = completeHandler; newInfo._window = Window.GetWindow(control); newInfo._window.Closed += new EventHandler(_window_Closed); _downloadList.Add(newInfo); if (_downloadList.Count <= 1) { DownloadAsync(); } return(true); }
/// <summary> /// Updates the specified download. /// </summary> /// <param name="wd">The wd.</param> public void Update(WebDownload wd) { // Make sure we're on the right thread if (this.InvokeRequired) { // Update progress asynchronously DownloadCompleteHandler dlgt = new DownloadCompleteHandler(Update); this.Invoke(dlgt, new object[] { wd }); return; } foreach (DebugItem item in listView.Items) { if (item.WebDownload == wd) { item.Update(wd); if (logToFile) { if (wd.Exception != null) { Log.Write(logCategory, "Error : " + wd.Url.Replace("http://", "")); Log.Write(logCategory, " \\---" + wd.Exception.Message); } if (wd.ContentLength == wd.BytesProcessed) { string msg = string.Format(CultureInfo.CurrentCulture, "Done ({0:f2}s): {1}", item.ElapsedTime.TotalSeconds, wd.Url.Replace("http://", "")); Log.Write(logCategory, msg); } } return; } } if (!isRunning) { return; } if (listView.Items.Count >= maxItems) { RemoveOldestItem(); } if (logToFile) { Log.Write(logCategory, "Get : " + wd.Url); if (wd.SavedFilePath != null) { Log.Write(logCategory, " \\--- " + wd.SavedFilePath); } } DebugItem newItem = new DebugItem(wd); newItem.Update(wd); listView.Items.Insert(0, newItem); }
public bool DownloadFile(string filePath, DownloadCompleteHandler completeHandler, string strServerPath) { DownloadInfo newInfo = new DownloadInfo(); newInfo._filePath = filePath; newInfo._completeHandler = completeHandler; newInfo._strServerPath = strServerPath; DownloadAsync(newInfo); return(true); }
/// <summary> /// Aborts the current download. /// </summary> public void Cancel() { CompleteCallback = null; ProgressCallback = null; if (dlThread != null && dlThread != Thread.CurrentThread) { if (dlThread.IsAlive) { dlThread.Abort(); } dlThread = null; } }
public bool DownloadFile(string filePath, DownloadCompleteHandler completeHandler, Control control) { DownloadInfo newInfo = new DownloadInfo(); newInfo._filePath = filePath; newInfo._completeHandler = completeHandler; newInfo._window = Window.GetWindow(control); //newInfo._window.Closed += new EventHandler(_window_Closed); DownloadAsync(newInfo); return(true); }
/// <summary> /// Aborts the current download. /// </summary> public void Cancel() { CompleteCallback = null; ProgressCallback = null; if (dlThread != null && dlThread != Thread.CurrentThread) { if (dlThread.IsAlive) { stopFlag = true; if (!dlThread.Join(500)) { dlThread.Abort(); } } dlThread = null; } }
/// <summary> /// Aborts the current download. /// </summary> public void Cancel() { CompleteCallback = null; ProgressCallback = null; if (dlThread != null && dlThread != Thread.CurrentThread) { if (dlThread.IsAlive) { Log.Write(Log.Levels.Verbose, "WebDownload.Cancel() : stopping download thread..."); stopFlag = true; if (!dlThread.Join(500)) { Log.Write(Log.Levels.Warning, "WebDownload.Cancel() : download thread refuses to die, forcing Abort()"); dlThread.Abort(); } } dlThread = null; } }
public static Task <Uri> CompletionOfDownload(MusicItem song) { var downloadInfo = song2task(song); if (IsDownloading(downloadInfo)) { var tcs = new TaskCompletionSource <Uri>(); DownloadCompleteHandler handler = null; handler = filePath => { if (filePath == LocalLibrary.AbsolutePathTo(song)) { DownloadCompleteEvent -= handler; tcs.SetResult(new Uri(filePath, UriKind.Relative)); } }; DownloadCompleteEvent += handler; return(tcs.Task); } else { return(Download(song)); } }
/// <summary> /// Asynchronous download of HTTP data to in-memory buffer. /// </summary> public void BackgroundDownloadMemory(DownloadCompleteHandler completeCallback) { CompleteCallback += completeCallback; BackgroundDownloadMemory(); }
/// <summary> /// Asynchronous download of HTTP data to file. /// </summary> public void BackgroundDownloadFile(string destinationFile, DownloadCompleteHandler completeCallback) { SavedFilePath = destinationFile; CompleteCallback += completeCallback; BackgroundDownloadFile(); }
public void StartDownload(DownloadCompleteHandler oHandler) { m_oCallback = oHandler; ThreadPool.QueueUserWorkItem(new WaitCallback(BuildRequest)); }
/// <summary> /// Updates the specified download. /// </summary> /// <param name="wd">The wd.</param> public void Update(WebDownload wd) { // Make sure we're on the right thread if (this.InvokeRequired) { // Update progress asynchronously DownloadCompleteHandler dlgt = new DownloadCompleteHandler(Update); this.Invoke(dlgt, new object[] {wd}); return; } foreach (DebugItem item in listView.Items) { if (item.WebDownload == wd) { item.Update(wd); if (logToFile) { if (wd.Exception != null) { Log.Write(logCategory, "Error : " + wd.Url.Replace("http://", "")); Log.Write(logCategory, " \\---" + wd.Exception.Message); } if (wd.ContentLength == wd.BytesProcessed) { string msg = string.Format(CultureInfo.CurrentCulture, "Done ({0:f2}s): {1}", item.ElapsedTime.TotalSeconds, wd.Url.Replace("http://", "")); Log.Write(logCategory, msg); } } return; } } if (!isRunning) { return; } if (listView.Items.Count >= maxItems) { RemoveOldestItem(); } if (logToFile) { Log.Write(logCategory, "Get : " + wd.Url); if (wd.SavedFilePath != null) { Log.Write(logCategory, " \\--- " + wd.SavedFilePath); } } DebugItem newItem = new DebugItem(wd); newItem.Update(wd); listView.Items.Insert(0, newItem); }
/// <summary> /// Aborts the current download. /// </summary> public void Cancel() { CompleteCallback = null; ProgressCallback = null; if (dlThread!=null && dlThread != Thread.CurrentThread) { if (dlThread.IsAlive) { Log.Write(Log.Levels.Verbose, "WebDownload.Cancel() : stopping download thread..."); stopFlag = true; if (!dlThread.Join(500)) { Log.Write(Log.Levels.Warning, "WebDownload.Cancel() : download thread refuses to die, forcing Abort()"); dlThread.Abort(); } } dlThread = null; } }