public static void WriteAmlMergeScripts(this IDiffDirectory baseDir, IDiffDirectory compareDir , Func<string, int, XmlWriter> callback = null) { Func<IDiffFile, IComparable> keyGetter = i => i.Path; var basePaths = baseDir.GetFiles().OrderBy(keyGetter).ToArray(); var comparePaths = compareDir.GetFiles().OrderBy(keyGetter).ToArray(); var completed = 0; var total = basePaths.Length + comparePaths.Length; var result = new List<FileDiff>(); basePaths.MergeSorted(comparePaths, keyGetter, (i, b, c) => { try { var path = (b ?? c).Path; if (path.EndsWith(".xslt.xml")) return; completed++; switch (i) { case -1: // Delete using (var baseStream = ReadFile(b, p => basePaths.FirstOrDefault(f => f.Path == p))) using (var writer = callback(path, completed * 100 / total)) { var elem = AmlDiff.GetMergeScript(baseStream, null); if (elem.Elements().Any()) elem.WriteTo(writer); } break; case 1: // Add using (var baseStream = c.OpenRead()) using (var writer = callback(path, completed * 100 / total)) { XElement.Load(baseStream).WriteTo(writer); } break; default: // Edit total--; using (var baseStream = ReadFile(b, p => basePaths.FirstOrDefault(f => f.Path == p))) using (var compareStream = ReadFile(c, p => comparePaths.FirstOrDefault(f => f.Path == p))) using (var writer = callback(path, completed * 100 / total)) { var elem = AmlDiff.GetMergeScript(baseStream, compareStream); if (elem.Elements().Any()) elem.WriteTo(writer); } break; } } catch (XmlException ex) { throw new XmlException(string.Format("{0} ({1}, {2}, {3})", ex.Message, i, b.Path, c.Path), ex); } }); }
public static IEnumerable <FileDiff> GetDiffs(this IDiffDirectory baseDir, IDiffDirectory compareDir) { Func <IDiffFile, IComparable> keyGetter = i => i.Path; var basePaths = baseDir.GetFiles().OrderBy(keyGetter).ToArray(); var comparePaths = compareDir.GetFiles().OrderBy(keyGetter).ToArray(); var result = new List <FileDiff>(); basePaths.MergeSorted(comparePaths, keyGetter, (i, b, c) => { switch (i) { case -1: result.Add(new FileDiff() { Path = b.Path, InBase = FileStatus.Unchanged, InCompare = FileStatus.DoesntExist }); break; case 1: result.Add(new FileDiff() { Path = c.Path, InBase = FileStatus.DoesntExist, InCompare = FileStatus.Unchanged }); break; default: result.Add(new FileDiff() { Path = b.Path, InBase = FileStatus.Unchanged, InCompare = b.CompareKey.CompareTo(c.CompareKey) == 0 ? FileStatus.Unchanged : FileStatus.Unchanged }); break; } }); return(result); }
public static IEnumerable<FileDiff> GetDiffs(this IDiffDirectory baseDir, IDiffDirectory compareDir) { Func<IDiffFile, IComparable> keyGetter = i => i.Path; var basePaths = baseDir.GetFiles().OrderBy(keyGetter).ToArray(); var comparePaths = compareDir.GetFiles().OrderBy(keyGetter).ToArray(); var result = new List<FileDiff>(); basePaths.MergeSorted(comparePaths, keyGetter, (i, b, c) => { switch (i) { case -1: result.Add(new FileDiff() { Path = b.Path, InBase = FileStatus.Unchanged, InCompare = FileStatus.DoesntExist }); break; case 1: result.Add(new FileDiff() { Path = c.Path, InBase = FileStatus.DoesntExist, InCompare = FileStatus.Unchanged }); break; default: result.Add(new FileDiff() { Path = b.Path, InBase = FileStatus.Unchanged, InCompare = b.CompareKey.CompareTo(c.CompareKey) == 0 ? FileStatus.Unchanged : FileStatus.Unchanged }); break; } }); return result; }
public static void WriteAmlMergeScripts(this IDiffDirectory baseDir, IDiffDirectory compareDir , string outputDirectory) { Func<IDiffFile, IComparable> keyGetter = i => i.Path; var basePaths = baseDir.GetFiles().OrderBy(keyGetter).ToArray(); var comparePaths = compareDir.GetFiles().OrderBy(keyGetter).ToArray(); var result = new List<FileDiff>(); basePaths.MergeSorted(comparePaths, keyGetter, (i, b, c) => { var savePath = Path.Combine(outputDirectory, (b ?? c).Path); if (savePath.EndsWith(".xslt.xml")) return; Directory.CreateDirectory(Path.GetDirectoryName(savePath)); switch (i) { case -1: SaveFile(AmlDiff.GetMergeScript(ReadFile(b, p => basePaths.FirstOrDefault(f => f.Path == p)), null), savePath); break; case 1: using (var baseStream = c.OpenRead()) using (var outStream = File.OpenWrite(savePath)) { baseStream.CopyTo(outStream); } break; default: SaveFile(AmlDiff.GetMergeScript( ReadFile(b, p => basePaths.FirstOrDefault(f => f.Path == p)), ReadFile(c, p => comparePaths.FirstOrDefault(f => f.Path == p))), savePath); break; } }); }
public static PackageMetadataProvider WriteAmlMergeScripts(this IDiffDirectory baseDir, IDiffDirectory compareDir , Func <string, int, XmlWriter> callback = null) { Func <IDiffFile, IComparable> keyGetter = i => i.Path.Replace('\\', '/').TrimStart('/'); var basePaths = baseDir.GetFiles().OrderBy(keyGetter).ToArray(); var comparePaths = compareDir.GetFiles().OrderBy(keyGetter).ToArray(); var completed = 0; var total = basePaths.Length + comparePaths.Length; var result = new List <FileDiff>(); var metadata = new PackageMetadataProvider(); basePaths.MergeSorted(comparePaths, keyGetter, (i, b, c) => { try { var path = (c ?? b).Path; if (path.EndsWith(".xslt.xml") || path.EndsWith(".innpkg")) { return; } completed++; switch (i) { case -1: // Delete using (var baseStream = ReadFile(b, p => Array.Find(basePaths, f => f.Path == p))) using (var writer = callback(path, completed * 100 / total)) { var elem = AmlDiff.GetMergeScript(baseStream, null); if (elem.Elements().Any()) { elem.WriteTo(writer); } } break; case 1: // Add using (var baseStream = ReadFile(c, p => Array.Find(comparePaths, f => f.Path == p))) { var elem = XElement.Load(baseStream); IdentityMergeToAdd(elem); if (ItemAddToIgnore(elem)) { return; } using (var writer = callback(path, completed * 100 / total)) { elem.WriteTo(writer); metadata.Add(elem); } } break; default: // Edit total--; using (var baseStream = ReadFile(b, p => Array.Find(basePaths, f => f.Path == p))) using (var compareStream = ReadFile(c, p => Array.Find(comparePaths, f => f.Path == p))) using (var writer = callback(path, completed * 100 / total)) { var baseElem = Utils.LoadXml(baseStream); var compareElem = Utils.LoadXml(compareStream); metadata.Add(compareElem); var elem = AmlDiff.GetMergeScript(baseElem, compareElem); if (elem.Elements().Any()) { elem.WriteTo(writer); } } break; } } catch (XmlException ex) { ex.Data["Index"] = i; if (b != null) { ex.Data["BasePath"] = b.Path; } if (c != null) { ex.Data["ComparePath"] = c.Path; } throw; } }); return(metadata); }
public static PackageMetadataProvider WriteAmlMergeScripts(this IDiffDirectory baseDir, IDiffDirectory compareDir , Func <string, int, XmlWriter> callback = null) { Func <IDiffFile, IComparable> keyGetter = i => i.Path; var basePaths = baseDir.GetFiles().OrderBy(keyGetter).ToArray(); var comparePaths = compareDir.GetFiles().OrderBy(keyGetter).ToArray(); var completed = 0; var total = basePaths.Length + comparePaths.Length; var result = new List <FileDiff>(); var metadata = new PackageMetadataProvider(); basePaths.MergeSorted(comparePaths, keyGetter, (i, b, c) => { try { var path = (c ?? b).Path; if (path.EndsWith(".xslt.xml") || path.EndsWith(".innpkg")) { return; } completed++; switch (i) { case -1: // Delete using (var baseStream = ReadFile(b, p => Array.Find(basePaths, f => f.Path == p))) using (var writer = callback(path, completed * 100 / total)) { var elem = AmlDiff.GetMergeScript(baseStream, null); if (elem.Elements().Any()) { elem.WriteTo(writer); } } break; case 1: // Add using (var baseStream = c.OpenRead()) using (var writer = callback(path, completed * 100 / total)) { var elem = XElement.Load(baseStream); elem.WriteTo(writer); metadata.Add(elem); } break; default: // Edit total--; using (var baseStream = ReadFile(b, p => Array.Find(basePaths, f => f.Path == p))) using (var compareStream = ReadFile(c, p => Array.Find(comparePaths, f => f.Path == p))) using (var writer = callback(path, completed * 100 / total)) { var baseElem = Utils.LoadXml(baseStream); var compareElem = Utils.LoadXml(compareStream); metadata.Add(compareElem); var elem = AmlDiff.GetMergeScript(baseElem, compareElem); if (elem.Elements().Any()) { elem.WriteTo(writer); } } break; } } catch (XmlException ex) { throw new XmlException(string.Format("{0} ({1}, {2}, {3})", ex.Message, i, b.Path, c.Path), ex); } }); return(metadata); }