Пример #1
0
        /// <summary>
        /// Gets the XML for an ESD controlled list or mapping, cacheing it if possible
        /// </summary>
        /// <param name="configKey">Key for XML file name &lt;Escc.Web.Metadata/ControlledListXml&gt; 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 EsdXmlDocument GetEsdDocument(string configKey, bool withDom)
        {
            // TODO: Ideally this would check the format of the file to decide, but as a quick fix
            // just check whether the key includes the word "mapping"

            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 (configKey.ToLower(CultureInfo.CurrentCulture).IndexOf("mapping") > -1)
                {
                    return(EsdMapping.GetMapping(configKey, withDom));
                }
                else
                {
                    return(EsdControlledList.GetControlledList(configKey, withDom));
                }
            }
            else
            {
                return(null);
            }
        }
Пример #2
0
        /// <summary>
        /// Gets the XML for an ESD list-to-list mapping, 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 EsdMapping GetMapping(Uri xmlFileUri, bool withDom)
        {
            HttpContext ctx      = HttpContext.Current;
            EsdMapping  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 = (EsdMapping)ctx.Cache.Get(cacheKey);
            }

            // Not in cache, so load XML
            if (xmlDoc == null)
            {
                xmlDoc = new EsdMapping();
                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));
                }
            }

            return(xmlDoc);
        }
Пример #3
0
        /// <summary>
        /// Gets the XML for an ESD controlled list or mapping, 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>
        /// <exception cref="FileNotFoundException">Thrown if the file doesn't exist</exception>
        /// <exception cref="XmlException">Thrown if the file isn't XML</exception>
        /// <exception cref="ArgumentException">Thrown if the file isn't recognised as ESD Taxonomy XML</exception>
        public static EsdXmlDocument GetEsdDocument(Uri xmlFileUri, bool withDom)
        {
            Type documentType = EsdXmlDocument.GetEsdDocumentType(xmlFileUri);

            if (documentType == typeof(EsdControlledList))
            {
                return(EsdControlledList.GetControlledList(xmlFileUri, withDom));
            }
            else if (documentType == typeof(EsdMapping))
            {
                return(EsdMapping.GetMapping(xmlFileUri, withDom));
            }

            // Need this to compile. Shouldn't ever return null, because if neither of those two match an exception should have been thrown
            return(null);
        }
Пример #4
0
        /// <summary>
        /// Gets the XML for an ESD list-to-list mapping, cacheing it if possible
        /// </summary>
        /// <param name="configKey">Key for XML file name &lt;Escc.Web.Metadata/ControlledListXml&gt; 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 EsdMapping GetMapping(string configKey, bool withDom)
        {
            HttpContext ctx      = HttpContext.Current;
            EsdMapping  xmlDoc   = null;
            string      cacheKey = String.Format(CultureInfo.InvariantCulture, "EsdXml_{0}", configKey);

            // Check for the document in the Application Data Cache
            if (ctx != null)
            {
                xmlDoc = (EsdMapping)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)
                {
                    xmlDoc = new EsdMapping();
                    if (withDom)
                    {
                        xmlDoc.LoadDom(config[configKey]);
                    }
                    else
                    {
                        xmlDoc.LoadXPath(config[configKey]);
                    }
                }

                // Cache me if you can
                if (ctx != null)
                {
                    ctx.Cache.Insert(cacheKey, xmlDoc, null, DateTime.MaxValue, TimeSpan.FromMinutes(15));
                }
            }

            return(xmlDoc);
        }
Пример #5
0
 /// <summary>
 /// Gets the XML for an ESD list-to-list mapping, cacheing it if possible
 /// </summary>
 /// <param name="configKey">Key for XML file name &lt;Escc.Web.Metadata/ControlledListXml&gt; section of web.config</param>
 /// <returns>Populated XML document, or null if not found</returns>
 public static EsdMapping GetMapping(string configKey)
 {
     return(EsdMapping.GetMapping(configKey, false));
 }
Пример #6
0
 /// <summary>
 /// Gets the XML for an ESD list-to-list mapping, cacheing it if possible
 /// </summary>
 /// <param name="xmlFileUri">The URI of the XML file.</param>
 /// <returns>Populated XML document, or null if not found</returns>
 public static EsdMapping GetMapping(Uri xmlFileUri)
 {
     return(EsdMapping.GetMapping(xmlFileUri, false));
 }