Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
KycReference.cs
1using System;
3using System.Globalization;
4using System.Linq;
5using System.Threading.Tasks;
12
14{
18 [CollectionName("KycReferences")]
19 [Index(nameof(UpdatedUtc), nameof(UpdatedUtc))]
20 [Index(nameof(CreatedIdentityId))]
21 public class KycReference
22 {
23 private KycProcess? process;
24 private ApplicationReview? applicationReview;
25
29 [ObjectId]
30 public string? ObjectId { get; set; }
31
35 public string? KycXml { get; set; }
36
40 public DateTime CreatedUtc { get; set; }
41
45 public DateTime UpdatedUtc { get; set; }
46
50 public DateTime FetchedUtc { get; set; }
51
56 [DefaultValue(0)]
57 public int Version { get; set; }
58
62 [DefaultValueNull]
63 public KycFieldValue[]? Fields { get; set; }
64
68 [DefaultValueStringEmpty]
69 public string FriendlyName { get; set; } = string.Empty;
70
74 [DefaultValueNull]
75 public string? CreatedIdentityId { get; set; }
76
80 [DefaultValueNull]
81 public IdentityState? CreatedIdentityState { get; set; }
82
86 [DefaultValue(0.0)]
87 public double Progress { get; set; }
88
92 [DefaultValueNull]
93 public string? LastVisitedPageId { get; set; }
94
98 [DefaultValueStringEmpty]
99 public string LastVisitedMode { get; set; } = "Form";
100
104 [DefaultValueNull]
106 {
107 get
108 {
109 if (this.applicationReview is null)
110 this.TryMigrateLegacyReview();
111
112 return this.applicationReview;
113 }
114
115 set => this.applicationReview = value;
116 }
117
121 [DefaultValueNull]
122 [Obsolete("Use ApplicationReview instead.")]
123 public string? RejectionMessage { get; set; }
124
128 [DefaultValueNull]
129 [Obsolete("Use ApplicationReview instead.")]
130 public string? RejectionCode { get; set; }
131
135 [DefaultValueNull]
136 [Obsolete("Use ApplicationReview instead.")]
137 public string[]? InvalidClaims { get; set; }
138
142 [DefaultValueNull]
143 [Obsolete("Use ApplicationReview instead.")]
144 public string[]? InvalidPhotos { get; set; }
145
149 [DefaultValueNull]
150 [Obsolete("Use ApplicationReview instead.")]
151 public KycInvalidClaim[]? InvalidClaimDetails { get; set; }
152
156 [DefaultValueNull]
157 [Obsolete("Use ApplicationReview instead.")]
158 public KycInvalidPhoto[]? InvalidPhotoDetails { get; set; }
159
165 public async Task<KycProcess?> GetProcess(string? lang = null)
166 {
167 if (this.process is null && this.KycXml is not null)
168 {
169 this.process = await KycProcessParser.LoadProcessAsync(this.KycXml, lang).ConfigureAwait(false);
170
171 if (this.Fields is not null)
172 {
173 foreach (KycFieldValue Field in this.Fields)
174 this.process.Values[Field.FieldId] = Field.Value;
175
176 foreach (KycPage Page in this.process.Pages)
177 {
178 foreach (ObservableKycField Field in Page.AllFields)
179 this.ApplyFieldValue(Field);
180
181 foreach (KycSection Section in Page.AllSections)
182 foreach (ObservableKycField Field in Section.AllFields)
183 this.ApplyFieldValue(Field);
184 }
185 }
186 }
187
188 return this.process;
189 }
190
196 public void SetProcess(KycProcess process, string xml)
197 {
198 this.SetProcess(process, xml, DateTime.UtcNow, DateTime.UtcNow);
199 }
200
208 public void SetProcess(KycProcess process, string xml, DateTime created, DateTime updated)
209 {
210 this.process = process;
211 this.KycXml = xml;
212 this.CreatedUtc = created;
213 this.UpdatedUtc = updated;
214 this.FetchedUtc = DateTime.UtcNow;
215 this.Fields = process.Values.Select(p => new KycFieldValue(p.Key, p.Value)).ToArray();
216 }
217
218 public void ApplyFieldValue(ObservableKycField Field)
219 {
220 if (this.process is null || !this.process.Values.TryGetValue(Field.Id, out string? Val) || Val is null)
221 return;
222 Field.StringValue = Val;
223 }
224
225 // SetFieldValue removed; logic is now in Field.StringValue
226
234 public static KycReference FromProcess(KycProcess process, string xml, string? friendlyName = null)
235 {
236 KycReference Reference = new KycReference
237 {
238 process = process,
239 KycXml = xml,
240 CreatedUtc = DateTime.UtcNow,
241 UpdatedUtc = DateTime.UtcNow,
242 FetchedUtc = DateTime.UtcNow,
243 Fields = process.Values.Select(P => new KycFieldValue(P.Key, P.Value)).ToArray(),
244 FriendlyName = friendlyName ?? string.Empty
245 };
246 return Reference;
247 }
248
256 public async Task ApplyFieldsToProcessAsync(string? lang = null)
257 {
258 KycProcess? Proc = await this.GetProcess(lang).ConfigureAwait(false);
259
260 if (Proc is null || this.Fields is null)
261 return;
262
263 foreach (KycFieldValue Field in this.Fields)
264 Proc.Values[Field.FieldId] = Field.Value;
265
266 foreach (KycPage Page in Proc.Pages)
267 {
268 foreach (ObservableKycField Field in Page.AllFields)
269 this.ApplyFieldValue(Field);
270
271 foreach (KycSection Section in Page.AllSections)
272 foreach (ObservableKycField Field in Section.AllFields)
273 this.ApplyFieldValue(Field);
274
275 Page.UpdateVisibilities(Proc.Values);
276 }
277 }
278
284 public async Task<KycProcess?> ToProcess(string? lang = null)
285 {
286 return await this.GetProcess(lang);
287 }
288
289 private void TryMigrateLegacyReview()
290 {
291 if (this.applicationReview is not null)
292 return;
293
294 bool hasLegacyData =
295 !string.IsNullOrWhiteSpace(this.RejectionMessage) ||
296 !string.IsNullOrWhiteSpace(this.RejectionCode) ||
297 (this.InvalidClaims?.Length ?? 0) > 0 ||
298 (this.InvalidPhotos?.Length ?? 0) > 0 ||
299 (this.InvalidClaimDetails?.Length ?? 0) > 0 ||
300 (this.InvalidPhotoDetails?.Length ?? 0) > 0;
301
302 if (!hasLegacyData)
303 return;
304
306 {
307 Message = this.RejectionMessage ?? string.Empty,
308 Code = this.RejectionCode,
309 ReceivedUtc = this.UpdatedUtc
310 };
311
312 string[]? invalidClaims = this.InvalidClaims?
313 .Where(s => !string.IsNullOrWhiteSpace(s))
314 .Select(s => s.Trim())
315 .ToArray();
316 string[]? invalidPhotos = this.InvalidPhotos?
317 .Where(s => !string.IsNullOrWhiteSpace(s))
318 .Select(s => s.Trim())
319 .ToArray();
320
321 Migrated.InvalidClaims = invalidClaims is { Length: > 0 } ? invalidClaims : Array.Empty<string>();
322 Migrated.InvalidPhotos = invalidPhotos is { Length: > 0 } ? invalidPhotos : Array.Empty<string>();
323
325 .Where(c => c is not null && !string.IsNullOrWhiteSpace(c.Claim))
326 .Select(c =>
327 {
328 string Claim = c.Claim.Trim();
329 string Reason = c.Reason ?? string.Empty;
330 return new ApplicationReviewClaimDetail(Claim, Reason, c.ReasonLanguage, c.ReasonCode, c.Service);
331 })
332 .ToArray() ?? Array.Empty<ApplicationReviewClaimDetail>();
333
335 .Where(p => p is not null && (!string.IsNullOrWhiteSpace(p.Mapping) || !string.IsNullOrWhiteSpace(p.FileName)))
336 .Select(p =>
337 {
338 string FileName = (p.FileName ?? string.Empty).Trim();
339 string DisplayName = !string.IsNullOrWhiteSpace(p.Mapping) ? p.Mapping.Trim() : FileName;
340 return new ApplicationReviewPhotoDetail(FileName, DisplayName, p.Reason ?? string.Empty, p.ReasonLanguage, p.ReasonCode, p.Service);
341 })
342 .ToArray() ?? Array.Empty<ApplicationReviewPhotoDetail>();
343
344 Migrated.InvalidClaimDetails = claimDetails;
345 Migrated.InvalidPhotoDetails = photoDetails;
346
347 this.applicationReview = Migrated;
348 this.RejectionMessage = null;
349 this.RejectionCode = null;
350 this.InvalidClaims = null;
351 this.InvalidPhotos = null;
352 this.InvalidClaimDetails = null;
353 this.InvalidPhotoDetails = null;
354 }
355 }
356}
Contains additional data about an invalid claim.
Captures the result of an application review returned from backend services.
Contains additional data about an invalid photo.
Parses an XML-described KYC process into view-model objects.
static Task< KycProcess > LoadProcessAsync(string Xml, string? Lang=null)
Parses the KYC pages from an XML string.
Contains a local reference to a KYC process.
Definition: KycReference.cs:22
string? LastVisitedPageId
Last visited page identifier to support resuming.
Definition: KycReference.cs:93
static KycReference FromProcess(KycProcess process, string xml, string? friendlyName=null)
Creates a KycReference from a KycProcess, serializing its field values.
IdentityState? CreatedIdentityState
Last known state of the created identity (if any), for quick status tagging offline.
Definition: KycReference.cs:81
double Progress
Progress of the KYC process (0.0–1.0), persisted for UI display.
Definition: KycReference.cs:87
KycInvalidPhoto?[] InvalidPhotoDetails
Legacy invalid photo detail payload retained for persistence migration. Do not use directly.
string FriendlyName
Optional friendly name.
Definition: KycReference.cs:69
void SetProcess(KycProcess process, string xml, DateTime created, DateTime updated)
Stores a parsed KYC process into the reference with explicit timestamps.
string LastVisitedMode
Last visited mode: "Form" or "Summary". Default is "Form".
Definition: KycReference.cs:99
string?[] InvalidClaims
Legacy invalid claim collection retained for persistence migration. Do not use directly.
string? RejectionCode
Legacy rejection code retained for persistence migration. Do not use directly.
async Task ApplyFieldsToProcessAsync(string? lang=null)
Ensures the current process reflects values in Fields by applying them into the cached process instan...
string? RejectionMessage
Legacy rejection message retained for persistence migration. Do not use directly.
async Task< KycProcess?> GetProcess(string? lang=null)
Gets a parsed KYC process, populating its fields from the reference.
string? CreatedIdentityId
The legal ID of the created identity (if any).
Definition: KycReference.cs:75
KycFieldValue?[] Fields
Field values in the process.
Definition: KycReference.cs:63
KycInvalidClaim?[] InvalidClaimDetails
Legacy invalid claim detail payload retained for persistence migration. Do not use directly.
int Version
Monotonically increasing version for optimistic concurrency and snapshot ordering....
Definition: KycReference.cs:57
DateTime CreatedUtc
When the reference was created.
Definition: KycReference.cs:40
DateTime FetchedUtc
When the process was last fetched.
Definition: KycReference.cs:50
void SetProcess(KycProcess process, string xml)
Stores a parsed KYC process into the reference.
async Task< KycProcess?> ToProcess(string? lang=null)
Creates a KycProcess from this reference, populating its fields.
DateTime UpdatedUtc
When the reference was last updated.
Definition: KycReference.cs:45
string?[] InvalidPhotos
Legacy invalid photo collection retained for persistence migration. Do not use directly.
string? KycXml
XML describing the KYC process.
Definition: KycReference.cs:35
Represents a field value in a KYC process reference.
string FieldId
Gets or sets the field identifier (unique within the process).
string? Value
Gets or sets the value of the field as a string.
Detailed reason info for an invalidated claim.
Detailed reason info for an invalidated photo/attachment.
Represents a page in a KYC process containing fields and sections.
Definition: KycPage.cs:20
ObservableCollection< KycSection > AllSections
Gets all sections contained in the page.
Definition: KycPage.cs:64
void UpdateVisibilities(IDictionary< string, string?> Values)
Updates visibility flags for fields and sections based on current values.
Definition: KycPage.cs:78
ObservableCollection< ObservableKycField > AllFields
Gets all fields directly contained in the page (excluding sections).
Definition: KycPage.cs:51
Represents a parsed KYC process with pages, fields, and current values.
Definition: KycProcess.cs:11
ObservableCollection< KycPage > Pages
Gets the collection of pages in the KYC process.
Definition: KycProcess.cs:26
IDictionary< string, string?> Values
Gets a modifiable dictionary of field values keyed by field identifier.
Definition: KycProcess.cs:21
The base KYC field model. Use as-is for generic fields, or subclass for custom logic.
string Id
The unique identifier for the field.
IdentityState
Lists recognized legal identity states.