Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
TokenItem.cs
1using CommunityToolkit.Mvvm.ComponentModel;
2using CommunityToolkit.Mvvm.Input;
7using NeuroFeatures;
9using Waher.Content;
11using Waher.Security;
12
14{
18 public partial class TokenItem : ObservableObject, IUniqueItem
19 {
20 private readonly Token token;
21 private readonly TaskCompletionSource<TokenItem?>? selected;
22 private bool? @new;
23 private int nrEvents;
24 private NotificationEvent[] notificationEvents;
25
32 : this(Token, null, NotificationEvents)
33 {
34 }
35
42 public TokenItem(Token Token, TaskCompletionSource<TokenItem?>? Selected, NotificationEvent[] NotificationEvents)
43 {
44 this.token = Token;
45 this.selected = Selected;
46 this.notificationEvents = NotificationEvents;
47
48 if (this.Glyph is not null && this.GlyphContentType.StartsWith("image/", StringComparison.OrdinalIgnoreCase))
49 {
50 this.GlyphImage = ImageSource.FromStream(() => new MemoryStream(this.Glyph));
51 this.HasGlyphImage = true;
52
53 double s = 32.0 / this.token.GlyphWidth;
54 double s2 = 32.0 / this.token.GlyphHeight;
55
56 if (s2 < s)
57 s = s2;
58 else if (s > 1)
59 s = 1;
60
61 this.GlyphWidth = (int)(this.token.GlyphWidth * s + 0.5);
62 this.GlyphHeight = (int)(this.token.GlyphHeight * s + 0.5);
63 }
64 else
65 {
66 this.GlyphImage = null;
67 this.HasGlyphImage = false;
68 this.GlyphWidth = 0;
69 this.GlyphHeight = 0;
70 }
71 }
72
76 public Token Token => this.token;
77
79 public string UniqueName => this.token.TokenId;
80
84 public DateTime Created => this.token.Created;
85
89 public DateTime Updated => this.token.Updated;
90
94 public DateTime Expires => this.token.Expires;
95
99 public Duration? ArchiveRequired => this.token.ArchiveRequired;
100
104 public Duration? ArchiveOptional => this.token.ArchiveOptional;
105
109 public DateTime SignatureTimestamp => this.token.SignatureTimestamp;
110
114 public byte[] Signature => this.token.Signature;
115
119 public byte[] DefinitionSchemaDigest => this.token.DefinitionSchemaDigest;
120
124 public HashFunction DefinitionSchemaHashFunction => this.token.DefinitionSchemaHashFunction;
125
129 public bool CreatorCanDestroy => this.token.CreatorCanDestroy;
130
134 public bool OwnerCanDestroyBatch => this.token.OwnerCanDestroyBatch;
135
139 public bool OwnerCanDestroyIndividual => this.token.OwnerCanDestroyIndividual;
140
144 public bool CertifierCanDestroy => this.token.CertifierCanDestroy;
145
149 public string FriendlyName => this.token.FriendlyName;
150
154 public string Category => this.token.Category;
155
159 public string Description => this.token.Description;
160
164 public byte[] Glyph => this.token.Glyph;
165
169 public string GlyphContentType => this.token.GlyphContentType;
170
174 public int Ordinal => this.token.Ordinal;
175
179 public decimal Value => this.token.Value;
180
184 public string[] Witness => this.token.Witness;
185
189 public string[] CertifierJids => this.token.CertifierJids;
190
194 public string[] Certifier => this.token.Certifier;
195
199 public TokenIdMethod TokenIdMethod => this.token.TokenIdMethod;
200
204 public string TokenId => this.token.TokenId;
205
209 public string ShortTokenId => this.token.ShortId;
210
214 public ContractVisibility Visibility => this.token.Visibility;
215
219 public string Creator => this.token.Creator;
220
224 public string CreatorJid => this.token.CreatorJid;
225
229 public string Owner => this.token.Owner;
230
234 public int BatchSize => this.token.BatchSize;
235
239 public string TrustProvider => this.token.TrustProvider;
240
244 public string OwnerJid => this.token.OwnerJid;
245
249 public string Currency => this.token.Currency;
250
254 public string Reference => this.token.Reference;
255
259 public string Definition => this.token.Definition;
260
264 public string DefinitionNamespace => this.token.DefinitionNamespace;
265
269 public string CreationContract => this.token.CreationContract;
270
274 public string OwnershipContract => this.token.OwnershipContract;
275
279 public string[] Valuator => this.token.Valuator;
280
284 public string[] Assessor => this.token.Assessor;
285
289 public string TrustProviderJid => this.token.TrustProviderJid;
290
294 public TokenTag[] Tags => this.token.Tags;
295
299 public bool HasStateMachine => this.token.HasStateMachine;
300
304 [ObservableProperty]
305 private ImageSource? glyphImage;
306
310 [ObservableProperty]
311 private bool hasGlyphImage;
312
316 [ObservableProperty]
317 private int glyphWidth;
318
322 [ObservableProperty]
323 private int glyphHeight;
324
328 public NotificationEvent[] NotificationEvents => this.notificationEvents;
329
333 public int NrEvents
334 {
335 get
336 {
337 this.CheckEvents();
338
339 return this.nrEvents;
340 }
341 }
342
346 public bool New
347 {
348 get
349 {
350 this.CheckEvents();
351
352 return this.@new ?? false;
353 }
354 }
355
356 private void CheckEvents()
357 {
358 if (!this.@new.HasValue)
359 {
360 this.nrEvents = this.notificationEvents.Length;
361 this.@new = this.nrEvents > 0;
362
363 if (this.@new.Value)
364 {
365 NotificationEvent[] ToDelete = this.notificationEvents;
366
367 this.notificationEvents = [];
368
369 Task.Run(() => ServiceRef.NotificationService.DeleteEvents(ToDelete));
370 }
371 }
372 }
373
377 [RelayCommand]
378 private async Task Clicked()
379 {
380 if (this.selected is null)
381 {
382 TokenDetailsNavigationArgs Args = new(this);
383
384 await ServiceRef.UiService.GoToAsync(nameof(TokenDetailsPage), Args, BackMethod.Pop);
385 }
386 else
387 {
388 this.selected.TrySetResult(this);
390 }
391 }
392 }
393}
Base class that references services in the app.
Definition: ServiceRef.cs:31
static IUiService UiService
Service serializing and managing UI-related tasks.
Definition: ServiceRef.cs:55
static INotificationService NotificationService
Service for managing notifications for the user.
Definition: ServiceRef.cs:211
string UniqueName
Unique name used to compare items.
Definition: TokenItem.cs:79
HashFunction DefinitionSchemaHashFunction
Hash function used to compute DefinitionSchemaDigest.
Definition: TokenItem.cs:124
Duration? ArchiveRequired
Required archiving time after token expires.
Definition: TokenItem.cs:99
string DefinitionNamespace
XML Namespace used in the Definition
Definition: TokenItem.cs:264
string CreationContract
Contract used to create the contract.
Definition: TokenItem.cs:269
bool OwnerCanDestroyBatch
If the owner can destroy the entire batch of tokens, if owner of every token in the batch.
Definition: TokenItem.cs:134
string Description
Description engraved into the token.
Definition: TokenItem.cs:159
TokenTag[] Tags
Any custom Token Tags provided during creation of the token.
Definition: TokenItem.cs:294
string TrustProvider
Trust Provider asserting the validity of the token
Definition: TokenItem.cs:239
int BatchSize
Number of tokens in batch being created.
Definition: TokenItem.cs:234
NotificationEvent[] NotificationEvents
Associated notification events
Definition: TokenItem.cs:328
byte[] DefinitionSchemaDigest
Digest of schema used to validate token definition XML.
Definition: TokenItem.cs:119
Duration? ArchiveOptional
Optional archiving time after required archiving time.
Definition: TokenItem.cs:104
string Reference
Any reference provided by the token creator.
Definition: TokenItem.cs:254
int NrEvents
Number of notification events recorded for the item.
Definition: TokenItem.cs:334
bool OwnerCanDestroyIndividual
If the owner can destroy an individual token.
Definition: TokenItem.cs:139
bool HasStateMachine
If the token is associated with a state-machine.
Definition: TokenItem.cs:299
bool CreatorCanDestroy
If the creator can destroy the token.
Definition: TokenItem.cs:129
ContractVisibility Visibility
Visibility of token
Definition: TokenItem.cs:214
bool CertifierCanDestroy
If a certifier can destroy the token.
Definition: TokenItem.cs:144
string OwnershipContract
Contract used to define the current ownership
Definition: TokenItem.cs:274
TokenItem(Token Token, NotificationEvent[] NotificationEvents)
Encapsulates a Token object.
Definition: TokenItem.cs:31
TokenItem(Token Token, TaskCompletionSource< TokenItem?>? Selected, NotificationEvent[] NotificationEvents)
Encapsulates a Token object.
Definition: TokenItem.cs:42
A page that allows the user to view information about a token.
Abstract base class for token tag references.
Definition: TokenTag.cs:12
Neuro-Feature Token
Definition: Token.cs:43
Abstract base class of signatures
Definition: Signature.cs:10
Task DeleteEvents(NotificationEventType Type, CaseInsensitiveString Category)
Deletes events for a given button and category.
Task GoToAsync(string Route, BackMethod BackMethod=BackMethod.Inherited, string? UniqueId=null)
Navigates the AppShell to the specified route, with page arguments to match.
Task GoBackAsync(bool Animate=true)
Returns to the previous page/route.
abstract class NotificationEvent()
Abstract base class of notification events.
BackMethod
Navigation Back Method
Definition: BackMethod.cs:7
TokenIdMethod
By which mechanism the Token ID was created
Definition: Token.cs:21
ContractVisibility
Visibility types for contracts.
Definition: Enumerations.cs:58
HashFunction
Hash method enumeration.
Definition: Hashes.cs:28
Represents a duration value, as defined by the xsd:duration data type: http://www....
Definition: Duration.cs:13