Esempio n. 1
0
        /// <summary>
        ///     Determines whether the specified a disallowed is disallowed.
        /// </summary>
        /// <param name = "aDisallowed">A disallowed.</param>
        /// <param name = "uri">The URI.</param>
        /// <returns>
        ///     <c>true</c> if the specified a disallowed is disallowed; otherwise, <c>false</c>.
        /// </returns>
        protected bool IsDisallowed(ADisallowed <TArachnodeDAO> aDisallowed, Uri uri)
        {
            bool isDisallowed = false;

            aDisallowed.OutputIsDisallowedReason = OutputIsDisallowedReason;

            #region Disallowed by AbsoluteUri.

            if (UserDefinedFunctions.IsDisallowedForAbsoluteUri(uri.AbsoluteUri, true, false))
            {
                isDisallowed = true;
            }

            if (_negateIsDisallowedForAbsoluteUri)
            {
                isDisallowed = !isDisallowed;
            }

            if (isDisallowed)
            {
                aDisallowed.IsDisallowedReason = "Disallowed by AbsoluteUri.";

                return(true);
            }

            #endregion

            #region Disallowed by Domain.

            if (UserDefinedFunctions.IsDisallowedForDomain(uri.AbsoluteUri, false, false))
            {
                isDisallowed = true;
            }

            if (_negateIsDisallowedForDomain)
            {
                isDisallowed = !isDisallowed;
            }

            if (isDisallowed)
            {
                aDisallowed.IsDisallowedReason = "Disallowed by Domain.";

                return(true);
            }

            #endregion

            #region Disallowed by Extension.

            if (UserDefinedFunctions.IsDisallowedForExtension(uri.AbsoluteUri, false, false))
            {
                isDisallowed = true;
            }

            if (_negateIsDisallowedForExtension)
            {
                isDisallowed = !isDisallowed;
            }

            if (isDisallowed)
            {
                aDisallowed.IsDisallowedReason = "Disallowed by Extension.";

                return(true);
            }

            #endregion

            #region Disallowed by FileExtension.

            if (UserDefinedFunctions.IsDisallowedForFileExtension(uri.AbsoluteUri, false, false))
            {
                isDisallowed = true;
            }

            if (_negateIsDisallowedForFileExtension)
            {
                isDisallowed = !isDisallowed;
            }

            if (isDisallowed)
            {
                aDisallowed.IsDisallowedReason = "Disallowed by FileExtension.";

                return(true);
            }

            #endregion

            #region Disallowed by Host.

            if (UserDefinedFunctions.IsDisallowedForHost(uri.AbsoluteUri, false, false))
            {
                isDisallowed = true;
            }

            if (_negateIsDisallowedForHost)
            {
                isDisallowed = !isDisallowed;
            }

            if (isDisallowed)
            {
                aDisallowed.IsDisallowedReason = "Disallowed by Host.";

                return(true);
            }

            #endregion

            #region Disallowed by Scheme.

            if (UserDefinedFunctions.IsDisallowedForScheme(uri.AbsoluteUri, false, false))
            {
                isDisallowed = true;
            }

            if (_negateIsDisallowedForScheme)
            {
                isDisallowed = !isDisallowed;
            }

            if (isDisallowed)
            {
                aDisallowed.IsDisallowedReason = "Disallowed by Scheme.";

                return(true);
            }

            #endregion

            #region Disallowed by repeating AbsoluteUri.

            if (_detectRepeatingAbsoluteUrisRegex.IsMatch(uri.AbsoluteUri))
            {
                isDisallowed = true;
            }

            if (_negateIsDisallowedForRepeatingAbsoluteUri)
            {
                isDisallowed = !isDisallowed;
            }

            if (isDisallowed)
            {
                aDisallowed.IsDisallowedReason = "Disallowed by repeating AbsoluteUri.";

                return(true);
            }

            #endregion

            #region Disallowed by maximum directory depth.

            if (uri.AbsoluteUri.Replace("/", string.Empty).Length < uri.AbsoluteUri.Length - (_maximumDirectoryDepth + 2))
            {
                isDisallowed = true;
            }

            if (_negateIsDisallowedForMaximumDirectoryDepth)
            {
                isDisallowed = !isDisallowed;
            }

            if (isDisallowed)
            {
                aDisallowed.IsDisallowedReason = "Disallowed by maximum directory depth.";

                return(true);
            }

            #endregion

            #region Disallowed by named anchor.

            //if (_disallowNamedAnchors && _detectAbsoluteUrisWithNamedAnchorRegex.IsMatch(discovery.Uri.AbsoluteUri))
            if (_disallowNamedAnchors && !string.IsNullOrEmpty(uri.Fragment))
            {
                isDisallowed = true;
            }

            if (_negateIsDisallowedForNamedAnchor)
            {
                isDisallowed = !isDisallowed;
            }

            if (isDisallowed)
            {
                aDisallowed.IsDisallowedReason = "Disallowed by named anchor.";

                return(true);
            }

            #endregion

            #region Disallowed by query string.

            //if (_disallowQueryStrings && _detectAbsoluteUrisWithQueryStringRegex.IsMatch(discovery.Uri.AbsoluteUri))
            if (_disallowQueryStrings && !string.IsNullOrEmpty(uri.Query))
            {
                isDisallowed = true;
            }

            if (_negateIsDisallowedForQueryString)
            {
                isDisallowed = !isDisallowed;
            }

            if (isDisallowed)
            {
                aDisallowed.IsDisallowedReason = "Disallowed by query string.";

                return(true);
            }

            #endregion

            return(false);
        }