Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ClientSignatureViewModel.cs
1using CommunityToolkit.Mvvm.ComponentModel;
2using System.Globalization;
8using CommunityToolkit.Mvvm.Input;
9
11{
16 {
17 private readonly Waher.Networking.XMPP.Contracts.ClientSignature? clientSignature;
18 private readonly LegalIdentity? identity;
19
25 {
26 if (Args is not null)
27 {
28 this.clientSignature = Args.Signature;
29 this.identity = Args.Identity;
30 }
31 }
32
34 protected override async Task OnInitialize()
35 {
36 await base.OnInitialize();
37
38 this.AssignProperties();
39 }
40
41 #region Properties
42
46 [ObservableProperty]
47 private DateTime? created;
48
52 [ObservableProperty]
53 private DateTime? updated;
54
58 [ObservableProperty]
59 private string? legalId;
60
64 [ObservableProperty]
65 private IdentityState? state;
66
70 [ObservableProperty]
71 private DateTime? from;
72
76 [ObservableProperty]
77 private DateTime? to;
78
82 [ObservableProperty]
83 private string? firstName;
84
88 [ObservableProperty]
89 private string? middleNames;
90
94 [ObservableProperty]
95 private string? lastNames;
96
100 [ObservableProperty]
101 private string? personalNumber;
102
106 [ObservableProperty]
107 private string? address;
108
112 [ObservableProperty]
113 private string? address2;
114
118 [ObservableProperty]
119 private string? zipCode;
120
124 [ObservableProperty]
125 private string? area;
126
130 [ObservableProperty]
131 private string? city;
132
136 [ObservableProperty]
137 private string? region;
138
142 [ObservableProperty]
143 private string? countryCode;
144
148 [ObservableProperty]
149 private string? nationalityCode;
150
154 [ObservableProperty]
155 private string? gender;
156
160 [ObservableProperty]
161 private DateTime? birthDate;
162
166 [ObservableProperty]
167 private string? orgName;
168
172 [ObservableProperty]
173 private string? orgNumber;
174
178 [ObservableProperty]
179 private string? orgDepartment;
180
184 [ObservableProperty]
185 private string? orgRole;
186
190 [ObservableProperty]
191 private string? orgAddress;
192
196 [ObservableProperty]
197 private string? orgAddress2;
198
202 [ObservableProperty]
203 private string? orgZipCode;
204
208 [ObservableProperty]
209 private string? orgArea;
210
214 [ObservableProperty]
215 private string? orgCity;
216
220 [ObservableProperty]
221 private string? orgRegion;
222
226 [ObservableProperty]
227 private string? orgCountryCode;
228
232 [ObservableProperty]
233 private bool? hasOrg;
234
238 [ObservableProperty]
239 private bool? isApproved;
240
244 [ObservableProperty]
245 private string? role;
246
250 [ObservableProperty]
251 private string? timestamp;
252
256 [ObservableProperty]
257 private string? isTransferable;
258
262 [ObservableProperty]
263 private string? bareJid;
264
268 [ObservableProperty]
269 private string? phoneNr;
270
274 [ObservableProperty]
275 private string? eMail;
276
280 [ObservableProperty]
281 private string? signature;
282
283 #endregion
284
285 private void AssignProperties()
286 {
287 if (this.identity is not null)
288 {
289 this.Created = this.identity.Created;
290 this.Updated = this.identity.Updated.GetDateOrNullIfMinValue();
291 this.LegalId = this.identity.Id;
292 this.State = this.identity.State;
293 this.From = this.identity.From.GetDateOrNullIfMinValue();
294 this.To = this.identity.To.GetDateOrNullIfMinValue();
295 this.FirstName = this.identity[Constants.XmppProperties.FirstName];
296 this.MiddleNames = this.identity[Constants.XmppProperties.MiddleNames];
297 this.LastNames = this.identity[Constants.XmppProperties.LastNames];
298 this.PersonalNumber = this.identity[Constants.XmppProperties.PersonalNumber];
299 this.Address = this.identity[Constants.XmppProperties.Address];
300 this.Address2 = this.identity[Constants.XmppProperties.Address2];
301 this.ZipCode = this.identity[Constants.XmppProperties.ZipCode];
302 this.Area = this.identity[Constants.XmppProperties.Area];
303 this.City = this.identity[Constants.XmppProperties.City];
304 this.Region = this.identity[Constants.XmppProperties.Region];
305 this.CountryCode = this.identity[Constants.XmppProperties.Country];
306 this.NationalityCode = this.identity[Constants.XmppProperties.Nationality];
307 this.Gender = this.identity[Constants.XmppProperties.Gender];
308
309 string BirthDayStr = this.identity[Constants.XmppProperties.BirthDay];
310 string BirthMonthStr = this.identity[Constants.XmppProperties.BirthMonth];
311 string BirthYearStr = this.identity[Constants.XmppProperties.BirthYear];
312
313 if (!string.IsNullOrEmpty(BirthDayStr) && int.TryParse(BirthDayStr, out int BirthDay) &&
314 !string.IsNullOrEmpty(BirthMonthStr) && int.TryParse(BirthMonthStr, out int BirthMonth) &&
315 !string.IsNullOrEmpty(BirthYearStr) && int.TryParse(BirthYearStr, out int BirthYear))
316 {
317 try
318 {
319 this.BirthDate = new DateTime(BirthYear, BirthMonth, BirthDay);
320 }
321 catch (Exception ex)
322 {
323 ServiceRef.LogService.LogException(ex);
324 this.BirthDate = null;
325 }
326 }
327
328 this.OrgName = this.identity[Constants.XmppProperties.OrgName];
329 this.OrgNumber = this.identity[Constants.XmppProperties.OrgNumber];
330 this.OrgDepartment = this.identity[Constants.XmppProperties.OrgDepartment];
331 this.OrgRole = this.identity[Constants.XmppProperties.OrgRole];
332 this.OrgAddress = this.identity[Constants.XmppProperties.OrgAddress];
333 this.OrgAddress2 = this.identity[Constants.XmppProperties.OrgAddress2];
334 this.OrgZipCode = this.identity[Constants.XmppProperties.OrgZipCode];
335 this.OrgArea = this.identity[Constants.XmppProperties.OrgArea];
336 this.OrgCity = this.identity[Constants.XmppProperties.OrgCity];
337 this.OrgRegion = this.identity[Constants.XmppProperties.OrgRegion];
338 this.OrgCountryCode = this.identity[Constants.XmppProperties.OrgCountry];
339 this.HasOrg =
340 !string.IsNullOrEmpty(this.OrgName) ||
341 !string.IsNullOrEmpty(this.OrgNumber) ||
342 !string.IsNullOrEmpty(this.OrgDepartment) ||
343 !string.IsNullOrEmpty(this.OrgRole) ||
344 !string.IsNullOrEmpty(this.OrgAddress) ||
345 !string.IsNullOrEmpty(this.OrgAddress2) ||
346 !string.IsNullOrEmpty(this.OrgZipCode) ||
347 !string.IsNullOrEmpty(this.OrgArea) ||
348 !string.IsNullOrEmpty(this.OrgCity) ||
349 !string.IsNullOrEmpty(this.OrgRegion) ||
350 !string.IsNullOrEmpty(this.OrgCountryCode);
351 this.IsApproved = this.identity.State == IdentityState.Approved;
352 this.BareJid = this.identity.GetJid(Constants.NotAvailableValue);
353 this.PhoneNr = this.identity[Constants.XmppProperties.Phone];
354 this.EMail = this.identity[Constants.XmppProperties.EMail];
355 }
356 else
357 {
358 this.Created = DateTime.MinValue;
359 this.Updated = DateTime.MinValue;
360 this.LegalId = Constants.NotAvailableValue;
361 this.State = IdentityState.Compromised;
362 this.From = null;
363 this.To = null;
364 this.FirstName = Constants.NotAvailableValue;
365 this.MiddleNames = Constants.NotAvailableValue;
366 this.LastNames = Constants.NotAvailableValue;
367 this.PersonalNumber = Constants.NotAvailableValue;
368 this.Address = Constants.NotAvailableValue;
369 this.Address2 = Constants.NotAvailableValue;
370 this.ZipCode = Constants.NotAvailableValue;
371 this.Area = Constants.NotAvailableValue;
372 this.City = Constants.NotAvailableValue;
373 this.Region = Constants.NotAvailableValue;
374 this.CountryCode = Constants.NotAvailableValue;
375 this.NationalityCode = Constants.NotAvailableValue;
376 this.Gender = Constants.NotAvailableValue;
377 this.BirthDate = null;
378 this.OrgName = Constants.NotAvailableValue;
379 this.OrgNumber = Constants.NotAvailableValue;
380 this.OrgDepartment = Constants.NotAvailableValue;
381 this.OrgRole = Constants.NotAvailableValue;
382 this.OrgAddress = Constants.NotAvailableValue;
383 this.OrgAddress2 = Constants.NotAvailableValue;
384 this.OrgZipCode = Constants.NotAvailableValue;
385 this.OrgArea = Constants.NotAvailableValue;
386 this.OrgCity = Constants.NotAvailableValue;
387 this.OrgRegion = Constants.NotAvailableValue;
388 this.OrgCountryCode = Constants.NotAvailableValue;
389 this.HasOrg = false;
390 this.IsApproved = false;
391 this.BareJid = Constants.NotAvailableValue;
392 this.PhoneNr = Constants.NotAvailableValue;
393 this.EMail = Constants.NotAvailableValue;
394 }
395 if (this.clientSignature is not null)
396 {
397 this.Role = this.clientSignature.Role;
398 this.Timestamp = this.clientSignature.Timestamp.ToString(CultureInfo.CurrentCulture);
399 this.IsTransferable = this.clientSignature.Transferable.ToYesNo();
400 this.BareJid = this.clientSignature.BareJid;
401 this.Signature = Convert.ToBase64String(this.clientSignature.DigitalSignature);
402 }
403 else
404 {
405 this.Role = Constants.NotAvailableValue;
406 this.Timestamp = Constants.NotAvailableValue;
407 this.IsTransferable = ServiceRef.Localizer[nameof(AppResources.No)];
408 this.Signature = Constants.NotAvailableValue;
409 }
410 }
411
415 [RelayCommand]
416 private static async Task Copy(object Item)
417 {
418 try
419 {
420 if (Item is string Label)
421 await Clipboard.SetTextAsync(Label);
422 else
423 await Clipboard.SetTextAsync(Item?.ToString() ?? string.Empty);
424
425 await ServiceRef.UiService.DisplayAlert(
426 ServiceRef.Localizer[nameof(AppResources.SuccessTitle)],
427 ServiceRef.Localizer[nameof(AppResources.TagValueCopiedToClipboard)]);
428 }
429 catch (Exception ex)
430 {
431 ServiceRef.LogService.LogException(ex);
432 await ServiceRef.UiService.DisplayException(ex);
433 }
434 }
435
436 #region ILinkableView
437
441 public bool IsLinkable => true;
442
446 public bool EncodeAppLinks => true;
447
451 public string Link => Constants.UriSchemes.IotId + ":" + this.LegalId;
452
456 public Task<string> Title => this.GetTitle();
457
458 private async Task<string> GetTitle()
459 {
460 if (this.identity is null)
461 return await ContactInfo.GetFriendlyName(this.LegalId);
462 else
463 return ContactInfo.GetFriendlyName(this.identity);
464 }
465
469 public bool HasMedia => false;
470
474 public byte[]? Media => null;
475
479 public string? MediaContentType => null;
480
481 #endregion
482
483 }
484}
const string PersonalNumber
Personal number
Definition: Constants.cs:284
const string OrgAddress2
Organization Address line 2
Definition: Constants.cs:364
const string OrgArea
Organization Area
Definition: Constants.cs:369
const string OrgRegion
Organization Region
Definition: Constants.cs:384
const string Nationality
Nationality
Definition: Constants.cs:324
const string BirthYear
Birth Year
Definition: Constants.cs:344
const string OrgCity
Organization City
Definition: Constants.cs:374
const string OrgRole
Organization Role
Definition: Constants.cs:399
const string Phone
Phone number
Definition: Constants.cs:414
const string EMail
e-Mail address
Definition: Constants.cs:419
const string OrgZipCode
Organization Zip Code
Definition: Constants.cs:379
const string MiddleNames
Middle names
Definition: Constants.cs:274
const string OrgCountry
Organization Country
Definition: Constants.cs:389
const string OrgDepartment
Organization Department
Definition: Constants.cs:394
const string Address2
Address line 2
Definition: Constants.cs:294
const string OrgAddress
Organization Address line 1
Definition: Constants.cs:359
const string Address
Address line 1
Definition: Constants.cs:289
const string LastNames
Last names
Definition: Constants.cs:279
const string OrgNumber
Organization number
Definition: Constants.cs:354
const string BirthMonth
Birth Month
Definition: Constants.cs:339
const string FirstName
First name
Definition: Constants.cs:269
const string OrgName
Organization name
Definition: Constants.cs:349
A set of never changing property constants and helpful values.
Definition: Constants.cs:7
const string NotAvailableValue
A generic "no value available" string.
Definition: Constants.cs:11
Contains information about a contact.
Definition: ContactInfo.cs:21
static async Task< string > GetFriendlyName(CaseInsensitiveString RemoteId)
Gets the friendly name of a remote identity (Legal ID or Bare JID).
Definition: ContactInfo.cs:257
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 IStringLocalizer Localizer
Localization service
Definition: ServiceRef.cs:235
A base class for all view models, inheriting from the BindableObject. NOTE: using this class requir...
Holds navigation parameters specific to views displaying a client signature.
Waher.Networking.XMPP.Contracts.? ClientSignature Signature
The signature to display.
The view model to bind to for when displaying client signatures.
ClientSignatureViewModel(ClientSignatureNavigationArgs? Args)
Creates an instance of the ClientSignatureViewModel class.
override async Task OnInitialize()
Method called when view is initialized for the first time. Use this method to implement registration ...
Represents a digital signature on a contract.
string Role
Role of the legal identity in the contract.
bool Transferable
If the signature is transferable to contracts based on the current contract as a template,...
string BareJid
Bare JID of the client used to generate the signature.
byte[] DigitalSignature
Digital Signature
Definition: Signature.cs:27
DateTime Timestamp
Timestamp of signature.
Definition: Signature.cs:18
Interface for linkable views.
Definition: ILinkableView.cs:7
delegate string ToString(IElement Element)
Delegate for callback methods that convert an element value to a string.
IdentityState
Lists recognized legal identity states.
Definition: App.xaml.cs:4