C# Class BiliRanking.Core.Download.HttpDownloadClient

Inheritance: IDownloader
Show file Open project: SkiTiSu/BiliRanking Class Usage Examples

Public Methods

Method Description
BeginDownload ( ) : void

Start to download using ThreadPool.

BeginResume ( ) : void

Resume the download using ThreadPool.

Cancel ( ) : void

Cancel the download.

CheckUrl ( string &fileName ) : void

Check the Uri to find its size, and whether it supports "Pause".

Download ( ) : void

Start to download.

HttpDownloadClient ( string url ) : System

Download the whole file.

HttpDownloadClient ( string url, long startPoint ) : System

Download the file from a start point to the end.

HttpDownloadClient ( string url, long startPoint, long endPoint ) : System

Download a block of the file. The default buffer size is 1KB, memory cache is 1MB, and buffer count per notification is 64.

HttpDownloadClient ( string url, long startPoint, long endPoint, int bufferSize, int cacheSize, int bufferCountPerNotification ) : System
Pause ( ) : void

Pause the download.

Resume ( ) : void

Resume the download.

Protected Methods

Method Description
OnDownloadCompleted ( DownloadCompletedEventArgs e ) : void

The method will be called by the OnStatusChanged method.

OnDownloadProgressChanged ( DownloadProgressChangedEventArgs e ) : void
OnStatusChanged ( EventArgs e ) : void

Private Methods

Method Description
CheckFileOrCreateFile ( ) : void

Check whether the destination file exists. If not, create a file with the same size as the file to be downloaded.

CheckUrlAndFile ( string &fileName ) : void
DownloadInternal ( object obj ) : void

Download the data using HttpWebRequest. It will read a buffer of bytes from the response stream, and store the buffer to a MemoryStream cache first. If the cache is full, or the download is paused, canceled or completed, write the data in cache to local file.

EnsurePropertyValid ( ) : void
InternalDownloadProgressChanged ( int cachedSize ) : void

Calculate the download speed and fire the DownloadProgressChanged event.

WriteCacheToFile ( MemoryStream downloadCache, int cachedSize ) : void

Write the data in cache to local file.

Method Details

BeginDownload() public method

Start to download using ThreadPool.
public BeginDownload ( ) : void
return void

BeginResume() public method

Resume the download using ThreadPool.
public BeginResume ( ) : void
return void

Cancel() public method

Cancel the download.
public Cancel ( ) : void
return void

CheckUrl() public method

Check the Uri to find its size, and whether it supports "Pause".
public CheckUrl ( string &fileName ) : void
fileName string
return void

Download() public method

Start to download.
public Download ( ) : void
return void

HttpDownloadClient() public method

Download the whole file.
public HttpDownloadClient ( string url ) : System
url string
return System

HttpDownloadClient() public method

Download the file from a start point to the end.
public HttpDownloadClient ( string url, long startPoint ) : System
url string
startPoint long
return System

HttpDownloadClient() public method

Download a block of the file. The default buffer size is 1KB, memory cache is 1MB, and buffer count per notification is 64.
public HttpDownloadClient ( string url, long startPoint, long endPoint ) : System
url string
startPoint long
endPoint long
return System

HttpDownloadClient() public method

public HttpDownloadClient ( string url, long startPoint, long endPoint, int bufferSize, int cacheSize, int bufferCountPerNotification ) : System
url string
startPoint long
endPoint long
bufferSize int
cacheSize int
bufferCountPerNotification int
return System

OnDownloadCompleted() protected method

The method will be called by the OnStatusChanged method.
protected OnDownloadCompleted ( DownloadCompletedEventArgs e ) : void
e DownloadCompletedEventArgs
return void

OnDownloadProgressChanged() protected method

protected OnDownloadProgressChanged ( DownloadProgressChangedEventArgs e ) : void
e DownloadProgressChangedEventArgs
return void

OnStatusChanged() protected method

protected OnStatusChanged ( EventArgs e ) : void
e System.EventArgs
return void

Pause() public method

Pause the download.
public Pause ( ) : void
return void

Resume() public method

Resume the download.
public Resume ( ) : void
return void