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;
2using System.Collections.Generic;
3using System.Threading.Tasks;
4using System.Xml;
5using Waher.Content;
11using Waher.Script;
14
16{
23 {
30 : base("Xmpp/RegisterEventHandler",
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(PresenceProbe).Namespace + ".JSON.RegisterEventHandler.req");
37 private static readonly string xmlPattern = Resources.LoadResourceAsText(typeof(PresenceProbe).Namespace + ".XML.RegisterEventHandler.req");
38
47 public override Task POST(HttpRequest Request, HttpResponse Response, Dictionary<string, IElement> Parameters)
48 {
50 string LocalName = (string)Parameters["PLocalName"]?.AssociatedObjectValue;
51 string Namespace = (string)Parameters["PNamespace"]?.AssociatedObjectValue;
52 string Type = (string)Parameters["PType"]?.AssociatedObjectValue;
53 string Function = (string)Parameters["PFunction"]?.AssociatedObjectValue;
54 string TabId = (string)Parameters["PTabId"].AssociatedObjectValue;
55 string BareJid = User.UserName + "@" + (Gateway.Domain?.Value ?? string.Empty);
56
57 if (string.IsNullOrEmpty(LocalName))
58 throw new BadRequestException("Local Name not defined.");
59
60 if (string.IsNullOrEmpty(Namespace))
61 throw new BadRequestException("Namespace not defined.");
62
63 PersistenceLayer.RegisterEventsTab(BareJid, Type, LocalName, Namespace, Function, TabId);
64
65 return Response.Return(new NamedDictionary<string, object>("EventHandlerRegistered", AgentNamespace));
66 }
67 }
68}
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,...
Class managing a script expression.
Definition: Expression.cs:39
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,...