3using System.Threading.Tasks;
54 StringBuilder Xml =
new StringBuilder();
56 Xml.Append(
"<newToken xmlns='");
58 Xml.Append(
"' service='");
59 Xml.Append(Service.ToString());
60 Xml.Append(
"' clientType='");
62 Xml.Append(
"' token='");
66 return this.
client.
SendIqSet(
string.Empty, Xml.ToString(), Callback, State);
77 TaskCompletionSource<bool> Result =
new TaskCompletionSource<bool>();
82 Result.TrySetResult(
true);
84 Result.TrySetException(e.StanzaError ??
new Exception(
"Unable to report new token."));
86 return Task.CompletedTask;
101 public Task
RemoveToken(EventHandlerAsync<IqResultEventArgs> Callback,
object State)
103 StringBuilder Xml =
new StringBuilder();
105 Xml.Append(
"<removeToken xmlns='");
109 return this.
client.
SendIqSet(
string.Empty, Xml.ToString(), Callback, State);
117 TaskCompletionSource<bool> Result =
new TaskCompletionSource<bool>();
122 Result.TrySetResult(
true);
124 Result.TrySetException(e.StanzaError ??
new Exception(
"Unable to remove token."));
126 return Task.CompletedTask;
141 public Task
ClearRules(EventHandlerAsync<IqResultEventArgs> Callback,
object State)
143 StringBuilder Xml =
new StringBuilder();
145 Xml.Append(
"<clearRules xmlns='");
149 return this.
client.
SendIqSet(
string.Empty, Xml.ToString(), Callback, State);
157 TaskCompletionSource<bool> Result =
new TaskCompletionSource<bool>();
162 Result.TrySetResult(
true);
164 Result.TrySetException(e.StanzaError ??
new Exception(
"Unable to clear available rules."));
166 return Task.CompletedTask;
174 #region Add Push Notification Rule
198 string PatternMatchingScript,
string ContentScript, EventHandlerAsync<IqResultEventArgs> Callback,
object State)
200 StringBuilder Xml =
new StringBuilder();
202 Xml.Append(
"<addRule xmlns='");
204 Xml.Append(
"' type='");
209 Xml.Append(
"' localName='");
211 Xml.Append(
"' namespace='");
213 Xml.Append(
"' channel='");
215 Xml.Append(
"' variable='");
219 if (!
string.IsNullOrEmpty(PatternMatchingScript))
221 Xml.Append(
"<PatternMatching>");
222 Xml.Append(
XML.
Encode(PatternMatchingScript));
223 Xml.Append(
"</PatternMatching>");
226 if (!
string.IsNullOrEmpty(ContentScript))
228 Xml.Append(
"<Content>");
230 Xml.Append(
"</Content>");
233 Xml.Append(
"</addRule>");
235 return this.
client.
SendIqSet(
string.Empty, Xml.ToString(), Callback, State);
258 string PatternMatchingScript,
string ContentScript)
260 TaskCompletionSource<bool> Result =
new TaskCompletionSource<bool>();
262 await this.
AddRule(MessageType, LocalName, Namespace, Channel, MessageVariable, PatternMatchingScript, ContentScript, (Sender, e) =>
265 Result.TrySetResult(
true);
267 Result.TrySetException(e.StanzaError ??
new Exception(
"Unable to add push notification rule."));
269 return Task.CompletedTask;
277 #region Remove Push Notification Rule
289 StringBuilder Xml =
new StringBuilder();
291 Xml.Append(
"<removeRule xmlns='");
293 Xml.Append(
"' type='");
298 Xml.Append(
"' localName='");
300 Xml.Append(
"' namespace='");
304 return this.
client.
SendIqSet(
string.Empty, Xml.ToString(), Callback, State);
315 TaskCompletionSource<bool> Result =
new TaskCompletionSource<bool>();
317 await this.
RemoveRule(MessageType, LocalName, Namespace, (Sender, e) =>
320 Result.TrySetResult(
true);
322 Result.TrySetException(e.StanzaError ??
new Exception(
"Unable to remove push notification rule."));
324 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.
override void Dispose()
Disposes of the extension.
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.
Task 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.