Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
TokenEventsViewModel.cs
1using CommunityToolkit.Mvvm.ComponentModel;
2using CommunityToolkit.Mvvm.Input;
7using System.Collections.ObjectModel;
9
11{
15 public partial class TokenEventsViewModel : BaseViewModel
16 {
17 private readonly TokenEventsNavigationArgs? navigationArguments;
18
24 : base()
25 {
26 this.navigationArguments = Args;
27 this.TokenId = Args?.TokenId;
28
29 this.Events = [];
30 }
31
33 public override async Task OnInitializeAsync()
34 {
35 await base.OnInitializeAsync();
36
37 if (this.navigationArguments is not null)
38 {
39 this.Events.Clear();
40
41 if (this.navigationArguments.Events is not null)
42 {
43 foreach (TokenEvent Event in this.navigationArguments.Events)
44 {
45 EventItem Item = EventItem.Create(Event);
46 await Item.DoBind();
47 this.Events.Add(Item);
48 }
49 }
50 }
51 }
52
54 public override async Task OnDisposeAsync()
55 {
56 this.Events.Clear();
57
58 await base.OnDisposeAsync();
59 }
60
61 #region Properties
62
66 public ObservableCollection<EventItem> Events { get; }
67
71 [ObservableProperty]
72 private string? tokenId;
73
74 #endregion
75
76 #region Commands
77
81 [RelayCommand]
82 private async Task AddNote()
83 {
84 try
85 {
88
90 bool? Result = await AddTextNoteViewModel.Result;
91
92 if (Result.HasValue && Result.Value)
93 {
94 NoteItem NewEvent;
95
97 {
98 await ServiceRef.XmppService.AddNeuroFeatureXmlNote(this.TokenId!, AddTextNoteViewModel.TextNote!, AddTextNoteViewModel.Personal);
99
100 NewEvent = new NoteXmlItem(new NoteXml()
101 {
102 Note = AddTextNoteViewModel.TextNote,
103 Personal = AddTextNoteViewModel.Personal,
104 TokenId = this.TokenId,
105 Timestamp = DateTime.Now
106 });
107 }
108 else
109 {
110 await ServiceRef.XmppService.AddNeuroFeatureTextNote(this.TokenId!, AddTextNoteViewModel.TextNote!, AddTextNoteViewModel.Personal);
111
112 NewEvent = new NoteTextItem(new NoteText()
113 {
114 Note = AddTextNoteViewModel.TextNote,
115 Personal = AddTextNoteViewModel.Personal,
116 TokenId = this.TokenId,
117 Timestamp = DateTime.Now
118 });
119 }
120
121 await NewEvent.DoBind();
122
123 this.Events.Insert(0, NewEvent);
124 }
125 }
126 catch (Exception ex)
127 {
128 ServiceRef.LogService.LogException(ex);
129 await ServiceRef.UiService.DisplayException(ex);
130 }
131 }
132
133 #endregion
134
135 }
136}
Base class that references services in the app.
Definition: ServiceRef.cs:43
static ILogService LogService
Log service.
Definition: ServiceRef.cs:214
static IUiService UiService
Service serializing and managing UI-related tasks.
Definition: ServiceRef.cs:130
static IPopupService PopupService
Popup service for presenting application popups.
Definition: ServiceRef.cs:142
static IXmppService XmppService
The XMPP service for XMPP communication.
Definition: ServiceRef.cs:190
A base class for all view models, inheriting from the BindableObject. NOTE: using this class requir...
static EventItem Create(TokenEvent Event)
Creates an Event Item view model for a token event.
Definition: EventItem.cs:153
Holds navigation parameters containing the events of a token.
The view model to bind to for when displaying the events of a token.
TokenEventsViewModel(TokenEventsNavigationArgs? Args)
Creates an instance of the TokenEventsViewModel class.
override async Task OnDisposeAsync()
Method called when the view is disposed, and will not be used more. Use this method to unregister eve...
override async Task OnInitializeAsync()
Method called when view is initialized for the first time. Use this method to implement registration ...
Prompts the user for text to add as a note for a token.
View model for popup page prompting the user for a text note to be added.
Task< bool?> Result
Result will be provided here. If dialog is cancelled, null is returned.
A text note logged on the token.
Definition: NoteText.cs:9
An xml note logged on the token.
Definition: NoteXml.cs:9
Abstract base class for token events.
Definition: TokenEvent.cs:12
Helps with common XML-related tasks.
Definition: XML.cs:21
static bool IsValidXml(string Xml)
Checks if a string is valid XML
Definition: XML.cs:1397
abstract class NoteItem(TokenNoteEvent Event)
Represents a token note.
Definition: NoteItem.cs:9
class NoteXmlItem(NoteXml Event)
Represents an XML note on a token.
Definition: NoteXmlItem.cs:9
class NoteTextItem(NoteText Event)
Represents a text note on a token.
Definition: NoteTextItem.cs:9