public override List <RedirectItemValidationResult> HandleValidation(RedirectItem redirectItem, IEnumerable <RedirectItem> otherRedirectItems)
        {
            var response = new RedirectItemValidationResult();

            var linkUrl = string.Empty;

            if (!string.IsNullOrEmpty(redirectItem.LinkUrl))
            {
                linkUrl = redirectItem.LinkUrl;
            }

            var destinationRedirect = otherRedirectItems.FirstOrDefault(item => item.Url == linkUrl && item.QueryString == redirectItem.QueryString && item.UniqueId != redirectItem.UniqueId);

            if (destinationRedirect != null)
            {
                if (destinationRedirect.LinkUrl == redirectItem.Url)
                {
                    response.Status       = ImportErrorLevel.Error;
                    response.ErrorMessage = string.Format("This redirect would create a redirect loop as another redirect exists with the URL ({0}) in the file. It has not been imported.", redirectItem.LinkUrl);

                    ErrorsResult.Add(response);

                    return(ErrorsResult);
                }

                response.Status       = ImportErrorLevel.Warning;
                response.ErrorMessage = string.Format("This redirect links to the URL ({0}) in the file. This will result in a redirect chain", redirectItem.LinkUrl);

                ErrorsResult.Add(response);

                return(ErrorsResult);
            }

            if (Successor != null)
            {
                return(Successor.HandleValidation(redirectItem, otherRedirectItems));
            }

            ErrorsResult.Add(response);

            return(ErrorsResult);
        }
Exemple #2
0
        /// <summary>
        /// Handles validation for Source Url
        /// </summary>
        /// <param name="redirectItem">A redirect item</param>
        /// <param name="otherRedirectItems">All redirect items in the file</param>
        /// <returns></returns>
        public override List <RedirectItemValidationResult> HandleValidation(RedirectItem redirectItem, IEnumerable <RedirectItem> otherRedirectItems)
        {
            var response = new RedirectItemValidationResult();

            if (string.IsNullOrEmpty(redirectItem.Url))
            {
                response.Status       = ImportErrorLevel.Error;
                response.ErrorMessage = "No source URL was provided or is in the wrong format";

                ErrorsResult.Add(response);

                return(ErrorsResult);
            }

            if (Successor != null)
            {
                return(Successor.HandleValidation(redirectItem, otherRedirectItems));
            }

            ErrorsResult.Add(response);

            return(ErrorsResult);
        }
Exemple #3
0
        public override List <RedirectItemValidationResult> HandleValidation(RedirectItem redirectItem, IEnumerable <RedirectItem> otherRedirectItems)
        {
            var response          = new RedirectItemValidationResult();
            var duplicateRedirect = otherRedirectItems.FirstOrDefault(item => item.Url == redirectItem.Url && item.QueryString == redirectItem.QueryString && item.UniqueId != redirectItem.UniqueId);

            if (duplicateRedirect != null)
            {
                response.Status       = ImportErrorLevel.Error;
                response.ErrorMessage = "This redirect has a duplicate row in the file with the same source URL. It has not been imported.";

                ErrorsResult.Add(response);

                return(ErrorsResult);
            }

            if (Successor != null)
            {
                return(Successor.HandleValidation(redirectItem, otherRedirectItems));
            }

            ErrorsResult.Add(response);

            return(ErrorsResult);
        }