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;
3using Mopups.Services;
8using System.Collections.ObjectModel;
10
12{
16 public partial class TokenEventsViewModel : BaseViewModel
17 {
18 private readonly TokenEventsNavigationArgs? navigationArguments;
19
25 : base()
26 {
27 this.navigationArguments = Args;
28 this.TokenId = Args?.TokenId;
29
30 this.Events = [];
31 }
32
34 protected override async Task OnInitialize()
35 {
36 await base.OnInitialize();
37
38 if (this.navigationArguments is not null)
39 {
40 this.Events.Clear();
41
42 if (this.navigationArguments.Events is not null)
43 {
44 foreach (TokenEvent Event in this.navigationArguments.Events)
45 {
46 EventItem Item = EventItem.Create(Event);
47 await Item.DoBind();
48 this.Events.Add(Item);
49 }
50 }
51 }
52 }
53
55 protected override async Task OnDispose()
56 {
57 this.Events.Clear();
58
59 await base.OnDispose();
60 }
61
62 #region Properties
63
67 public ObservableCollection<EventItem> Events { get; }
68
72 [ObservableProperty]
73 private string? tokenId;
74
75 #endregion
76
77 #region Commands
78
82 [RelayCommand]
83 private async Task AddNote()
84 {
85 try
86 {
89
90 await MopupService.Instance.PushAsync(AddTextNotePopup);
91 bool? Result = await AddTextNoteViewModel.Result;
92
93 if (Result.HasValue && Result.Value)
94 {
95 NoteItem NewEvent;
96
98 {
99 await ServiceRef.XmppService.AddNeuroFeatureXmlNote(this.TokenId!, AddTextNoteViewModel.TextNote!, AddTextNoteViewModel.Personal);
100
101 NewEvent = new NoteXmlItem(new NoteXml()
102 {
103 Note = AddTextNoteViewModel.TextNote,
104 Personal = AddTextNoteViewModel.Personal,
105 TokenId = this.TokenId,
106 Timestamp = DateTime.Now
107 });
108 }
109 else
110 {
111 await ServiceRef.XmppService.AddNeuroFeatureTextNote(this.TokenId!, AddTextNoteViewModel.TextNote!, AddTextNoteViewModel.Personal);
112
113 NewEvent = new NoteTextItem(new NoteText()
114 {
115 Note = AddTextNoteViewModel.TextNote,
116 Personal = AddTextNoteViewModel.Personal,
117 TokenId = this.TokenId,
118 Timestamp = DateTime.Now
119 });
120 }
121
122 await NewEvent.DoBind();
123
124 this.Events.Insert(0, NewEvent);
125 }
126 }
127 catch (Exception ex)
128 {
129 ServiceRef.LogService.LogException(ex);
130 await ServiceRef.UiService.DisplayException(ex);
131 }
132 }
133
134 #endregion
135
136 }
137}
Base class that references services in the app.
Definition: ServiceRef.cs:31
static ILogService LogService
Log service.
Definition: ServiceRef.cs:91
static IUiService UiService
Service serializing and managing UI-related tasks.
Definition: ServiceRef.cs:55
static IXmppService XmppService
The XMPP service for XMPP communication.
Definition: ServiceRef.cs:67
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:143
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 OnDispose()
Method called when the view is disposed, and will not be used more. Use this method to unregister eve...
override async Task OnInitialize()
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:13
Helps with common XML-related tasks.
Definition: XML.cs:19
static bool IsValidXml(string Xml)
Checks if a string is valid XML
Definition: XML.cs:1223
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