/// <summary> /// Create links /// </summary> /// <param name="metaId">META-ID</param> /// <param name="language">Language</param> /// <param name="dictionary">Dictionary containing the link formats</param> /// <returns></returns> private MetaLink[] GetLinks(string metaId, string language, Dictionary <string, Dictionary <string, MetaLinkFormat> > dictionary) { List <MetaLink> lst = new List <MetaLink>(); // Get link-information per system string[] systemLinks = metaId.Split(_systemSeparator, StringSplitOptions.RemoveEmptyEntries); foreach (MetadataSystem system in _metadataSystems) { foreach (string systemLink in systemLinks) { // Split the system link into parameters object[] systemLinkParams = systemLink.Split(_paramSeparator, StringSplitOptions.RemoveEmptyEntries); if (systemLinkParams.Length > 0) { string sysId = (string)systemLinkParams[0]; // The first parameter shall be the id of the metadata system if (system.ID.Equals(sysId)) { // Verify that we have metadata format information for the specified system and language if (dictionary.ContainsKey(sysId) && dictionary[sysId].ContainsKey(language)) { // Remove first parameter value which is the metadata system id systemLinkParams = systemLinkParams.Where((val, idx) => idx != 0).ToArray(); // Get format object from dictionary MetaLinkFormat format = dictionary[sysId][language]; // How many parameters are required for the link text? int parameters = format.NumberOfTextParameters(); if (systemLinkParams.Length >= parameters) { MetaLink lnk = new MetaLink(); lnk.System = system.ID; // Create link text lnk.LinkText = string.Format(format.LinkTextFormat, systemLinkParams); // How many parameters are required for the link? parameters = format.NumberOfLinkParameters(); if (systemLinkParams.Length >= parameters) { // Create the link lnk.Link = string.Format(format.LinkFormat, systemLinkParams); lnk.Target = format.Target; // Add link to the return-list lst.Add(lnk); } } } } } } } return(lst.ToArray()); }
/// <summary> /// Load sub section of the configuration file /// </summary> /// <param name="section">Name of the section</param> /// <param name="dictionary">Dictionary to store section data in</param> /// <returns></returns> private bool LoadConfigurationSection(string section, Dictionary <string, Dictionary <string, MetaLinkFormat> > dictionary) { string xpath; XmlNode node; XmlNodeList xmlnodes; xpath = "/metaId/" + section; node = _xdoc.SelectSingleNode(xpath); // Find all system nodes xpath = ".//metaSystem"; xmlnodes = node.SelectNodes(xpath); foreach (XmlNode sysNode in xmlnodes) { string sysId = sysNode.Attributes["id"].Value; // system id if (!string.IsNullOrWhiteSpace(sysId)) { AddMetadataSystem(sysId); if (!dictionary.ContainsKey(sysId)) { dictionary.Add(sysId, new Dictionary <string, MetaLinkFormat>()); // add system to dictionary // Find all language nodes for the system xpath = ".//link"; XmlNodeList langNodes = sysNode.SelectNodes(xpath); foreach (XmlNode langNode in langNodes) { string language = langNode.Attributes["px-lang"].Value; string textFormat = langNode.Attributes["labelStringFormat"].Value; string linkFormat = langNode.Attributes["urlStringFormat"].Value; string target; if ((langNode.Attributes["target"] != null) && (!string.IsNullOrEmpty(langNode.Attributes["target"].Value))) { target = langNode.Attributes["target"].Value; } else { target = "_blank"; } if (!string.IsNullOrWhiteSpace(language) && !string.IsNullOrWhiteSpace(textFormat) && !string.IsNullOrWhiteSpace(linkFormat)) { if (!dictionary[sysId].ContainsKey(language)) { MetaLinkFormat format = new MetaLinkFormat(); format.LinkTextFormat = textFormat; format.LinkFormat = linkFormat; format.Target = target; dictionary[sysId].Add(language, format); // Add format for this language to dictionary } } } } } } return(true); }