Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
AppShellViewModel.cs
1using CommunityToolkit.Mvvm.ComponentModel;
2using CommunityToolkit.Mvvm.Input;
3using EDaler;
15
17{
21 public partial class AppShellViewModel : BaseViewModel
22 {
27 {
28 }
29
31 protected override Task OnInitialize()
32 {
33 this.UpdateProperties();
34
35 ServiceRef.TagProfile.OnPropertiesChanged += this.TagProfile_OnPropertiesChanged;
36 ServiceRef.XmppService.OnRosterItemAdded += this.XmppService_OnRosterItemAdded;
37 ServiceRef.XmppService.OnRosterItemRemoved += this.XmppService_OnRosterItemRemoved;
38 ServiceRef.XmppService.ConnectionStateChanged += this.XmppService_ConnectionStateChanged;
39
40 return base.OnInitialize();
41 }
42
44 protected override Task OnDispose()
45 {
46 ServiceRef.TagProfile.OnPropertiesChanged -= this.TagProfile_OnPropertiesChanged;
47 ServiceRef.XmppService.OnRosterItemAdded -= this.XmppService_OnRosterItemAdded;
48 ServiceRef.XmppService.OnRosterItemRemoved -= this.XmppService_OnRosterItemRemoved;
49 ServiceRef.XmppService.ConnectionStateChanged -= this.XmppService_ConnectionStateChanged;
50
51 return base.OnDispose();
52 }
53
54 private void TagProfile_OnPropertiesChanged(object? sender, EventArgs e)
55 {
56 this.UpdateProperties();
57 }
58
59 private Task XmppService_ConnectionStateChanged(object Sender, Waher.Networking.XMPP.XmppState NewState)
60 {
61 if (NewState == Waher.Networking.XMPP.XmppState.Connected)
62 this.UpdateProperties();
63
64 return Task.CompletedTask;
65 }
66
67 private Task XmppService_OnRosterItemRemoved(object Sender, Waher.Networking.XMPP.RosterItem Item)
68 {
69 this.UpdateProperties();
70
71 return Task.CompletedTask;
72 }
73
74 private Task XmppService_OnRosterItemAdded(object Sender, Waher.Networking.XMPP.RosterItem Item)
75 {
76 this.UpdateProperties();
77
78 return Task.CompletedTask;
79 }
80
81 private void UpdateProperties()
82 {
83 this.CanShowMyContractsCommand = ServiceRef.TagProfile.HasContractReferences;
84 this.CanShowCreateContractCommand = ServiceRef.TagProfile.HasContractTemplateReferences;
85 this.CanShowCreateTokenCommand = ServiceRef.TagProfile.HasContractTokenCreationTemplatesReferences;
86 this.CanShowContactsCommand = ServiceRef.XmppService.Roster is not null && ServiceRef.XmppService.Roster.Length > 0;
87 this.CanShowWalletCommand = ServiceRef.TagProfile.HasWallet;
88 this.CanShowThingsCommand = ServiceRef.TagProfile.HasThing;
89 }
90
95 [RelayCommand]
96 private static async Task Close()
97 {
98 try
99 {
100 AppShell.Current.FlyoutIsPresented = false;
101 await App.Stop();
102 }
103 catch (Exception ex)
104 {
105 ServiceRef.LogService.LogException(ex);
106 }
107 }
108
112 [RelayCommand]
113 private static async Task ViewId()
114 {
115 try
116 {
119 }
120 catch (Exception ex)
121 {
122 ServiceRef.LogService.LogException(ex);
123 }
124 }
125
129 [RelayCommand]
130 private static async Task ShowSettings()
131 {
132 try
133 {
135 }
136 catch (Exception ex)
137 {
138 ServiceRef.LogService.LogException(ex);
139 }
140 }
141
145 [RelayCommand]
146 private static async Task ShowApplications()
147 {
148 try
149 {
151 }
152 catch (Exception ex)
153 {
154 ServiceRef.LogService.LogException(ex);
155 }
156 }
157
161 [ObservableProperty]
162 private bool canShowMyContractsCommand;
163
164 [RelayCommand]
165 private static async Task ShowMyContracts()
166 {
167 try
168 {
169 MyContractsNavigationArgs Args = new(ContractsListMode.Contracts);
170 await ServiceRef.UiService.GoToAsync(nameof(MyContractsPage), Args, BackMethod.Pop);
171 }
172 catch (Exception ex)
173 {
174 ServiceRef.LogService.LogException(ex);
175 }
176 }
177
181 [ObservableProperty]
182 private bool canShowCreateContractCommand;
183
184 [RelayCommand]
185 private static async Task CreateContract()
186 {
187 try
188 {
189 MyContractsNavigationArgs Args = new(ContractsListMode.ContractTemplates);
190 await ServiceRef.UiService.GoToAsync(nameof(MyContractsPage), Args, BackMethod.Pop);
191 }
192 catch (Exception ex)
193 {
194 ServiceRef.LogService.LogException(ex);
195 }
196 }
197
201 [ObservableProperty]
202 private bool canShowCreateTokenCommand;
203
204 [RelayCommand]
205 private static async Task CreateToken()
206 {
207 try
208 {
209 MyContractsNavigationArgs Args = new(ContractsListMode.TokenCreationTemplates);
210 await ServiceRef.UiService.GoToAsync(nameof(MyContractsPage), Args, BackMethod.Pop);
211 }
212 catch (Exception ex)
213 {
214 ServiceRef.LogService.LogException(ex);
215 }
216 }
217
221 [ObservableProperty]
222 private bool canShowContactsCommand;
223
224 [RelayCommand]
225 private static async Task ShowContacts()
226 {
227 try
228 {
229 ContactListNavigationArgs Args = new();
230 await ServiceRef.UiService.GoToAsync(nameof(MyContactsPage), Args, BackMethod.Pop);
231 }
232 catch (Exception ex)
233 {
234 ServiceRef.LogService.LogException(ex);
235 }
236 }
237
241 [ObservableProperty]
242 private bool canShowWalletCommand;
243
244 [RelayCommand]
245 internal static async Task ShowWallet()
246 {
247 try
248 {
249 Balance Balance = await ServiceRef.XmppService.GetEDalerBalance();
250 (decimal PendingAmount, string PendingCurrency, PendingPayment[] PendingPayments) = await ServiceRef.XmppService.GetPendingEDalerPayments();
251 (AccountEvent[] Events, bool More) = await ServiceRef.XmppService.GetEDalerAccountEvents(Constants.BatchSizes.AccountEventBatchSize);
252
253 WalletNavigationArgs Args = new(Balance, PendingAmount, PendingCurrency, PendingPayments, Events, More);
254
256 }
257 catch (Exception ex)
258 {
259 ServiceRef.LogService.LogException(ex);
261 }
262 }
263
264 [ObservableProperty]
265 private bool canShowThingsCommand;
266
267 [RelayCommand]
268 private static async Task ShowThings()
269 {
270 try
271 {
273 }
274 catch (Exception ex)
275 {
276 ServiceRef.LogService.LogException(ex);
277 }
278 }
279 }
280}
Account event
Definition: AccountEvent.cs:16
Contains information about a balance.
Definition: Balance.cs:11
Contains information about a pending payment.
The Application class, representing an instance of the Neuro-Access app.
Definition: App.xaml.cs:69
static Task< bool > AuthenticateUser(AuthenticationPurpose Purpose, bool Force=false)
Authenticates the user using the configured authentication method.
Definition: App.xaml.cs:981
const int AccountEventBatchSize
Number of account events to load in a single batch.
Definition: Constants.cs:779
A set of never changing property constants and helpful values.
Definition: Constants.cs:7
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 ITagProfile TagProfile
TAG Profile service.
Definition: ServiceRef.cs:79
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...
Holds navigation parameters specific to views displaying a list of contacts.
A page that displays a list of the current user's contacts.
Holds navigation parameters specific to views displaying a list of contacts.
A page that displays a list of the current user's contracts.
A page to display when the user wants to view an identity.
override Task OnInitialize()
Method called when view is initialized for the first time. Use this method to implement registration ...
AppShellViewModel()
View model for the AppShell.
override Task OnDispose()
Method called when the view is disposed, and will not be used more. Use this method to unregister eve...
A page that displays a list of the current user's things.
A page that allows the user to view the contents of its eDaler wallet, pending payments and recent ac...
Holds navigation parameters specific to the eDaler wallet.
Maintains information about an item in the roster.
Definition: RosterItem.cs:75
Task DisplayException(Exception Exception, string? Title=null)
Displays an alert/message box to the user.
Task GoToAsync(string Route, BackMethod BackMethod=BackMethod.Inherited, string? UniqueId=null)
Navigates the AppShell to the specified route, with page arguments to match.
BackMethod
Navigation Back Method
Definition: BackMethod.cs:7
AuthenticationPurpose
Purpose for requesting the user to authenticate itself.
Definition: App.xaml.cs:4