コード例 #1
0
        internal void IncludeDirectory(string directoryVirtualPath, string searchPattern, PatternType patternType, bool searchSubdirectories)
        {
            IncludeDirectoryData includeDirectoryData = new IncludeDirectoryData();

            includeDirectoryData.DirectoryVirtualPath = directoryVirtualPath;
            includeDirectoryData.SearchPattern        = searchPattern;
            includeDirectoryData.SearchSubdirectories = searchSubdirectories;
            includeDirectoryData.PatternType          = patternType;
            IncludeDirectoryDataStructures.Add(includeDirectoryData);
        }
コード例 #2
0
        public void ProcessDirectory(BundleContext context, IncludeDirectoryData includeDirectoryData, string directoryPath, ref Dictionary <string, BundleFile> files)
        {
            IEnumerable <IFileInfo> directoryFiles;
            IDirectoryContents      directoryContent = context.FileProvider.GetDirectoryContents(directoryPath);

            if (directoryContent != null)
            {
                Regex regEx;
                switch (includeDirectoryData.PatternType)
                {
                // We used to be able to just call DirectoryInfo.GetFiles,
                // now we have to add support for * and {version} syntax on top of VPP
                case PatternType.Version:
                    regEx          = PatternHelper.BuildRegex(includeDirectoryData.SearchPattern);
                    directoryFiles = directoryContent.Where(file => regEx.IsMatch(file.Name) && !file.IsDirectory);
                    break;

                case PatternType.All:
                    directoryFiles = directoryContent.Where(file => !file.IsDirectory);
                    break;

                case PatternType.Exact:
                    directoryFiles = directoryContent.Where(file => String.Equals(file.Name, includeDirectoryData.SearchPattern, StringComparison.OrdinalIgnoreCase) && !file.IsDirectory);
                    break;

                case PatternType.Suffix:
                case PatternType.Prefix:
                default:
                    regEx          = PatternHelper.BuildWildcardRegex(includeDirectoryData.SearchPattern);
                    directoryFiles = directoryContent.Where(file => regEx.IsMatch(file.Name) && !file.IsDirectory);
                    break;
                }

                // Sort the directory files so we get deterministic order
                directoryFiles = directoryFiles.OrderBy(file => file, PhysicalFileComparer.Instance);

                //List<BundleFile> filterList = new List<BundleFile>();
                //foreach (IFileInfo file in directoryFiles)
                //{
                //    filterList.Add(new BundleFile());
                //}
                //files.AddRange(context.BundleCollection.DirectoryFilter.FilterIgnoredFiles(context, filterList));

                foreach (IFileInfo file in directoryFiles)
                {
                    files.Add(directoryPath + "/" + file.Name, new BundleFile(context.Parent)
                    {
                        PhysicalPath = file.PhysicalPath, VirtualPath = directoryPath + "/" + file.Name
                    });
                }

                // Need to recurse on subdirectories if requested
                if (includeDirectoryData.SearchSubdirectories)
                {
                    foreach (IFileInfo subDir in directoryContent.Where(file => file.IsDirectory))
                    {
                        ProcessDirectory(context, includeDirectoryData, directoryPath + "/" + subDir.Name, ref files);
                    }
                }
            }
        }