3using System.Threading.Tasks;
32 public override string[]
Extensions => Array.Empty<
string>();
46 StringBuilder Xml =
new StringBuilder();
48 Xml.Append(
"<newToken xmlns='");
50 Xml.Append(
"' service='");
51 Xml.Append(Service.ToString());
52 Xml.Append(
"' clientType='");
54 Xml.Append(
"' token='");
58 return this.
client.
SendIqSet(
string.Empty, Xml.ToString(), Callback, State);
69 TaskCompletionSource<bool> Result =
new TaskCompletionSource<bool>();
74 Result.TrySetResult(
true);
76 Result.TrySetException(e.StanzaError ??
new Exception(
"Unable to report new token."));
78 return Task.CompletedTask;
93 public Task
RemoveToken(EventHandlerAsync<IqResultEventArgs> Callback,
object State)
95 StringBuilder Xml =
new StringBuilder();
97 Xml.Append(
"<removeToken xmlns='");
101 return this.
client.
SendIqSet(
string.Empty, Xml.ToString(), Callback, State);
109 TaskCompletionSource<bool> Result =
new TaskCompletionSource<bool>();
114 Result.TrySetResult(
true);
116 Result.TrySetException(e.StanzaError ??
new Exception(
"Unable to remove token."));
118 return Task.CompletedTask;
133 public Task
ClearRules(EventHandlerAsync<IqResultEventArgs> Callback,
object State)
135 StringBuilder Xml =
new StringBuilder();
137 Xml.Append(
"<clearRules xmlns='");
141 return this.
client.
SendIqSet(
string.Empty, Xml.ToString(), Callback, State);
149 TaskCompletionSource<bool> Result =
new TaskCompletionSource<bool>();
154 Result.TrySetResult(
true);
156 Result.TrySetException(e.StanzaError ??
new Exception(
"Unable to clear available rules."));
158 return Task.CompletedTask;
166 #region Add Push Notification Rule
190 string PatternMatchingScript,
string ContentScript, EventHandlerAsync<IqResultEventArgs> Callback,
object State)
192 StringBuilder Xml =
new StringBuilder();
194 Xml.Append(
"<addRule xmlns='");
196 Xml.Append(
"' type='");
201 Xml.Append(
"' localName='");
203 Xml.Append(
"' namespace='");
205 Xml.Append(
"' channel='");
207 Xml.Append(
"' variable='");
211 if (!
string.IsNullOrEmpty(PatternMatchingScript))
213 Xml.Append(
"<PatternMatching>");
214 Xml.Append(
XML.
Encode(PatternMatchingScript));
215 Xml.Append(
"</PatternMatching>");
218 if (!
string.IsNullOrEmpty(ContentScript))
220 Xml.Append(
"<Content>");
222 Xml.Append(
"</Content>");
225 Xml.Append(
"</addRule>");
227 return this.
client.
SendIqSet(
string.Empty, Xml.ToString(), Callback, State);
250 string PatternMatchingScript,
string ContentScript)
252 TaskCompletionSource<bool> Result =
new TaskCompletionSource<bool>();
254 await this.
AddRule(MessageType, LocalName, Namespace, Channel, MessageVariable, PatternMatchingScript, ContentScript, (Sender, e) =>
257 Result.TrySetResult(
true);
259 Result.TrySetException(e.StanzaError ??
new Exception(
"Unable to add push notification rule."));
261 return Task.CompletedTask;
269 #region Remove Push Notification Rule
281 StringBuilder Xml =
new StringBuilder();
283 Xml.Append(
"<removeRule xmlns='");
285 Xml.Append(
"' type='");
290 Xml.Append(
"' localName='");
292 Xml.Append(
"' namespace='");
296 return this.
client.
SendIqSet(
string.Empty, Xml.ToString(), Callback, State);
307 TaskCompletionSource<bool> Result =
new TaskCompletionSource<bool>();
309 await this.
RemoveRule(MessageType, LocalName, Namespace, (Sender, e) =>
312 Result.TrySetResult(
true);
314 Result.TrySetException(e.StanzaError ??
new Exception(
"Unable to remove push notification rule."));
316 return Task.CompletedTask;
Helps with common XML-related tasks.
static string Encode(string s)
Encodes a string for use in XML.
async Task NewTokenAsync(string Token, PushMessagingService Service, ClientType ClientType)
Reports a new push token to the server.
Task RemoveRule(MessageType MessageType, string LocalName, string Namespace, EventHandlerAsync< IqResultEventArgs > Callback, object State)
Removes a push notification rule from the client account.
override string[] Extensions
Implemented extensions.
PushNotificationClient(XmppClient Client)
Push Notification Client
Task ClearRules(EventHandlerAsync< IqResultEventArgs > Callback, object State)
Clears available push notification rules for the client.
Task AddRule(MessageType MessageType, string LocalName, string Namespace, string Channel, string MessageVariable, string PatternMatchingScript, string ContentScript, EventHandlerAsync< IqResultEventArgs > Callback, object State)
Adds a push notification rule to the client account.
const string MessagePushNamespace
http://waher.se/Schema/PushNotification.xsd
async Task RemoveTokenAsync()
Removes the last push token from the server.
Task RemoveToken(EventHandlerAsync< IqResultEventArgs > Callback, object State)
Removes the last push token from the server.
async Task AddRuleAsync(MessageType MessageType, string LocalName, string Namespace, string Channel, string MessageVariable, string PatternMatchingScript, string ContentScript)
Adds a push notification rule to the client account.
async Task RemoveRuleAsync(MessageType MessageType, string LocalName, string Namespace)
Removes a push notification rule from the client account.
async Task ClearRulesAsync()
Clears available push notification rules for the client.
Task NewToken(string Token, PushMessagingService Service, ClientType ClientType, EventHandlerAsync< IqResultEventArgs > Callback, object State)
Reports a new push token to the server.
Manages an XMPP client connection. Implements XMPP, as defined in https://tools.ietf....
Task< uint > SendIqSet(string To, string Xml, EventHandlerAsync< IqResultEventArgs > Callback, object State)
Sends an IQ Set request.
Base class for XMPP Extensions.
XmppClient client
XMPP Client used by the extension.
void Exception(Exception Exception)
Called to inform the viewer of an exception state.
XmppClient Client
XMPP Client.
ClientType
Type of client requesting notification.
PushMessagingService
Push messaging service used.
MessageType
Type of message received.