/// <summary>
        /// Read the custom redirects from the dynamic data store, and 
        /// stores them in the CustomRedirect property
        /// </summary>
        protected void LoadCustomRedirects()
        {
            DataStoreHandler dynamicHandler = new DataStoreHandler();
            _customRedirects = new CustomRedirectCollection();

            foreach (CustomRedirect redirect in dynamicHandler.GetCustomRedirects(false))
                _customRedirects.Add(redirect);
        }
        /// <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);
            }

        }
 /// <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 void SaveCustomRedirects(CustomRedirectCollection redirects)
 {
     DataStoreHandler dynamicHandler = new DataStoreHandler();
     foreach (CustomRedirect redirect in redirects)
     {
         // Add redirect 
         dynamicHandler.SaveCustomRedirect(redirect);
     }
     DataStoreEventHandlerHook.DataStoreUpdated();
 }
        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();
        }
 public ActionResult Unignore(string url)
 {
     CheckAccess();
     DataStoreHandler dsHandler = new DataStoreHandler();
     dsHandler.DeleteCustomRedirect(url);
     return Ignored();
 }
 public void SaveRedirect(string oldUrl, string newUrl, string skipWildCardAppend)
 {
     Logger.Debug("Adding redirect: '{0}' -> '{1}'", oldUrl, newUrl);
     // Get hold of the datastore
     DataStoreHandler dsHandler = new DataStoreHandler();
     dsHandler.SaveCustomRedirect(new CustomRedirect(oldUrl.Trim(), newUrl.Trim(), skipWildCardAppend == null ? false : true));
     DataStoreEventHandlerHook.DataStoreUpdated();
 }
        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 ActionResult Ignored()
 {
     CheckAccess();
     DataStoreHandler dsHandler = new DataStoreHandler();
     var ignoredRedirects = dsHandler.GetIgnoredRedirect();
     return View("Ignored", ignoredRedirects);
 }
        public List<CustomRedirect> GetDeletedUrls()
        {
            DataStoreHandler dsHandler = new DataStoreHandler();
            List<CustomRedirect> customRedirectList;
            customRedirectList = dsHandler.GetDeletedRedirect();

            return customRedirectList;
        }
        /// <summary>
        /// Get custom redirect data from dynamic data store.
        /// </summary>
        /// <param name="searchWord"></param>
        /// <returns></returns>
        public List<CustomRedirect> GetData(String searchWord)
        {
            DataStoreHandler dsHandler = new DataStoreHandler();
            List<CustomRedirect> customRedirectList;
            if (string.IsNullOrEmpty(searchWord))
            {
                customRedirectList = dsHandler.GetCustomRedirects(true);
            }
            else
                customRedirectList = dsHandler.SearchCustomRedirects(searchWord);

            return customRedirectList;
        }
        public XmlActionResult ExportAllRedirects()
        {
            CheckAccess();
            DataStoreHandler dsHandler = new DataStoreHandler();

            List<CustomRedirect> redirects = dsHandler.GetCustomRedirects(true);

            XmlDocument document = new RedirectsXmlParser().Export(redirects);

            return new XmlActionResult(document);
        }
 /// <summary>
 /// Removed Deleted (410) redirect
 /// </summary>
 /// <param name="url"></param>
 /// <returns></returns>
 public ActionResult DeleteDeleted(string url)
 {
     CheckAccess();
     var dsHandler = new DataStoreHandler();
     dsHandler.DeleteCustomRedirect(url);
     return Deleted();
 }
 public ActionResult Deleted()
 {
     CheckAccess();
     DataStoreHandler dsHandler = new DataStoreHandler();
     var deletedRedirects = dsHandler.GetDeletedRedirect();
     return View("Deleted", deletedRedirects);
 }
 public ActionResult DeleteAllRedirects()
 {
     CheckAccess();
     DataStoreHandler dsHandler = new DataStoreHandler();
     dsHandler.DeleteAllCustomRedirects();
     DataStoreEventHandlerHook.DataStoreUpdated();
     ViewData["information"] = LocalizationService.Current.GetString("/gadget/redirects/redirectsdeleted");
     return View("Administer");
 }
 public ActionResult DeleteAllIgnored()
 {
     CheckAccess();
     var dsHandler = new DataStoreHandler();
     int deleteCount = dsHandler.DeleteAllIgnoredRedirects();
     string infoText = string.Format(LocalizationService.Current.GetString("/gadget/redirects/ignoredremoved"), deleteCount);
     ViewData["information"] = infoText;
     return View("Administer");
 }
        public ActionResult Delete(string oldUrl, int? pageNumber, string searchWord, int? pageSize)
        {
            CheckAccess();

            Logger.Debug("Deleting redirect: '{0}'", oldUrl);

            DataStoreHandler dsHandler = new DataStoreHandler();
            dsHandler.DeleteCustomRedirect(oldUrl);
            DataStoreEventHandlerHook.DataStoreUpdated();
            List<CustomRedirect> customRedirectList = GetData(searchWord);
            //Make sure that the searchinfo is contained after an item has been deleted - if there is any.
            return View("Index", GetRedirectIndexViewData(pageNumber, customRedirectList, GetSearchResultInfo(searchWord, customRedirectList.Count, false), searchWord, pageSize, false, true));
        }