Exemple #1
0
        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>()
                    let endsWithStar = element.Path.EndsWith("*")
                                       select endsWithStar // Path.Combine does not like paths with a "*" in them.
                        ? Path.Combine(HttpRuntime.AppDomainAppPath, element.Path.Substring(0, element.Path.Length - 1)) + "*"
                        : 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);
        }