5 using System.Collections.ObjectModel;
6 using System.Globalization;
15 private const string XmlLanguageNamespace =
"http://www.w3.org/XML/1998/namespace";
16 private readonly IReadOnlyDictionary<string, string> localizedNames;
17 private readonly
string? primaryDisplayName;
23 string? serviceAddress,
26 IReadOnlyDictionary<string, string> localizedNames,
27 string? primaryDisplayName)
31 this.ProcessXml = processXml;
32 this.ServiceAddress = serviceAddress;
33 this.Publisher = publisher;
34 this.Published = published;
35 this.localizedNames = localizedNames;
36 this.primaryDisplayName = primaryDisplayName;
72 public IReadOnlyDictionary<string, string>
LocalizedNames => this.localizedNames;
81 if (!
string.IsNullOrEmpty(this.primaryDisplayName))
83 return this.primaryDisplayName;
85 string Preferred = CultureInfo.CurrentUICulture.TwoLetterISOLanguageName;
87 return Value ??
string.Empty;
109 if (
string.IsNullOrWhiteSpace(
ItemId))
112 XmlElement? Payload = Item.
Item;
115 string? PayloadXml = Item.
Payload;
116 if (
string.IsNullOrWhiteSpace(PayloadXml))
121 XmlDocument Document =
new XmlDocument();
122 Document.LoadXml(PayloadXml);
123 Payload = Document.DocumentElement;
134 XmlElement? PayloadElement = NormalizePayload(Payload);
135 if (PayloadElement is
null)
142 Dictionary<string, string> NamesDictionary = ExtractLocalizedNames(PayloadElement, out
string? PrimaryName);
143 ReadOnlyDictionary<string, string> Names =
new ReadOnlyDictionary<string, string>(NamesDictionary);
145 string NodeId = Item.Node ??
string.Empty;
159 public static IReadOnlyList<KycApplicationItem>
CreateMany(IEnumerable<PubSubItem> Items)
161 List<KycApplicationItem> Results =
new List<KycApplicationItem>();
168 Results.Add(Application);
181 if (Language is not
null && this.localizedNames.TryGetValue(Language, out
string? Value))
184 if (this.localizedNames.TryGetValue(
"en", out
string? English))
187 foreach (KeyValuePair<string, string> Pair
in this.localizedNames)
193 private static XmlElement? NormalizePayload(XmlElement Payload)
197 foreach (XmlNode Child
in Payload.ChildNodes)
199 if (Child is XmlElement Element)
209 private static Dictionary<string, string> ExtractLocalizedNames(XmlElement Payload, out
string? primaryName)
211 Dictionary<string, string> Names =
new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
213 XmlElement? NameElement = SelectChild(Payload,
"Name");
214 if (NameElement is
null)
217 foreach (XmlNode Child
in NameElement.ChildNodes)
219 if (Child is not XmlElement TextElement)
222 if (!
string.Equals(TextElement.LocalName,
"Text", StringComparison.Ordinal))
225 string Language = TextElement.GetAttribute(
"lang", XmlLanguageNamespace);
226 if (
string.IsNullOrWhiteSpace(Language))
229 string Value = TextElement.InnerText;
230 if (
string.IsNullOrWhiteSpace(Value))
233 Names[Language] = Value.Trim();
234 if (primaryName is
null)
235 primaryName = Value.Trim();
241 private static XmlElement? SelectChild(XmlElement Parent,
string LocalName,
string? NamespaceUri =
null)
243 foreach (XmlNode Child
in Parent.ChildNodes)
245 if (Child is not XmlElement Candidate)
248 if (!
string.Equals(Candidate.LocalName, LocalName, StringComparison.Ordinal))
251 if (NamespaceUri is not
null && !
string.Equals(Candidate.NamespaceURI, NamespaceUri, StringComparison.Ordinal))
Represents a KYC application template retrieved from PubSub storage.
string? ServiceAddress
Gets the service address that hosted the node, if available.
IReadOnlyDictionary< string, string > LocalizedNames
Gets localized display names extracted from the payload.
string ItemId
Gets the PubSub item identifier.
string NodeId
Gets the PubSub node identifier that produced the item.
static bool TryCreate(PubSubItem Item, out KycApplicationItem? Application)
Attempts to create an instance from a PubSub item.
string? GetLocalizedName(string? Language)
Retrieves a localized name for the provided language code.
string DisplayName
Gets a localized display name using the current UI culture as the preference.
string? Publisher
Gets the publisher that submitted the item, if available.
static IReadOnlyList< KycApplicationItem > CreateMany(IEnumerable< PubSubItem > Items)
Converts a collection of PubSub items to KYC application descriptors.
string ProcessXml
Gets the raw KYC process XML payload.
string? PrimaryDisplayName
Gets the first display name found in the payload, if available.
DateTime? Published
Gets the publish timestamp, if available.
Client managing communication with a Publish/Subscribe component. https://xmpp.org/extensions/xep-006...
const string NamespacePubSub
http://jabber.org/protocol/pubsub
Represents a published item.
string ServiceAddress
Address of service hosting the node.
string Publisher
Publisher of content.
XmlElement Item
Item XML Element.
class Names(Vector NamesVector)
Contains a collection of distinguished names.