コード例 #1
0
        /// <summary>
        /// Adds all files in a single directory to a fileListsByAssetType
        /// </summary>
        /// <param name="fileListsByAssetType"></param>
        /// <param name="dirPath"></param>
        private void AddRequiredFilesSingleDirectory(FileListsByAssetType fileListsByAssetType, AssetPath dirPath)
        {
            string absolutePath = dirPath.AbsolutePath;
            IEnumerable<string> filePaths = Directory.EnumerateFiles(absolutePath);

            // Need to first process the nuspec files, and then the asset files.
            // This because the asset files may depend on the files pointed at by the nuspec files.
            for (int i = 0; i < 2; i++)
            {
                foreach (string filePath in filePaths)
                {
                    if (i == 0)
                    {
                        if (NuspecFile.IsNuspecFile(filePath))
                        {
                            fileListsByAssetType.Append(GetDependencies(filePath, dirPath));
                        }
                    }
                    else
                    {
                        AssetType? assetType = AssetTypeOfFile(filePath);
                        if (assetType != null)
                        {
                            fileListsByAssetType.Add(dirPath.AbsolutePathToAssetPath(filePath), assetType.Value);
                        }
                    }
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Adds all files in a single directory to a fileListsByAssetType
        /// </summary>
        /// <param name="fileListsByAssetType"></param>
        /// <param name="dirPath"></param>
        private void AddRequiredFilesSingleDirectory(FileListsByAssetType fileListsByAssetType, AssetPath dirPath)
        {
            string absolutePath = dirPath.AbsolutePath;

            string[] filePaths = Directory.EnumerateFiles(absolutePath).ToArray();

            // Need to first process the nuspec files, and then the asset files.
            // This because the asset files may depend on the files pointed at by the nuspec files.
            for (int i = 0; i < 2; i++)
            {
                foreach (string filePath in filePaths)
                {
                    if (i == 0)
                    {
                        if (NuspecFile.IsNuspecFile(filePath))
                        {
                            fileListsByAssetType.Append(GetDependencies(filePath, dirPath));
                        }
                    }
                    else
                    {
                        AssetType?assetType = AssetTypeOfFile(filePath);
                        if (assetType != null)
                        {
                            fileListsByAssetType.Add(dirPath.AbsolutePathToAssetPath(filePath), assetType.Value);
                        }
                    }
                }
            }
        }
コード例 #3
0
 private List<string> CreateBundles(FileListsByAssetType fileListsByAssetType, AssetType assetType, Func<string, string[], Bundle> bundleFactory)
 {
     List<AssetPath> files = fileListsByAssetType.GetList(assetType);
     List<List<AssetPath>> filesByAreaController = RouteHelper.FilePathsSortedByRoute(files);
     List<string> bundleVirtualPaths = BundleHelper.AddFileListsAsBundles(_bundles, filesByAreaController, bundleFactory);
     return bundleVirtualPaths;
 }
コード例 #4
0
        private List <string> CreateBundles(FileListsByAssetType fileListsByAssetType, AssetType assetType, Func <string, string[], Bundle> bundleFactory)
        {
            List <AssetPath> files = fileListsByAssetType.GetList(assetType);

            // ignore minified file if non-minified file is found
            for (var i = files.Count - 1; i >= 0; i--)
            {
                var file                     = files[i];
                var directoryName            = Path.GetDirectoryName(file.AbsolutePath);
                var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(file.AbsolutePath);

                if (directoryName != null && fileNameWithoutExtension.EndsWith(".min"))
                {
                    var extension               = Path.GetExtension(file.AbsolutePath);
                    var nonMinifiedFileName     = fileNameWithoutExtension.Substring(0, fileNameWithoutExtension.Length - 4) + extension;
                    var nonMinifiedAbsolutePath = Path.Combine(directoryName, nonMinifiedFileName);
                    if (files.Any(ap => ap.AbsolutePath == nonMinifiedAbsolutePath))
                    {
                        files.RemoveAt(i);
                    }
                }
            }

            List <List <AssetPath> > filesByAreaController = RouteHelper.FilePathsSortedByRoute(files);
            List <string>            bundleVirtualPaths    = BundleHelper.AddFileListsAsBundles(_bundles, filesByAreaController, bundleFactory);

            return(bundleVirtualPaths);
        }
コード例 #5
0
        private List <string> CreateBundles(FileListsByAssetType fileListsByAssetType, AssetType assetType, Func <string, string[], Bundle> bundleFactory)
        {
            List <AssetPath>         files = fileListsByAssetType.GetList(assetType);
            List <List <AssetPath> > filesByAreaController = RouteHelper.FilePathsSortedByRoute(files);
            List <string>            bundleVirtualPaths    = BundleHelper.AddFileListsAsBundles(_bundles, filesByAreaController, bundleFactory);

            return(bundleVirtualPaths);
        }
コード例 #6
0
        /// <summary>
        /// Reads the dependencies in a Nuspec file. These are directories.
        /// Accumulates the assets in those directories to in a FileListsByAssetType.
        /// This is then returned.
        ///
        /// This method calls the dependency resolver concurrently.
        /// </summary>
        /// <param name="absoluteNuspecPath">
        /// Path of the nuspec file
        /// </param>
        /// <param name="nuspecFileDirPath">
        /// The directory where the nuspec file is located.
        /// </param>
        /// <returns></returns>
        private FileListsByAssetType GetDependencies(string absoluteNuspecPath, AssetPath nuspecFileDirPath)
        {
            FileListsByAssetType fileListsByAssetType = new FileListsByAssetType();

            var nuspecFile = new NuspecFile(absoluteNuspecPath);
            List <AssetPath> dependencyAssetPaths = nuspecFile.DependencyIds.Select(d => nuspecFileDirPath.Create(d)).ToList();

            // Call the dependency resolver concurrently for each dependency
            foreach (AssetPath dependencyAssetPath in dependencyAssetPaths)
            {
                fileListsByAssetType.Append(GetRequiredFilesForDirectory(dependencyAssetPath));
            }

            return(fileListsByAssetType);
        }
コード例 #7
0
        /// <summary>
        /// Builds the bundles that need to be loaded on the page.
        /// </summary>
        /// <param name="assetDirectoryList">
        /// The directories with assets that need to be included. These directories may have dependencies
        /// on other directories, such as via .nuspec dependencies files and parent directories.
        /// 
        /// When a view is processed, its directory is normally added to this list.
        /// </param>
        /// <param name="scriptBundleVirtualPaths">
        /// The virtual paths of the generated script bundles.
        /// </param>
        /// <param name="styleBundleVirtualPaths">
        /// The virtual paths of the generated style bundles.
        /// </param>
        public void Builder(List<AssetPath> assetDirectoryList, 
                            out List<string> scriptBundleVirtualPaths,
                            out List<string> styleBundleVirtualPaths)
        {
            var fileListsByAssetType = new FileListsByAssetType();
            var dependencyResolver = new DependencyResolver(_cacheHelper);

            foreach (AssetPath assetDirectory in assetDirectoryList)
            {
                FileListsByAssetType requiredFilesByAssetType = dependencyResolver.GetRequiredFilesForDirectory(assetDirectory);
                fileListsByAssetType.Append(requiredFilesByAssetType);
            }

            // fileListsByAssetType now contains all required files by asset type

            scriptBundleVirtualPaths = CreateBundles(fileListsByAssetType, AssetType.Script, _bundleFactories.ScriptBundleFactory);
            styleBundleVirtualPaths = CreateBundles(fileListsByAssetType, AssetType.StyleSheet, _bundleFactories.StyleBundleFactory);
        }
コード例 #8
0
        /// <summary>
        /// Builds the bundles that need to be loaded on the page.
        /// </summary>
        /// <param name="assetDirectoryList">
        /// The directories with assets that need to be included. These directories may have dependencies
        /// on other directories, such as via .nuspec dependencies files and parent directories.
        ///
        /// When a view is processed, its directory is normally added to this list.
        /// </param>
        /// <param name="scriptBundleVirtualPaths">
        /// The virtual paths of the generated script bundles.
        /// </param>
        /// <param name="styleBundleVirtualPaths">
        /// The virtual paths of the generated style bundles.
        /// </param>
        public void Builder(List <AssetPath> assetDirectoryList,
                            out List <string> scriptBundleVirtualPaths,
                            out List <string> styleBundleVirtualPaths)
        {
            var fileListsByAssetType = new FileListsByAssetType();
            var dependencyResolver   = new DependencyResolver(_cacheHelper);

            foreach (AssetPath assetDirectory in assetDirectoryList)
            {
                FileListsByAssetType requiredFilesByAssetType = dependencyResolver.GetRequiredFilesForDirectory(assetDirectory);
                fileListsByAssetType.Append(requiredFilesByAssetType);
            }

            // fileListsByAssetType now contains all required files by asset type

            scriptBundleVirtualPaths = CreateBundles(fileListsByAssetType, AssetType.Script, _bundleFactories.ScriptBundleFactory);
            styleBundleVirtualPaths  = CreateBundles(fileListsByAssetType, AssetType.StyleSheet, _bundleFactories.StyleBundleFactory);
        }
コード例 #9
0
        /// <summary>
        /// Same as GetRequiredFilesForDirectory, but uncached.
        /// </summary>
        /// <param name="dirPath">
        /// Path to the directory.
        /// </param>
        /// <returns></returns>
        private FileListsByAssetType GetRequiredFilesForDirectoryUnchached(AssetPath dirPath)
        {
            FileListsByAssetType fileListsByAssetType = new FileListsByAssetType();

            // Note: parentDirs will contain dirPath itself.
            //
            // dirPath.ParentDirs will give you something like
            // ~/Views/Shared/EditorTemplates/HomeAddress
            // ~/Views/Shared/EditorTemplates
            // ~/Views/Shared
            // However, the longer directory tends to have the more specific files. If there is a dependency between files in these
            // directories, it would be from more specific to less specific, not the other way around. So process the directories in
            // reverse order, so CSS and JS files in more common directories are loaded first.

            IEnumerable <AssetPath> parentDirs = dirPath.ParentDirs("Views").Reverse();

            foreach (AssetPath parentDir in parentDirs)
            {
                AddRequiredFilesSingleDirectory(fileListsByAssetType, parentDir);
            }

            return(fileListsByAssetType);
        }
コード例 #10
0
        /// <summary>
        /// Same as GetRequiredFilesForDirectory, but uncached.
        /// </summary>
        /// <param name="dirPath">
        /// Path to the directory. 
        /// </param>
        /// <returns></returns>
        private FileListsByAssetType GetRequiredFilesForDirectoryUnchached(AssetPath dirPath)
        {
            FileListsByAssetType fileListsByAssetType = new FileListsByAssetType();

            // Note: parentDirs will contain dirPath itself.
            //
            // dirPath.ParentDirs will give you something like
            /// ~/Views/Shared/EditorTemplates/HomeAddress
            /// ~/Views/Shared/EditorTemplates
            /// ~/Views/Shared
            // However, the longer directory tends to have the more specific files. If there is a dependency between files in these
            // directories, it would be from more specific to less specific, not the other way around. So process the directories in
            // reverse order, so CSS and JS files in more common directories are loaded first.

            IEnumerable<AssetPath> parentDirs = dirPath.ParentDirs("Views").Reverse();
            foreach (AssetPath parentDir in parentDirs)
            {
                AddRequiredFilesSingleDirectory(fileListsByAssetType, parentDir);
            }

            return fileListsByAssetType;
        }
コード例 #11
0
        /// <summary>
        /// Reads the dependencies in a Nuspec file. These are directories.
        /// Accumulates the assets in those directories to in a FileListsByAssetType.
        /// This is then returned.
        /// 
        /// This method calls the dependency resolver concurrently.
        /// </summary>
        /// <param name="absoluteNuspecPath">
        /// Path of the nuspec file
        /// </param>
        /// <param name="nuspecFileDirPath">
        /// The directory where the nuspec file is located.
        /// </param>
        /// <returns></returns>
        private FileListsByAssetType GetDependencies(string absoluteNuspecPath, AssetPath nuspecFileDirPath)
        {
            FileListsByAssetType fileListsByAssetType = new FileListsByAssetType();

            var nuspecFile = new NuspecFile(absoluteNuspecPath);
            List<AssetPath> dependencyAssetPaths = nuspecFile.DependencyIds.Select(d => nuspecFileDirPath.Create(d)).ToList();

            // Call the dependency resolver concurrently for each dependency
            foreach (AssetPath dependencyAssetPath in dependencyAssetPaths)
            {
                fileListsByAssetType.Append(GetRequiredFilesForDirectory(dependencyAssetPath));
            }

            return fileListsByAssetType;
        }