14 internal sealed
class KycOrderingComparer : IComparer<string>
16 private readonly Dictionary<string, OrderKey> orderByKey;
17 private readonly PropertyOrderComparer propertyComparer;
18 private readonly DisplayQuadOrderComparer displayComparer;
20 private KycOrderingComparer(Dictionary<string, OrderKey> OrderByKey)
22 this.orderByKey = OrderByKey;
23 this.propertyComparer =
new PropertyOrderComparer(
this);
24 this.displayComparer =
new DisplayQuadOrderComparer(
this);
27 public static KycOrderingComparer Create(
KycProcess Process)
31 throw new ArgumentNullException(nameof(Process));
34 Dictionary<string, OrderKey> Map = BuildOrderMap(Process);
35 return new KycOrderingComparer(Map);
38 public IComparer<Property> PropertyComparer => this.propertyComparer;
40 public IComparer<DisplayQuad> DisplayComparer => this.displayComparer;
42 public int Compare(
string? Left,
string? Right)
44 OrderKey LeftKey = this.GetOrderKey(Left);
45 OrderKey RightKey = this.GetOrderKey(Right);
47 int Result = LeftKey.PageIndex.CompareTo(RightKey.PageIndex);
53 Result = LeftKey.FieldIndex.CompareTo(RightKey.FieldIndex);
59 Result = LeftKey.MappingIndex.CompareTo(RightKey.MappingIndex);
65 return string.Compare(LeftKey.Name, RightKey.Name, StringComparison.OrdinalIgnoreCase);
68 private OrderKey GetOrderKey(
string? Key)
70 if (
string.IsNullOrWhiteSpace(Key))
72 return OrderKey.Unknown;
75 if (this.orderByKey.TryGetValue(Key, out OrderKey Existing))
80 string Normalized = Key.Trim();
81 return new OrderKey(
int.MaxValue,
int.MaxValue,
int.MaxValue, Normalized);
84 private static Dictionary<string, OrderKey> BuildOrderMap(
KycProcess process)
86 Dictionary<string, OrderKey> Map =
new Dictionary<string, OrderKey>(StringComparer.OrdinalIgnoreCase);
87 for (
int PageIndex = 0; PageIndex < process.
Pages.Count; PageIndex++)
94 RegisterFieldMappings(Map, Field, PageIndex, FieldIndex);
102 RegisterFieldMappings(Map, Field, PageIndex, FieldIndex);
111 private static void RegisterFieldMappings(Dictionary<string, OrderKey> map,
ObservableKycField field,
int pageIndex,
int fieldIndex)
118 for (
int MappingIndex = 0; MappingIndex < field.
Mappings.Count; MappingIndex++)
126 string Key = Mapping.Key ??
string.Empty;
127 if (
string.IsNullOrWhiteSpace(Key))
132 string TrimmedKey = Key.Trim();
133 if (map.ContainsKey(TrimmedKey))
138 OrderKey Order =
new OrderKey(pageIndex, fieldIndex, MappingIndex, TrimmedKey);
139 map[TrimmedKey] = Order;
141 HandleAliases(map, TrimmedKey, Order);
145 private static void HandleAliases(Dictionary<string, OrderKey> map,
string key, OrderKey order)
154 if (key.StartsWith(
"ORGREP", StringComparison.OrdinalIgnoreCase))
156 RegisterAlias(map,
"ORGREPBDATE", order);
160 private static void RegisterAlias(Dictionary<string, OrderKey> map,
string alias, OrderKey order)
162 if (
string.IsNullOrWhiteSpace(alias))
167 if (map.ContainsKey(alias))
172 OrderKey AliasOrder =
new OrderKey(order.PageIndex, order.FieldIndex, order.MappingIndex, alias.Trim());
173 map[alias] = AliasOrder;
176 private readonly
struct OrderKey
178 public OrderKey(
int pageIndex,
int fieldIndex,
int mappingIndex,
string name)
180 this.PageIndex = pageIndex;
181 this.FieldIndex = fieldIndex;
182 this.MappingIndex = mappingIndex;
186 public int PageIndex {
get; }
188 public int FieldIndex {
get; }
190 public int MappingIndex {
get; }
192 public string Name {
get; }
194 public static OrderKey Unknown =>
new OrderKey(
int.MaxValue,
int.MaxValue,
int.MaxValue,
string.Empty);
197 private sealed
class PropertyOrderComparer : IComparer<Property>
199 private readonly KycOrderingComparer owner;
201 public PropertyOrderComparer(KycOrderingComparer owner)
208 if (left is
null && right is
null)
223 return this.owner.Compare(left.
Name, right.
Name);
227 private sealed
class DisplayQuadOrderComparer : IComparer<DisplayQuad>
229 private readonly KycOrderingComparer owner;
231 public DisplayQuadOrderComparer(KycOrderingComparer owner)
238 if (left is
null && right is
null)
253 int Result = this.owner.Compare(left.Mapping, right.Mapping);
259 return string.Compare(left.Label, right.Label, StringComparison.OrdinalIgnoreCase);
Custom XMPP Protocol Properties.
const string BirthDate
Full birthday
XMPP Protocol Properties.
const string BirthYear
Birth Year
const string BirthDay
Birth Day
const string BirthMonth
Birth Month
A set of never changing property constants and helpful values.
Represents a displayable set of three related strings: a label, a value, and an optional mapping.
Mapping from a field value to an identity property, including optional transform pipeline.
Represents a page in a KYC process containing fields and sections.
ObservableCollection< KycSection > AllSections
Gets all sections contained in the page.
ObservableCollection< ObservableKycField > AllFields
Gets all fields directly contained in the page (excluding sections).
Represents a parsed KYC process with pages, fields, and current values.
ObservableCollection< KycPage > Pages
Gets the collection of pages in the KYC process.
The base KYC field model. Use as-is for generic fields, or subclass for custom logic.
ObservableCollection< KycMapping > Mappings
Mappings to apply output.
string Name
Name of property