Exemple #1
0
        public static void AssertPositiveNumber(int?optionalNumber, string source)
        {
            BaseValidator.CheckNullAndThrow(optionalNumber, source);
            int number = optionalNumber.Value;

            if (number <= 0)
            {
                throw new ArgumentException(source + " : " + "Positive number expected");
            }
        }
        public static void ValidateMediaRoot(string mediaLibraryRootItemPath, string source)
        {
            BaseValidator.CheckForNullEmptyAndWhiteSpaceOrThrow(mediaLibraryRootItemPath, source);

            string lowerCasePath     = mediaLibraryRootItemPath.ToLowerInvariant();
            bool   isValidPathPrefix = lowerCasePath.StartsWith("/");

            if (!isValidPathPrefix)
            {
                throw new ArgumentException(source + " : Path must begin with '/'");
            }
        }
        public static void ValidateItemId(string itemId, string source)
        {
            //TODO: @igk investigate and test in unit tests base id criterias, no info in documentation is available
            BaseValidator.CheckForNullEmptyAndWhiteSpaceOrThrow(itemId, source);

            bool correctIdLenght = (itemId.Length == 36 || itemId.Length == 38);

            if (!correctIdLenght)
            {
                throw new ArgumentException(source + " : " + INVALID_ID_MESSAGE);
            }
        }
        public static void ValidateItemId(string itemId, string source)
        {
            BaseValidator.CheckForNullEmptyAndWhiteSpaceOrThrow(itemId, source);

            bool hasOpeningBrace    = itemId.StartsWith("{");
            bool hasClosingBrace    = itemId.EndsWith("}");
            bool hasNonBraceSymbols = (itemId.Length > 2);

            bool isValidId = hasOpeningBrace && hasClosingBrace && hasNonBraceSymbols;

            if (!isValidId)
            {
                throw new ArgumentException(source + " : " + INVALID_ID_MESSAGE);
            }
        }
Exemple #5
0
        private static void CommonValidatePath(string itemPath, string source)
        {
            BaseValidator.CheckForNullEmptyAndWhiteSpaceOrThrow(itemPath, source);

            char[] unexpectedSymbols     = { '.' };
            int    unexpectedSymbolIndex = itemPath.IndexOfAny(unexpectedSymbols);
            bool   hasUnexpectedSymbols  = (-1 != unexpectedSymbolIndex);

            if (hasUnexpectedSymbols)
            {
                var    unexpectedSymbol = itemPath[unexpectedSymbolIndex];
                string message          = string.Format("{0} : cannot contain '{1}'", source, unexpectedSymbol);

                throw new ArgumentException(message);
            }
        }
        public void ValidateMediaPath(string itemPath, string source)
        {
            BaseValidator.CheckForNullEmptyAndWhiteSpaceOrThrow(itemPath, source);

            bool isAbsoluteItemPath = IsItemPathStartsWithSlash(itemPath);
            bool isMediaHookPresent = this.IsItemPathHasMediaHook(itemPath);
            bool isValidPrefix      = isAbsoluteItemPath || isMediaHookPresent;

            if (!isValidPrefix)
            {
                throw new ArgumentException(source + " : Should begin with '/' or '~'");
            }

            if (isAbsoluteItemPath)
            {
                bool hasExtension = IsItemPathHasExtension(itemPath);
                if (hasExtension)
                {
                    throw new ArgumentException(source + " : Starting with '/' cannot have an extension (.ashx and others)");
                }
            }
        }
 public static void ValidateSearchRequest(string term, string source)
 {
     //TODO: @igk investigate and test in unit tests base id criterias, no info in documentation is available
     BaseValidator.CheckForNullEmptyAndWhiteSpaceOrThrow(term, source);
 }