コード例 #1
0
 public virtual void SetUp()
 {
     _configuration = new RedirectConfiguration();
     _redirects = new CustomRedirectCollection();
     _sut = new Redirecter(_redirects, _configuration);
     RequestLogger.Instance = new RequestLogger(_configuration);
 }
        /// <summary>
        ///     Read the custom redirects from the dynamic data store, and
        ///     stores them in the CustomRedirect property
        /// </summary>
        protected virtual CustomRedirectCollection LoadCustomRedirects()
        {
            var customRedirects = new CustomRedirectCollection();

            foreach (var redirect in _dataStoreHandler.GetCustomRedirects(false))
                customRedirects.Add(redirect);

            return customRedirects;
        }
 /// <summary>
 ///     Save a collection of redirects, and call method to raise an event in order to clear cache on all servers.
 /// </summary>
 /// <param name="redirects"></param>
 public virtual void SaveCustomRedirects(CustomRedirectCollection redirects)
 {
     Logger.Log(Level.Debug, "Saving custom redirects");
     foreach (CustomRedirect redirect in redirects)
     {
         // Add redirect 
         _dataStoreHandler.SaveCustomRedirect(redirect);
     }
     DataStoreEventHandlerHook.DataStoreUpdated();
 }
コード例 #4
0
        /// <summary>
        ///     Parses the xml file and reads all redirects.
        /// </summary>
        /// <returns>A collection of CustomRedirect objects</returns>
        public CustomRedirectCollection Load()
        {
            const string URLPATH = "/redirects/urls/url";
            const string NEWURL = "new";
            const string OLDURL = "old";
            const string SKIPWILDCARD = "onWildCardMatchSkipAppend";

            var redirects = new CustomRedirectCollection();

            // Parse all url nodes
            XmlNodeList nodes = _customRedirectsXmlFile.SelectNodes(URLPATH);
            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);
                foreach (XmlNode oldNode in oldNodes)
                {
                    bool skipWildCardAppend = false;
                    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
                    var redirect = new CustomRedirect(oldNode.InnerText, newNode.InnerText, skipWildCardAppend, true, true, 0);
                    redirects.Add(redirect);
                }
            }

            return redirects;
        }
コード例 #5
0
 public Redirecter(CustomRedirectCollection customRedirects, RedirectConfiguration redirectConfiguration)
 {
     _customRedirects = customRedirects;
     _redirectConfiguration = redirectConfiguration;
 }