public void chunk_should_have_correct_old_range() { var diff = Differ.Compare("one", fileOneContent, "two", fileTwoContent); var chunk = diff.Chunks.First(); Assert.AreEqual(10, chunk.OriginalRange.StartLine); Assert.AreEqual(10, chunk.OriginalRange.LinesAffected); }
public void second_chunk_should_have_correct_new_range() { var diff = Differ.Compare("one", fileOneContent, "two", fileTwoContent); var chunk = diff.Chunks.ElementAt(1); Assert.AreEqual(7, chunk.NewRange.StartLine); Assert.AreEqual(6, chunk.NewRange.LinesAffected); }
public void MediumDiff3() { string a = "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"; string b = "abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij"; var result = Differ.ComputeDiff(a, b); Assert.True(result.Any()); }
public static int GetLevel(string Source, string Destination) { Differ DiffMaker = new Differ(); SideBySideDiffBuilder SideBySideDiffer = new SideBySideDiffBuilder(DiffMaker); SideBySideDiffModel SideBySideDiffResult = SideBySideDiffer.BuildDiffModel(Source, Destination); return(GetLevel(SideBySideDiffResult, Source, Destination)); }
public static bool Run(int updatedBy) { var docUsers = DocUtilProcs.GetDocUsers(); var batches = docUsers.Count / BATCH_SIZE; var now = DateTime.Now.ToString(); for (var b = 0; b < batches + 1; b++) { var tsql = new StringBuilder(); var firstRow = b * BATCH_SIZE; var lastRow = (b + 1) * BATCH_SIZE > docUsers.Count ? docUsers.Count : (b + 1) * BATCH_SIZE; // only pulling 20 users' build records each time // to fit Azure multi-tenant limitted connection time situation var docs = DocUtilProcs.GetDocs(docUsers.Skip(firstRow).Take(lastRow - firstRow)) .GroupBy(d => d.UserId).ToDictionary(d => new { User = d.Key, Docs = d.Select(x => new { x.Document, x.SolutionName, x.FileName, x.BuildId, x.DocumentId }).ToList(), }); foreach (var u in docs.Keys) { var orderedUserDocs = docs[u].OrderBy(d => d.FileName).OrderBy(d => d.EventDate).ToArray(); // every user's first build doc is new tsql.AppendFormat(SQLTemplateUpdateBuildDocuments.Template, 0, 0, 0, string.Empty, now, updatedBy, orderedUserDocs[0].BuildId, orderedUserDocs[0].DocumentId); for (var idx = 1; idx < orderedUserDocs.Count(); idx++) { if (string.Compare(orderedUserDocs[idx - 1].FileName, orderedUserDocs[idx].FileName, true) != 0) { // starting a different user build doc tsql.AppendFormat(SQLTemplateUpdateBuildDocuments.Template, 0, 0, 0, string.Empty, now, updatedBy, orderedUserDocs[idx].BuildId, orderedUserDocs[idx].DocumentId); } else { // comparing this and the previous version of the build doc var differ = new Differ(); var inlineBuilder = new SideBySideDiffBuilder(differ); var result = inlineBuilder.BuildDiffModel(orderedUserDocs[idx - 1].Document, orderedUserDocs[idx].Document); var deleted = result.OldText.Lines.Count(l => l.Type == ChangeType.Deleted); var inserted = result.NewText.Lines.Count(l => l.Type == ChangeType.Inserted); var modified = result.NewText.Lines.Count(l => l.Type == ChangeType.Modified); var modifiedPositions = result.NewText.Lines.Where(l => l.Position.HasValue && l.Type == ChangeType.Modified).Select(l => l.Position.Value); tsql.AppendFormat(SQLTemplateUpdateBuildDocuments.Template, inserted, modified, deleted, string.Join(",", modifiedPositions), now, updatedBy, orderedUserDocs[idx].BuildId, orderedUserDocs[idx].DocumentId); } } } DynamicSQLExecutor.Execute(tsql.ToString()); } return(true); }
protected IEnumerable <BaseCommand> GetCommands <T>( DtoMetadataCache cache, T oldDto, T newDto, int expectedDifferenceCount, int expectedOperationCount, int expectedInsertOperations, int expectedUpdateOperations, int expectedDeleteOperations, int expectedCommandCount, int expectedInsertCommands, int expectedUpdateCommands, int expectedDeleteCommands, bool assertOnCounts = true) { var differ = new Differ(cache); var differences = differ.Diff(oldDto, newDto); if (assertOnCounts) { Assert.AreEqual(expectedDifferenceCount, differences.Count(), "Unexpected number of differences."); } var operationBuilder = new OperationBuilder(); var operations = operationBuilder.Build(differences); var commandBuilder = new CommandBuilder(); var commands = commandBuilder.Coalesce(operations); if (assertOnCounts) { Assert.AreEqual(expectedOperationCount, operations.Count(), "Unexpected number of operations."); var counts = CountItemsByType(operations); CheckCount(counts, typeof(InsertOperation), expectedInsertOperations); CheckCount(counts, typeof(UpdateOperation), expectedUpdateOperations); CheckCount(counts, typeof(DeleteOperation), expectedDeleteOperations); Assert.AreEqual(expectedCommandCount, commands.Count(), "Unexpected number of commands."); counts = CountItemsByType(commands); CheckCount(counts, typeof(InsertCommand), expectedInsertCommands); CheckCount(counts, typeof(UpdateCommand), expectedUpdateCommands); CheckCount(counts, typeof(DeleteCommand), expectedDeleteCommands); } var scriptBuilder = new ScriptBuilder(cache); var transactionScript = scriptBuilder.Build(commands); Assert.IsNotNull(transactionScript, "#badtimes - null transaction script"); Assert.IsTrue(transactionScript.Count > 0, "Should be at least one script."); foreach (var script in transactionScript) { Assert.IsTrue(script.Buffer.Length > 0, "#badtimes - empty transaction script"); } CheckNoReferenceTypesInParameters(transactionScript); return(commands); }
public static void Diff(this string expected, string actual, string message = null) { var d = new Differ(); var inlineBuilder = new InlineDiffBuilder(d); var result = inlineBuilder.BuildDiffModel(expected, actual); var hasChanges = result.Lines.Any(l => l.Type != ChangeType.Unchanged); if (!hasChanges) { return; } var diff = result.Lines.Aggregate(new StringBuilder().AppendLine(message), (sb, line) => { if (line.Type == ChangeType.Inserted) { sb.Append("+ "); } else if (line.Type == ChangeType.Deleted) { sb.Append("- "); } else { sb.Append(" "); } sb.AppendLine(line.Text); return(sb); }, sb => sb.ToString()); diff += "\r\n C# approximation of actual ------ "; diff += "\r\n new "; var approx = Regex.Replace(actual, @"^(?=.*:.*)[^:]+:", (s) => s .Value.Replace("\"", "") .Replace(":", " =") , RegexOptions.Multiline) .Replace(" = {", " = new {") .Replace(" = [", " = new [] {") ; approx = Regex.Replace(approx, @"^\s*\],?.*$", s => s.Value.Replace("]", "}"), RegexOptions.Multiline); diff += approx + ";"; diff += "\r\n C# approximation of expected ------ "; diff += "\r\n new "; approx = Regex.Replace(expected, @"^(?=.*:.*)[^:]+:", (s) => s .Value.Replace("\"", "") .Replace(":", " =") , RegexOptions.Multiline) .Replace(" = {", " = new {") .Replace(" = [", " = new [] {") ; approx = Regex.Replace(approx, @"^\s*\],?.*$", s => s.Value.Replace("]", "}"), RegexOptions.Multiline); diff += approx + ";"; throw new Exception(diff.Substring(0, diff.Length > 4896 ? 4896 : diff.Length)); }
public static IEnumerable <IDiff <Person> > Diff(this IEnumerable <Person> people, IEnumerable <Person> others) { return(Differ.Differences( people, others, (x) => (x), (x) => (x.FirstName, x.LastName), (x, y) => (x.FirstName == y.FirstName && x.LastName == y.LastName && x.Age == y.Age && x.Dependents.Diff(y.Dependents).AllSame()))); }
public void when_compared_ignore_bom_should_consider_bom_changes_as_insignificant() { var diff = Differ.Compare("one", fileOneContent, "two", fileTwoContent, new CompareOptions { BomMode = BomMode.Ignore }); Assert.AreEqual(0, diff.Chunks.Count, "Should have no chunks (identical)"); }
public string DiffTest(string left, string right, bool NoOrderInBasicTypeValueJArray = false) { Differ differ = new Differ(NoOrderInBasicTypeValueJArray); JArray r = differ.Diff(left, right); string s = JsonConvert.SerializeObject(r); Console.WriteLine(s); return(s); }
public void SideBySideDiff(string oldValue, string newValue, out string oldDiff, out string newDiff) { var d = new Differ(); var differ = new SideBySideFullDiffBuilder(d); var diffRes = differ.BuildDiffModel(oldValue, newValue); oldDiff = PangoRender.RenderDiffLines(diffRes.OldText); newDiff = PangoRender.RenderDiffLines(diffRes.NewText); }
public static DiffResult CompareByWords(string oldText, string newText) { char[] _wordSeparators = { ' ' }; var differ = new Differ(); return(differ.CreateWordDiffs(newText, oldText, true, _wordSeparators)); //return diffResuls = differ.CreateWordDiffs(oldText, newText, true, _wordSeparators); }
public string GetDiff(SiteResponse currentResponse, SiteResponse lastResponse) { string currentResponseText = SiteHtmlUtil.StripHTMLAdvanced(currentResponse.Contents); string lastResponseText = ""; if (lastResponse != null) { lastResponseText = SiteHtmlUtil.StripHTMLAdvanced(lastResponse.Contents); } StringBuilder stringBuilder = new StringBuilder(); Differ differ = new Differ(); InlineDiffBuilder inlineDiffBuilder = new InlineDiffBuilder(differ); var result = inlineDiffBuilder.BuildDiffModel(lastResponseText, currentResponseText); bool added_anchor_to_first_change = false; foreach (var line in result.Lines) { if (line.Type == ChangeType.Inserted) { if (!added_anchor_to_first_change) { stringBuilder.Append("<p class='added'><a name='anchor'>+</a> "); added_anchor_to_first_change = true; } else { stringBuilder.Append("<p class='added'>+ "); } stringBuilder.AppendLine(line.Text); stringBuilder.Append("</p>"); } else if (line.Type == ChangeType.Deleted) { if (!added_anchor_to_first_change) { stringBuilder.Append("<p class='removed'><a name='anchor'>-</a> "); added_anchor_to_first_change = true; } else { stringBuilder.Append("<p class='removed'>- "); } stringBuilder.AppendLine(line.Text); stringBuilder.Append("</p>"); } else { stringBuilder.Append("<p class='notchanged'>"); stringBuilder.AppendLine(line.Text); stringBuilder.Append("</p>"); } //stringBuilder.Append("<br/>"); } return(stringBuilder.ToString()); }
public static string GetFormattedDiff(string oldText, string newText) { var differ = new Differ(); var diff = GetDiff(differ, oldText, newText); return(diff.Lines.Any(x => x.Type != ChangeType.Unchanged) ? FormatDiff(diff) : string.Empty); }
public void TestCreateDiffFromDifferentGeoms() { var geom1 = ReadWkt("POINT(1 1)"); var geom2 = ReadWkt("LINESTRING(1 1, 2 2, 3 3)"); var ex = Assert.Throws <GeometryTypeException>(delegate { Differ.CreateDiff(geom1, geom2); }); Assert.AreEqual("Cannot create patch from Point to LineString!", ex.Message); }
public void TestCreateDiffFromUnsupportedGeometry() { var gc1 = ReadWkt("GEOMETRYCOLLECTION (POINT (40 10))"); var gc2 = ReadWkt("GEOMETRYCOLLECTION (POINT (40 11))"); var ex = Assert.Throws <GeometryTypeException>(delegate { Differ.CreateDiff(gc1, gc2); }); Assert.AreEqual("Geometry type not supported: GeometryCollection", ex.Message); }
public void TestCreateInsertDiff() { var p = ReadWkt <MultiLineString>("MULTILINESTRING((1 1, 2 2, 3 3, 4 4), (10 10, 20 20))"); var n = (MultiLineStringDiff)Differ.CreateDiff(null, p); Assert.AreEqual(0, n.Index); Assert.AreEqual(Operation.Insert, n.Operation); Assert.AreEqual(2, n.Value.Count); }
public void TestCreateModifyDiff() { var p = ReadWkt <MultiPoint>("MULTIPOINT((2 2), (3 3))"); var p2 = ReadWkt <MultiPoint>("MULTIPOINT((1 2), (1.5 2.5))"); var n = (MultiPointDiff)Differ.CreateDiff(p, p2); Assert.AreEqual(0, n.Index); Assert.AreEqual(Operation.Modify, n.Operation); Assert.AreEqual(2, n.Value.Count); }
public void TestLineStringChangeZOnly() { var g1 = ReadWkt("LINESTRING(0 0 0, 2 2 1, 3 3, 4 4)"); var g2 = ReadWkt("LINESTRING(0 0 1, 2 2 2, 3 3, 4 4)"); var diff = (LineStringDiff)Differ.CreateDiff(g1, g2); Assert.AreEqual(Operation.Modify, diff.Operation); Assert.AreEqual(2, diff.Value.Count); }
public void OnlySuffixInCommon() { var result = Differ.ComputeDiff("1234", "xyz1234"); Assert.Equal(2, result.Length); Assert.Equal(Operation.INSERT, result[0].Operation); Assert.Equal("xyz", result[0].GetText()); Assert.Equal(Operation.EQUAL, result[1].Operation); Assert.Equal("1234", result[1].GetText()); }
public void TestCreateModifyDiff() { var p = ReadWkt <MultiLineString>("MULTILINESTRING((1 1, 2 2, 3 3, 4 4), (10 10, 20 20))"); var p2 = ReadWkt <MultiLineString>("MULTILINESTRING((0 0, 1.5 1.5, 2 2, 3 3), (4 5, 6 7))"); var n = (MultiLineStringDiff)Differ.CreateDiff(p, p2); Assert.AreEqual(0, n.Index); Assert.AreEqual(Operation.Modify, n.Operation); Assert.AreEqual(2, n.Value.Count); }
public static ChangeType[] SimpleDiff(string current, string old) { IDiffer differ = new Differ(); SideBySideDiffBuilder builder = new SideBySideDiffBuilder(differ); var diffModel = builder.BuildDiffModel(old, current); ClassifyCodeChangeType(current, old); return(diffModel.NewText.Lines.Select(l => l.Type).ToArray()); }
public void TestCreateInsertDiff() { var p = ReadWkt <MultiPolygon>("MULTIPOLYGON(((0 0, 1 1, 2 2, 0 0), (3 3, 4 4, 5 5, 3 3), (5 5, 6 6, 7 7, 5 5)), ((10 10, 10 20, 20 20, 20 10, 10 10)))"); var n = (MultiPolygonDiff)Differ.CreateDiff(null, p); Assert.AreEqual(0, n.Index); Assert.AreEqual(Operation.Insert, n.Operation); Assert.AreEqual(2, n.Value.Count); }
public void TestCreateModifyDiff() { var p = ReadWkt <MultiPolygon>("MULTIPOLYGON(((0 0, 1 1, 2 2, 0 0), (3 3, 4 4, 5 5, 3 3), (5 5, 6 6, 7 7, 5 5)), ((10 10, 10 20, 20 20, 20 10, 10 10)))"); var p2 = ReadWkt <MultiPolygon>("MULTIPOLYGON(((0 0, 1 1, 0.5 1.5, 2 2, 0 0), (5 5, 6 6, 7 7, 5 5)), ((30 30, 30 40, 40 40, 40 30, 30 30), (35 35, 35 36, 36 36, 36 35, 35 35)))"); var n = (MultiPolygonDiff)Differ.CreateDiff(p, p2); Assert.AreEqual(0, n.Index); Assert.AreEqual(Operation.Modify, n.Operation); Assert.AreEqual(2, n.Value.Count); }
public void TestCreateInsertDiff() { var p = ReadWkt <MultiPoint>("MULTIPOINT((2 2), (3 3))"); var n = (MultiPointDiff)Differ.CreateDiff(null, p); Assert.AreEqual(0, n.Index); Assert.AreEqual(Operation.Insert, n.Operation); Assert.AreEqual(2, n.Value.Count); }
public void CommonOverlap() { var result = Differ.ComputeDiff("abc", "abcd"); Assert.Equal(2, result.Length); Assert.Equal(Operation.INSERT, result[0].Operation); Assert.Equal("d", result[0].GetText()); Assert.Equal(Operation.EQUAL, result[1].Operation); Assert.Equal("abc", result[1].GetText()); }
private void MakeDiffPangoMarkup() { var d = new Differ(); var differ = new SideBySideFullDiffBuilder(d); var diffRes = differ.BuildDiffModel(OldValue, NewValue); OldPangoText = PangoRender.RenderDiffLines(diffRes.OldText); NewPangoText = PangoRender.RenderDiffLines(diffRes.NewText); isPangoMade = true; }
public void NothingInCommon() { var result = Differ.ComputeDiff("abc", "xyz"); Assert.Equal(2, result.Length); Assert.Equal(Operation.DELETE, result[0].Operation); Assert.Equal("abc", result[0].GetText()); Assert.Equal(Operation.INSERT, result[1].Operation); Assert.Equal("xyz", result[1].GetText()); }
public static void DifferSmall() { var differ = new Differ <C, C>(new[] { "a", "b" }); var res = differ.Compare(c1, c2); // compare different types! var differ2 = new Differ <C, D>(new[] { "a", "b" }); res = differ2.Compare(c1, d1); }
public void DocumentUpdated() { Differ differ = new Differ(); SideBySideDiffBuilder diffBuilder = new SideBySideDiffBuilder(differ); if (_documentManager.Document != null) { Diff = diffBuilder.BuildDiffModel(_documentManager.SavedDocument.ToString(), _documentManager.Document.ToString()); RaisePropertyChangedEvent("Diff"); } }
private static void Main(string[] args) { var d = new Differ(); var inlineBuilder = new InlineDiffBuilder(d); var result = inlineBuilder.BuildDiffModel(OldText, NewText); foreach (var line in result.Lines) { if(line.Type == ChangeType.Inserted) Console.Write("+ "); else if(line.Type == ChangeType.Deleted) Console.Write("- "); else Console.Write(" "); Console.WriteLine(line.Text); } }
public void diff_shows_differences_between_nested_objects() { var dao1 = CreateAcquiringOfferTrnDao(); var dao2 = CreateAcquiringOfferTrnDao(); dao2.TypeOfTransaction = new TypeOfTransactionLutDao() { FieldItemKey = 0, FieldItem = new FieldItemLutDao() { FieldItemKey = 0, }, TypeOfTransactionEnumKey = OppTypeOfTransactionEnum.None }; var differ = new Differ(new DtoMetadataCache()); var diffs = differ.Diff(dao1, dao2); Assert.IsTrue(diffs.Count > 0, "Should have found some differences."); }
/// <summary> /// Compare two Outputs /// </summary> /// <param name="targetOutput"></param> /// <param name="updatedOutput"></param> /// <returns>Any differences found.</returns> private static ArrayList CompareOutput(Output targetOutput, Output updatedOutput) { ArrayList differences = new ArrayList(); Differ differ = new Differ(); differ.SuppressKeepingSpecialRows = true; Output transform = differ.Diff(targetOutput, updatedOutput); foreach (Table table in transform.Tables) { switch (table.Operation) { case TableOperation.Add: differences.Add(String.Format(CultureInfo.InvariantCulture, "The {0} table has been added.", table.Name)); break; case TableOperation.Drop: differences.Add(String.Format(CultureInfo.InvariantCulture, "The {0} table has been dropped.", table.Name)); continue; } // index the target rows for better error messages Hashtable targetRows = new Hashtable(); Table targetTable = targetOutput.Tables[table.Name]; if (null != targetTable) { foreach (Row row in targetTable.Rows) { string primaryKey = row.GetPrimaryKey('/'); // only index rows with primary keys since these are the ones that can be modified if (null != primaryKey) { targetRows.Add(primaryKey, row); } } } foreach (Row row in table.Rows) { switch (row.Operation) { case RowOperation.Add: differences.Add(String.Format(CultureInfo.InvariantCulture, "The {0} table, row '{1}' has been added.", table.Name, row.ToString())); break; case RowOperation.Delete: differences.Add(String.Format(CultureInfo.InvariantCulture, "The {0} table, row '{1}' has been deleted.", table.Name, row.ToString())); break; case RowOperation.Modify: if (!Ignore(row)) { string primaryKey = row.GetPrimaryKey('/'); Row targetRow = (Row)targetRows[primaryKey]; differences.Add(String.Format(CultureInfo.InvariantCulture, "The {0} table, row '{1}' has changed to '{2}'.", table.Name, targetRow.ToString(), row.ToString())); } break; default: throw new InvalidOperationException("Unknown diff row."); } } } return differences; }
/// <summary> /// Main running method for the application. /// </summary> /// <param name="args">Commandline arguments to the application.</param> /// <returns>Returns the application error code.</returns> private int Run(string[] args) { Microsoft.Tools.WindowsInstallerXml.Binder binder = null; Differ differ = null; Unbinder unbinder = null; TempFileCollection tempFileCollection = null; try { // parse the command line this.ParseCommandLine(args); // validate the inputs if (this.xmlInputs && this.adminImage) { this.messageHandler.Display(this, WixErrors.IllegalCommandlineArgumentCombination("a", "xi")); this.showHelp = true; } string[] allValidExtensions = new string[] { wixMstExtension, wixOutExtension, wixPdbExtension, msiExtension }; string[] expectedSingleInputExtensions = new string[] { wixMstExtension, wixOutExtension }; string[] expectedDoubleInputXmlExtensions = new string[] { wixOutExtension, wixPdbExtension }; string[] expectedDoubleInputMsiExtensions = new string[] { msiExtension }; // Validate that all inputs have the correct extension and we dont have too many inputs. if (1 == this.inputFiles.Count) { string inputFile = this.inputFiles[0]; bool hasValidExtension = false; foreach (string extension in expectedSingleInputExtensions) { if (String.Equals(Path.GetExtension(inputFile), extension, StringComparison.OrdinalIgnoreCase)) { hasValidExtension = true; break; } } if (!hasValidExtension) { bool missingInput = false; // Check if its using an extension that could be valid in other scenarios. foreach (string validExtension in allValidExtensions) { if (String.Equals(Path.GetExtension(inputFile), validExtension, StringComparison.OrdinalIgnoreCase)) { this.messageHandler.Display(this, WixErrors.WrongFileExtensionForNumberOfInputs(Path.GetExtension(inputFile), inputFile)); missingInput = true; break; } } if (!missingInput) { this.messageHandler.Display(this, WixErrors.UnexpectedFileExtension(inputFile, String.Join(", ", expectedSingleInputExtensions))); } } } else if (2 == this.inputFiles.Count) { foreach (string inputFile in inputFiles) { bool hasValidExtension = false; string[] expectedExtensions = allValidExtensions; if (this.xmlInputs) { foreach (string extension in expectedDoubleInputXmlExtensions) { if (String.Equals(Path.GetExtension(inputFile), extension, StringComparison.OrdinalIgnoreCase)) { hasValidExtension = true; expectedExtensions = expectedDoubleInputXmlExtensions; break; } } } else { foreach (string extension in expectedDoubleInputMsiExtensions) { if (String.Equals(Path.GetExtension(inputFile), extension, StringComparison.OrdinalIgnoreCase)) { hasValidExtension = true; expectedExtensions = expectedDoubleInputMsiExtensions; break; } } } if (!hasValidExtension) { this.messageHandler.Display(this, WixErrors.UnexpectedFileExtension(inputFile, String.Join(", ", expectedExtensions))); } } } else { this.showHelp = true; } // exit if there was an error parsing the command line or with a file extension (otherwise the logo appears after error messages) if (this.messageHandler.EncounteredError) { return this.messageHandler.LastErrorNumber; } if (null == this.outputFile) { this.showHelp = true; } if (this.showLogo) { AppCommon.DisplayToolHeader(); } if (this.showHelp) { Console.WriteLine(TorchStrings.HelpMessage); AppCommon.DisplayToolFooter(); return this.messageHandler.LastErrorNumber; } foreach (string parameter in this.invalidArgs) { this.messageHandler.Display(this, WixWarnings.UnsupportedCommandLineArgument(parameter)); } this.invalidArgs = null; binder = new Microsoft.Tools.WindowsInstallerXml.Binder(); differ = new Differ(); unbinder = new Unbinder(); // load any extensions foreach (string extension in this.extensionList) { WixExtension wixExtension = WixExtension.Load(extension); unbinder.AddExtension(wixExtension); binder.AddExtension(wixExtension); differ.AddExtension(wixExtension); } binder.Message += new MessageEventHandler(this.messageHandler.Display); differ.Message += new MessageEventHandler(this.messageHandler.Display); unbinder.Message += new MessageEventHandler(this.messageHandler.Display); binder.TempFilesLocation = Environment.GetEnvironmentVariable("WIX_TEMP"); unbinder.TempFilesLocation = Environment.GetEnvironmentVariable("WIX_TEMP"); tempFileCollection = new TempFileCollection(Environment.GetEnvironmentVariable("WIX_TEMP")); binder.WixVariableResolver = new WixVariableResolver(); differ.PreserveUnchangedRows = this.preserveUnchangedRows; differ.ShowPedanticMessages = this.showPedanticMessages; unbinder.SuppressExtractCabinets = true; unbinder.IsAdminImage = this.adminImage; if (null == this.exportBasePath) { this.exportBasePath = tempFileCollection.BasePath; } // load and process the inputs Output transform; if (1 == this.inputFiles.Count) { transform = Output.Load(this.inputFiles[0], false, false); if (OutputType.Transform != transform.Type) { this.messageHandler.Display(this, WixErrors.InvalidWixTransform(this.inputFiles[0])); return this.messageHandler.LastErrorNumber; } } else // 2 inputs { Output targetOutput; Output updatedOutput; if (this.xmlInputs) { // load the target database if (String.Equals(Path.GetExtension(inputFiles[0]), wixPdbExtension, StringComparison.OrdinalIgnoreCase)) { Pdb targetPdb = Pdb.Load(this.inputFiles[0], false, false); targetOutput = targetPdb.Output; } else { targetOutput = Output.Load(this.inputFiles[0], false, false); } // load the updated database if (String.Equals(Path.GetExtension(inputFiles[1]), wixPdbExtension, StringComparison.OrdinalIgnoreCase)) { Pdb updatedPdb = Pdb.Load(this.inputFiles[1], false, false); updatedOutput = updatedPdb.Output; } else { updatedOutput = Output.Load(this.inputFiles[1], false, false); } this.xmlOutput = true; } else { // load the target database targetOutput = unbinder.Unbind(this.inputFiles[0], OutputType.Product, Path.Combine(this.exportBasePath, "targetBinaries")); // load the updated database updatedOutput = unbinder.Unbind(this.inputFiles[1], OutputType.Product, Path.Combine(this.exportBasePath, "updatedBinaries")); } // diff the target and updated databases transform = differ.Diff(targetOutput, updatedOutput, this.validationFlags); if (null == transform.Tables || 0 >= transform.Tables.Count) { throw new WixException(WixErrors.NoDifferencesInTransform(transform.SourceLineNumbers)); } } // output the transform if (null != transform) { // If either the user selected xml output or gave xml input, save as xml output. // With xml inputs, many funtions of the binder have not been performed on the inputs (ie. file sequencing). This results in bad IDT files which cannot be put in a transform. if (this.xmlOutput) { transform.Save(this.outputFile, null, null, tempFileCollection.BasePath); } else { binder.Bind(transform, this.outputFile); } } } catch (WixException we) { if (we is WixInvalidIdtException) { // make sure the IDT files stay around this.tidy = false; } this.messageHandler.Display(this, we.Error); } catch (Exception e) { // make sure the files stay around for debugging this.tidy = false; this.messageHandler.Display(this, WixErrors.UnexpectedException(e.Message, e.GetType().ToString(), e.StackTrace)); if (e is NullReferenceException || e is SEHException) { throw; } } finally { if (null != binder) { if (this.tidy) { if (!binder.DeleteTempFiles()) { Console.WriteLine(TorchStrings.WAR_FailedToDeleteTempDir, binder.TempFilesLocation); } } else { Console.WriteLine(TorchStrings.INF_BinderTempDirLocatedAt, binder.TempFilesLocation); } } if (null != unbinder) { if (this.tidy) { if (!unbinder.DeleteTempFiles()) { Console.WriteLine(TorchStrings.WAR_FailedToDeleteTempDir, binder.TempFilesLocation); } } else { Console.WriteLine(TorchStrings.INF_UnbinderTempDirLocatedAt, binder.TempFilesLocation); } } if (null != tempFileCollection) { if (this.tidy) { try { Directory.Delete(tempFileCollection.BasePath, true); } catch (DirectoryNotFoundException) { // if the path doesn't exist, then there is nothing for us to worry about } catch { Console.WriteLine(TorchStrings.WAR_FailedToDeleteTempDir, tempFileCollection.BasePath); } } else { Console.WriteLine(TorchStrings.INF_TorchTempDirLocatedAt, tempFileCollection.BasePath); } } } return this.messageHandler.LastErrorNumber; }
public void diff_does_not_drill_past_simple_save_ignore_where_differences_beneath() { var dao1 = CreateApplicationForUpdateWithAcquiringOffer(); var dao2 = CreateApplicationForUpdateWithAcquiringOffer(); dao2.Locations[0].Opportunities[0].CurrentOffer.AcquiringOffer.TypeOfTransaction = new TypeOfTransactionLutDao() { FieldItemKey = 0, FieldItem = new FieldItemLutDao() { FieldItemKey = 0, }, TypeOfTransactionEnumKey = OppTypeOfTransactionEnum.None }; var differ = new Differ(new DtoMetadataCache()); var diffs = differ.Diff(dao1, dao2); Assert.AreEqual(0, diffs.Count, "Should not have found any differences."); }