4using System.Collections.Generic;
6using System.Threading.Tasks;
8using System.Windows.Input;
57 private readonly Dictionary<string, IdentityWrapper> identities =
new();
107 this.apply =
new Command(this.CanExecuteApply, this.ExecuteApply);
110 this.contracts.EnableE2eEncryption(
true);
111 this.contracts.IdentityUpdated += this.Contracts_IdentityUpdated;
112 this.contracts.PetitionForIdentityReceived += this.Contracts_PetitionForIdentityReceived;
120 this.contracts.Dispose();
143 MainWindow.currentInstance.LegalIdTab.DataContext =
this;
144 MainWindow.currentInstance.ContractsTab.DataContext =
this;
145 MainWindow.currentInstance.ContractsTab.ContractCommands.DataContext =
this;
147 return Task.CompletedTask;
150 await this.contracts.LoadKeys(
true);
154 lock (this.identities)
157 this.identities[Identity.
Id] =
new IdentityWrapper(this.contracts.Client.Domain, Identity);
163 List<TemplateReferenceModel>
Templates =
new();
165 foreach (KeyValuePair<string, object> Setting
in Settings)
167 if (Setting.Value is
string ContractId)
176 #region Legal Identity properties
183 get => this.firstName.Value;
184 set => this.firstName.Value = value;
192 get => this.middleName.Value;
193 set => this.middleName.Value = value;
201 get => this.lastName.Value;
202 set => this.lastName.Value = value;
210 get => this.personalNumber.Value;
211 set => this.personalNumber.Value = value;
219 get => this.address.Value;
220 set => this.address.Value = value;
228 get => this.address2.Value;
229 set => this.address2.Value = value;
237 get => this.zip.Value;
238 set => this.zip.Value = value;
246 get => this.area.Value;
247 set => this.area.Value = value;
255 get => this.city.Value;
256 set => this.city.Value = value;
264 get => this.region.Value;
265 set => this.region.Value = value;
273 get => this.country.Value;
274 set => this.country.Value = value;
292 get => this.nationality.Value;
293 set => this.nationality.Value = value;
301 get => this.gender.Value;
302 set => this.gender.Value = value;
310 get => this.birthDate.Value;
311 set => this.birthDate.Value = value;
319 get => this.eMail.Value;
320 set => this.eMail.Value = value;
328 get => this.orgName.Value;
329 set => this.orgName.Value = value;
337 get => this.orgDepartment.Value;
338 set => this.orgDepartment.Value = value;
346 get => this.orgRole.Value;
347 set => this.orgRole.Value = value;
355 get => this.orgNumber.Value;
356 set => this.orgNumber.Value = value;
364 get => this.orgAddress.Value;
365 set => this.orgAddress.Value = value;
373 get => this.orgAddress2.Value;
374 set => this.orgAddress2.Value = value;
382 get => this.orgZip.Value;
383 set => this.orgZip.Value = value;
391 get => this.orgArea.Value;
392 set => this.orgArea.Value = value;
400 get => this.orgCity.Value;
401 set => this.orgCity.Value = value;
409 get => this.orgRegion.Value;
410 set => this.orgRegion.Value = value;
418 get => this.orgCountry.Value;
419 set => this.orgCountry.Value = value;
424 #region Legal Identities
433 lock (this.identities)
436 this.identities.Values.CopyTo(Result, 0);
444 lock (this.identities)
451 return Task.CompletedTask;
456 #region Apply for new Legal Identity
461 public ICommand
Apply => this.apply;
463 private bool CanExecuteApply()
465 return this.contracts.Client.State ==
XmppState.Connected;
468 private async Task ExecuteApply()
477 await this.contracts.ObsoleteLegalIdentityAsync(OldIdentity.
Id);
480 List<Property> Properties =
new();
482 AddProperty(Properties,
"FIRST", this.
FirstName);
483 AddProperty(Properties,
"MIDDLE", this.
MiddleName);
484 AddProperty(Properties,
"LAST", this.
LastName);
486 AddProperty(Properties,
"ADDR", this.
Address);
487 AddProperty(Properties,
"ADDR2", this.
Address2);
488 AddProperty(Properties,
"ZIP", this.
Zip);
489 AddProperty(Properties,
"AREA", this.
Area);
490 AddProperty(Properties,
"CITY", this.
City);
491 AddProperty(Properties,
"REGION", this.
Region);
492 AddProperty(Properties,
"COUNTRY", this.
Country);
493 AddProperty(Properties,
"NATIONALITY", this.
Nationality);
494 AddProperty(Properties,
"GENDER", this.
Gender);
495 AddProperty(Properties,
"EMAIL", this.
EMail);
499 AddProperty(Properties,
"BDAY", this.
BirthDate.Value.Day.ToString());
500 AddProperty(Properties,
"BMONTH", this.
BirthDate.Value.Month.ToString());
501 AddProperty(Properties,
"BYEAR", this.
BirthDate.Value.Year.ToString());
504 AddProperty(Properties,
"ORGNAME", this.
OrgName);
506 AddProperty(Properties,
"ORGROLE", this.
OrgRole);
507 AddProperty(Properties,
"ORGNR", this.
OrgNumber);
508 AddProperty(Properties,
"ORGADDR", this.
OrgAddress);
509 AddProperty(Properties,
"ORGADDR2", this.
OrgAddress2);
510 AddProperty(Properties,
"ORGZIP", this.
OrgZip);
511 AddProperty(Properties,
"ORGAREA", this.
OrgArea);
512 AddProperty(Properties,
"ORGCITY", this.
OrgCity);
513 AddProperty(Properties,
"ORGREGION", this.
OrgRegion);
514 AddProperty(Properties,
"ORGCOUNTRY", this.
OrgCountry);
516 AddProperty(Properties,
"JID", this.contracts.Client.BareJID);
518 LegalIdentity Identity = await this.contracts.ApplyAsync(Properties.ToArray());
520 lock (this.identities)
522 this.identities[Identity.
Id] =
new IdentityWrapper(this.contracts.Client.Domain, Identity);
533 private static void AddProperty(List<Property> Properties,
string Name,
string Value)
535 if (!
string.IsNullOrEmpty(Value))
536 Properties.Add(
new Property(Name, Value));
541 #region Legal Identity Petitions
545 StringBuilder Question =
new();
547 Question.Append(
"A petition for your legal identity has been received for the following purpose: ");
549 Question.Append(
" The petition was sent by");
556 Question.Append(
", at");
566 if (!
string.IsNullOrEmpty(s))
571 Append(Question, s,
" ",
string.Empty);
576 Question.Append(
". Do you want to return your identity information?");
580 switch (MessageBox.Show(Question.ToString(),
"Petition received", MessageBoxButton.YesNoCancel, MessageBoxImage.Question, MessageBoxResult.No))
582 case MessageBoxResult.Yes:
583 Task.Run(() => this.contracts.PetitionIdentityResponseAsync(e.RequestedIdentityId, e.PetitionId, e.RequestorFullJid, true));
586 case MessageBoxResult.No:
587 Task.Run(() => this.contracts.PetitionIdentityResponseAsync(e.RequestedIdentityId, e.PetitionId, e.RequestorFullJid, false));
591 return Task.CompletedTask;
594 return Task.CompletedTask;
597 private static void Append(StringBuilder Question,
string Value,
string PrefixIfNotEmpty,
string SuffixIfNotEmpty)
599 if (!
string.IsNullOrEmpty(Value))
601 Question.Append(PrefixIfNotEmpty);
602 Question.Append(Value);
603 Question.Append(SuffixIfNotEmpty);
609 #region Create Contracts
616 get => this.templates.Value;
617 set => this.templates.Value = value;
625 get => this.contractTemplateName.Value;
628 this.contractTemplateName.Value = value;
640 this.contractTemplateName.Value = Name;
642 await this.LoadTemplate(Name, PresetValues);
650 get => this.
template.Value;
651 set => this.template.Value = value;
661 SortedDictionary<string, TemplateReferenceModel>
Templates =
new();
668 this.Templates =
Templates.ToValueArray();
671 private async Task LoadTemplate(
string TemplateName, Dictionary<CaseInsensitiveString, object> PresetValues)
676 if (
string.IsNullOrEmpty(ContractId))
680 this.Template = await this.contracts.GetContractAsync(ContractId);
683 if (this.currentContract is not
null)
684 await this.currentContract.
Stop();
687 MainWindow.currentInstance.ContractsTab.MachineReadableXmlEditor);
689 await this.currentContract.
Start();
692 MainWindow.currentInstance.ContractsTab.LanguageOptions,
693 MainWindow.currentInstance.ContractsTab.CreateParameters,
694 MainWindow.currentInstance.ContractsTab.CreateCommands,
698 MainWindow.currentInstance.ContractsTab.ContractToCreate,
699 MainWindow.currentInstance.ContractsTab.ContractToCreateHumanReadable);
Interaction logic for MainWindow.xaml
static void MouseHourglass()
Displays an hourglass cursor (or similar for waiting purposes).
static void ErrorBox(string ErrorMessage)
Displays an error message on the screen, on the main UI thread.
static DesignModel DesignModel
Design model
static void UpdateGui(GuiDelegate Method)
Calls a method from the Main UI thread.
static void MouseDefault()
Returns to default mouse pointer.
Defines a custom command.
async Task PopulateContract(StackPanel ContractLayout, StackPanel HumanReadableText)
Displays the contents of the contract
override Task Stop()
Stops the model.
static async Task< ContractModel > CreateAsync(ContractsClient Contracts, Contract Contract, DesignModel DesignModel, NonScrollingTextEditor XmlEditor)
Creates the contract model
override Task Start()
Starts the model.
virtual async Task< Control > PopulateParameters(StackPanel Languages, StackPanel Parameters, StackPanel AdditionalCommands, Dictionary< CaseInsensitiveString, object > PresetValues)
Populates a StackPanel with parameter controls.
Wrapper around a LegalIdentity, for purposes of displaying it to the user.
static Iso_3166_1.Record[] CountryCodes
ISO 3166-1 country codes
string OrgZip
Organization ZIP or postal code
static Iso_5218.Record[] GenderCodes
ISO 5218 gender codes
string Address2
Address, second row
string FirstName
First name of person
IdentityWrapper[] Identities
Legal Identities registered on the account.
TemplateReferenceModel[] Templates
Template References
string EMail
e-Mail address
string OrgName
Organization name
ContractsClient Contracts
Contracts client.
string OrgNumber
Organization number
string OrgRole
Organization Role
string LastName
Last name of person
string OrgArea
Organization Area
string OrgCountry
Organization Country
string OrgAddress2
Organization Address, second row
string ContractTemplateName
Contract Template Name
string OrgAddress
Organization Address
void ContractTemplateAdded(string TemplateName, Contract Contract)
A contract template has been added.
Contract Template
Template selected as basis for new contracts
string OrgCity
Organization City
async Task SetContractTemplateName(string Name, Dictionary< CaseInsensitiveString, object > PresetValues)
Selects the template to use.
ICommand Apply
Apply command
string OrgDepartment
Organization Department
string MiddleName
Middle name of person
LegalModel(XmppClient Client, string ComponentJid, string FileUploadJid, long? MaxFileSize)
Legal ID Model
string OrgRegion
Organization Region
override async Task Start()
Starts the model.
HttpFileUploadClient FileUpload
HTTP File Upload client.
string PersonalNumber
Personal number
string Zip
ZIP or postal code
ContractModel CurrentContract
Current contract model.
string Nationality
Nationality
DateTime? BirthDate
Birth Date
string TemplateName
Template Name
virtual Task Start()
Starts the model.
virtual void RaisePropertyChanged(string PropertyName)
Raises the PropertyChanged event.
Abstract base class for persistant view models
void Add(IPersistedProperty Property)
Adds a persistant property
Generic class for persistant properties
Generic class for properties
Contains one record of the ISO 3166-1 data set.
Static class containing ISO 3166-1 country codes
static bool CodeToCountry(string Code, out string Country)
Tries to get the country name corresponding to an ISO 3166-1 country code.
static readonly Record[] Data
Available country codes
Contains one record of the ISO 5218 data set.
Static class containing ISO 5218 gender codes
static readonly Record[] Data
Available gender codes
Contains the definition of a contract
string ContractId
Contract identity
Adds support for legal identities, smart contracts and signatures to an XMPP client.
Event arguments for legal identity responses
LegalIdentity Identity
Legal Identity
Event arguments for legal identity petitions
LegalIdentity RequestorIdentity
Legal Identity of requesting entity.
string RequestorFullJid
Full JID of requestor.
IdentityState State
Current state of identity
string Id
ID of the legal identity
Class managing HTTP File uploads, as defined in XEP-0363.
Manages an XMPP client connection. Implements XMPP, as defined in https://tools.ietf....
Static class managing persistent settings.
static Task< Dictionary< string, object > > GetWhereKeyLikeAsync(string Key, string Wildcard)
Gets available settings, matching a search filter.
static async Task< string > GetAsync(string Key, string DefaultValue)
Gets a string-valued setting.
IdentityState
Lists recognized legal identity states.
XmppState
State of XMPP connection.