Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
WebDeleter.cs
1using System;
3using System.Net.Http;
4using System.Security.Cryptography.X509Certificates;
5using System.Threading.Tasks;
8
10{
14 public class WebDeleter : DeleterBase
15 {
19 public WebDeleter()
20 {
21 }
22
26 public override string[] UriSchemes => new string[] { "http", "https" };
27
34 public override bool CanDelete(Uri Uri, out Grade Grade)
35 {
36 switch (Uri.Scheme.ToLower())
37 {
38 case "http":
39 case "https":
40 Grade = Grade.Ok;
41 return true;
42
43 default:
44 Grade = Grade.NotAtAll;
45 return false;
46 }
47 }
48
58 public override async Task<ContentResponse> DeleteAsync(Uri Uri, X509Certificate Certificate,
59 EventHandler<RemoteCertificateEventArgs> RemoteCertificateValidator, int TimeoutMs, params KeyValuePair<string, string>[] Headers)
60 {
61 HttpClientHandler Handler = WebGetter.GetClientHandler(Certificate, RemoteCertificateValidator, Uri);
62 using (HttpClient HttpClient = new HttpClient(Handler, true)
63 {
64 Timeout = TimeSpan.FromMilliseconds(TimeoutMs)
65 })
66 {
67 using (HttpRequestMessage Request = new HttpRequestMessage()
68 {
69 Method = HttpMethod.Delete
70 })
71 {
72 Request.RequestUri = WebGetter.CheckUri(Uri, Request);
73 WebGetter.PrepareHeaders(Request, Headers, Handler);
74
75 HttpResponseMessage Response = await HttpClient.SendAsync(Request);
76
77 return await WebGetter.ProcessResponse(Response, Uri);
78 }
79 }
80 }
81 }
82}
Abstract base class for deleters.
Definition: DeleterBase.cs:13
Deletes to resources on the Web (i.e. using HTTP or HTTPS).
Definition: WebDeleter.cs:15
override bool CanDelete(Uri Uri, out Grade Grade)
If the deleter is able to delete to a resource, given its URI.
Definition: WebDeleter.cs:34
override async Task< ContentResponse > DeleteAsync(Uri Uri, X509Certificate Certificate, EventHandler< RemoteCertificateEventArgs > RemoteCertificateValidator, int TimeoutMs, params KeyValuePair< string, string >[] Headers)
Deletes a resource, using a Uniform Resource Identifier (or Locator).
Definition: WebDeleter.cs:58
override string[] UriSchemes
Supported URI schemes.
Definition: WebDeleter.cs:26
WebDeleter()
Deletes to resources on the Web (i.e. using HTTP or HTTPS).
Definition: WebDeleter.cs:19
Gets resources from the Web (i.e. using HTTP or HTTPS).
Definition: WebGetter.cs:25
static async Task< ContentResponse > ProcessResponse(HttpResponseMessage Response, Uri Uri)
Decodes a response from the web. If the response is a success, the decoded response is returned....
Definition: WebGetter.cs:386
static void PrepareHeaders(HttpRequestMessage Request, KeyValuePair< string, string >[] Headers, HttpClientHandler Handler)
Prepares headers for a HTTP request.
Definition: WebGetter.cs:447
static HttpClientHandler GetClientHandler()
Gets a HTTP Client handler
Definition: WebGetter.cs:153
static Uri CheckUri(Uri Uri, HttpRequestMessage Request)
Checks the URI, if it is suitable for processing, or if it needs to be modified.
Definition: WebGetter.cs:260
Grade
Grade enumeration
Definition: Grade.cs:7