18 private readonly
string legalId;
19 private readonly Dictionary<string, ValidClaim> validatedClaims =
20 new Dictionary<string, ValidClaim>();
21 private readonly Dictionary<string, InvalidClaim> invalidatedClaims =
22 new Dictionary<string, InvalidClaim>();
23 private readonly Dictionary<string, bool> unvalidatedClaims =
24 new Dictionary<string, bool>();
25 private readonly Dictionary<string, ValidPhoto> validatedPhotos =
26 new Dictionary<string, ValidPhoto>();
27 private readonly Dictionary<string, InvalidPhoto> invalidatedPhotos =
28 new Dictionary<string, InvalidPhoto>();
29 private readonly Dictionary<string, IPhoto> unvalidatedPhotos =
30 new Dictionary<string, IPhoto>();
31 private readonly Dictionary<string, PotentialClaim> potentialClaims =
32 new Dictionary<string, PotentialClaim>();
37 private readonly KeyValuePair<string, object>[] claims;
38 private readonly IEnumerable<IPhoto> photos;
39 private readonly IEnumerable<XmlDocument> documents;
41 private readonly
object synchObj =
new object();
42 private readonly
string @
namespace;
43 private readonly
int nrPhotos;
44 private readonly
bool preview;
63 Array.Empty<XmlDocument>(),
Account)
85 this.legalId = LegalId;
87 this.@
namespace = Namespace;
88 this.preview = Preview;
93 this.documents = Documents;
98 foreach (KeyValuePair<string, object> Claim
in Claims)
99 this.unvalidatedClaims[Claim.Key] =
true;
111 this.legalId = Application.legalId;
112 this.account = Application.Account;
113 this.@
namespace = Application.@namespace;
114 this.preview = Application.
Preview;
115 this.personalInformation = Application.PersonalInformation;
116 this.claims = Application.Claims;
117 this.photos = Application.Photos;
118 this.nrPhotos = Application.NrPhotos;
119 this.documents = Application.Documents;
121 foreach (KeyValuePair<string, object> Claim
in Application.Claims)
122 this.unvalidatedClaims[Claim.Key] =
true;
147 public KeyValuePair<string, object>[]
Claims => this.claims;
152 public IEnumerable<IPhoto>
Photos => this.photos;
162 public IEnumerable<XmlDocument>
Documents => this.documents;
173 if (this.unvalidatedClaims.Remove(Claim))
175 this.invalidatedClaims.Remove(Claim);
176 this.potentialClaims.Remove(Claim);
178 this.validatedClaims[Claim] =
new ValidClaim(Claim, Service);
180 if (!this.services.Contains(Service))
181 this.services.Add(Service);
195 public void ClaimInvalid(
string Claim,
string Reason,
string ReasonLanguage,
196 string ReasonCode,
object Service)
200 if (this.unvalidatedClaims.Remove(Claim))
202 this.validatedClaims.Remove(Claim);
203 this.potentialClaims.Remove(Claim);
205 this.invalidatedClaims[Claim] =
new InvalidClaim(Claim, Reason, ReasonLanguage, ReasonCode, Service);
207 if (!this.services.Contains(Service))
208 this.services.Add(Service);
222 if (this.unvalidatedPhotos.Remove(
Photo.
Id))
224 this.invalidatedPhotos.Remove(
Photo.
Id);
227 if (!this.services.Contains(Service))
228 this.services.Add(Service);
243 string ReasonCode,
object Service)
247 if (this.unvalidatedPhotos.Remove(
Photo.
Id))
249 this.validatedPhotos.Remove(
Photo.
Id);
252 if (!this.services.Contains(Service))
253 this.services.Add(Service);
267 public void ReportError(
string Error,
string ErrorLanguage,
string ErrorCode,
273 ErrorCode, Service,
Tags));
275 if (!this.services.Contains(Service))
276 this.services.Add(Service);
290 this.validatedClaims.Values.CopyTo(Result, 0);
306 this.invalidatedClaims.Values.CopyTo(Result, 0);
321 string[] Result =
new string[this.unvalidatedClaims.Count];
322 this.unvalidatedClaims.Keys.CopyTo(Result, 0);
338 this.validatedPhotos.Values.CopyTo(Result, 0);
354 this.invalidatedPhotos.Values.CopyTo(Result, 0);
369 IPhoto[] Result =
new IPhoto[this.unvalidatedPhotos.Count];
370 this.unvalidatedPhotos.Values.CopyTo(Result, 0);
386 this.potentialClaims.Values.CopyTo(Result, 0);
401 return this.errors.ToArray();
415 return this.errors.Count > 0;
429 return this.errors.Count;
443 return this.services.ToArray();
457 return this.services.Count > 0;
471 return this.services.Count;
486 if (this.invalidatedClaims.Count > 0 ||
this.invalidatedPhotos.Count > 0)
489 if (this.errors.Count > 0)
498 if (this.unvalidatedClaims.Count > 0 ||
499 this.unvalidatedPhotos.Count > 0 ||
500 this.errors.Count > 0)
519 return this.validatedClaims.Count > 0;
533 return this.validatedPhotos.Count > 0;
547 return this.potentialClaims.Count > 0;
555 public KeyValuePair<string, object>[]
Tags
565 int NrErrors = this.invalidatedClaims.Count + this.invalidatedPhotos.Count + this.errors.Count;
570 foreach (KeyValuePair<string, object> Claim
in this.claims)
577 foreach (
object Service
in this.services)
579 Result.
Add(
new KeyValuePair<string, object>(
581 Service.GetType().Namespace));
596 AppendTags(Result, Error, ref i,
NrErrors);
604 private static void AppendTags(
ChunkedList<KeyValuePair<string, object>> Result,
609 Result.Add(
new KeyValuePair<string, object>(
613 Result.Add(
new KeyValuePair<string, object>(
614 TagName(
"Error Language", i,
NrErrors),
617 Result.Add(
new KeyValuePair<string, object>(
621 Result.Add(
new KeyValuePair<string, object>(
633 new KeyValuePair<string, object>(
"Result", this.
IsValid),
634 new KeyValuePair<string, object>(
"Contact", this.personalInformation.EMail)
639 foreach (KeyValuePair<string, ValidClaim> Claim
in this.validatedClaims)
640 Result.
Add(
new KeyValuePair<string, object>(Claim.Key,
"Validator:" + Claim.Value.Service.GetType().FullName));
642 foreach (KeyValuePair<string, ValidPhoto> Claim
in this.validatedPhotos)
643 Result.
Add(
new KeyValuePair<string, object>(Claim.Key,
"Validator:" + Claim.Value.Service.GetType().FullName));
645 foreach (KeyValuePair<string, InvalidClaim> Claim
in this.invalidatedClaims)
646 Result.
Add(
new KeyValuePair<string, object>(Claim.Key,
"Invalidator:" + Claim.Value.Service.GetType().FullName));
648 foreach (KeyValuePair<string, InvalidPhoto> Claim
in this.invalidatedPhotos)
649 Result.
Add(
new KeyValuePair<string, object>(Claim.Key,
"Invalidator:" + Claim.Value.Service.GetType().FullName));
651 foreach (KeyValuePair<string, bool> Claim
in this.unvalidatedClaims)
652 Result.
Add(
new KeyValuePair<string, object>(Claim.Key,
"Unvalidated"));
654 foreach (KeyValuePair<string, IPhoto> Claim
in this.unvalidatedPhotos)
655 Result.
Add(
new KeyValuePair<string, object>(Claim.Key,
"Unvalidated"));
659 this.personalInformation.Jid,
"IdReviewPerformed", Result.
ToArray());
662 private static string TagName(
string Base,
int Index,
int Nr)
665 return Base +
" " + Index.ToString();
702 string DefaultMessageCode,
string DefaultLanguage)
704 StringBuilder Xml =
new StringBuilder();
709 Xml.Append(
"<body>");
711 Xml.Append(
"</body>");
712 Xml.Append(
"<clientMessage xmlns='");
713 Xml.Append(this.@
namespace);
714 Xml.Append(
"' id='");
716 Xml.Append(
"' code='");
718 Xml.Append(
"' type='");
719 Xml.Append(Error?.ErrorType.ToString() ??
"Client");
722 this.AppendApplicationStatus(Xml);
724 Xml.Append(
"</clientMessage>");
726 return Xml.ToString();
735 StringBuilder Xml =
new StringBuilder();
737 Xml.Append(
"<identityReview xmlns='");
738 Xml.Append(this.@
namespace);
739 Xml.Append(
"' id='");
743 this.AppendApplicationStatus(Xml);
745 Xml.Append(
"</identityReview>");
747 return Xml.ToString();
750 private void AppendApplicationStatus(StringBuilder Xml)
756 Xml.Append(
"<invalidClaim claim='");
758 Xml.Append(
"' message='");
763 Xml.Append(
"' code='");
767 AppendService(Xml, InvalidClaim.
Service);
771 Xml.Append(
"' xml:lang='");
778 foreach (InvalidPhoto InvalidPhoto
in this.invalidatedPhotos.Values)
780 Xml.Append(
"<invalidPhoto fileName='");
781 Xml.Append(
XML.
Encode(InvalidPhoto.Photo.FileName));
782 Xml.Append(
"' message='");
783 Xml.Append(
XML.
Encode(InvalidPhoto.Reason));
785 if (!
string.IsNullOrEmpty(InvalidPhoto.ReasonCode))
787 Xml.Append(
"' code='");
788 Xml.Append(
XML.
Encode(InvalidPhoto.ReasonCode));
791 AppendService(Xml, InvalidPhoto.Service);
793 if (!
string.IsNullOrEmpty(InvalidPhoto.ReasonLanguage))
795 Xml.Append(
"' xml:lang='");
796 Xml.Append(
XML.
Encode(InvalidPhoto.ReasonLanguage));
802 foreach (ValidationError ValidationError
in this.errors)
804 Xml.Append(
"<error message='");
805 Xml.Append(
XML.
Encode(ValidationError.ErrorMessage));
806 Xml.Append(
"' type='");
807 Xml.Append(
XML.
Encode(ValidationError.ErrorType.ToString()));
809 if (!
string.IsNullOrEmpty(ValidationError.ErrorCode))
811 Xml.Append(
"' code='");
812 Xml.Append(
XML.
Encode(ValidationError.ErrorCode));
815 AppendService(Xml, ValidationError.Service);
817 if (!
string.IsNullOrEmpty(ValidationError.ErrorLanguage))
819 Xml.Append(
"' xml:lang='");
820 Xml.Append(
XML.
Encode(ValidationError.ErrorLanguage));
823 if (ValidationError.Tags.Length == 0)
829 Xml.Append(
"</error>");
833 foreach (ValidClaim ValidClaim
in this.validatedClaims.Values)
835 Xml.Append(
"<validatedClaim claim='");
836 Xml.Append(
XML.
Encode(ValidClaim.Claim));
837 AppendService(Xml, ValidClaim.Service);
841 foreach (ValidPhoto ValidPhoto
in this.validatedPhotos.Values)
843 Xml.Append(
"<validatedPhoto fileName='");
844 Xml.Append(
XML.
Encode(ValidPhoto.Photo.FileName));
845 AppendService(Xml, ValidPhoto.Service);
849 foreach (PotentialClaim PotentialClaim
in this.potentialClaims.Values)
851 if (PotentialClaim.InformUser)
853 Xml.Append(
"<potentialClaim claim='");
854 Xml.Append(
XML.
Encode(PotentialClaim.Claim));
855 Xml.Append(
"' value='");
856 Xml.Append(
XML.
Encode(PotentialClaim.Value?.ToString() ??
string.Empty));
857 AppendService(Xml, PotentialClaim.Service);
862 foreach (
string UnvalidatedClaim
in this.unvalidatedClaims.Keys)
864 Xml.Append(
"<unvalidatedClaim claim='");
865 Xml.Append(
XML.
Encode(UnvalidatedClaim));
869 foreach (IPhoto UnvalidatedPhoto
in this.unvalidatedPhotos.Values)
871 Xml.Append(
"<unvalidatedPhoto fileName='");
872 Xml.Append(
XML.
Encode(UnvalidatedPhoto.FileName));
878 private static void AppendService(StringBuilder Xml,
object Service)
880 if (!(Service is
null))
882 Xml.Append(
"' service='");
884 if (Service is Type T)
887 Xml.Append(
XML.
Encode(Service.GetType().FullName));
896 foreach (KeyValuePair<string, object> Claim
in this.Claims)
919 foreach (KeyValuePair<string, object> Claim
in this.Claims)
920 this.
ClaimInvalid(Claim.Key, Reason, ReasonLanguage, ReasonCode,
this);
935 this.
PhotoInvalid(Photo, Reason, ReasonLanguage, ReasonCode,
this);
947 public bool TryGetValue<T>(
string Claim,
object Value,
object Service, out T TypedValue)
949 if (Value is T Typed)
956 this.
ClaimInvalid(Claim,
"Expected value of type " + typeof(T).FullName +
".",
957 "en",
"InvalidType", Service);
959 TypedValue =
default;
978 if (!this.unvalidatedClaims.Remove(Claim))
980 if (this.invalidatedClaims.ContainsKey(Claim) ||
981 this.validatedClaims.ContainsKey(Claim) ||
982 this.potentialClaims.ContainsKey(Claim))
988 this.validatedClaims.Remove(Claim);
989 this.invalidatedClaims.Remove(Claim);
991 this.potentialClaims[Claim] =
new PotentialClaim(Claim, Value, InformUser, Service);
993 if (!this.services.Contains(Service))
994 this.services.Add(Service);
Contains information about a legal identity application.
ValidPhoto[] ValidatedPhotos
Validated photos.
string[] UnvalidatedClaims
Unvalidated claims.
int NrPhotos
Number of photos provided.
IEnumerable< IPhoto > Photos
Photos provided.
void ReportError(string Error, string ErrorLanguage, string ErrorCode, ValidationErrorType ErrorType, object Service, params KeyValuePair< string, object >[] Tags)
Reports an error encountered during validation.
void ClaimValid(string Claim, object Service)
An identity authenticator service validates a claim.
bool HasValidatedClaims
If the application has validated claims.
bool HasValidatedPhotos
If the application has validated photos.
IdentityApplication(string LegalId, string Namespace, bool Preview, PersonalInformation PersonalInformation, KeyValuePair< string, object >[] Claims, IEnumerable< IPhoto > Photos, IEnumerable< XmlDocument > Documents, IAccount Account)
Contains information about a legal identity application.
bool HasErrors
If errors are reported.
bool TryGetValue< T >(string Claim, object Value, object Service, out T TypedValue)
Tries to get a typed claim value from an untyped claim value.
IPhoto[] UnvalidatedPhotos
Unvalidated photos.
IAccount Account
Account over which the application was made.
void PhotoInvalid(IPhoto Photo, string Reason, string ReasonLanguage, string ReasonCode, object Service)
An identity authenticator service invalidates a photo.
InvalidPhoto[] InvalidatedPhotos
Invalidated photos.
void InvalidateAllClaims(string Reason, string ReasonLanguage, string ReasonCode)
Invalidates all claims.
PotentialClaim[] PotentialClaims
Potential claims
string GetIdentityReviewXml()
Gets information about the review as XML.
bool Preview
If the application is a preview of an application. Previewed applications should not be persisted.
void ValidateAllClaims()
Validates all claims.
KeyValuePair< string, object >[] Tags
Tags annotating the application, as reported by the different services.
int NrErrors
Number of errors reported.
ValidClaim[] ValidatedClaims
Validated claims.
IdentityApplication(string LegalId, string Namespace, bool Preview, PersonalInformation PersonalInformation, KeyValuePair< string, object >[] Claims, IEnumerable< IPhoto > Photos, IAccount Account)
Contains information about a legal identity application.
void InvalidateAllPhotos(string Reason, string ReasonLanguage, string ReasonCode)
Invalidates all photos
int NrServices
Number of services returning feedback on the the application.
string GetClientErrorMessageXml(out string Language, string DefaultMessage, string DefaultMessageCode, string DefaultLanguage)
Gets the XML of the client error message.
void LogResults()
Logs the results of the validation process to the event log.
void AddPotentialClaims(string Claim, object Value, bool InformUser, object Service)
Adds potential claims to the application that can be used in a subsequent applcation....
bool HasServices
If services have returned feedback on the application.
IValidationError FirstError
First error encountered during validation.
object[] Services
Services involved in returning feedback on the application.
void ValidateAllPhotos()
Validates all photos
IEnumerable< XmlDocument > Documents
Associated XML document attachments provided.
void ClaimInvalid(string Claim, string Reason, string ReasonLanguage, string ReasonCode, object Service)
An identity authenticator service invalidates a claim.
bool HasPotentialClaims
If the application has potential claims.
IdentityApplication(IdentityApplication Application)
Contains information about a legal identity application.
InvalidClaim[] InvalidatedClaims
Invalidated claims.
bool? IsValid
If the application has been validated (true), invalidated (false), or not yet validated (null).
KeyValuePair< string, object >[] Claims
Full set of claims made regarding the identity, as meta-data tags.
ValidationError[] Errors
Any errors reported during validation.
void PhotoValid(IPhoto Photo, object Service)
An identity authenticator service validates a photo.
Represents an invalidated claim.
string Reason
Reason for invalidating claim.
string Claim
Identifier of claim
string ReasonLanguage
ISO code of language used for Reason.
string ReasonCode
A machine-readable code for the reason for invalidating the claim. (Each service can define its own r...
object Service
Service invalidating claim.
Represents an invalidated photo.
Represents a photo in an identity application.
string Id
Unique identifier for photo.
Represents a potential claim.
Represents a validated claim.
Represents a validated photo.
Contains information about a validation error.
string ErrorLanguage
Language ISO code of ErrorMessage.
string ErrorCode
Machine-readable error code (service-specific).
string ErrorMessage
Error message that can be sent to origin
ValidationErrorType ErrorType
Type of error.
Helps with common XML-related tasks.
static string Encode(string s)
Encodes a string for use in XML.
Static class managing the application event log. Applications and services log events on this static ...
static void Informational(string Message, string Object, string Actor, string EventId, EventLevel Level, string Facility, string Module, string StackTrace, params KeyValuePair< string, object >[] Tags)
Logs an informational event.
Event sink sending events to a destination over the XMPP network.
static void AppendTags(StringBuilder Xml, params KeyValuePair< string, object >[] Tags)
Appends a collection of tags to an XML string.
A chunked list is a linked list of chunks of objects of type T .
void Add(T Item)
Adds an item to the collection.
T[] ToArray()
Returns an array containing all elements of the collection.
Interface for identity applications.
Contains information about a validation error.
string ErrorLanguage
Language ISO code of ErrorMessage.
string ErrorMessage
Error message that can be sent to origin
string ErrorCode
Machine-readable error code (service-specific).
Interface for SMTP user accounts.
ValidationErrorType
Type of validation error.