IEnumerable<string> GetDirectoriesToWatch(ModuleCollection modules, string conventionalTopLevelDirectory) { var paths = new List<string>(); if (modules.Count == 0) { // Use conventional directory e.g. "scripts". var scriptsPath = Path.Combine(HttpRuntime.AppDomainAppPath, conventionalTopLevelDirectory); if (Directory.Exists(scriptsPath)) { paths.Add(scriptsPath); // HACK: CacheDependency does not seem to monitor file changes within subdirectories // so manually watch each subdirectory of "scripts" as well. paths.AddRange(Directory.GetDirectories(scriptsPath)); } } else { var configPaths = from element in modules.Cast<ModuleElement>() select Path.Combine(HttpRuntime.AppDomainAppPath, element.Path); foreach (var path in configPaths) { if (path.EndsWith("*")) // e.g. "scripts/*" { // So we watch all of "scripts". var topLevel = path.Substring(0, path.Length - 2); paths.Add(topLevel); // HACK: CacheDependency does not seem to monitor file changes within subdirectories // so manually watch each subdirectory of "scripts" as well. paths.AddRange(Directory.GetDirectories(topLevel)); } else { paths.Add(path); } } } return paths; }
void AddModulesFromConfig(ModuleCollection moduleElements, ModuleContainerBuilder builder) { foreach (ModuleElement module in moduleElements) { // "foo/*" implies each sub-directory of "~/foo" is a module. if (module.Path.EndsWith("*")) { var path = module.Path.Substring(0, module.Path.Length - 2); builder.AddModuleForEachSubdirectoryOf(path, module.Location); } else // the given path is the module itself. { builder.AddModule(module.Path, module.Location); } } }
ModuleContainer BuildModuleContainer(ModuleContainerBuilder builder, ModuleCollection modules, string topLevelDirectoryNameConvention) { if (modules.Count == 0) { // By convention, each subdirectory of topLevelDirectoryNameConvention is a module. builder.AddModuleForEachSubdirectoryOf(topLevelDirectoryNameConvention, ""); } else { AddModulesFromConfig(modules, builder); } return builder.Build(); }