public int IndexOf(CustomRedirect customRedirect)
		{
			for(int i = 0; i < List.Count; i++)
				if (this[i] == customRedirect)    // Found it
					return i;
			return -1;
		}
        /// <summary>
        /// Create redirects table and SP for version number
        /// </summary>
        private static void Create()
        {
            bool create = true;

            var dba = DataAccessBaseEx.GetWorker();

            _log.Info("Create 404 handler redirects table START");
            string createTableScript = @"CREATE TABLE [dbo].[BVN.NotFoundRequests](
	                                    [ID] [int] IDENTITY(1,1) NOT NULL,
	                                    [OldUrl] [nvarchar](2000) NOT NULL,
	                                    [Requested] [datetime] NULL,
	                                    [Referer] [nvarchar](2000) NULL
                                        ) ON [PRIMARY]";
            create = dba.ExecuteNonQuery(createTableScript);

            _log.Info("Create 404 handler redirects table END");


            if (create)
            {
                _log.Info("Create 404 handler version SP START");
                string versionSP = @"CREATE PROCEDURE [dbo].[bvn_notfoundversion] AS RETURN " + Configuration.Configuration.CURRENT_VERSION;

                if (!dba.ExecuteNonQuery(versionSP))
                {
                    create = false;
                    _log.Error("An error occured during the creation of the 404 handler version stored procedure. Canceling.");

                    _log.Info("Create 404 handler version SP END");
                }
            }
            Valid = create;

            // copy dds items, if there are any.
            try
            {
                // the old redirect class is obsolete, and should only be used for this upgrade
                var oldCustomrRedirectStore = DataStoreFactory.GetStore(typeof(FileNotFound.CustomRedirects.CustomRedirect));
                var oldCustomRedirects = oldCustomrRedirectStore.Items<FileNotFound.CustomRedirects.CustomRedirect>().ToList();

                if (oldCustomRedirects.Count > 0)
                {
                    var newCustomrRedirectStore = DataStoreFactory.GetStore(typeof(CustomRedirect));
                    DataStoreHandler dsHandler = new DataStoreHandler();
                    foreach (var oldCustomRedirect in oldCustomRedirects)
                    {
                        var newRedirect = new CustomRedirect(oldCustomRedirect.OldUrl, oldCustomRedirect.NewUrl, oldCustomRedirect.WildCardSkipAppend);
                        dsHandler.SaveCustomRedirect(newRedirect);
                    }
                    // oldCustomrRedirectStore.DeleteAll();
                }
            }
            catch (Exception ex)
            {
                _log.Error("Error during DDS upgrade: " + ex);
            }

        }
Example #3
0
        public Suggestion(CustomRedirect customRedirect, int pageNumber, int pageSize, string searchWord)
        {
            CustomRedirect = customRedirect;
            PageNumber = pageNumber;
            PageSize = pageSize;
            SearchWord = searchWord;


        }
 public int IndexOf(CustomRedirect customRedirect)
 {
     for (var i = 0; i < List.Count; i++)
     {
         if (this[i] == customRedirect)
         {
             return(i);                           // Found
         }
     }
     return(-1);
 }
        public void AddOrUpdate(CustomRedirect redirect)
        {
            var match = _redirectLoader.GetByOldUrl(redirect.OldUrl);

            //if there is a match, replace the value.
            if (match != null)
            {
                redirect.Id = match.Id;
            }
            _repository.Save(redirect);
        }
 public void SaveCustomRedirect(CustomRedirect currentCustomRedirect)
 {
     // Get hold of the datastore
     DynamicDataStore store = DataStoreFactory.GetStore(typeof(CustomRedirect));
     //check if there is an exisiting object with matching property "OldUrl"
     CustomRedirect match = store.Find<CustomRedirect>(OLD_URL_PROPERTY_NAME, currentCustomRedirect.OldUrl.ToLower()).SingleOrDefault();
     //if there is a match, replace the value.
     if (match != null)
         store.Save(currentCustomRedirect, match.Id);
     else
         store.Save(currentCustomRedirect);
 }
        private CustomRedirect FindInternal(string url)
        {
            object foundRedirect = _quickLookupTable[url];

            if (foundRedirect != null)
            {
                return(foundRedirect as CustomRedirect);
            }
            else
            {
                // No exact match could be done, so we'll check if the 404 url
                // starts with one of the urls we're matching against. This
                // will be kind of a wild card match (even though we only check
                // for the start of the url
                // Example: http://www.mysite.com/news/mynews.html is not found
                // We have defined an "<old>/news</old>" entry in the config
                // file. We will get a match on the /news part of /news/myne...
                // Depending on the skip wild card append setting, we will either
                // redirect using the <new> url as is, or we'll append the 404
                // url to the <new> url.
                IDictionaryEnumerator _enumerator = _quickLookupTable.GetEnumerator();
                while (_enumerator.MoveNext())
                {
                    // See if this "old" url (the one that cannot be found) starts with one
                    if (url.StartsWith(_enumerator.Key.ToString(), StringComparison.InvariantCultureIgnoreCase))
                    {
                        foundRedirect = _quickLookupTable[_enumerator.Key];
                        CustomRedirect cr = foundRedirect as CustomRedirect;
                        if (cr.State == (int)DataStoreHandler.State.Ignored)
                        {
                            return(null);
                        }
                        if (cr.WildCardSkipAppend == true)
                        {
                            // We'll redirect without appending the 404 url
                            return(cr);
                        }
                        else
                        {
                            // We need to append the 404 to the end of the
                            // new one. Make a copy of the redir object as we
                            // are changing it.
                            CustomRedirect redirCopy = new CustomRedirect(cr);
                            redirCopy.NewUrl = redirCopy.NewUrl + url.Substring(_enumerator.Key.ToString().Length);
                            return(redirCopy);
                        }
                    }
                }
            }
            return(null);
        }
        public static bool HandleRequest(string referer, Uri urlNotFound, out CustomRedirect foundRedirect)
        {
            // Try to match the requested url my matching it
            // to the static list of custom redirects
            CustomRedirectHandler fnfHandler = CustomRedirectHandler.Current;
            CustomRedirect redirect = fnfHandler.CustomRedirects.Find(urlNotFound);
            string pathAndQuery = urlNotFound.PathAndQuery;
            foundRedirect = null;
            if (redirect == null)
            {
                redirect = fnfHandler.CustomRedirects.FindInProviders(urlNotFound.AbsoluteUri);
            }

            if (redirect != null)
            {
                // Url has been deleted from this site
                if (redirect.State.Equals((int)DataStoreHandler.State.Deleted))
                {
                    foundRedirect = redirect;
                    return true;
                }

                if (redirect.State.Equals((int)DataStoreHandler.State.Saved))
                {
                    // Found it, however, we need to make sure we're not running in an
                    // infinite loop. The new url must not be the referrer to this page
                    if (string.Compare(redirect.NewUrl, pathAndQuery, StringComparison.InvariantCultureIgnoreCase) != 0)
                    {

                        foundRedirect = redirect;
                        return true;
                    }
                }
            }
            else
            {
                // log request to database - if logging is turned on.
                if (Configuration.Configuration.Logging == LoggerMode.On)
                {
                    // Safe logging
                    RequestLogger.Instance.LogRequest(pathAndQuery, referer);
                }
            }
            return false;
        }
Example #9
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";

            var redirects = new CustomRedirectCollection();

            // Parse all url nodes
            var 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
                var newNode = node.SelectSingleNode(Newurl);

                var oldNodes = node.SelectNodes(Oldurl);
                foreach (XmlNode oldNode in oldNodes)
                {
                    var skipWildCardAppend = false;
                    var 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);
                    }

                    var redirectType     = Data.RedirectType.Permanent;
                    var redirectTypeAttr = oldNode.Attributes[RedirectType];
                    if (redirectTypeAttr != null)
                    {
                        Enum.TryParse(redirectTypeAttr.Value, out redirectType);
                    }

                    // Create new custom redirect nodes
                    var redirect = new CustomRedirect(oldNode.InnerText, newNode.InnerText, skipWildCardAppend, redirectType);
                    redirects.Add(redirect);
                }
            }

            return(redirects);
        }
        public ActionResult AddDeletedUrl(string oldUrl)
        {
            CheckAccess();

            // add redirect to dds with state "deleted"
            var redirect = new CustomRedirect();
            redirect.OldUrl = oldUrl;
            redirect.State = Convert.ToInt32(DataStoreHandler.State.Deleted);
            DataStoreHandler dsHandler = new DataStoreHandler();
            dsHandler.SaveCustomRedirect(redirect);
            DataStoreEventHandlerHook.DataStoreUpdated();

            // delete rows from DB
            var dbAccess = DataAccessBaseEx.GetWorker();
            dbAccess.DeleteRowsForRequest(oldUrl);

            //
            List<CustomRedirect> customRedirectList = GetDeletedUrls();
            DataStoreEventHandlerHook.DataStoreUpdated();
            return Deleted();
        }
        // TODO: If desired, change parameters to Find method to search based on a property of CustomRedirect.
        public CustomRedirect Find(Uri urlNotFound)
        {
            // Handle absolute addresses first
            string         url           = urlNotFound.AbsoluteUri;
            CustomRedirect foundRedirect = FindInternal(url);

            // Common case
            if (foundRedirect == null)
            {
                url           = urlNotFound.PathAndQuery;;
                foundRedirect = FindInternal(url);
            }

            // Handle legacy databases with encoded values
            if (foundRedirect == null)
            {
                url           = HttpUtility.HtmlEncode(url);
                foundRedirect = FindInternal(url);
            }

            return(foundRedirect);
        }
        /// <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";

            CustomRedirectCollection 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
                    CustomRedirect redirect = new CustomRedirect(oldNode.InnerText, newNode.InnerText, skipWildCardAppend);
                    redirects.Add(redirect);
                }
            }

            return(redirects);
        }
        /// <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";

            CustomRedirectCollection 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
                    CustomRedirect redirect = new CustomRedirect(oldNode.InnerText, newNode.InnerText, skipWildCardAppend);
                    redirects.Add(redirect);
                }
            }

            return redirects;
        }
 public void Remove(CustomRedirect customRedirect)
 {
     _quickLookupTable.Remove(customRedirect);
     List.Remove(customRedirect);
 }
 public int Add(CustomRedirect customRedirect)
 {
     // Add to quick look up table too
     _quickLookupTable.Add(customRedirect.OldUrl, customRedirect);
     return(List.Add(customRedirect));
 }
Example #16
0
 public CustomRedirect(CustomRedirect redirect)
 {
     _oldUrl             = redirect._oldUrl;
     _newUrl             = redirect._newUrl;
     _wildCardSkipAppend = redirect._wildCardSkipAppend;
 }
 public CustomRedirect(CustomRedirect redirect)
 {
     _oldUrl = redirect._oldUrl;
     _newUrl = redirect._newUrl;
     _wildCardSkipAppend = redirect._wildCardSkipAppend;
 }
        public ActionResult IgnoreRedirect(string oldUrl, int pageNumber, string searchWord, int pageSize)
        {
            CheckAccess();
            // delete rows from DB
            var dbAccess = DataAccessBaseEx.GetWorker();
            dbAccess.DeleteRowsForRequest(oldUrl);

            // add redirect to dds with state "ignored"
            var redirect = new CustomRedirect();
            redirect.OldUrl = oldUrl;
            redirect.State = Convert.ToInt32(DataStoreHandler.State.Ignored);
            DataStoreHandler dsHandler = new DataStoreHandler();
            dsHandler.SaveCustomRedirect(redirect);
            DataStoreEventHandlerHook.DataStoreUpdated();

            List<CustomRedirect> customRedirectList = GetSuggestions(searchWord);
            string actionInfo = string.Format(LocalizationService.Current.GetString("/gadget/redirects/ignoreredirect"), oldUrl);
            RedirectIndexViewData viewData = GetRedirectIndexViewData(pageNumber, customRedirectList, actionInfo, searchWord, pageSize, true, true);
            viewData.HighestSuggestionValue = customRedirectList.First().NotfoundErrorCount;
            viewData.LowestSuggestionValue = customRedirectList.Last().NotfoundErrorCount;
            return View("Index", viewData);
        }
 public void Insert(int index, CustomRedirect customRedirect)
 {
     _quickLookupTable.Add(customRedirect, customRedirect);
     List.Insert(index, customRedirect);
 }
		// TODO: If desired, change parameters to Find method to search based on a property of CustomRedirect.
		public CustomRedirect Find(Uri urlNotFound)
		{
		    string pathAndQuery = HttpUtility.HtmlEncode(urlNotFound.PathAndQuery);

			object foundRedirect = _quickLookupTable[urlNotFound.AbsoluteUri] ?? _quickLookupTable[pathAndQuery];
            if (foundRedirect != null)
            {
                return foundRedirect as CustomRedirect;
            }
            else
            {
                // No exact match could be done, so we'll check if the 404 url
                // starts with one of the urls we're matching against. This
                // will be kind of a wild card match (even though we only check
                // for the start of the url
                // Example: http://www.mysite.com/news/mynews.html is not found
                // We have defined an "<old>/news</old>" entry in the config
                // file. We will get a match on the /news part of /news/myne...
                // Depending on the skip wild card append setting, we will either
                // redirect using the <new> url as is, or we'll append the 404
                // url to the <new> url.
                IDictionaryEnumerator _enumerator = _quickLookupTable.GetEnumerator();
                while (_enumerator.MoveNext())
                {             
                    // See if this "old" url (the one that cannot be found) starts with one 
                    if (pathAndQuery.StartsWith(_enumerator.Key.ToString(), StringComparison.InvariantCultureIgnoreCase))
                    {
                        foundRedirect = _quickLookupTable[_enumerator.Key];
                        CustomRedirect cr = foundRedirect as CustomRedirect;
                        if (cr.WildCardSkipAppend == true)
                        {
                            // We'll redirect without appending the 404 url
                            return cr;
                        }
                        else
                        {
                            // We need to append the 404 to the end of the
                            // new one. Make a copy of the redir object as we
                            // are changing it.
                            CustomRedirect redirCopy = new CustomRedirect(cr);
                            redirCopy.NewUrl = redirCopy.NewUrl + pathAndQuery.Substring(_enumerator.Key.ToString().Length);
                            return redirCopy;
                        }
                    }
                }
            }
			return null;
		}
		public void Remove(CustomRedirect customRedirect)
		{
			_quickLookupTable.Remove(customRedirect);
			List.Remove(customRedirect);
		}
		public void Insert(int index, CustomRedirect customRedirect)
		{
			_quickLookupTable.Add(customRedirect, customRedirect);
			List.Insert(index, customRedirect);
		}
		// public methods...
		#region Add
		public int Add(CustomRedirect customRedirect)
		{
			// Add to quick look up table too
			_quickLookupTable.Add(customRedirect.OldUrl, customRedirect);
			return List.Add(customRedirect);
		}