Пример #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;

            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);
                        }
                    }
                }
            }
        }
Пример #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;
            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);
                        }
                    }
                }
            }
        }
Пример #3
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);
        }
        /// <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);
        }
        /// <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);
        }
Пример #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;
        }