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;
3using System.Text;
4using System.Threading.Tasks;
5using System.Xml;
6using Waher.Content;
12using Waher.Script;
18
20{
25 {
30 : base("StateMachines/GetCurrentState",
31 new KeyValuePair<Type, Expression>(typeof(Dictionary<string, object>), new Expression(jsonPattern)),
32 new KeyValuePair<Type, Expression>(typeof(XmlDocument), new Expression(xmlPattern)))
33 {
34 }
35
36 private static readonly string jsonPattern = Resources.LoadResourceAsText(typeof(GetCurrentState).Namespace + ".JSON.GetCurrentState.req");
37 private static readonly string xmlPattern = Resources.LoadResourceAsText(typeof(GetCurrentState).Namespace + ".XML.GetCurrentState.req");
38
47 public override async Task POST(HttpRequest Request, HttpResponse Response, Dictionary<string, IElement> Parameters)
48 {
50 string TokenId = (string)Parameters["PTokenId"].AssociatedObjectValue;
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(Request, Token, new XmppAddress(BareJid));
57
58 StateMachineProcessor.CacheRecord Record = await StateMachineProcessor.GetStateMachine(Token.MachineId, false)
59 ?? throw new NotFoundException("State-Machine not found.");
60
61 StringBuilder Xml = new StringBuilder();
62 await StateMachineProcessor.Export(Record.CurrentState, Xml);
63
64 XmlDocument Doc = XML.ParseXml(Xml.ToString(), true);
65
66 await Response.Return(new NamedDictionary<string, object>("StateResult", AgentNamespace)
67 {
68 { "CurrentState", Doc }
69 });
70 }
71 }
72}
A Named dictionary is a dictionary, with a local name and a namespace. Use it to return content that ...
Helps with common XML-related tasks.
Definition: XML.cs:21
static XmlDocument ParseXml(string Xml)
Parses an XML Document from its string representation.
Definition: XML.cs:713
Static class managing the runtime environment of the IoT Gateway.
Definition: Gateway.cs:147
static CaseInsensitiveString Domain
Domain name.
Definition: Gateway.cs:3087
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.
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
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
Marketplace processor, brokering sales of items via tenders and offers defined in smart contracts.
CaseInsensitiveString MachineId
State Machine ID, if any
Definition: Token.cs:163
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.