Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
GetCurrentState.cs
1using System;
2using System.Collections.Generic;
3using System.Text;
4using System.Threading.Tasks;
5using System.Xml;
6using Waher.Content;
10using Waher.Script;
16
18{
23 {
28 : base("StateMachines/GetCurrentState",
29 new KeyValuePair<Type, Expression>(typeof(Dictionary<string, object>), new Expression(jsonPattern)),
30 new KeyValuePair<Type, Expression>(typeof(XmlDocument), new Expression(xmlPattern)))
31 {
32 }
33
34 private static readonly string jsonPattern = Resources.LoadResourceAsText(typeof(GetCurrentState).Namespace + ".JSON.GetCurrentState.req");
35 private static readonly string xmlPattern = Resources.LoadResourceAsText(typeof(GetCurrentState).Namespace + ".XML.GetCurrentState.req");
36
45 public override async Task POST(HttpRequest Request, HttpResponse Response, Dictionary<string, IElement> Parameters)
46 {
48 string TokenId = (string)Parameters["PTokenId"].AssociatedObjectValue;
49 string BareJid = User.UserName + "@" + Gateway.Domain;
50
51 Token Token = await NeuroFeaturesProcessor.GetToken(TokenId, true)
52 ?? throw new NotFoundException("Token not found.");
53
54 await GetToken.AssertAuthorization(Token, new XmppAddress(BareJid));
55
56 StateMachineProcessor.CacheRecord Record = await StateMachineProcessor.GetStateMachine(Token.MachineId)
57 ?? throw new NotFoundException("State-Machine not found.");
58
59 StringBuilder Xml = new StringBuilder();
60 StateMachineProcessor.Export(Record.CurrentState, Xml);
61
62 XmlDocument Doc = new XmlDocument()
63 {
64 PreserveWhitespace = true
65 };
66 Doc.LoadXml(Xml.ToString());
67
68 await Response.Return(new NamedDictionary<string, object>("StateResult", AgentNamespace)
69 {
70 { "CurrentState", Doc }
71 });
72 }
73 }
74}
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
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.
CaseInsensitiveString MachineId
State Machine ID, if any
Definition: Token.cs:157
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.