Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
RegisterEventHandler.cs
1using System;
3using System.Threading.Tasks;
4using System.Xml;
5using Waher.Content;
9using Waher.Script;
12
14{
21 {
28 : base("Xmpp/RegisterEventHandler",
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(PresenceProbe).Namespace + ".JSON.RegisterEventHandler.req");
35 private static readonly string xmlPattern = Resources.LoadResourceAsText(typeof(PresenceProbe).Namespace + ".XML.RegisterEventHandler.req");
36
45 public override Task POST(HttpRequest Request, HttpResponse Response, Dictionary<string, IElement> Parameters)
46 {
48 string LocalName = (string)Parameters["PLocalName"]?.AssociatedObjectValue;
49 string Namespace = (string)Parameters["PNamespace"]?.AssociatedObjectValue;
50 string Type = (string)Parameters["PType"]?.AssociatedObjectValue;
51 string Function = (string)Parameters["PFunction"]?.AssociatedObjectValue;
52 string TabId = (string)Parameters["PTabId"].AssociatedObjectValue;
53 string BareJid = User.UserName + "@" + (Gateway.Domain?.Value ?? string.Empty);
54
55 if (string.IsNullOrEmpty(LocalName))
56 throw new BadRequestException("Local Name not defined.");
57
58 if (string.IsNullOrEmpty(Namespace))
59 throw new BadRequestException("Namespace not defined.");
60
61 PersistenceLayer.RegisterEventsTab(BareJid, Type, LocalName, Namespace, Function, TabId);
62
63 return Response.Return(new NamedDictionary<string, object>("EventHandlerRegistered", AgentNamespace));
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 the runtime environment of the IoT Gateway.
Definition: Gateway.cs:147
static CaseInsensitiveString Domain
Domain name.
Definition: Gateway.cs:3087
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: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
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
Abstract base class for XMPP resources.
Performs a presence probe on one of the contacts to which the account has an approved presence subscr...
Registers an event handler for a specific type of message. If such an XMPP message is received,...
override Task POST(HttpRequest Request, HttpResponse Response, Dictionary< string, IElement > Parameters)
Executes the POST method on the resource.
RegisterEventHandler()
Registers an event handler for a specific type of message. If such an XMPP message is received,...