1using System.Globalization;
2using CommunityToolkit.Mvvm.ComponentModel;
3using CommunityToolkit.Mvvm.Input;
29 await base.OnInitialize();
37 return MainThread.InvokeOnMainThreadAsync(async () =>
39 await base.XmppService_ConnectionStateChanged(Sender, NewState);
50 return Task.CompletedTask;
56 base.SetIsBusy(IsBusy);
65 this.ApplyCommand.NotifyCanExecuteChanged();
72 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
74 private string? firstName =
"";
80 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
82 private string? middleNames;
88 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
90 private string? lastNames;
96 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
98 private string? personalNumber;
104 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
105 [NotifyPropertyChangedFor(nameof(
AddressOk))]
106 private string? address;
112 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
113 [NotifyPropertyChangedFor(nameof(
Address2Ok))]
114 private string? address2;
120 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
121 [NotifyPropertyChangedFor(nameof(
ZipCodeOk))]
122 private string? zipCode;
128 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
129 [NotifyPropertyChangedFor(nameof(
AreaOk))]
130 private string? area;
136 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
137 [NotifyPropertyChangedFor(nameof(
CityOk))]
138 private string? city;
144 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
145 [NotifyPropertyChangedFor(nameof(
RegionOk))]
146 private string? region;
152 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
153 [NotifyPropertyChangedFor(nameof(
CountryOk))]
154 private string? countryCode;
160 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
162 private string? nationalityCode;
168 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
169 [NotifyPropertyChangedFor(nameof(
GenderOk))]
170 private string? genderCode;
177 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
180 private DateTime birthDate = DateTime.Today;
186 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
187 [NotifyPropertyChangedFor(nameof(
OrgNameOk))]
188 private string? orgName;
194 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
196 private string? orgNumber;
202 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
204 private string? orgAddress;
210 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
212 private string? orgAddress2;
218 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
220 private string? orgZipCode;
226 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
227 [NotifyPropertyChangedFor(nameof(
OrgAreaOk))]
228 private string? orgArea;
234 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
235 [NotifyPropertyChangedFor(nameof(
OrgCityOk))]
236 private string? orgCity;
242 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
244 private string? orgRegion;
250 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
251 private string? orgCountryCode;
257 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
259 private string? orgDepartment;
265 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
266 [NotifyPropertyChangedFor(nameof(
OrgRoleOk))]
267 private string? orgRole;
273 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
274 private string? phoneNr;
280 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
281 private string? eMail;
287 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
288 private string? deviceId;
294 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
301 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
303 private bool requiresFirstName;
309 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
311 private bool requiresMiddleNames;
317 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
319 private bool requiresLastNames;
325 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
327 private bool requiresPersonalNumber;
333 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
334 [NotifyPropertyChangedFor(nameof(
AddressOk))]
335 private bool requiresAddress;
341 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
342 [NotifyPropertyChangedFor(nameof(
Address2Ok))]
343 private bool requiresAddress2;
349 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
350 [NotifyPropertyChangedFor(nameof(
ZipCodeOk))]
351 private bool requiresZipCode;
357 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
358 [NotifyPropertyChangedFor(nameof(
AreaOk))]
359 private bool requiresArea;
365 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
366 [NotifyPropertyChangedFor(nameof(
CityOk))]
367 private bool requiresCity;
373 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
374 [NotifyPropertyChangedFor(nameof(
RegionOk))]
375 private bool requiresRegion;
381 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
382 [NotifyPropertyChangedFor(nameof(
CountryOk))]
383 private bool requiresCountry;
389 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
390 [NotifyPropertyChangedFor(nameof(
CountryOk))]
391 private bool requiresCountryIso3166;
397 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
399 private bool requiresNationality;
405 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
406 [NotifyPropertyChangedFor(nameof(
GenderOk))]
407 private bool requiresGender;
413 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
415 private bool requiresBirthDate;
421 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
422 [NotifyPropertyChangedFor(nameof(
OrgNameOk))]
423 private bool requiresOrgName;
429 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
431 private bool requiresOrgDepartment;
437 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
438 [NotifyPropertyChangedFor(nameof(
OrgRoleOk))]
439 private bool requiresOrgRole;
445 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
447 private bool requiresOrgNumber;
453 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
455 private bool requiresOrgAddress;
461 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
463 private bool requiresOrgAddress2;
469 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
471 private bool requiresOrgZipCode;
477 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
478 [NotifyPropertyChangedFor(nameof(
OrgAreaOk))]
479 private bool requiresOrgArea;
485 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
486 [NotifyPropertyChangedFor(nameof(
OrgCityOk))]
487 private bool requiresOrgCity;
493 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
495 private bool requiresOrgRegion;
501 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
503 private bool requiresOrgCountry;
508 public bool FirstNameOk => !this.RequiresFirstName || !
string.IsNullOrWhiteSpace(this.FirstName);
513 public bool MiddleNamesOk => !this.RequiresMiddleNames || !
string.IsNullOrWhiteSpace(this.MiddleNames);
518 public bool LastNamesOk => !this.RequiresLastNames || !
string.IsNullOrWhiteSpace(this.LastNames);
527 if (
string.IsNullOrWhiteSpace(this.PersonalNumber))
528 return !this.RequiresPersonalNumber;
530 if (
string.IsNullOrWhiteSpace(this.CountryCode))
535 return !Info.IsValid.HasValue || Info.
IsValid.Value;
542 public bool AddressOk => !this.RequiresAddress || !
string.IsNullOrWhiteSpace(this.Address);
547 public bool Address2Ok => !this.RequiresAddress2 || !
string.IsNullOrWhiteSpace(this.Address2);
552 public bool ZipCodeOk => !this.RequiresZipCode || !
string.IsNullOrWhiteSpace(this.ZipCode);
557 public bool AreaOk => !this.RequiresArea || !
string.IsNullOrWhiteSpace(this.Area);
562 public bool CityOk => !this.RequiresCity || !
string.IsNullOrWhiteSpace(this.City);
567 public bool RegionOk => !this.RequiresRegion || !
string.IsNullOrWhiteSpace(this.Region);
576 if (
string.IsNullOrWhiteSpace(this.CountryCode))
577 return !this.RequiresCountry;
593 if (
string.IsNullOrWhiteSpace(this.NationalityCode))
594 return !this.RequiresNationality;
610 if (
string.IsNullOrEmpty(this.GenderCode))
611 return !this.RequiresGender;
639 if (this.NullIfInvalidBirthDate.HasValue && (
this.BirthDate >
this.MaxBirthDate ||
this.BirthDate <
this.MinBirthDate))
642 return !this.RequiresBirthDate;
649 public bool OrgNameOk => !this.RequiresOrgName || !
string.IsNullOrWhiteSpace(this.OrgName);
654 public bool OrgDepartmentOk => !this.RequiresOrgDepartment || !
string.IsNullOrWhiteSpace(this.OrgDepartment);
659 public bool OrgRoleOk => !this.RequiresOrgRole || !
string.IsNullOrWhiteSpace(this.OrgRole);
664 public bool OrgNumberOk => !this.RequiresOrgNumber || !
string.IsNullOrEmpty(this.OrgNumber);
669 public bool OrgAddressOk => !this.RequiresOrgAddress || !
string.IsNullOrWhiteSpace(this.OrgAddress);
674 public bool OrgAddress2Ok => !this.RequiresOrgAddress2 || !
string.IsNullOrWhiteSpace(this.OrgAddress2);
679 public bool OrgZipCodeOk => !this.RequiresOrgZipCode || !
string.IsNullOrWhiteSpace(this.OrgZipCode);
684 public bool OrgAreaOk => !this.RequiresOrgArea || !
string.IsNullOrWhiteSpace(this.OrgArea);
689 public bool OrgCityOk => !this.RequiresOrgCity || !
string.IsNullOrWhiteSpace(this.OrgCity);
694 public bool OrgRegionOk => !this.RequiresOrgRegion || !
string.IsNullOrWhiteSpace(this.OrgRegion);
703 if (
string.IsNullOrWhiteSpace(this.OrgCountryCode))
704 return !this.RequiresOrgCountry;
720 List<Property> Properties = [];
736 if (this.NullIfInvalidBirthDate.HasValue)
759 return [.. Properties];
762 private static void AddProperty(List<Property> Properties,
string PropertyName,
string? PropertyValue)
764 string? s = PropertyValue?.Trim();
766 if (!
string.IsNullOrWhiteSpace(s))
767 Properties.Add(
new Property(PropertyName, s));
779 bool SetOrganizationalProperties,
bool SetAppProperties)
781 if (ClearPropertiesNotFound)
783 this.FirstName =
string.Empty;
784 this.MiddleNames =
string.Empty;
785 this.LastNames =
string.Empty;
786 this.PersonalNumber =
string.Empty;
787 this.Address =
string.Empty;
788 this.Address2 =
string.Empty;
789 this.ZipCode =
string.Empty;
790 this.Area =
string.Empty;
791 this.City =
string.Empty;
792 this.Region =
string.Empty;
793 this.CountryCode =
string.Empty;
794 this.NationalityCode =
string.Empty;
795 this.GenderCode =
string.Empty;
796 this.BirthDate = DateTime.Today;
797 this.OrgName =
string.Empty;
798 this.OrgNumber =
string.Empty;
799 this.OrgAddress =
string.Empty;
800 this.OrgAddress2 =
string.Empty;
801 this.OrgZipCode =
string.Empty;
802 this.OrgArea =
string.Empty;
803 this.OrgCity =
string.Empty;
804 this.OrgRegion =
string.Empty;
805 this.OrgCountryCode =
string.Empty;
806 this.OrgDepartment =
string.Empty;
807 this.OrgRole =
string.Empty;
808 this.PhoneNr =
string.Empty;
809 this.EMail =
string.Empty;
810 this.DeviceId =
string.Empty;
811 this.Jid =
string.Empty;
814 int? BirthDay =
null;
815 int? BirthMonth =
null;
816 int? BirthYear =
null;
818 foreach (
Property P
in Identity.Properties)
823 if (SetPersonalProperties)
824 this.FirstName = P.
Value;
828 if (SetPersonalProperties)
829 this.MiddleNames = P.
Value;
833 if (SetPersonalProperties)
834 this.LastNames = P.
Value;
838 if (SetPersonalProperties)
839 this.PersonalNumber = P.
Value;
843 if (SetPersonalProperties)
844 this.Address = P.
Value;
848 if (SetPersonalProperties)
849 this.Address2 = P.
Value;
853 if (SetPersonalProperties)
854 this.ZipCode = P.
Value;
858 if (SetPersonalProperties)
863 if (SetPersonalProperties)
868 if (SetPersonalProperties)
869 this.Region = P.
Value;
873 if (SetPersonalProperties)
874 this.CountryCode = P.
Value;
878 if (SetPersonalProperties)
879 this.NationalityCode = P.
Value;
883 if (SetPersonalProperties)
884 this.GenderCode = P.
Value;
888 if (
int.TryParse(P.
Value, out
int i))
893 if (
int.TryParse(P.
Value, out i))
898 if (
int.TryParse(P.
Value, out i))
903 if (SetOrganizationalProperties)
904 this.OrgName = P.
Value;
908 if (SetOrganizationalProperties)
909 this.OrgNumber = P.
Value;
913 if (SetOrganizationalProperties)
914 this.OrgRole = P.
Value;
918 if (SetOrganizationalProperties)
919 this.OrgDepartment = P.
Value;
923 if (SetOrganizationalProperties)
924 this.OrgAddress = P.
Value;
928 if (SetOrganizationalProperties)
929 this.OrgAddress2 = P.
Value;
933 if (SetOrganizationalProperties)
934 this.OrgZipCode = P.
Value;
938 if (SetOrganizationalProperties)
939 this.OrgArea = P.
Value;
943 if (SetOrganizationalProperties)
944 this.OrgCity = P.
Value;
948 if (SetOrganizationalProperties)
949 this.OrgRegion = P.
Value;
953 if (SetOrganizationalProperties)
954 this.OrgCountryCode = P.
Value;
958 this.DeviceId = P.
Value;
966 this.PhoneNr = P.
Value;
970 this.EMail = P.
Value;
975 if (SetPersonalProperties && BirthDay.HasValue && BirthMonth.HasValue && BirthYear.HasValue)
979 this.BirthDate =
new DateTime(BirthYear.Value, BirthMonth.Value, BirthDay.Value);
984 this.BirthDate = DateTime.Today;
988 if (SetAppProperties)
990 this.DeviceId =
ServiceRef.PlatformSpecific.GetDeviceId();
996 return Task.CompletedTask;
1012 [RelayCommand(CanExecute = nameof(
CanApply))]
1015 return Task.CompletedTask;
const int MinAge
Minimum age for applying for an ID
const int MaxAge
Maximum age for applying for an ID
XMPP Protocol Properties.
const string PersonalNumber
Personal number
const string OrgAddress2
Organization Address line 2
const string DeviceId
Device ID
const string Country
Country
const string OrgArea
Organization Area
const string Region
Region
const string OrgRegion
Organization Region
const string Nationality
Nationality
const string ZipCode
Zip Code
const string BirthYear
Birth Year
const string OrgCity
Organization City
const string OrgRole
Organization Role
const string Phone
Phone number
const string EMail
e-Mail address
const string OrgZipCode
Organization Zip Code
const string MiddleNames
Middle names
const string BirthDay
Birth Day
const string OrgCountry
Organization Country
const string OrgDepartment
Organization Department
const string Address2
Address line 2
const string Jid
Jabber ID
const string OrgAddress
Organization Address line 1
const string Address
Address line 1
const string LastNames
Last names
const string OrgNumber
Organization number
const string BirthMonth
Birth Month
const string FirstName
First name
const string Gender
Gender
const string OrgName
Organization name
A set of never changing property constants and helpful values.
Conversion between Country Names and ISO-3166-1 country codes.
static bool TryGetCountryByCode(string? CountryCode, [NotNullWhen(true)] out ISO_3166_Country? Country)
Tries to get the country, given its country code.
static ? string ToCode(string? CountryName)
Converts the name to a country code (if found). If not found, returns the original name.
Static class containing ISO 5218 gender codes
static bool LetterToGender(string Letter, out ISO_5218_Gender? Gender)
Tries to get the gender label corresponding to an ISO 5218 gender code.
Personal Number Schemes available in different countries.
static async Task< NumberInformation > Validate(string CountryCode, string PersonalNumber)
Checks if a personal number is valid, in accordance with registered personal number schemes.
Base class that references services in the app.
static ILogService LogService
Log service.
static ITagProfile TagProfile
TAG Profile service.
static IXmppService XmppService
The XMPP service for XMPP communication.
The data model for registering an identity.
virtual bool CanExecuteCommands
Used to find out if a command can execute
bool OrgCityOk
If OrgCity is OK.
bool OrgNumberOk
If OrgNumber is OK.
bool CityOk
If City is OK.
bool GenderOk
If GenderCode is OK.
bool OrgRoleOk
If OrgRole is OK.
DateTime MinBirthDate
Minimum birth date. (i.e. Maximum age.)
bool OrgAreaOk
If OrgArea is OK.
bool MiddleNamesOk
If MiddleNames is OK.
bool OrgCountryOk
If OrgCountryCode is OK.
Property[] ToProperties(IXmppService XmppService)
Converts the RegisterIdentityModel to an array of .
bool OrgRegionOk
If OrgRegion is OK.
virtual Task OnConnected()
Gets called when the app gets connected.
override async Task OnInitialize()
Method called when view is initialized for the first time. Use this method to implement registration ...
RegisterIdentityModel()
The data model for registering an identity.
virtual bool CanApply
If user can apply for an identity.
bool PersonalNumberOk
If PersonalNumber is OK.
DateTime MaxBirthDate
Maximum birth date. (i.e. Minimum age.)
bool LastNamesOk
If LastNames is OK.
bool OrgAddress2Ok
If OrgAddress2 is OK.
bool NationalityOk
If NationalityCode is OK.
bool CountryOk
If CountryCode is OK.
bool OrgAddressOk
If OrgAddress is OK.
bool RegionOk
If Region is OK.
override Task XmppService_ConnectionStateChanged(object? Sender, XmppState NewState)
Listens to connection state changes from the XMPP server.
bool ZipCodeOk
If ZipCode is OK.
bool OrgNameOk
If OrgName is OK.
virtual void NotifyCommandsCanExecuteChanged()
Updates status of commands.
override void SetIsBusy(bool IsBusy)
Sets the IsBusy property.
bool OrgZipCodeOk
If OrgZipCode is OK.
bool FirstNameOk
If FirstName is OK.
virtual Task SetProperties(LegalIdentity Identity, bool ClearPropertiesNotFound, bool SetPersonalProperties, bool SetOrganizationalProperties, bool SetAppProperties)
Sets the properties of the view model.
bool AddressOk
If Address is OK.
bool AreaOk
If Area is OK.
bool BirthDateOk
If OrgName is OK.
bool OrgDepartmentOk
If OrgDepartment is OK.
DateTime? NullIfInvalidBirthDate
Returns null if birth date is the minimum birth date. Else returns BirthDate.
virtual Task Apply()
Executes the application command.
bool Address2Ok
If Address2 is OK.
A view model that holds the XMPP state.
string Name
Name of property
string Value
Property value
Represents an abstraction of a connection to an XMPP Server.
string BareJid
The Bare Jid of the current connection, or null.
XmppState
State of XMPP connection.