/// <summary>
        /// Adds a bundle for each sub-directory of the given path.
        /// </summary>
        /// <typeparam name="T">The type of bundles to create.</typeparam>
        /// <param name="bundleCollection">The collection to add to.</param>
        /// <param name="applicationRelativePath">The path to the directory containing sub-directories.</param>
        /// <param name="fileSearch">A file source that gets the files to include from a directory.</param>
        /// <param name="customizeBundle">A delegate that is called for each created bundle to allow customization.</param>
        /// <param name="excludeTopLevel">Prevents the creation of an extra bundle from the top-level files of the path, if any.</param>
        public static void AddPerSubDirectory <T>(this BundleCollection bundleCollection, string applicationRelativePath, IFileSearch fileSearch, Action <T> customizeBundle, bool excludeTopLevel = false)
            where T : Bundle
        {
            Trace.Source.TraceInformation(string.Format("Creating {0} for each subdirectory of {1}", typeof(T).Name, applicationRelativePath));

            fileSearch = fileSearch ?? bundleCollection.Settings.DefaultFileSearches[typeof(T)];

            var bundleFactory   = (IBundleFactory <T>)bundleCollection.Settings.BundleFactories[typeof(T)];
            var parentDirectory = bundleCollection.Settings.SourceDirectory.GetDirectory(applicationRelativePath);

            if (!excludeTopLevel)
            {
                var topLevelFiles = fileSearch.FindFiles(parentDirectory)
                                    .Where(f => f.Directory == parentDirectory)
                                    .ToArray();
                var directoryBundle = CreateDirectoryBundle(applicationRelativePath, bundleFactory, topLevelFiles, parentDirectory);
                if (topLevelFiles.Any() || directoryBundle is IExternalBundle)
                {
                    if (customizeBundle != null)
                    {
                        customizeBundle(directoryBundle);
                    }
                    bundleCollection.Add(directoryBundle);
                }
            }

            var directories = parentDirectory.GetDirectories().Where(IsNotHidden);

            foreach (var directory in directories)
            {
                Trace.Source.TraceInformation(string.Format("Creating {0} for {1}", typeof(T).Name, directory.FullPath));
                var allFiles = fileSearch.FindFiles(directory).ToArray();

                var descriptorFile = TryGetDescriptorFile(directory);
                var descriptor     = descriptorFile.Exists
                                     ? new BundleDescriptorReader(descriptorFile).Read()
                                     : new BundleDescriptor {
                    AssetFilenames = { "*" }
                };

                if (!allFiles.Any() && descriptor.ExternalUrl == null)
                {
                    continue;
                }

                var bundle = bundleFactory.CreateBundle(directory.FullPath, allFiles, descriptor);
                if (customizeBundle != null)
                {
                    customizeBundle(bundle);
                }
                TraceAssetFilePaths(bundle);
                bundleCollection.Add(bundle);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds a bundle for each sub-directory of the given path.
        /// </summary>
        /// <typeparam name="T">The type of bundles to create.</typeparam>
        /// <param name="applicationRelativePath">The path to the directory containing sub-directories.</param>
        /// <param name="fileSearch">A file source that gets the files to include from a directory.</param>
        /// <param name="customizeBundle">A delegate that is called for each created bundle to allow customization.</param>
        /// <param name="excludeTopLevel">Prevents the creation of an extra bundle from the top-level files of the path, if any.</param>
        public void AddPerSubDirectory <T>(string applicationRelativePath, IFileSearch fileSearch, Action <T> customizeBundle, bool excludeTopLevel = false)
            where T : Bundle
        {
            Trace.Source.TraceInformation(string.Format("Creating {0} for each subdirectory of {1}", typeof(T).Name, applicationRelativePath));

            fileSearch = fileSearch ?? fileSearchProvider.GetFileSearch(typeof(T));

            var bundleFactory   = bundleFactoryProvider.GetBundleFactory <T>();
            var parentDirectory = settings.SourceDirectory.GetDirectory(applicationRelativePath);

            if (!excludeTopLevel)
            {
                var topLevelFiles = fileSearch.FindFiles(parentDirectory)
                                    .Where(f => f.Directory.Equals(parentDirectory))
                                    .ToArray();
                var directoryBundle = CreateDirectoryBundle(applicationRelativePath, bundleFactory, topLevelFiles, parentDirectory);
                if (topLevelFiles.Any() || directoryBundle is IExternalBundle)
                {
                    if (customizeBundle != null)
                    {
                        customizeBundle(directoryBundle);
                    }
                    Add(directoryBundle);
                }
            }

            var directories = parentDirectory.GetDirectories().Where(IsNotHidden);

            foreach (var directory in directories)
            {
                Trace.Source.TraceInformation(string.Format("Creating {0} for {1}", typeof(T).Name, directory.FullPath));
                var allFiles = fileSearch.FindFiles(directory).ToArray();

                var descriptorFile = TryGetDescriptorFile <T>(directory);
                var descriptor     = ReadOrCreateBundleDescriptor(descriptorFile);

                if (!allFiles.Any() && descriptor.ExternalUrl == null)
                {
                    continue;
                }

                var bundle = bundleFactory.CreateBundle(directory.FullPath, allFiles, descriptor);
                if (customizeBundle != null)
                {
                    customizeBundle(bundle);
                }
                TraceAssetFilePaths(bundle);
                Add(bundle);
            }
        }
        /// <summary>
        /// Adds a bundle for each individual file found using the file search. If no file search is provided the application
        /// default file search for the bundle type is used.
        /// </summary>
        /// <typeparam name="T">The type of bundle to create.</typeparam>
        /// <param name="bundleCollection">The bundle collection to add to.</param>
        /// <param name="directoryPath">The path to the directory to search. If null or empty the application source directory is used.</param>
        /// <param name="fileSearch">The <see cref="IFileSearch"/> used to find files. If null the application default file search for the bundle type is used.</param>
        /// <param name="customizeBundle">An optional action delegate called for each bundle.</param>
        public static void AddPerIndividualFile <T>(this BundleCollection bundleCollection, string directoryPath = null, IFileSearch fileSearch = null, Action <T> customizeBundle = null)
            where T : Bundle
        {
            var directory = string.IsNullOrEmpty(directoryPath)
                ? bundleCollection.Settings.SourceDirectory
                : bundleCollection.Settings.SourceDirectory.GetDirectory(directoryPath);

            fileSearch = fileSearch ?? bundleCollection.Settings.DefaultFileSearches[typeof(T)];
            var files         = fileSearch.FindFiles(directory);
            var bundleFactory = (IBundleFactory <T>)bundleCollection.Settings.BundleFactories[typeof(T)];

            foreach (var file in files)
            {
                var bundle = bundleFactory.CreateBundle(
                    file.FullPath,
                    new[] { file },
                    new BundleDescriptor {
                    AssetFilenames = { "*" }
                }
                    );
                if (customizeBundle != null)
                {
                    customizeBundle(bundle);
                }
                bundleCollection.Add(bundle);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Adds a bundle for each individual file found using the file search. If no file search is provided the application
        /// default file search for the bundle type is used.
        /// </summary>
        /// <typeparam name="T">The type of bundle to create.</typeparam>
        /// <param name="directoryPath">The path to the directory to search. If null or empty the application source directory is used.</param>
        /// <param name="fileSearch">The <see cref="IFileSearch"/> used to find files. If null the application default file search for the bundle type is used.</param>
        /// <param name="customizeBundle">An optional action delegate called for each bundle.</param>
        public void AddPerIndividualFile <T>(string directoryPath = null, IFileSearch fileSearch = null, Action <T> customizeBundle = null)
            where T : Bundle
        {
            var directory = string.IsNullOrEmpty(directoryPath)
                                ? settings.SourceDirectory
                                : settings.SourceDirectory.GetDirectory(directoryPath);

            fileSearch = fileSearch ?? fileSearchProvider.GetFileSearch(typeof(T));
            var files         = fileSearch.FindFiles(directory);
            var bundleFactory = bundleFactoryProvider.GetBundleFactory <T>();

            foreach (var file in files)
            {
                var bundle = bundleFactory.CreateBundle(
                    file.FullPath,
                    new[] { file },
                    new BundleDescriptor {
                    AssetFilenames = { "*" }
                }
                    );
                if (customizeBundle != null)
                {
                    customizeBundle(bundle);
                }
                Add(bundle);
            }
        }
Ejemplo n.º 5
0
        public async Task RefreshFromFileSystem()
        {
            var foundFiles = new List <IFile>();

            foundFiles.AddRange(await _search.FindFiles());
            await await Task.Factory.StartNew(async() => {
                foreach (var file in foundFiles.Where(x => !FoundFiles.Keys.Contains(x.PathSha1)))
                {
                    FoundFiles.AddOrUpdate(file.PathSha1, file, (k, v) => v = file);
                }
                await UpdateStorage();
                foreach (var file in FoundFiles.Values.Where(x => x.GetFileInfo() == null))
                {
                    if (file is Nupkg nu)
                    {
                        await _store.DeleteFile(nu);
                    }
                    else if (file is Project pj)
                    {
                        await _store.DeleteFile(pj);
                    }
                    else if (file is Solution sol)
                    {
                        await _store.DeleteFile(sol);
                    }
                }
            });
        }
        /// <summary>
        /// Adds a bundle of type <typeparamref name="T"/> using asset files found in the given path.
        /// </summary>
        /// <typeparam name="T">The type of bundle to create.</typeparam>
        /// <param name="bundleCollection">The bundle collection to add to.</param>
        /// <param name="applicationRelativePath">The application relative path to the bundle's asset files.</param>
        /// <param name="fileSearch">The file search used to find asset files to include in the bundle.</param>
        /// <param name="customizeBundle">The delegate used to customize the created bundle before adding it to the collection.</param>
        public static void Add <T>(this BundleCollection bundleCollection, string applicationRelativePath, IFileSearch fileSearch, Action <T> customizeBundle)
            where T : Bundle
        {
            applicationRelativePath = PathUtilities.AppRelative(applicationRelativePath);
            Trace.Source.TraceInformation(string.Format("Creating {0} for {1}", typeof(T).Name, applicationRelativePath));

            T   bundle;
            var bundleFactory = (IBundleFactory <T>)bundleCollection.Settings.BundleFactories[typeof(T)];

            var source = bundleCollection.Settings.SourceDirectory;

            if (source.DirectoryExists(applicationRelativePath))
            {
                fileSearch = fileSearch ?? bundleCollection.Settings.DefaultFileSearches[typeof(T)];
                var directory = source.GetDirectory(applicationRelativePath);
                var allFiles  = fileSearch.FindFiles(directory);
                bundle = CreateDirectoryBundle(applicationRelativePath, bundleFactory, allFiles, directory);
            }
            else
            {
                var file = source.GetFile(applicationRelativePath);
                if (file.Exists)
                {
                    bundle = CreateSingleFileBundle(applicationRelativePath, file, bundleFactory);
                }
                else
                {
                    throw new DirectoryNotFoundException(string.Format("Bundle path not found: {0}", applicationRelativePath));
                }
            }

            if (customizeBundle != null)
            {
                customizeBundle(bundle);
            }

            TraceAssetFilePaths(bundle);

            bundleCollection.Add(bundle);
        }