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 System.Xml;
2using CommunityToolkit.Mvvm.ComponentModel;
3using CommunityToolkit.Mvvm.Input;
9using NeuroFeatures;
11using SkiaSharp;
12using Waher.Content;
14using Waher.Security;
15
17{
21 public partial class TokenItem : ObservableObject, IUniqueItem
22 {
23 private readonly Token token;
24 private readonly TaskCompletionSource<TokenItem?>? selected;
25 private bool? @new;
26 private int nrEvents;
27 private NotificationEvent[] notificationEvents;
28
35 : this(Token, null, NotificationEvents)
36 {
37 }
38
45 public TokenItem(Token Token, TaskCompletionSource<TokenItem?>? Selected, NotificationEvent[] NotificationEvents)
46 {
47 this.token = Token;
48 this.selected = Selected;
49 this.notificationEvents = NotificationEvents;
50
51 if (this.Glyph is not null && this.GlyphContentType.StartsWith("image/", StringComparison.OrdinalIgnoreCase))
52 {
53 this.GlyphImage = ImageSource.FromStream(() => new MemoryStream(this.Glyph));
54 this.HasGlyphImage = true;
55
56 double s = 32.0 / this.token.GlyphWidth;
57 double s2 = 32.0 / this.token.GlyphHeight;
58
59 if (s2 < s)
60 s = s2;
61 else if (s > 1)
62 s = 1;
63
64 this.GlyphWidth = (int)(this.token.GlyphWidth * s + 0.5);
65 this.GlyphHeight = (int)(this.token.GlyphHeight * s + 0.5);
66 }
67 else
68 {
69 this.GlyphImage = null;
70 this.HasGlyphImage = false;
71 this.GlyphWidth = 0;
72 this.GlyphHeight = 0;
73 }
74 }
75
79 public Token Token => this.token;
80
82 public string UniqueName => this.token.TokenId;
83
87 public DateTime Created => this.token.Created;
88
92 public DateTime Updated => this.token.Updated;
93
97 public DateTime Expires => this.token.Expires;
98
102 public Duration? ArchiveRequired => this.token.ArchiveRequired;
103
107 public Duration? ArchiveOptional => this.token.ArchiveOptional;
108
112 public DateTime SignatureTimestamp => this.token.SignatureTimestamp;
113
117 public byte[] Signature => this.token.Signature;
118
122 public byte[] DefinitionSchemaDigest => this.token.DefinitionSchemaDigest;
123
127 public HashFunction DefinitionSchemaHashFunction => this.token.DefinitionSchemaHashFunction;
128
132 public bool CreatorCanDestroy => this.token.CreatorCanDestroy;
133
137 public bool OwnerCanDestroyBatch => this.token.OwnerCanDestroyBatch;
138
142 public bool OwnerCanDestroyIndividual => this.token.OwnerCanDestroyIndividual;
143
147 public bool CertifierCanDestroy => this.token.CertifierCanDestroy;
148
152 public string FriendlyName => this.token.FriendlyName;
153
157 public string Category => this.token.Category;
158
162 public string Description => this.token.Description;
163
167 public byte[] Glyph => this.token.Glyph;
168
172 public string GlyphContentType => this.token.GlyphContentType;
173
177 public int Ordinal => this.token.Ordinal;
178
182 public decimal Value => this.token.Value;
183
187 public string[] Witness => this.token.Witness;
188
192 public string[] CertifierJids => this.token.CertifierJids;
193
197 public string[] Certifier => this.token.Certifier;
198
202 public TokenIdMethod TokenIdMethod => this.token.TokenIdMethod;
203
207 public string TokenId => this.token.TokenId;
208
212 public string ShortTokenId => this.token.ShortId;
213
217 public ContractVisibility Visibility => this.token.Visibility;
218
222 public string Creator => this.token.Creator;
223
227 public string CreatorJid => this.token.CreatorJid;
228
232 public string Owner => this.token.Owner;
233
237 public int BatchSize => this.token.BatchSize;
238
242 public string TrustProvider => this.token.TrustProvider;
243
247 public string OwnerJid => this.token.OwnerJid;
248
252 public string Currency => this.token.Currency;
253
257 public string Reference => this.token.Reference;
258
262 public string Definition => this.token.Definition;
263
267 public string DefinitionNamespace => this.token.DefinitionNamespace;
268
272 public string CreationContract => this.token.CreationContract;
273
277 public string OwnershipContract => this.token.OwnershipContract;
278
282 public string[] Valuator => this.token.Valuator;
283
287 public string[] Assessor => this.token.Assessor;
288
292 public string TrustProviderJid => this.token.TrustProviderJid;
293
297 public TokenTag[] Tags => this.token.Tags;
298
302 public bool HasStateMachine => this.token.HasStateMachine;
303
307 public bool HasEmbeddedLayout => this.token.HasEmbeddedLayout;
308
312 public XmlElement EmbeddedLayoutDefinition => this.token.EmbeddedLayoutDefinition;
313
317 [ObservableProperty]
318 private ImageSource? glyphImage;
319
323 [ObservableProperty]
324 private bool hasGlyphImage;
325
329 [ObservableProperty]
330 private int glyphWidth;
331
335 [ObservableProperty]
336 private int glyphHeight;
337
341 public NotificationEvent[] NotificationEvents => this.notificationEvents;
342
346 public int NrEvents
347 {
348 get
349 {
350 this.CheckEvents();
351
352 return this.nrEvents;
353 }
354 }
355
359 public bool New
360 {
361 get
362 {
363 this.CheckEvents();
364
365 return this.@new ?? false;
366 }
367 }
368
369 private void CheckEvents()
370 {
371 if (!this.@new.HasValue)
372 {
373 this.nrEvents = this.notificationEvents.Length;
374 this.@new = this.nrEvents > 0;
375
376 if (this.@new.Value)
377 {
378 NotificationEvent[] ToDelete = this.notificationEvents;
379
380 this.notificationEvents = [];
381
382 Task.Run(() => ServiceRef.NotificationService.DeleteEvents(ToDelete));
383 }
384 }
385 }
386
387 public async Task<ImageSource?> RenderEmbeddedLayout()
388 {
389 if (!this.Token.HasEmbeddedLayout)
390 return null;
391
392 SkiaSharp.SKImage Img = await this.Token.RenderEmbeddedLayout();
393
394 return ImageSource.FromStream(() =>
395 {
396 SKData Data = Img.Encode(SKEncodedImageFormat.Png, 100);
397 return Data.AsStream();
398 });
399 }
400
404 [RelayCommand]
405 private async Task Clicked()
406 {
407 if (this.selected is null)
408 {
409 TokenDetailsNavigationArgs Args = new(this);
410
412 }
413 else
414 {
415 this.selected.TrySetResult(this);
417 }
418 }
419 }
420}
Base class that references services in the app.
Definition: ServiceRef.cs:43
static IUiService UiService
Service serializing and managing UI-related tasks.
Definition: ServiceRef.cs:130
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
string UniqueName
Unique name used to compare items.
Definition: TokenItem.cs:82
HashFunction DefinitionSchemaHashFunction
Hash function used to compute DefinitionSchemaDigest.
Definition: TokenItem.cs:127
Duration? ArchiveRequired
Required archiving time after token expires.
Definition: TokenItem.cs:102
string DefinitionNamespace
XML Namespace used in the Definition
Definition: TokenItem.cs:267
bool HasEmbeddedLayout
If the token have an embedded layout.
Definition: TokenItem.cs:307
string CreationContract
Contract used to create the contract.
Definition: TokenItem.cs:272
bool OwnerCanDestroyBatch
If the owner can destroy the entire batch of tokens, if owner of every token in the batch.
Definition: TokenItem.cs:137
string Description
Description engraved into the token.
Definition: TokenItem.cs:162
TokenTag[] Tags
Any custom Token Tags provided during creation of the token.
Definition: TokenItem.cs:297
string TrustProvider
Trust Provider asserting the validity of the token
Definition: TokenItem.cs:242
int BatchSize
Number of tokens in batch being created.
Definition: TokenItem.cs:237
NotificationEvent[] NotificationEvents
Associated notification events
Definition: TokenItem.cs:341
byte[] DefinitionSchemaDigest
Digest of schema used to validate token definition XML.
Definition: TokenItem.cs:122
Duration? ArchiveOptional
Optional archiving time after required archiving time.
Definition: TokenItem.cs:107
string Reference
Any reference provided by the token creator.
Definition: TokenItem.cs:257
int NrEvents
Number of notification events recorded for the item.
Definition: TokenItem.cs:347
bool OwnerCanDestroyIndividual
If the owner can destroy an individual token.
Definition: TokenItem.cs:142
bool HasStateMachine
If the token is associated with a state-machine.
Definition: TokenItem.cs:302
bool CreatorCanDestroy
If the creator can destroy the token.
Definition: TokenItem.cs:132
ContractVisibility Visibility
Visibility of token
Definition: TokenItem.cs:217
bool CertifierCanDestroy
If a certifier can destroy the token.
Definition: TokenItem.cs:147
string OwnershipContract
Contract used to define the current ownership
Definition: TokenItem.cs:277
TokenItem(Token Token, NotificationEvent[] NotificationEvents)
Encapsulates a Token object.
Definition: TokenItem.cs:34
XmlElement EmbeddedLayoutDefinition
The embedded layout of the token.
Definition: TokenItem.cs:312
TokenItem(Token Token, TaskCompletionSource< TokenItem?>? Selected, NotificationEvent[] NotificationEvents)
Encapsulates a Token object.
Definition: TokenItem.cs:45
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:46
Task< SKImage > RenderEmbeddedLayout()
Renders the embedded layout.
Definition: Token.cs:1238
bool HasEmbeddedLayout
If the token has embedded layout information.
Definition: Token.cs:1194
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)
Navigates to the specified route and pushes the page onto the navigation stack.
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:24
ContractVisibility
Visibility types for contracts.
Definition: Enumerations.cs:56
HashFunction
Hash method enumeration.
Definition: Hashes.cs:26
Represents a duration value, as defined by the xsd:duration data type: http://www....
Definition: Duration.cs:14