Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
        }