Exemplo n.º 1
0
        /// <summary>
        /// Ignores the specified pattern for a specific <see cref="OptimizationMode"/>.
        /// </summary>
        /// <param name="pattern">The ignore pattern.</param>
        /// <param name="mode"><see cref="OptimizationMode"/> in which to apply the ignore pattern.</param>
        public void Ignore(string pattern, OptimizationMode mode)
        {
            if (String.IsNullOrEmpty(pattern))
            {
                throw ExceptionUtil.ParameterNullOrEmpty("pattern");
            }
            PatternType type  = PatternHelper.GetPatternType(pattern);
            Exception   error = PatternHelper.ValidatePattern(type, pattern, "item");

            if (error != null)
            {
                throw error;
            }
            error = ValidateIgnoreMode(mode, "mode");
            if (error != null)
            {
                throw error;
            }

            switch (type)
            {
            case PatternType.All:
                _matches.Add(new AllMatch(mode));
                break;

            case PatternType.Exact:
                switch (mode)
                {
                case OptimizationMode.Always:
                    _exactAlways.Add(pattern);
                    break;

                case OptimizationMode.WhenEnabled:
                    _exactWhenOptimized.Add(pattern);
                    break;

                case OptimizationMode.WhenDisabled:
                    _exactWhenUnoptimized.Add(pattern);
                    break;
                }
                break;

            case PatternType.Prefix:
                _matches.Add(new PrefixMatch(pattern.Substring(0, pattern.Length - 1), mode));
                break;

            case PatternType.Suffix:
                _matches.Add(new SuffixMatch(pattern.Substring(1), mode));
                break;

            case PatternType.Version:
                _matches.Add(new VersionMatch(pattern, mode));
                break;
            }
        }
Exemplo n.º 2
0
        internal Exception IncludePath(string virtualPath, params IItemTransform[] transforms)
        {
            Exception error = ExceptionUtil.ValidateVirtualPath(virtualPath, "virtualPath");

            if (error != null)
            {
                return(error);
            }
            if (virtualPath.Contains('*') || virtualPath.Contains('{'))
            {
                // Wildcards can only be in the last path segment, and also can only be the first or last char there
                int    lastSlash     = virtualPath.LastIndexOf('/');            // Guaranteed to be one from above check
                string directoryPath = virtualPath.Substring(0, lastSlash + 1); // Want to keep the trailing / for app root case
                if (directoryPath.Contains('*'))
                {
                    return(new ArgumentException(String.Format(CultureInfo.CurrentCulture, OptimizationResources.InvalidPattern, virtualPath), "virtualPath"));
                }
                string searchPattern = "";
                if (lastSlash < virtualPath.Length - 1)
                {
                    searchPattern = virtualPath.Substring(lastSlash + 1);
                }
                PatternType patternType = PatternHelper.GetPatternType(searchPattern);
                error = PatternHelper.ValidatePattern(patternType, searchPattern, "virtualPath");
                if (error != null)
                {
                    return(error);
                }

                error = IncludeDirectory(directoryPath, searchPattern, patternType, searchSubdirectories: false, transforms: transforms);
                if (error != null)
                {
                    return(error);
                }
            }
            else
            {
                if (VirtualPathProvider == null || VirtualPathProvider.FileExists(virtualPath))
                {
                    Add(new BundleItem(virtualPath, transforms));
                }
            }
            return(null);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Includes all files in a directory that match a search pattern.
        /// </summary>
        /// <param name="directoryVirtualPath">The virtual path to the directory from which to search for files.</param>
        /// <param name="searchPattern">The search pattern to use in selecting files to add to the bundle.</param>
        /// <param name="searchSubdirectories">Specifies whether to recursively search subdirectories of <paramref name="directoryVirtualPath"/>.</param>
        /// <returns>The <see cref="Bundle"/> object itself for use in subsequent method chaining.</returns>
        public virtual Bundle IncludeDirectory(string directoryVirtualPath, string searchPattern, bool searchSubdirectories)
        {
            if (ExceptionUtil.IsPureWildcardSearchPattern(searchPattern))
            {
                throw new ArgumentException(OptimizationResources.InvalidWildcardSearchPattern, "searchPattern");
            }
            PatternType patternType = PatternHelper.GetPatternType(searchPattern);
            Exception   error       = PatternHelper.ValidatePattern(patternType, searchPattern, "virtualPaths");

            if (error != null)
            {
                throw error;
            }
            error = Items.IncludeDirectory(directoryVirtualPath, searchPattern, patternType, searchSubdirectories);
            if (error != null)
            {
                throw error;
            }

            return(this);
        }