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;
2using System.Collections.Generic;
3using System.Threading.Tasks;
4using System.Xml;
5using Waher.Content;
8using Waher.Script;
11
13{
18 {
22 public ValidatePNr()
23 : base("Legal/ValidatePNr",
24 new KeyValuePair<Type, Expression>(typeof(Dictionary<string, object>), new Expression(jsonPattern)),
25 new KeyValuePair<Type, Expression>(typeof(XmlDocument), new Expression(xmlPattern)))
26 {
27 }
28
29 private static readonly string jsonPattern = Resources.LoadResourceAsText(typeof(ValidatePNr).Namespace + ".JSON.ValidatePNr.req");
30 private static readonly string xmlPattern = Resources.LoadResourceAsText(typeof(ValidatePNr).Namespace + ".XML.ValidatePNr.req");
31
40 public override async Task POST(HttpRequest Request, HttpResponse Response, Dictionary<string, IElement> Parameters)
41 {
43
44 string CountryCode = (string)Parameters["PCountryCode"].AssociatedObjectValue;
45 string PNr = (string)Parameters["PPNr"].AssociatedObjectValue;
46
47 bool CountrySupported = PersonalNumberSchemes.Supports(CountryCode) > Grade.NotAtAll;
48 string Normalized = CountrySupported ? await PersonalNumberSchemes.Normalize(CountryCode, PNr) : null;
49 bool? Isvalid = CountrySupported ? await PersonalNumberSchemes.IsValid(CountryCode, Normalized) : null;
50
51 await Response.Return(new NamedDictionary<string, object>("ValidatePNrResponse", AgentNamespace)
52 {
53 { "countrySupported", CountrySupported },
54 { "isValid", Isvalid },
55 { "normalized", Normalized }
56 });
57 }
58
59 }
60}
A Named dictionary is a dictionary, with a local name and a namespace. Use it to return content that ...
Static class managing loading of resources stored as embedded resources or in content files.
Definition: Resources.cs:15
static string LoadResourceAsText(string ResourceName)
Loads a text resource from an embedded resource.
Definition: Resources.cs:96
Represents an HTTP request.
Definition: HttpRequest.cs:18
Represets a response of an HTTP client request.
Definition: HttpResponse.cs:21
async Task Return(object Object)
Returns an object to the client. This method can only be called once per response,...
Class managing a script expression.
Definition: Expression.cs:39
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