/// <summary> /// Gets the XML for an ESD controlled list, cacheing it if possible /// </summary> /// <param name="configKey">Key for XML file name <Escc.Web.Metadata/ControlledListXml> section of web.config</param> /// <param name="withDom">true to include DOM and XPath support; false for XPath only</param> /// <returns>Populated XML document, or null if not found</returns> public static EsdControlledList GetControlledList(string configKey, bool withDom) { HttpContext ctx = HttpContext.Current; EsdControlledList xmlDoc = null; string cacheKey = String.Format(CultureInfo.InvariantCulture, "EsdXml_{0}", configKey); // Check for the document in the Application Data Cache if (ctx != null) { xmlDoc = (EsdControlledList)ctx.Cache.Get(cacheKey); } // Not in cache, so load XML if (xmlDoc == null) { NameValueCollection config = ConfigurationManager.GetSection("Escc.Web.Metadata/ControlledListXml") as NameValueCollection; if (config == null) { config = ConfigurationManager.GetSection("EsccWebTeam.Egms/ControlledListXml") as NameValueCollection; } if (config == null) { config = ConfigurationManager.GetSection("egmsXml") as NameValueCollection; } if (config != null) { if (String.IsNullOrEmpty(config[configKey])) { throw new ConfigurationErrorsException(String.Format(CultureInfo.CurrentCulture, Resources.ErrorConfigListNotFound, configKey)); } xmlDoc = new EsdControlledList(); if (withDom) { xmlDoc.LoadDom(config[configKey]); } else { xmlDoc.LoadXPath(config[configKey]); } } else { throw new ConfigurationErrorsException(Resources.ErrorConfig); } // Cache me if you can if (ctx != null) { ctx.Cache.Insert(cacheKey, xmlDoc, null, DateTime.MaxValue, TimeSpan.FromMinutes(15)); } } // See whether this XML is in the new SKOS-compatible format or the old format. The old format used the Preferred attribute. xmlDoc.skosCompatible = (xmlDoc.SelectNodes("ns:Item[@Preferred]").Count == 0); return(xmlDoc); }
/// <summary> /// Gets the XML for an ESD controlled list, cacheing it if possible /// </summary> /// <param name="xmlFileUri">The URI of the XML file.</param> /// <param name="withDom">true to include DOM and XPath support; false for XPath only</param> /// <returns>Populated XML document, or null if not found</returns> public static EsdControlledList GetControlledList(Uri xmlFileUri, bool withDom) { HttpContext ctx = HttpContext.Current; EsdControlledList xmlDoc = null; string cacheKey = String.Format(CultureInfo.InvariantCulture, "EsdXml_{0}", Regex.Replace(xmlFileUri.ToString(), "[^A-Za-z]", String.Empty)); // Check for the document in the Application Data Cache if (ctx != null) { xmlDoc = (EsdControlledList)ctx.Cache.Get(cacheKey); } // Not in cache, so load XML if (xmlDoc == null) { xmlDoc = new EsdControlledList(); if (withDom) { xmlDoc.LoadDom(xmlFileUri.ToString()); } else { xmlDoc.LoadXPath(xmlFileUri.ToString()); } // Cache me if you can if (ctx != null) { ctx.Cache.Insert(cacheKey, xmlDoc, null, DateTime.MaxValue, TimeSpan.FromMinutes(15)); } } // See whether this XML is in the new SKOS-compatible format or the old format. The old format used the Preferred attribute. xmlDoc.skosCompatible = (xmlDoc.SelectNodes("ns:Item[@Preferred]").Count == 0); return(xmlDoc); }