Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
GetDescription.cs
1using System;
2using System.Collections.Generic;
3using System.Threading.Tasks;
4using System.Xml;
5using Waher.Content;
9using Waher.Script;
13
15{
20 {
25 : base("Tokens/GetDescription",
26 new KeyValuePair<Type, Expression>(typeof(Dictionary<string, object>), new Expression(jsonPattern)),
27 new KeyValuePair<Type, Expression>(typeof(XmlDocument), new Expression(xmlPattern)))
28 {
29 }
30
31 private static readonly string jsonPattern = Resources.LoadResourceAsText(typeof(GetDescription).Namespace + ".JSON.GetDescription.req");
32 private static readonly string xmlPattern = Resources.LoadResourceAsText(typeof(GetDescription).Namespace + ".XML.GetDescription.req");
33
42 public override async Task POST(HttpRequest Request, HttpResponse Response, Dictionary<string, IElement> Parameters)
43 {
45 string TokenId = (string)Parameters["PTokenId"].AssociatedObjectValue;
46 string ReportFormatStr = (string)Parameters["PReportFormat"].AssociatedObjectValue;
47
48 if (!Enum.TryParse(ReportFormatStr, out ReportFormat ReportFormat))
49 throw new BadRequestException("Invalid report format.");
50
51 string BareJid = User.UserName + "@" + Gateway.Domain;
52
53 Token Token = await NeuroFeaturesProcessor.GetToken(TokenId, true)
54 ?? throw new NotFoundException("Token not found.");
55
56 await GetToken.AssertAuthorization(Token, new XmppAddress(BareJid));
57
58 string Report = await NeuroFeaturesProcessor.GetDescription(Token, ReportFormat);
59
60 await Response.Return(new NamedDictionary<string, object>("ReportResult", AgentNamespace)
61 {
62 { "report", Report }
63 });
64 }
65 }
66}
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
Static class managing the runtime environment of the IoT Gateway.
Definition: Gateway.cs:126
static CaseInsensitiveString Domain
Domain name.
Definition: Gateway.cs:2354
The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repe...
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,...
The server has not found anything matching the Request-URI. No indication is given of whether the con...
Contains information about one XMPP address.
Definition: XmppAddress.cs:9
Class managing a script expression.
Definition: Expression.cs:39
Marketplace processor, brokering sales of items via tenders and offers defined in smart contracts.
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
override async Task POST(HttpRequest Request, HttpResponse Response, Dictionary< string, IElement > Parameters)
Executes the POST method on the resource.
ReportFormat
Desired report format
Definition: ReportFormat.cs:7