diff options
Diffstat (limited to 'tools/DocStat/DocStat/ParallelXmlHelper.cs')
-rw-r--r-- | tools/DocStat/DocStat/ParallelXmlHelper.cs | 53 |
1 files changed, 27 insertions, 26 deletions
diff --git a/tools/DocStat/DocStat/ParallelXmlHelper.cs b/tools/DocStat/DocStat/ParallelXmlHelper.cs index 69f05ea0..bac32386 100644 --- a/tools/DocStat/DocStat/ParallelXmlHelper.cs +++ b/tools/DocStat/DocStat/ParallelXmlHelper.cs @@ -99,38 +99,39 @@ namespace DocStat }; } - public static XElement ParallelElement(XElement sourceElement, - string sourcePath, - string sourceRoot, - string refRoot, - HashSet<string> refPaths) + public static string GetParallelFilePathFor(string pathToTypeToFix, + string rootOfReferenceFiles, + string rootOfFilesToFix, + Func<string, string> referenceRootTransform = null, + Func<string, string> referencePathTransform = null) { - string parallelPath = GetParallelFilePathFor(sourcePath, refRoot, sourceRoot); + + string fullFixPath = Path.GetFullPath(pathToTypeToFix); - // bail early if we can + string fullFixRoot = Path.GetFullPath(rootOfFilesToFix); - if (!File.Exists(parallelPath) || !refPaths.Contains(parallelPath)) - return null; + rootOfReferenceFiles = + null == referenceRootTransform ? rootOfReferenceFiles : referenceRootTransform(rootOfReferenceFiles); + string fullRefRoot = Path.GetFullPath(rootOfReferenceFiles); - FileAttributes attr = File.GetAttributes(parallelPath); - if ((attr & FileAttributes.Directory) == FileAttributes.Directory) - return null; + string fullReferencePath = fullFixPath.Replace(fullFixRoot, fullRefRoot); - XDocument refToSearch = XDocument.Load(parallelPath); - Console.WriteLine("Found parallel document"); - var toReturn = GetSelectorFor(sourceElement).Invoke(refToSearch); - Console.WriteLine("Got the parallel element"); - return toReturn; + fullReferencePath = + null == referencePathTransform ? fullReferencePath : referencePathTransform(fullReferencePath); + return fullReferencePath; } - public static string GetParallelFilePathFor(string pathToTypeToFix, - string rootOfFilesToUse, - string rootOfFilesToFix) - { - string fullFixPath = Path.GetFullPath(pathToTypeToFix); - string fullFixRoot = Path.GetFullPath(rootOfFilesToFix); - string fullRefRoot = Path.GetFullPath(rootOfFilesToUse); - return fullFixPath.Replace(fullFixRoot, fullRefRoot); - } + public static XDocument GetParallelXDocFor(string parallelFilePath, + HashSet<string> refPaths = null) + { + + if (!File.Exists(parallelFilePath)) + return null; + + if ((null != refPaths) && !refPaths.Contains(parallelFilePath)) + return null; + + return XDocument.Load(parallelFilePath); + } } } |