Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ValidatePNr.cs
1using System;
3using System.Threading.Tasks;
4using System.Xml;
5using Waher.Content;
9using Waher.Script;
12
14{
19 {
23 public ValidatePNr()
24 : base("Legal/ValidatePNr",
25 new KeyValuePair<Type, Expression>(typeof(Dictionary<string, object>), new Expression(jsonPattern)),
26 new KeyValuePair<Type, Expression>(typeof(XmlDocument), new Expression(xmlPattern)))
27 {
28 }
29
30 private static readonly string jsonPattern = Resources.LoadResourceAsText(typeof(ValidatePNr).Namespace + ".JSON.ValidatePNr.req");
31 private static readonly string xmlPattern = Resources.LoadResourceAsText(typeof(ValidatePNr).Namespace + ".XML.ValidatePNr.req");
32
41 public override async Task POST(HttpRequest Request, HttpResponse Response, Dictionary<string, IElement> Parameters)
42 {
44
45 string CountryCode = (string)Parameters["PCountryCode"].AssociatedObjectValue;
46 string PNr = (string)Parameters["PPNr"].AssociatedObjectValue;
47
48 bool CountrySupported = PersonalNumberSchemes.Supports(CountryCode) > Grade.NotAtAll;
49 string Normalized = CountrySupported ? await PersonalNumberSchemes.Normalize(CountryCode, PNr) : null;
50 bool? Isvalid = CountrySupported ? await PersonalNumberSchemes.IsValid(CountryCode, Normalized) : null;
51
52 await Response.Return(new NamedDictionary<string, object>("ValidatePNrResponse", AgentNamespace)
53 {
54 { "countrySupported", CountrySupported },
55 { "isValid", Isvalid },
56 { "normalized", Normalized }
57 });
58 }
59
60 }
61}
A Named dictionary is a dictionary, with a local name and a namespace. Use it to return content that ...
Represents an HTTP request.
Definition: HttpRequest.cs:22
Represets a response of an HTTP client request.
Definition: HttpResponse.cs:23
Task Return(Exception ex)
Returns an error to the client.
Static class managing loading of resources stored as embedded resources or in content files.
Definition: Resources.cs:13
static string LoadResourceAsText(string ResourceName)
Loads a text resource from an embedded resource.
Definition: Resources.cs:55
Class managing a script expression.
Definition: Expression.cs:41
Abstract base class for agent resources supporting the POST method.
static AccountUser AssertUserAuthenticated(HttpRequest Request)
Makes sure the request is made by an authenticated API user.
const string AgentNamespace
https://waher.se/Schema/BrokerAgent.xsd
Grade
Grade enumeration
Definition: Grade.cs:7