Пример #1
0
        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);
        }
Пример #2
0
        /// <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);
        }
Пример #3
0
        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);
        }
Пример #4
0
 /// <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;
     }
 }
Пример #5
0
        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);
        }
Пример #6
0
 /// <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;
     }
 }
Пример #7
0
 /// <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;
     }
 }
Пример #8
0
        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));
            }
        }
Пример #9
0
 /// <summary>
 /// Asynchronous download of HTTP data to in-memory buffer.
 /// </summary>
 public void BackgroundDownloadMemory(DownloadCompleteHandler completeCallback)
 {
     CompleteCallback += completeCallback;
     BackgroundDownloadMemory();
 }
Пример #10
0
 /// <summary>
 /// Asynchronous download of HTTP data to file.
 /// </summary>
 public void BackgroundDownloadFile(string destinationFile, DownloadCompleteHandler completeCallback)
 {
     SavedFilePath     = destinationFile;
     CompleteCallback += completeCallback;
     BackgroundDownloadFile();
 }
Пример #11
0
 /// <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;
     }
 }
Пример #12
0
 /// <summary>
 /// Asynchronous download of HTTP data to in-memory buffer. 
 /// </summary>
 public void BackgroundDownloadMemory(DownloadCompleteHandler completeCallback)
 {
     CompleteCallback += completeCallback;
     BackgroundDownloadMemory();
 }
Пример #13
0
 public void StartDownload(DownloadCompleteHandler oHandler)
 {
     m_oCallback = oHandler;
     ThreadPool.QueueUserWorkItem(new WaitCallback(BuildRequest));
 }
Пример #14
0
        /// <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);
        }
Пример #15
0
		/// <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;
			}		
		}