Example #1
0
        /// <summary>
        /// Read the custom redirects from the dynamic data store, and
        /// stores them in the CustomRedirect property
        /// </summary>
        protected void LoadCustomRedirects(int siteId)
        {
            DataStoreHandler dynamicHandler = new DataStoreHandler();

            _customRedirects = new CustomRedirectCollection();

            foreach (CustomRedirect redirect in dynamicHandler.GetCustomRedirects(false, siteId))
            {
                _customRedirects.Add(redirect);
            }
        }
Example #2
0
        /// <summary>
        /// Parses the xml file and reads all redirects.
        /// </summary>
        /// <returns>A collection of CustomRedirect objects</returns>
        public CustomRedirectCollection Load(int siteId)
        {
            // ReSharper disable InconsistentNaming
            const string URLPATH      = "/redirects/urls/url";
            const string NEWURL       = "new";
            const string OLDURL       = "old";
            const string SKIPWILDCARD = "onWildCardMatchSkipAppend";
            // ReSharper restore InconsistentNaming

            CustomRedirectCollection redirects = new CustomRedirectCollection();

            // Parse all url nodes
            XmlNodeList nodes = _customRedirectsXmlFile.SelectNodes(URLPATH);

            if (nodes != null)
            {
                foreach (XmlNode node in nodes)
                {
                    // Each url new url can have several old values
                    // we need to create a redirect object for each pair
                    XmlNode newNode = node.SelectSingleNode(NEWURL);

                    XmlNodeList oldNodes = node.SelectNodes(OLDURL);
                    if (oldNodes != null)
                    {
                        foreach (XmlNode oldNode in oldNodes)
                        {
                            bool skipWildCardAppend = false;
                            if (oldNode.Attributes != null)
                            {
                                XmlAttribute skipWildCardAttr = oldNode.Attributes[SKIPWILDCARD];
                                if (skipWildCardAttr != null)
                                {
                                    // If value parsing fails, it will be false by default. We do
                                    // not really care to check if it fails, as we cannot do anything
                                    // about it (throwing an exception is not a good idea here)
                                    bool.TryParse(skipWildCardAttr.Value, out skipWildCardAppend);
                                }
                            }

                            // Create new custom redirect nodes
                            if (newNode != null)
                            {
                                CustomRedirect redirect = new CustomRedirect(oldNode.InnerText, newNode.InnerText, skipWildCardAppend, siteId);
                                redirects.Add(redirect);
                            }
                        }
                    }
                }
            }

            return(redirects);
        }