/// <summary> /// Calls GetDependents on the given filename, and then resolves the dependents /// and find further (second order and up) dependents. /// </summary> /// <param name="filename"></param> public void GetDependentsRecursive(string filename) { GetDependents(filename, true); while (true) { HashSet<string> unresolvedDependents = new HashSet<string>(new FilenameKeyComparer()); foreach (FileCandidates fileCandidates in AllFileCandidates.Values) { foreach (string candidate in fileCandidates.FullPathCandidates) { var dependents = GetDependents(candidate); foreach (string dependent in dependents) { if (!AllFileCandidates.ContainsKey(dependent)) { unresolvedDependents.Add(dependent); } } } } if (unresolvedDependents.Count == 0) { break; } foreach (string dependent in unresolvedDependents) { ResolveFilename(dependent); } } }
/// <summary> /// /// </summary> /// <param name="filename"></param> /// <returns></returns> public List<string> ResolveFilename(string filename) { string pathlessFilename = Path.GetFileName(filename); if (!AllFileCandidates.TryGetValue(pathlessFilename, out FileCandidates fileCandidates)) { fileCandidates = new FileCandidates() { PathlessFilename = pathlessFilename, SearchPathVersion = 0, }; AllFileCandidates.Add(pathlessFilename, fileCandidates); } if (Path.IsPathRooted(filename)) { // If this function is called with a rooted path, it is prevented from // conducting a search using the current list of search paths. var fileInfo = new FileInfo(filename); if (fileInfo.Exists) { string fullname = fileInfo.FullName; fileCandidates.FullPathCandidates.Add(fullname); return new List<string> { fullname }; } else { return new List<string>(); } } else if (fileCandidates.SearchPathVersion < SearchPathVersion) { // Conducting a search using the current list of search paths. // This section of code is only entered if search (using the same // list of search paths) has not been done before. foreach (string dir in SearchPaths) { var fileInfo = new FileInfo(Path.Combine(dir, filename)); if (fileInfo.Exists) { string fullname = fileInfo.FullName; fileCandidates.FullPathCandidates.Add(fullname); } } // Mark the completion of this search, so that if the same filename // is searched again while SearchPaths stays the same, no redundant // work is performed. fileCandidates.SearchPathVersion = SearchPaths.Count; } return new List<string>(fileCandidates.FullPathCandidates); }