1using System.Collections.ObjectModel;
2using System.Globalization;
3using CommunityToolkit.Mvvm.ComponentModel;
4using CommunityToolkit.Mvvm.Input;
31 await base.OnInitializeAsync();
39 return MainThread.InvokeOnMainThreadAsync(async () =>
41 await base.XmppService_ConnectionStateChanged(Sender, NewState);
52 return Task.CompletedTask;
58 base.SetIsBusy(IsBusy);
67 this.ApplyCommand.NotifyCanExecuteChanged();
70 public ObservableCollection<ObservableAttachmentCard> AdditionalPhotos {
get; } = [];
76 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
78 private string? firstName =
"";
84 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
86 private string? middleNames;
92 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
94 private string? lastNames;
100 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
102 private string? personalNumber;
108 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
109 [NotifyPropertyChangedFor(nameof(
AddressOk))]
110 private string? address;
116 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
117 [NotifyPropertyChangedFor(nameof(
Address2Ok))]
118 private string? address2;
124 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
125 [NotifyPropertyChangedFor(nameof(
ZipCodeOk))]
126 private string? zipCode;
132 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
133 [NotifyPropertyChangedFor(nameof(
AreaOk))]
134 private string? area;
140 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
141 [NotifyPropertyChangedFor(nameof(
CityOk))]
142 private string? city;
148 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
149 [NotifyPropertyChangedFor(nameof(
RegionOk))]
150 private string? region;
156 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
157 [NotifyPropertyChangedFor(nameof(
CountryOk))]
158 [NotifyPropertyChangedFor(nameof(PersonalNumberPlaceholder))]
159 private string? countryCode;
167 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
169 private string? nationalityCode;
175 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
176 [NotifyPropertyChangedFor(nameof(
GenderOk))]
177 private string? genderCode;
184 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
187 private DateTime birthDate = DateTime.Today;
193 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
194 [NotifyPropertyChangedFor(nameof(
OrgNameOk))]
195 private string? orgName;
201 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
203 private string? orgNumber;
209 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
211 private string? orgAddress;
217 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
219 private string? orgAddress2;
225 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
227 private string? orgZipCode;
233 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
234 [NotifyPropertyChangedFor(nameof(
OrgAreaOk))]
235 private string? orgArea;
241 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
242 [NotifyPropertyChangedFor(nameof(
OrgCityOk))]
243 private string? orgCity;
249 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
251 private string? orgRegion;
257 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
258 private string? orgCountryCode;
264 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
266 private string? orgDepartment;
272 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
273 [NotifyPropertyChangedFor(nameof(
OrgRoleOk))]
274 private string? orgRole;
280 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
281 private string? phoneNr;
287 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
288 private string? eMail;
294 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
295 private string? deviceId;
301 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
308 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
310 private bool requiresFirstName;
316 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
318 private bool requiresMiddleNames;
324 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
326 private bool requiresLastNames;
332 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
334 private bool requiresPersonalNumber;
340 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
341 [NotifyPropertyChangedFor(nameof(
AddressOk))]
342 private bool requiresAddress;
348 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
349 [NotifyPropertyChangedFor(nameof(
Address2Ok))]
350 private bool requiresAddress2;
356 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
357 [NotifyPropertyChangedFor(nameof(
ZipCodeOk))]
358 private bool requiresZipCode;
364 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
365 [NotifyPropertyChangedFor(nameof(
AreaOk))]
366 private bool requiresArea;
372 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
373 [NotifyPropertyChangedFor(nameof(
CityOk))]
374 private bool requiresCity;
380 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
381 [NotifyPropertyChangedFor(nameof(
RegionOk))]
382 private bool requiresRegion;
388 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
389 [NotifyPropertyChangedFor(nameof(
CountryOk))]
390 private bool requiresCountry;
396 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
397 [NotifyPropertyChangedFor(nameof(
CountryOk))]
398 private bool requiresCountryIso3166;
404 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
406 private bool requiresNationality;
412 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
413 [NotifyPropertyChangedFor(nameof(
GenderOk))]
414 private bool requiresGender;
420 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
422 private bool requiresBirthDate;
428 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
429 [NotifyPropertyChangedFor(nameof(
OrgNameOk))]
430 private bool requiresOrgName;
436 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
438 private bool requiresOrgDepartment;
444 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
445 [NotifyPropertyChangedFor(nameof(
OrgRoleOk))]
446 private bool requiresOrgRole;
452 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
454 private bool requiresOrgNumber;
460 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
462 private bool requiresOrgAddress;
468 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
470 private bool requiresOrgAddress2;
476 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
478 private bool requiresOrgZipCode;
484 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
485 [NotifyPropertyChangedFor(nameof(
OrgAreaOk))]
486 private bool requiresOrgArea;
492 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
493 [NotifyPropertyChangedFor(nameof(
OrgCityOk))]
494 private bool requiresOrgCity;
500 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
502 private bool requiresOrgRegion;
508 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
510 private bool requiresOrgCountry;
515 public bool FirstNameOk => !this.RequiresFirstName || !
string.IsNullOrWhiteSpace(this.FirstName);
520 public bool MiddleNamesOk => !this.RequiresMiddleNames || !
string.IsNullOrWhiteSpace(this.MiddleNames);
525 public bool LastNamesOk => !this.RequiresLastNames || !
string.IsNullOrWhiteSpace(this.LastNames);
534 if (
string.IsNullOrWhiteSpace(this.PersonalNumber))
535 return !this.RequiresPersonalNumber;
537 if (
string.IsNullOrWhiteSpace(this.CountryCode))
542 return !Info.IsValid.HasValue || Info.
IsValid.Value;
549 public bool AddressOk => !this.RequiresAddress || !
string.IsNullOrWhiteSpace(this.Address);
554 public bool Address2Ok => !this.RequiresAddress2 || !
string.IsNullOrWhiteSpace(this.Address2);
559 public bool ZipCodeOk => !this.RequiresZipCode || !
string.IsNullOrWhiteSpace(this.ZipCode);
564 public bool AreaOk => !this.RequiresArea || !
string.IsNullOrWhiteSpace(this.Area);
569 public bool CityOk => !this.RequiresCity || !
string.IsNullOrWhiteSpace(this.City);
574 public bool RegionOk => !this.RequiresRegion || !
string.IsNullOrWhiteSpace(this.Region);
583 if (
string.IsNullOrWhiteSpace(this.CountryCode))
584 return !this.RequiresCountry;
600 if (
string.IsNullOrWhiteSpace(this.NationalityCode))
601 return !this.RequiresNationality;
617 if (
string.IsNullOrEmpty(this.GenderCode))
618 return !this.RequiresGender;
639 get => (this.BirthDate == DateTime.Today) ?
null : this.BirthDate;
640 set => this.BirthDate = value ?? DateTime.Today;
649 if (this.
NullIfInvalidBirthDate.HasValue && (
this.BirthDate >
this.MaxBirthDate ||
this.BirthDate <
this.MinBirthDate))
652 return !this.RequiresBirthDate;
659 public bool OrgNameOk => !this.RequiresOrgName || !
string.IsNullOrWhiteSpace(this.OrgName);
664 public bool OrgDepartmentOk => !this.RequiresOrgDepartment || !
string.IsNullOrWhiteSpace(this.OrgDepartment);
669 public bool OrgRoleOk => !this.RequiresOrgRole || !
string.IsNullOrWhiteSpace(this.OrgRole);
674 public bool OrgNumberOk => !this.RequiresOrgNumber || !
string.IsNullOrEmpty(this.OrgNumber);
679 public bool OrgAddressOk => !this.RequiresOrgAddress || !
string.IsNullOrWhiteSpace(this.OrgAddress);
684 public bool OrgAddress2Ok => !this.RequiresOrgAddress2 || !
string.IsNullOrWhiteSpace(this.OrgAddress2);
689 public bool OrgZipCodeOk => !this.RequiresOrgZipCode || !
string.IsNullOrWhiteSpace(this.OrgZipCode);
694 public bool OrgAreaOk => !this.RequiresOrgArea || !
string.IsNullOrWhiteSpace(this.OrgArea);
699 public bool OrgCityOk => !this.RequiresOrgCity || !
string.IsNullOrWhiteSpace(this.OrgCity);
704 public bool OrgRegionOk => !this.RequiresOrgRegion || !
string.IsNullOrWhiteSpace(this.OrgRegion);
713 if (
string.IsNullOrWhiteSpace(this.OrgCountryCode))
714 return !this.RequiresOrgCountry;
730 List<Property> Properties = [];
769 return [.. Properties];
772 private static void AddProperty(List<Property> Properties,
string PropertyName,
string? PropertyValue)
774 string? s = PropertyValue?.Trim();
776 if (!
string.IsNullOrWhiteSpace(s))
777 Properties.Add(
new Property(PropertyName, s));
789 bool SetOrganizationalProperties,
bool SetAppProperties)
791 if (ClearPropertiesNotFound)
793 this.FirstName =
string.Empty;
794 this.MiddleNames =
string.Empty;
795 this.LastNames =
string.Empty;
796 this.PersonalNumber =
string.Empty;
797 this.Address =
string.Empty;
798 this.Address2 =
string.Empty;
799 this.ZipCode =
string.Empty;
800 this.Area =
string.Empty;
801 this.City =
string.Empty;
802 this.Region =
string.Empty;
803 this.CountryCode =
string.Empty;
804 this.NationalityCode =
string.Empty;
805 this.GenderCode =
string.Empty;
806 this.BirthDate = DateTime.Today;
807 this.OrgName =
string.Empty;
808 this.OrgNumber =
string.Empty;
809 this.OrgAddress =
string.Empty;
810 this.OrgAddress2 =
string.Empty;
811 this.OrgZipCode =
string.Empty;
812 this.OrgArea =
string.Empty;
813 this.OrgCity =
string.Empty;
814 this.OrgRegion =
string.Empty;
815 this.OrgCountryCode =
string.Empty;
816 this.OrgDepartment =
string.Empty;
817 this.OrgRole =
string.Empty;
818 this.PhoneNr =
string.Empty;
819 this.EMail =
string.Empty;
820 this.DeviceId =
string.Empty;
821 this.Jid =
string.Empty;
824 int? BirthDay =
null;
825 int? BirthMonth =
null;
826 int? BirthYear =
null;
828 foreach (
Property P
in Identity.Properties)
833 if (SetPersonalProperties)
834 this.FirstName = P.
Value;
838 if (SetPersonalProperties)
839 this.MiddleNames = P.
Value;
843 if (SetPersonalProperties)
844 this.LastNames = P.
Value;
848 if (SetPersonalProperties)
849 this.PersonalNumber = P.
Value;
853 if (SetPersonalProperties)
854 this.Address = P.
Value;
858 if (SetPersonalProperties)
859 this.Address2 = P.
Value;
863 if (SetPersonalProperties)
864 this.ZipCode = P.
Value;
868 if (SetPersonalProperties)
873 if (SetPersonalProperties)
878 if (SetPersonalProperties)
879 this.Region = P.
Value;
883 if (SetPersonalProperties)
884 this.CountryCode = P.
Value;
888 if (SetPersonalProperties)
889 this.NationalityCode = P.
Value;
893 if (SetPersonalProperties)
894 this.GenderCode = P.
Value;
898 if (
int.TryParse(P.
Value, out
int i))
903 if (
int.TryParse(P.
Value, out i))
908 if (
int.TryParse(P.
Value, out i))
913 if (SetOrganizationalProperties)
914 this.OrgName = P.
Value;
918 if (SetOrganizationalProperties)
919 this.OrgNumber = P.
Value;
923 if (SetOrganizationalProperties)
924 this.OrgRole = P.
Value;
928 if (SetOrganizationalProperties)
929 this.OrgDepartment = P.
Value;
933 if (SetOrganizationalProperties)
934 this.OrgAddress = P.
Value;
938 if (SetOrganizationalProperties)
939 this.OrgAddress2 = P.
Value;
943 if (SetOrganizationalProperties)
944 this.OrgZipCode = P.
Value;
948 if (SetOrganizationalProperties)
949 this.OrgArea = P.
Value;
953 if (SetOrganizationalProperties)
954 this.OrgCity = P.
Value;
958 if (SetOrganizationalProperties)
959 this.OrgRegion = P.
Value;
963 if (SetOrganizationalProperties)
964 this.OrgCountryCode = P.
Value;
968 this.DeviceId = P.
Value;
976 this.PhoneNr = P.
Value;
980 this.EMail = P.
Value;
985 if (SetPersonalProperties && BirthDay.HasValue && BirthMonth.HasValue && BirthYear.HasValue)
989 this.BirthDate =
new DateTime(BirthYear.Value, BirthMonth.Value, BirthDay.Value);
994 this.BirthDate = DateTime.Today;
998 if (SetAppProperties)
1006 return Task.CompletedTask;
1022 [RelayCommand(CanExecute = nameof(
CanApply))]
1025 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 ? string DisplayStringForCountry(string CountryCode)
Gets the expected personal number format for the given country.
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.
static IPlatformSpecific PlatformSpecific
Localization service
The data model for registering an identity.
bool OrgZipCodeOk
If OrgZipCode is OK.
bool LastNamesOk
If LastNames is OK.
bool AddressOk
If Address is OK.
RegisterIdentityModel()
The data model for registering an identity.
Property[] ToProperties(IXmppService XmppService)
Converts the RegisterIdentityModel to an array of .
bool OrgAreaOk
If OrgArea is OK.
bool MiddleNamesOk
If MiddleNames is OK.
bool AreaOk
If Area is OK.
DateTime MinBirthDate
Minimum birth date. (i.e. Maximum age.)
override void SetIsBusy(bool IsBusy)
Sets the IsBusy property.
override async Task OnInitializeAsync()
Method called when view is initialized for the first time. Use this method to implement registration ...
bool OrgAddress2Ok
If OrgAddress2 is OK.
bool OrgCountryOk
If OrgCountryCode is OK.
virtual void NotifyCommandsCanExecuteChanged()
Updates status of commands.
bool BirthDateOk
If OrgName is OK.
virtual bool CanApply
If user can apply for an identity.
bool NationalityOk
If NationalityCode is OK.
bool CityOk
If City is OK.
virtual Task SetProperties(LegalIdentity Identity, bool ClearPropertiesNotFound, bool SetPersonalProperties, bool SetOrganizationalProperties, bool SetAppProperties)
Sets the properties of the view model.
bool OrgNameOk
If OrgName is OK.
bool OrgRegionOk
If OrgRegion is OK.
virtual Task Apply()
Executes the application command.
bool OrgCityOk
If OrgCity is OK.
bool FirstNameOk
If FirstName is OK.
bool GenderOk
If GenderCode is OK.
bool OrgDepartmentOk
If OrgDepartment is OK.
bool ZipCodeOk
If ZipCode is OK.
bool OrgAddressOk
If OrgAddress is OK.
bool PersonalNumberOk
If PersonalNumber is OK.
bool OrgRoleOk
If OrgRole is OK.
DateTime MaxBirthDate
Maximum birth date. (i.e. Minimum age.)
bool CountryOk
If CountryCode is OK.
bool Address2Ok
If Address2 is OK.
DateTime? NullIfInvalidBirthDate
Returns null if birth date is the minimum birth date. Else returns BirthDate.
override Task XmppService_ConnectionStateChanged(object? Sender, XmppState NewState)
Listens to connection state changes from the XMPP server.
bool OrgNumberOk
If OrgNumber is OK.
bool RegionOk
If Region is OK.
virtual Task OnConnected()
Gets called when the app gets connected.
virtual bool CanExecuteCommands
Used to find out if a command can execute
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.