Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
TokenNotificationEvent.cs
3using NeuroFeatures;
4using System.Text;
5using System.Xml;
8using Microsoft.Maui.Controls.Shapes;
11
13{
18 {
19 private Token? token;
20 private Task<Token?>? tokenParseTask;
21
26 : base()
27 {
28 }
29
35 : base(e)
36 {
37 this.TokenId = e.Token.TokenId;
38 this.FriendlyName = e.Token.FriendlyName;
39 this.TokenCategory = e.Token.Category;
40 this.token = e.Token;
41 this.Category = e.Token.TokenId;
42
43 StringBuilder Xml = new();
44 e.Token.Serialize(Xml);
45 this.TokenXml = Xml.ToString();
46 }
47
53 : base(e)
54 {
55 this.TokenId = e.TokenId;
56 this.token = null;
57 this.TokenXml = null;
58 this.Category = e.TokenId;
59 }
60
64 public string? TokenId { get; set; }
65
69 public string? TokenCategory { get; set; }
70
74 public string? FriendlyName { get; set; }
75
79 public string? TokenXml { get; set; }
80
84 [IgnoreMember]
85 public Token? Token
86 {
87 get => this.token;
88
89 set
90 {
91 this.token = value;
92 this.tokenParseTask = null;
93
94 if (value is null)
95 this.TokenXml = null;
96 else
97 {
98 StringBuilder Xml = new();
99 value.Serialize(Xml);
100 this.TokenXml = Xml.ToString();
101 }
102 }
103 }
104
109 public async Task<Token?> GetTokenAsync()
110 {
111 if (this.token is not null)
112 return this.token;
113
114 if (string.IsNullOrEmpty(this.TokenXml))
115 return null;
116
117 if (this.tokenParseTask is null)
118 this.tokenParseTask = this.ParseTokenAsync();
119
120 Token? ParsedToken = await this.tokenParseTask;
121 if (ParsedToken is not null)
122 this.token = ParsedToken;
123
124 return this.token;
125 }
126
127 private async Task<Token?> ParseTokenAsync()
128 {
129 if (string.IsNullOrEmpty(this.TokenXml))
130 return null;
131
132 XmlDocument Doc = new()
133 {
134 PreserveWhitespace = true
135 };
136 Doc.LoadXml(this.TokenXml);
137
138 return await Token.TryParse(Doc.DocumentElement);
139 }
140
145 public override Task<Geometry> GetCategoryIcon()
146 {
147 return Task.FromResult(Geometries.TokenIconPath);
148 }
149
153 public override Task<string> GetDescription()
154 {
155 if (!string.IsNullOrEmpty(this.FriendlyName))
156 return Task.FromResult(this.FriendlyName);
157 else if (!string.IsNullOrEmpty(this.TokenCategory))
158 return Task.FromResult(this.TokenCategory);
159 else
160 return Task.FromResult(this.TokenId ?? string.Empty);
161 }
162
166 public override async Task Open()
167 {
168 if (string.IsNullOrEmpty(this.TokenId))
169 return;
170
171 Token? Token = await this.GetTokenAsync();
172 if (Token is null)
173 {
174 Token = await ServiceRef.XmppService.GetNeuroFeature(this.TokenId);
175 this.token = Token;
176 }
177
178 if (Token is null)
179 return;
180
181 if (!ServiceRef.NotificationService.TryGetNotificationEvents(NotificationEventType.Wallet, this.TokenId, out NotificationEvent[]? Events))
182 Events = [];
183
184 TokenDetailsNavigationArgs Args = new(new TokenItem(Token, Events));
185
187 }
188 }
189}
TokenNotificationEvent(TokenEventArgs e)
Abstract base class for token notification events.
override Task< Geometry > GetCategoryIcon()
Gets an icon for the category of event.
async Task< Token?> GetTokenAsync()
Gets the parsed token asynchronously, using cached XML if available.
TokenNotificationEvent(StateMachineEventArgs e)
Abstract base class for token notification events.
TokenNotificationEvent()
Abstract base class for token notification events.
override Task< string > GetDescription()
Gets a descriptive text for the event.
Base class that references services in the app.
Definition: ServiceRef.cs:43
static INavigationService NavigationService
The navigation service for navigating between pages.
Definition: ServiceRef.cs:178
static INotificationService NotificationService
Service for managing notifications for the user.
Definition: ServiceRef.cs:334
static IXmppService XmppService
The XMPP service for XMPP communication.
Definition: ServiceRef.cs:190
Static class containing SVG Paths for symbols used in the app.
Definition: Geometries.cs:11
static readonly Geometry TokenIconPath
Token symbol for QR codes
Definition: Geometries.cs:461
A page that allows the user to view information about a token.
Event arguments for state-machine events.
Event arguments for token events.
Neuro-Feature Token
Definition: Token.cs:46
string Category
A category for the token.
Definition: Token.cs:468
static async Task< Token > TryParse(XmlElement Xml)
Tries to parse a Token.
Definition: Token.cs:555
string FriendlyName
A friendly name for the token.
Definition: Token.cs:459
string TokenId
Token ID
Definition: Token.cs:116
void Serialize(StringBuilder Xml)
Serializes the Token, in normalized form.
Definition: Token.cs:997
Task GoToAsync(string Route)
Navigates to the specified route and pushes the page onto the navigation stack.
abstract class NotificationEvent()
Abstract base class of notification events.
NotificationEventType
Button on which event is to be displayed.
BackMethod
Navigation Back Method
Definition: BackMethod.cs:7