Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ReadoutRequestResolver.cs
1using System.Globalization;
6
8{
13 {
14 private readonly string bareJid;
15 private readonly string remoteJid;
16 private readonly RuleRange range;
17 private readonly ProvisioningToken? token;
18
22 public ReadoutRequestResolver(string BareJid, string RemoteJid, RuleRange Range)
23 {
24 this.bareJid = BareJid.ToLower(CultureInfo.InvariantCulture);
25 this.remoteJid = RemoteJid.ToLower(CultureInfo.InvariantCulture);
26 this.range = Range;
27 this.token = null;
28 }
29
33 public ReadoutRequestResolver(string BareJid, string RemoteJid, ProvisioningToken Token)
34 {
35 this.bareJid = BareJid.ToLower(CultureInfo.InvariantCulture);
36 this.remoteJid = RemoteJid.ToLower(CultureInfo.InvariantCulture);
37 this.range = default;
38 this.token = Token;
39 }
40
46 public bool Resolves(NotificationEvent Event)
47 {
48 if (Event.Type != NotificationEventType.Things || Event is not CanReadNotificationEvent CanReadNotificationEvent)
49 return false;
50
51 if (CanReadNotificationEvent.BareJid != this.bareJid)
52 return false;
53
54 if (this.token is null)
55 {
56 return this.range switch
57 {
58 RuleRange.All => true,
59 RuleRange.Domain => string.Equals(XmppClient.GetDomain(this.remoteJid), XmppClient.GetDomain(CanReadNotificationEvent.RemoteJid), StringComparison.OrdinalIgnoreCase),
60 RuleRange.Caller => string.Equals(this.remoteJid, CanReadNotificationEvent.RemoteJid?.ToLower(CultureInfo.InvariantCulture), StringComparison.OrdinalIgnoreCase),
61 _ => false,
62 };
63 }
64 else
65 {
66 return this.token.Type switch
67 {
68 TokenType.User => this.IsResolved(CanReadNotificationEvent.UserTokens),
69 TokenType.Service => this.IsResolved(CanReadNotificationEvent.ServiceTokens),
70 TokenType.Device => this.IsResolved(CanReadNotificationEvent.DeviceTokens),
71 _ => false,
72 };
73 }
74 }
75
76 private bool IsResolved(ProvisioningToken[]? Tokens)
77 {
78 if (Tokens is null)
79 return false;
80
81 foreach (ProvisioningToken Token in Tokens)
82 {
83 if (Token.Token == this.token?.Token)
84 return true;
85 }
86
87 return false;
88 }
89
90 }
91}
ReadoutRequestResolver(string BareJid, string RemoteJid, RuleRange Range)
Resolves pending readout requests
bool Resolves(NotificationEvent Event)
If the resolver resolves an event.
ReadoutRequestResolver(string BareJid, string RemoteJid, ProvisioningToken Token)
Resolves pending readout requests
Manages an XMPP client connection. Implements XMPP, as defined in https://tools.ietf....
Definition: XmppClient.cs:59
static string GetDomain(string JID)
Gets the domain part of a JID.
Definition: XmppClient.cs:6929
Interface for event resolvers. Such can be used to resolve multiple pending notifications at once.
abstract class NotificationEvent()
Abstract base class of notification events.
NotificationEventType
Button on which event is to be displayed.
RuleRange
Range of a rule change
Definition: RuleRange.cs:7