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));
        }
Ejemplo n.º 2
0
        private static void UpdateVersionNumber(DataAccessBaseEx dba)
        {
            var versionSp =
                $@"ALTER PROCEDURE [dbo].[bvn_notfoundversion] AS RETURN {Configuration.Configuration.CurrentVersion}";

            Valid = dba.ExecuteNonQuery(versionSp);
        }
Ejemplo n.º 3
0
        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
            {
                OldUrl = oldUrl,
                NewUrl = string.Empty,
                State  = Convert.ToInt32(RedirectState.Ignored)
            };

            _redirectsService.AddOrUpdate(redirect);
            CustomRedirectHandler.ClearCache();

            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);

            if (customRedirectList.Count > 0)
            {
                viewData.HighestSuggestionValue = customRedirectList.First().NotfoundErrorCount;
                viewData.LowestSuggestionValue  = customRedirectList.Last().NotfoundErrorCount;
            }
            return(View("Index", viewData));
        }
        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 SaveSuggestion(string oldUrl, string newUrl, string skipWildCardAppend, int?pageNumber, int?pageSize, int siteId = 0)
        {
            CheckAccess();
            if (siteId <= 0)
            {
                siteId = DataHandler.GetCurrentSiteId();
            }
            SaveRedirect(oldUrl, newUrl, skipWildCardAppend, siteId);

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

            dbAccess.DeleteRowsForRequest(oldUrl, siteId);

            //
            List <CustomRedirect> customRedirectList = GetSuggestions(null, siteId);
            string actionInfo = string.Format(LocalizationService.Current.GetString("/gadget/redirects/saveredirect"), oldUrl, newUrl);

            DataStoreEventHandlerHook.DataStoreUpdated();
            var viewData = GetRedirectIndexViewData(pageNumber, customRedirectList, actionInfo, null, pageSize, true, siteId);

            viewData.HighestSuggestionValue = customRedirectList.First().NotfoundErrorCount;
            viewData.LowestSuggestionValue  = customRedirectList.Last().NotfoundErrorCount;
            return(View("Index", viewData));
        }
        public ActionResult AddDeletedUrl(string oldUrl, int siteId = 0)
        {
            CheckAccess();
            if (siteId <= 0)
            {
                siteId = DataHandler.GetCurrentSiteId();
            }

            // add redirect to dds with state "deleted"
            var redirect = new CustomRedirect
            {
                OldUrl = oldUrl,
                SiteId = siteId,
                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, siteId);

            //TODO why this?
            List <CustomRedirect> customRedirectList = GetDeletedUrls(siteId);

            DataStoreEventHandlerHook.DataStoreUpdated();
            return(Deleted(siteId));
        }
Ejemplo n.º 7
0
 public ActionResult DeleteSuggestions(int maxErrors, int minimumDays)
 {
     CheckAccess();
     DataAccessBaseEx.GetWorker().DeleteSuggestions(maxErrors, minimumDays);
     ViewData["information"] = LocalizationService.Current.GetString("/gadget/redirects/suggestionsdeleted");
     return(View("Administer"));
 }
Ejemplo n.º 8
0
        public ActionResult AddDeletedUrl(string oldUrl)
        {
            CheckAccess();

            // add redirect to dds with state "deleted"
            var redirect = new CustomRedirect
            {
                OldUrl = oldUrl,
                NewUrl = string.Empty,
                State  = Convert.ToInt32(RedirectState.Deleted)
            };

            _redirectsService.AddOrUpdate(redirect);
            CustomRedirectHandler.ClearCache();

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

            dbAccess.DeleteRowsForRequest(oldUrl);

            //
            List <CustomRedirect> customRedirectList = GetDeletedUrls();

            CustomRedirectHandler.ClearCache();
            return(Deleted());
        }
Ejemplo n.º 9
0
        private static void Upgrade()
        {
            var dba = DataAccessBaseEx.GetWorker();

            string indexCheck =
                "SELECT COUNT(*) FROM sys.indexes WHERE name='NotFoundRequests_ID' AND object_id = OBJECT_ID('[dbo].[BVN.NotFoundRequests]')";

            int num = dba.ExecuteScalar(indexCheck);

            if (num == 0)
            {
                if (!dba.ExecuteNonQuery("CREATE CLUSTERED INDEX NotFoundRequests_ID ON [dbo].[BVN.NotFoundRequests] (ID)"))
                {
                    Valid = false;
                    _log.Error("An error occurred during the creation of the 404 handler redirects clustered index. Canceling.");
                }
                _log.Information("Create Clustered index END");
            }
            if (Valid)
            {
                string versionSP = @"ALTER PROCEDURE [dbo].[bvn_notfoundversion] AS RETURN " + Configuration.Configuration.CURRENT_VERSION;
                Valid = dba.ExecuteNonQuery(versionSP);
                // TODO: Alter table if necessary
            }
        }
Ejemplo n.º 10
0
        private void LogRequests(ConcurrentQueue <LogEvent> logEvents)
        {
            Logger.Debug("Logging 404 errors to database");
            var bufferSize = Configuration.Configuration.Instance.BufferSize;
            var threshold  = Configuration.Configuration.Instance.ThreshHold;
            var start      = logEvents.First().Requested;
            var end        = logEvents.Last().Requested;
            var diff       = (end - start).Seconds;

            if ((diff != 0 && bufferSize / diff <= threshold) ||
                bufferSize == 0)
            {
                var dba = DataAccessBaseEx.GetWorker();
                while (logEvents.Count > 0)
                {
                    if (logEvents.TryDequeue(out var logEvent))
                    {
                        dba.LogRequestToDb(logEvent.OldUrl, logEvent.Referer, logEvent.Requested);
                    }
                }
                Logger.Debug($"{bufferSize} 404 request(s) has been stored to the database.");
            }
            else
            {
                Logger.Warning("404 requests have been made too frequents (exceeded the threshold). Requests not logged to database.");
            }
        }
Ejemplo n.º 11
0
        private static bool ColumnExists(string tableName, string columnName, DataAccessBaseEx dba)
        {
            var cmd = $@"SELECT 1
                        FROM sys.columns
                        WHERE Name = '{columnName}'
                        AND  Object_ID = Object_ID(N'dbo.[{tableName}]')";
            var num = dba.ExecuteScalar(cmd);

            return(num != 0);
        }
Ejemplo n.º 12
0
        private static bool TableExists(string tableName, DataAccessBaseEx dba)
        {
            var cmd = $@"SELECT *
                 FROM INFORMATION_SCHEMA.TABLES
                 WHERE TABLE_SCHEMA = 'dbo'
                 AND  TABLE_NAME = '{tableName}'";
            var num = dba.ExecuteScalar(cmd);

            return(num != 0);
        }
Ejemplo n.º 13
0
        private static bool SuggestionsTableIndexExists(DataAccessBaseEx dba)
        {
            var indexCheck =
                $@"SELECT COUNT(*)
                 FROM sys.indexes
                 WHERE name='NotFoundRequests_ID' AND object_id = OBJECT_ID('[dbo].[BVN.NotFoundRequests]')";

            var num = dba.ExecuteScalar(indexCheck);

            return(num != 0);
        }
 public ActionResult DeleteAllSuggestions(int siteId = 0)
 {
     CheckAccess();
     if (siteId <= 0)
     {
         siteId = DataHandler.GetCurrentSiteId();
     }
     DataAccessBaseEx.GetWorker().DeleteAllSuggestions(siteId);
     ViewData["information"] = LocalizationService.Current.GetString("/gadget/redirects/suggestionsdeleted");
     return(View("Administer"));
 }
Ejemplo n.º 15
0
        private static bool AddRedirectTypeColumnToRedirectsTable(DataAccessBaseEx dba)
        {
            Logger.Information("Alter 404 handler redirects table to add RedirectType column START");
            var alterTableScript = @"ALTER TABLE [dbo].[404Handler.Redirects]
                                            ADD [RedirectType] int NOT NULL
                                        DEFAULT (301)
                                    WITH VALUES";
            var created          = dba.ExecuteNonQuery(alterTableScript);

            Logger.Information("Alter 404 handler redirects table to add RedirectType column END");

            return(created);
        }
Ejemplo n.º 16
0
        private static bool CreateSuggestionsTableIndex(DataAccessBaseEx dba)
        {
            Log.Information("Create suggestions table clustered index START");
            var clusteredIndex =
                "CREATE CLUSTERED INDEX NotFoundRequests_ID ON [dbo].[BVN.NotFoundRequests] (ID)";

            var created = dba.ExecuteNonQuery(clusteredIndex);

            if (!created)
            {
                Log.Error("An error occurred during the creation of the 404 handler redirects clustered index. Canceling.");
            }

            Log.Information("Create suggestions table clustered index END");
            return(created);
        }
Ejemplo n.º 17
0
        private static bool CreateVersionNumberSp(DataAccessBaseEx dba)
        {
            Log.Information("Create 404 handler version SP START");
            var versionSp =
                $@"CREATE PROCEDURE [dbo].[bvn_notfoundversion] AS RETURN {Configuration.Configuration.CurrentVersion}";

            var created = dba.ExecuteNonQuery(versionSp);

            if (!created)
            {
                Log.Error("An error occured during the creation of the 404 handler version stored procedure. Canceling.");
            }

            Log.Information("Create 404 handler version SP END");
            return(created);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Create redirects table and SP for version number
        /// </summary>
        private static void Create()
        {
            var dba = DataAccessBaseEx.GetWorker();

            Log.Information("Create 404 handler redirects table START");
            var 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]";
            var create            = dba.ExecuteNonQuery(createTableScript);

            Log.Information("Create 404 handler redirects table END");


            if (create)
            {
                Log.Information("Create 404 handler version SP START");
                var versionSp = @"CREATE PROCEDURE [dbo].[bvn_notfoundversion] AS RETURN " + Configuration.Configuration.CurrentVersion;

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

                Log.Information("Create 404 handler version SP END");
            }

            if (create)
            {
                Log.Information("Create Clustered index START");
                var clusteredIndex =
                    "CREATE CLUSTERED INDEX NotFoundRequests_ID ON [dbo].[BVN.NotFoundRequests] (ID)";

                if (!dba.ExecuteNonQuery(clusteredIndex))
                {
                    create = false;
                    Log.Error("An error occurred during the creation of the 404 handler redirects clustered index. Canceling.");
                }

                Log.Information("Create Clustered index END");
            }

            Valid = create;
        }
Ejemplo n.º 19
0
        private static bool CreateRedirectsTable(DataAccessBaseEx dba)
        {
            Log.Information("Create 404 handler redirects table START");
            var createTableScript = @"CREATE TABLE [dbo].[404Handler.Redirects](
                                        [Id] [uniqueidentifier] NOT NULL,
                                        [OldUrl] [nvarchar](2000) NOT NULL,
                                        [NewUrl] [nvarchar](2000) NOT NULL,
                                        [State] [int] NOT NULL,
                                        [WildCardSkipAppend] [bit] NOT NULL,
                                        CONSTRAINT [PK_404HandlerRedirects] PRIMARY KEY CLUSTERED ([Id] ASC) ON [PRIMARY]
                                        ) ON [PRIMARY]";
            var created           = dba.ExecuteNonQuery(createTableScript);

            Log.Information("Create 404 handler redirects table END");

            return(created);
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Create redirects and suggestions tables and SP for version number
        /// </summary>
        private static void Create()
        {
            var dba = DataAccessBaseEx.GetWorker();

            var created = CreateRedirectsTable(dba);

            if (created)
            {
                created = CreateSuggestionsTable(dba);
            }

            if (created)
            {
                created = CreateVersionNumberSp(dba);
            }

            Valid = created;
        }
        public void Initialize(InitializationEngine context)
        {
            _log.Debug("Initializing 404 handler version check");
            DataAccessBaseEx dba = DataAccessBaseEx.GetWorker();
            int version          = dba.Check404Version();

            if (version != Configuration.Configuration.CURRENT_VERSION)
            {
                _log.Debug("Older version found. Version nr. :" + version);
                Upgrader.Start(version);
            }
            else
            {
                Upgrader.Valid = true;
            }

            // Load all custom redirects into memory
            CustomRedirectHandler handler = CustomRedirectHandler.Current;
        }
Ejemplo n.º 22
0
        private static void Upgrade()
        {
            var dba = DataAccessBaseEx.GetWorker();

            if (!TableExists("404Handler.Redirects", dba))
            {
                Valid = CreateRedirectsTable(dba);
            }

            if (!SuggestionsTableIndexExists(dba))
            {
                Valid = CreateSuggestionsTableIndex(dba);
            }

            if (Valid)
            {
                UpdateVersionNumber(dba);
            }
        }
        // ReSharper restore UnusedAutoPropertyAccessor.Local

        public void Initialize(InitializationEngine context)
        {
            Logger.Debug("Initializing 404 handler version check");
            var dba     = DataAccessBaseEx.GetWorker();
            var version = dba.Check404Version();

            if (version != Configuration.Configuration.CurrentVersion)
            {
                Logger.Debug("Older version found. Version nr. :" + version);
                Upgrader.Start(version);
            }
            else
            {
                Upgrader.Valid = true;
            }

            // Load all custom redirects into memory
            // TODO: create better load of the cache
            var handler = CustomRedirectHandler.Current;
        }
Ejemplo n.º 24
0
        private static bool CreateSuggestionsTable(DataAccessBaseEx dba)
        {
            Log.Information("Create 404 handler suggestions table START");
            var 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]";
            var created           = dba.ExecuteNonQuery(createTableScript);

            Log.Information("Create 404 handler suggestions table END");

            if (created)
            {
                created = CreateSuggestionsTableIndex(dba);
            }

            return(created);
        }
Ejemplo n.º 25
0
        private void LogRequests(List <LogEvent> logEvents)
        {
            Logger.Debug("Logging 404 errors to database");
            int bufferSize = Configuration.Configuration.BufferSize;
            int threshold  = Configuration.Configuration.ThreshHold;
            var start      = logEvents.First().Requested;
            var end        = logEvents.Last().Requested;
            var diff       = (end - start).Seconds;

            if ((diff != 0 && bufferSize / diff <= threshold) || bufferSize == 0)
            {
                var dba = DataAccessBaseEx.GetWorker();
                foreach (LogEvent logEvent in logEvents)
                {
                    dba.LogRequestToDb(logEvent.OldUrl, logEvent.Referer, logEvent.Requested);
                }
                Logger.Debug(string.Format("{0} 404 request(s) has been stored to the database.", bufferSize));
            }
            else
            {
                Logger.Warning("404 requests have been made too frequents (exceeded the threshold). Requests not logged to database.");
            }
        }
        public ActionResult SaveSuggestion(string oldUrl, string newUrl, string skipWildCardAppend, int?pageNumber, int?pageSize)
        {
            CheckAccess();
            SaveRedirect(oldUrl, newUrl, skipWildCardAppend, RedirectType.Permanent);

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

            dbAccess.DeleteRowsForRequest(oldUrl);

            //
            List <CustomRedirect> customRedirectList = GetSuggestions(null);
            string actionInfo = string.Format(LocalizationService.Current.GetString("/gadget/redirects/saveredirect"), oldUrl, newUrl);

            CustomRedirectHandler.ClearCache();
            var viewData = GetRedirectIndexViewData(pageNumber, customRedirectList, actionInfo, null, pageSize, true, true);

            if (customRedirectList.Count > 0)
            {
                viewData.HighestSuggestionValue = customRedirectList.First().NotfoundErrorCount;
                viewData.LowestSuggestionValue  = customRedirectList.Last().NotfoundErrorCount;
            }
            return(View("Index", viewData));
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Create redirects table and SP for version number
        /// </summary>
        private static void Create()
        {
            bool create = true;

            var dba = DataAccessBaseEx.GetWorker();

            _log.Information("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.Information("Create 404 handler redirects table END");


            if (create)
            {
                _log.Information("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.Information("Create 404 handler version SP END");
            }

            if (create)
            {
                _log.Information("Create Clustered index START");
                string clusteredIndex =
                    "CREATE CLUSTERED INDEX NotFoundRequests_ID ON [dbo].[BVN.NotFoundRequests] (ID)";

                if (!dba.ExecuteNonQuery(clusteredIndex))
                {
                    create = false;
                    _log.Error("An error occurred during the creation of the 404 handler redirects clustered index. Canceling.");
                }

                _log.Information("Create Clustered index 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
#pragma warning disable CS0618
                var oldCustomrRedirectStore = DataStoreFactory.GetStore(typeof(FileNotFound.CustomRedirects.CustomRedirect));
                var oldCustomRedirects      = oldCustomrRedirectStore.Items <FileNotFound.CustomRedirects.CustomRedirect>().ToList();
#pragma warning restore CS0618
                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);
            }
        }