
DownloadLibrary
Shard HttpClient Library to handle Requests
The Shard Download Library is an on .Net 6.0 based wrapper around the HttpClient
to manage your HTTP requests. But it can also be used without the HttpClient
to handle CPU intensive tasks.
All Requests
will be handled by an PriorityChannel
in a Parallel asyncron state to have a simple and efficient way to handle many (simultaneously tested with more than 1000) HTTP Requests.
- Easy to use! 🔓
- Efficient ♾️
- ✨ Contains file downloader! ✨
Table of Contents
Features
At the moment:
- StatusRequest: Calls a Head request and returns a response message with the header information.🔎
- SiteRequest: Is parsing a the HTML body of a website and list all references and files. 🔖
- OwnRequest: Wrapper around your own requests. Easy to self-expand function of handling the requests.
- RequestContainer: A container class to merge requests together and to start, pause and await them.
- Request: Main abstract class that can be used to expand functionality on class-based level.
- All subclasses have a retry function
- A priority function 🔝
- A second thread for bigger files to hold the application responsive 🌐
- Delegates to notify when a
Request
started, failed, completed, or canceled
- Implementation for custom
CancellationToken
and a main CancellationTokenSource
on Downloader
to cancel all downloads
- LoadRequest: To download the response content into files.
- This is an HTTP file downloader with these functions:
- Pause and Start a download
- Resume a download
- Get the file name and extension from the server 📥
- Timeout function ⌛
- Monitor the progress of the download with
IProgress<float>
- Can set path and filename
- Download a specified range of a file 🔛
- Download a file into chunks ⛓️
- Exclude extensions for safety (.exe; .bat.; etc...) 🛡️
Expand and use as you like!
Tech
It is available on Github:
Installation
Installation over NuGet Package manager in Visual Studio or online.
Package Manager Console: PM> NuGet\Install-Package Shard.DonwloadLibrary
How to use
Import the Library.
using DownloaderLibrary.Web.Request;
Then create a new Request
object like this LoadRequest
.
This LoadRequest
downloads a file into the download's folder of the PC with a ".part" file and uses the name that the server provides.
new LoadRequest("[Your URL]");
To set options on the Request
create a RequestOption
or for a LoadRequest
a LoadRequestOption
.
LoadRequestOptions requestOptions = new()
{
FileName = "downloadfile",
Priority = RequestPriority.High,
DestinationPath = "C:\\Users\\[Your Username]\\Desktop",
IsDownload = true,
Mode = LoadMode.Create,
Progress = new Progress<float>(f => Console.WriteLine((f).ToString("0.0%"))),
Chunks = 3
};
And use it in the request.
new LoadRequest(" https://speed.hetzner.de/100MB.bin",requestOptions);
To wait on the request, use await or Wait();.
await new LoadRequest(" https://speed.hetzner.de/100MB.bin",requestOptions).Task;
Create an OwnRequest
like this:
new OwnRequest((downloadToken) =>
{
HttpRequestMessage requestMessage = new(HttpMethod.Get, "https://www.google.com");
var response = await RequestObject.HttpClient.SendAsync(requestMessage, downloadToken);
if (!response.IsSuccessStatusCode)
return false;
Console.WriteLine("Finished");
return true;
});
To create your own Request
child. Here is the implementation of the OwnRequest
class:
public class OwnRequest : : Request<RequestOptions<VoidStruct, VoidStruct>, VoidStruct, VoidStruct>
{
private readonly Func<CancellationToken, Task<bool>> _own;
public OwnRequest(Func<CancellationToken, Task<bool>> own, RequestOptions<VoidStruct, VoidStruct>? requestOptions = null) : base(requestOptions)
{
_own = own;
AutoStart();
}
protected override async Task<RequestReturn> RunRequestAsync() => new()
{
Successful = await _own.Invoke(Token)
};
}
License
MIT
Free Code and Free to Use
Have fun!