Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ContractSchemasGetter.cs
1using System;
2using System.Collections.Generic;
3using System.Security.Cryptography.X509Certificates;
4using System.Threading.Tasks;
5using Waher.Content;
10
12{
17 {
22 {
23 }
24
28 public string[] UriSchemes => new string[] { "urn" };
29
36 public bool CanGet(Uri Uri, out Grade Grade)
37 {
38 if (string.IsNullOrEmpty(UriToResource(Uri)))
39 {
40 Grade = Grade.NotAtAll;
41 return false;
42 }
43 else
44 {
45 Grade = Grade.Excellent;
46 return true;
47 }
48 }
49
50 private static string UriToResource(Uri Uri)
51 {
52 string SchemaName;
53
54 switch (Uri.OriginalString)
55 {
56 case "urn:nf:iot:e2e:1.0":
57 SchemaName = "E2E.xsd";
58 break;
59
60 case "urn:nf:iot:leg:id:1.0":
61 SchemaName = "LegalIdentities.xsd";
62 break;
63
64 case "urn:nf:iot:p2p:1.0":
65 SchemaName = "P2P.xsd";
66 break;
67
68 case "urn:nf:iot:leg:sc:1.0":
69 SchemaName = "SmartContracts.xsd";
70 break;
71
72 default:
73 return null;
74 }
75
76 return typeof(ContractsClient).Namespace + ".Schema." + SchemaName;
77 }
78
87 public Task<object> GetAsync(Uri Uri, X509Certificate Certificate, RemoteCertificateEventHandler RemoteCertificateValidator,
88 params KeyValuePair<string, string>[] Headers)
89 {
90 string SchemaName = UriToResource(Uri);
91 if (string.IsNullOrEmpty(SchemaName))
92 throw new Exception("URI not recognized.");
93
94 return Task.FromResult<object>(XSL.LoadSchema(SchemaName));
95 }
96
106 public Task<object> GetAsync(Uri Uri, X509Certificate Certificate, RemoteCertificateEventHandler RemoteCertificateValidator,
107 int TimeoutMs, params KeyValuePair<string, string>[] Headers)
108 {
109 return this.GetAsync(Uri, Certificate, RemoteCertificateValidator, Headers);
110 }
111
120 public async Task<KeyValuePair<string, TemporaryStream>> GetTempStreamAsync(Uri Uri, X509Certificate Certificate,
121 RemoteCertificateEventHandler RemoteCertificateValidator, params KeyValuePair<string, string>[] Headers)
122 {
123 string SchemaName = UriToResource(Uri);
124 if (string.IsNullOrEmpty(SchemaName))
125 throw new Exception("URI not recognized.");
126
127 byte[] Bin = Resources.LoadResource(SchemaName);
129 await f.WriteAsync(Bin, 0, Bin.Length);
130
131 return new KeyValuePair<string, TemporaryStream>(XmlCodec.DefaultContentType, f);
132
133 }
134
144 public Task<KeyValuePair<string, TemporaryStream>> GetTempStreamAsync(Uri Uri, X509Certificate Certificate,
145 RemoteCertificateEventHandler RemoteCertificateValidator, int TimeoutMs, params KeyValuePair<string, string>[] Headers)
146 {
147 return this.GetTempStreamAsync(Uri, Certificate, RemoteCertificateValidator, Headers);
148 }
149
156 public bool CanHead(Uri Uri, out Grade Grade)
157 {
158 Grade = Grade.NotAtAll;
159 return false;
160 }
161
170 public Task<object> HeadAsync(Uri Uri, X509Certificate Certificate, RemoteCertificateEventHandler RemoteCertificateValidator,
171 params KeyValuePair<string, string>[] Headers)
172 {
173 return Task.FromResult<object>(null);
174 }
175
185 public Task<object> HeadAsync(Uri Uri, X509Certificate Certificate, RemoteCertificateEventHandler RemoteCertificateValidator,
186 int TimeoutMs, params KeyValuePair<string, string>[] Headers)
187 {
188 return Task.FromResult<object>(null);
189 }
190 }
191}
Static class managing loading of resources stored as embedded resources or in content files.
Definition: Resources.cs:15
static byte[] LoadResource(string ResourceName)
Loads a resource from an embedded resource.
Definition: Resources.cs:61
XML encoder/decoder.
Definition: XmlCodec.cs:16
const string DefaultContentType
Default content type for XML documents.
Definition: XmlCodec.cs:27
Static class managing loading of XSL resources stored as embedded resources or in content files.
Definition: XSL.cs:15
static XmlSchema LoadSchema(string ResourceName)
Loads an XML schema from an embedded resource.
Definition: XSL.cs:23
bool CanGet(Uri Uri, out Grade Grade)
If the getter is able to get a resource, given its URI.
async Task< KeyValuePair< string, TemporaryStream > > GetTempStreamAsync(Uri Uri, X509Certificate Certificate, RemoteCertificateEventHandler RemoteCertificateValidator, params KeyValuePair< string, string >[] Headers)
Gets a (possibly big) resource, using a Uniform Resource Identifier (or Locator).
Task< KeyValuePair< string, TemporaryStream > > GetTempStreamAsync(Uri Uri, X509Certificate Certificate, RemoteCertificateEventHandler RemoteCertificateValidator, int TimeoutMs, params KeyValuePair< string, string >[] Headers)
Gets a (possibly big) resource, using a Uniform Resource Identifier (or Locator).
Task< object > HeadAsync(Uri Uri, X509Certificate Certificate, RemoteCertificateEventHandler RemoteCertificateValidator, params KeyValuePair< string, string >[] Headers)
Gets the headers of a resource, using a Uniform Resource Identifier (or Locator).
bool CanHead(Uri Uri, out Grade Grade)
If the getter is able to get headers of a resource, given its URI.
Task< object > GetAsync(Uri Uri, X509Certificate Certificate, RemoteCertificateEventHandler RemoteCertificateValidator, params KeyValuePair< string, string >[] Headers)
Gets a resource, using a Uniform Resource Identifier (or Locator).
ContractSchemasGetter()
Getter for well-known contract schemas.
Task< object > HeadAsync(Uri Uri, X509Certificate Certificate, RemoteCertificateEventHandler RemoteCertificateValidator, int TimeoutMs, params KeyValuePair< string, string >[] Headers)
Gets the headers of a resource, using a Uniform Resource Identifier (or Locator).
Task< object > GetAsync(Uri Uri, X509Certificate Certificate, RemoteCertificateEventHandler RemoteCertificateValidator, int TimeoutMs, params KeyValuePair< string, string >[] Headers)
Gets a resource, using a Uniform Resource Identifier (or Locator).
Manages a temporary stream. Contents is kept in-memory, if below a memory threshold,...
override async Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
Asynchronously writes a sequence of bytes to the current stream, advances the current position within...
Basic interface for Internet Content getters. A class implementing this interface and having a defaul...
Basic interface for Internet Content headers. A class implementing this interface and having a defaul...
delegate void RemoteCertificateEventHandler(object Sender, RemoteCertificateEventArgs e)
Delegate for remote certificate event handlers.
Grade
Grade enumeration
Definition: Grade.cs:7