Exemplo n.º 1
0
        internal virtual void InternalLoad(string physicalPath)
        {
            string text = CFiles.ReadFile(physicalPath);

            if (!string.IsNullOrEmpty(text))
            {
                using (StringReader stringReader = new StringReader(text))
                {
                    using (XmlReader xmlReader = XmlReader.Create(stringReader, new XmlReaderSettings
                    {
                        CloseInput = true,
                        IgnoreWhitespace = true,
                        IgnoreComments = true,
                        IgnoreProcessingInstructions = true
                    }))
                    {
                        XmlDocument xmlDocument = new XmlDocument();
                        xmlDocument.Load(xmlReader);
                        this.Reset();
                        if (xmlDocument.DocumentElement != null && xmlDocument.HasChildNodes)
                        {
                            base.CacheDurationInMinutes = XmlSiteMap.GetFloatValueFromAttribute(xmlDocument.DocumentElement, "cacheDurationInMinutes", SiteMapBase.DefaultCacheDurationInMinutes);
                            base.Compress = XmlSiteMap.GetBooleanValueFromAttribute(xmlDocument.DocumentElement, "compress", true);
                            base.GenerateSearchEngineMap = XmlSiteMap.GetBooleanValueFromAttribute(xmlDocument.DocumentElement, "generateSearchEngineMap", true);
                            XmlNode firstChild = xmlDocument.DocumentElement.FirstChild;
                            XmlSiteMap.Iterate(base.RootNode, firstChild);
                            this.InsertInCache(physicalPath);
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
 private static Func <SiteMapBase> CreateDefaultSiteMapFactory()
 {
     return(delegate
     {
         XmlSiteMap xmlSiteMap = new XmlSiteMap();
         xmlSiteMap.Load();
         return xmlSiteMap;
     });
 }
Exemplo n.º 3
0
        private static DateTime?GetDateValueFromAttribute(XmlNode node, string attributeName)
        {
            string   stringValueFromAttribute = XmlSiteMap.GetStringValueFromAttribute(node, attributeName);
            DateTime?result = null;
            DateTime value;

            if (!string.IsNullOrEmpty(stringValueFromAttribute) && DateTime.TryParse(stringValueFromAttribute, out value))
            {
                result = new DateTime?(value);
            }
            return(result);
        }
Exemplo n.º 4
0
        private static float GetFloatValueFromAttribute(XmlNode node, string attributeName, float defaultValue)
        {
            float  result = defaultValue;
            string stringValueFromAttribute = XmlSiteMap.GetStringValueFromAttribute(node, attributeName);
            float  num;

            if (!string.IsNullOrEmpty(stringValueFromAttribute) && float.TryParse(stringValueFromAttribute, out num))
            {
                result = num;
            }
            return(result);
        }
Exemplo n.º 5
0
        private static bool GetBooleanValueFromAttribute(XmlNode node, string attributeName, bool defaultValue)
        {
            bool   result = defaultValue;
            string stringValueFromAttribute = XmlSiteMap.GetStringValueFromAttribute(node, attributeName);
            bool   flag;

            if (!string.IsNullOrEmpty(stringValueFromAttribute) && bool.TryParse(stringValueFromAttribute, out flag))
            {
                result = flag;
            }
            return(result);
        }
Exemplo n.º 6
0
 private static void Iterate(SiteMapNode siteMapNode, XmlNode xmlNode)
 {
     XmlSiteMap.PopulateNode(siteMapNode, xmlNode);
     foreach (XmlNode xmlNode2 in xmlNode.ChildNodes)
     {
         if (xmlNode2.LocalName.IsCaseSensitiveEqual("siteMapNode"))
         {
             SiteMapNode siteMapNode2 = new SiteMapNode();
             siteMapNode.ChildNodes.Add(siteMapNode2);
             XmlSiteMap.Iterate(siteMapNode2, xmlNode2);
         }
     }
 }
Exemplo n.º 7
0
        private static void PopulateNode(SiteMapNode siteMapNode, XmlNode xmlNode)
        {
            RouteValueDictionary routeValueDictionary = new RouteValueDictionary();
            XmlNode firstChild = xmlNode.FirstChild;

            if (firstChild != null && firstChild.LocalName.IsCaseSensitiveEqual("routeValues"))
            {
                foreach (XmlNode xmlNode2 in firstChild.ChildNodes)
                {
                    routeValueDictionary[xmlNode2.LocalName] = xmlNode2.InnerText;
                }
            }
            siteMapNode.Title   = XmlSiteMap.GetStringValueFromAttribute(xmlNode, "title");
            siteMapNode.Visible = XmlSiteMap.GetBooleanValueFromAttribute(xmlNode, "visible", true);
            string stringValueFromAttribute  = XmlSiteMap.GetStringValueFromAttribute(xmlNode, "route");
            string stringValueFromAttribute2 = XmlSiteMap.GetStringValueFromAttribute(xmlNode, "controller");
            string stringValueFromAttribute3 = XmlSiteMap.GetStringValueFromAttribute(xmlNode, "action");
            string stringValueFromAttribute4 = XmlSiteMap.GetStringValueFromAttribute(xmlNode, "url");
            string stringValueFromAttribute5 = XmlSiteMap.GetStringValueFromAttribute(xmlNode, "area");

            if (stringValueFromAttribute5 != null)
            {
                routeValueDictionary["area"] = stringValueFromAttribute5;
            }
            if (!string.IsNullOrEmpty(stringValueFromAttribute))
            {
                siteMapNode.RouteName = stringValueFromAttribute;
                siteMapNode.RouteValues.Clear();
                siteMapNode.RouteValues.Merge(routeValueDictionary);
            }
            else
            {
                if (!string.IsNullOrEmpty(stringValueFromAttribute2) && !string.IsNullOrEmpty(stringValueFromAttribute3))
                {
                    siteMapNode.ControllerName = stringValueFromAttribute2;
                    siteMapNode.ActionName     = stringValueFromAttribute3;
                    siteMapNode.RouteValues.Clear();
                    siteMapNode.RouteValues.Merge(routeValueDictionary);
                }
                else
                {
                    if (!string.IsNullOrEmpty(stringValueFromAttribute4))
                    {
                        siteMapNode.Url = stringValueFromAttribute4;
                    }
                }
            }
            DateTime?dateValueFromAttribute = XmlSiteMap.GetDateValueFromAttribute(xmlNode, "lastModifiedAt");

            if (dateValueFromAttribute.HasValue)
            {
                siteMapNode.LastModifiedAt = new DateTime?(dateValueFromAttribute.Value);
            }
            siteMapNode.IncludeInSearchEngineIndex = XmlSiteMap.GetBooleanValueFromAttribute(xmlNode, "includeInSearchEngineIndex", true);
            foreach (XmlAttribute xmlAttribute in xmlNode.Attributes)
            {
                if (!string.IsNullOrEmpty(xmlAttribute.LocalName) && Array.BinarySearch <string>(XmlSiteMap.knownAttributes, xmlAttribute.LocalName, StringComparer.OrdinalIgnoreCase) < 0)
                {
                    siteMapNode.Attributes.Add(xmlAttribute.LocalName, xmlAttribute.Value);
                }
            }
        }