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;
2using System.Collections.Generic;
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<object> DeleteAsync(Uri Uri, X509Certificate Certificate,
59 RemoteCertificateEventHandler RemoteCertificateValidator, int TimeoutMs, params KeyValuePair<string, string>[] Headers)
60 {
61 HttpClientHandler Handler = WebGetter.GetClientHandler(Certificate, RemoteCertificateValidator);
62 using (HttpClient HttpClient = new HttpClient(Handler, true)
63 {
64 Timeout = TimeSpan.FromMilliseconds(TimeoutMs)
65 })
66 {
67 using (HttpRequestMessage Request = new HttpRequestMessage()
68 {
69 RequestUri = Uri,
70 Method = HttpMethod.Delete
71 })
72 {
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 async Task< object > DeleteAsync(Uri Uri, X509Certificate Certificate, RemoteCertificateEventHandler RemoteCertificateValidator, int TimeoutMs, params KeyValuePair< string, string >[] Headers)
Deletes a resource, using a Uniform Resource Identifier (or Locator).
Definition: WebDeleter.cs:58
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 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:20
static HttpClientHandler GetClientHandler()
Gets a HTTP Client handler
Definition: WebGetter.cs:107
static async Task< object > 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:189
delegate void RemoteCertificateEventHandler(object Sender, RemoteCertificateEventArgs e)
Delegate for remote certificate event handlers.
Grade
Grade enumeration
Definition: Grade.cs:7