private void AssertCanTransform(string sourceXml, string targetXml) { var doc1 = new XmlDocument(); doc1.LoadXml(sourceXml); // reordered xml but same values var doc2 = new XmlDocument(); doc2.LoadXml(targetXml); var tree1 = new XTree(doc1); var tree2 = new XTree(doc2); XDiff.Diff(tree1, tree2); var writer = new XdtDiffWriter(); var patch = writer.GetDiff(tree2); var transformed = Transform(doc1, patch); var transformedTree = new XTree(transformed); Assert.IsFalse(Enumerable.SequenceEqual(tree1.Root.Hash, tree2.Root.Hash)); Assert.IsTrue(Enumerable.SequenceEqual(transformedTree.Root.Hash, tree2.Root.Hash)); }
static int Main(string[] args) { var version = Assembly.GetEntryAssembly().GetName().Version; Console.WriteLine( "==================\n" + string.Format(" FatAntelope v{0}.{1}\n", version.Major, version.Minor) + "==================\n"); if (args == null || args.Length < 3 || args.Length > 4) { Console.WriteLine( "Error: Unexpected number of paramters.\n" + "Usage: FatAntelope source-file target-file output-file [transformed-file]\n" + " source-file : (Input) The original config file\n" + " target-file : (Input) The final config file\n" + " output-file : (Output) The output config transform patch file\n" + " transformed-file : (Optional Output) The config file resulting from applying the output-file to the source-file\n" + " This file should be semantically equal to the target-file.\n"); return((int)ExitCode.InvalidParameters); } Console.WriteLine("- Building xml trees . . .\n"); var tree1 = BuildTree(args[0]); var tree2 = BuildTree(args[1]); Console.WriteLine("- Comparing xml trees . . .\n"); XDiff.Diff(tree1, tree2); if (tree1.Root.Match == MatchType.Match && tree2.Root.Match == MatchType.Match && tree1.Root.Matching == tree2.Root) { Console.WriteLine("Warning: No difference found!\n"); return((int)ExitCode.NoDifference); } if (tree1.Root.Match == MatchType.NoMatch || tree2.Root.Match == MatchType.NoMatch) { Console.Error.WriteLine("Error: Root nodes must have the same name!\n"); return((int)ExitCode.RootNodeMismatch); } Console.WriteLine("- Writing XDT transform . . .\n"); var writer = new XdtDiffWriter(); var patch = writer.GetDiff(tree2); patch.Save(new FileStream(args[2], FileMode.Create)); /*if (args.Length > 3) * { * Console.WriteLine("- Applying transform to source . . .\n"); * var source = new XmlTransformation(); * source.Load(args[0]); * * var transform = new XmlTransformation(patch.OuterXml, false, null); * transform.Apply(source); * * source.Save(args[3]); * } * Console.WriteLine("- Finished successfully!\n");*/ return((int)ExitCode.Success); }
private void diffToolStripMenuItem_Click(object sender, EventArgs e) { try { var source = new XmlDocument(); source.LoadXml(fastColoredTextBoxSource.Text); var target = new XmlDocument(); target.LoadXml(fastColoredTextBoxTarget.Text); var tree1 = new XTree(source); var tree2 = new XTree(target); XDiff.Diff(tree1, tree2); if (tree1.Root.Match == MatchType.Match && tree2.Root.Match == MatchType.Match && tree1.Root.Matching == tree2.Root) { Message("Warning: No difference found!\n"); } if (tree1.Root.Match == MatchType.NoMatch || tree2.Root.Match == MatchType.NoMatch) { Message("Error: Root nodes must have the same name!\n"); } var writer = new XdtDiffWriter(); var patch = writer.GetDiff(tree2); fastColoredTextBoxXDT.Text = PrettyXml(patch.OuterXml); tabControl1.SelectedIndex = 2; } catch (Exception ex) { Message(ex.ToString()); } }
public void AttributeMarkedChanged() { var doc1 = new XmlDocument(); doc1.LoadXml(@" <root> <child1 name1='child1' type1='elem1'>child1</child1> <child2 name1='child2' type1='elem2'>child2</child2> </root>" ); // reordered xml but same values var doc2 = new XmlDocument(); doc2.LoadXml(@" <root> <child1 type1='elem1' name1='DIFFERENT'>child1</child1> <child2 name1='child2' type1='elem2'>child2</child2> </root>" ); var tree1 = new XTree(doc1); var tree2 = new XTree(doc2); XDiff.Diff(tree1, tree2); Assert.AreEqual(tree1.Root.Match, MatchType.Change); Assert.AreEqual(tree2.Root.Match, MatchType.Change); Assert.AreEqual(tree1.Root.Children.Length, 2); Assert.AreEqual(tree2.Root.Children.Length, 2); Assert.AreEqual(tree1.Root.Elements.Length, 2); Assert.AreEqual(tree2.Root.Elements.Length, 2); Assert.AreEqual(tree1.Root.Elements[0].Match, MatchType.Change); Assert.AreEqual(tree2.Root.Elements[0].Match, MatchType.Change); Assert.AreEqual(tree1.Root.Elements[1].Match, MatchType.Match); Assert.AreEqual(tree2.Root.Elements[1].Match, MatchType.Match); Assert.AreEqual(tree1.Root.Elements[0].Attributes.Length, 2); Assert.AreEqual(tree2.Root.Elements[0].Attributes.Length, 2); Assert.AreEqual(tree1.Root.Elements[0].Texts.Length, 1); Assert.AreEqual(tree2.Root.Elements[0].Texts.Length, 1); Assert.AreEqual(tree1.Root.Elements[0].Texts[0].Match, MatchType.Match); Assert.AreEqual(tree2.Root.Elements[0].Texts[0].Match, MatchType.Match); Assert.AreEqual(tree1.Root.Elements[0].Attributes[0].Match, MatchType.Change); Assert.AreEqual(tree2.Root.Elements[0].Attributes[0].Match, MatchType.Match); Assert.AreEqual(tree1.Root.Elements[0].Attributes[1].Match, MatchType.Match); Assert.AreEqual(tree2.Root.Elements[0].Attributes[1].Match, MatchType.Change); Assert.AreEqual(tree1.Root.Elements[0].Attributes[0].Matching, tree2.Root.Elements[0].Attributes[1]); }
public void ValidatePosition(int lastCorrectionRepondedTo, int lastControlApplied, Vector3 clientPosition, float clientAngle, NetworkMessageInfo info) { Player player = Players[info.sender.guid]; // 11B: Make sure the client has used the last correction we sent if (lastCorrectionRepondedTo < player.LastCorrectionSent) { return; } #region 11C: Get the difference between the player's state and the server's ObjectState serverStateAfterControl = player.StatesAfterControls[lastControlApplied]; if (serverStateAfterControl == null) { return; } XDiff = clientPosition.x - serverStateAfterControl.Position.x; YDiff = clientPosition.y - serverStateAfterControl.Position.y; ZDiff = clientPosition.z - serverStateAfterControl.Position.z; //XAngDiff = clientDirection.x - serverStateAfterControl.Forward.x; //YAngDiff = clientDirection.y - serverStateAfterControl.Forward.y; //ZAngDiff = clientDirection.z - serverStateAfterControl.Forward.z; AngDiff = clientAngle - serverStateAfterControl.Angle; Debug.Log( "Diff: " + XDiff.ToString() + ", " + YDiff.ToString() + ", " + ZDiff.ToString() + ", " + AngDiff.ToString() ); #endregion 11C #region 11D: If the player is out of tolerance, then send a correction if (Mathf.Abs(XDiff) > PosTolerance || Mathf.Abs(YDiff) > PosTolerance || Mathf.Abs(ZDiff) > PosTolerance || Mathf.Abs(AngDiff) > DirTolerance) //Mathf.Abs(XAngDiff) > DirTolerance || //Mathf.Abs(YAngDiff) > DirTolerance || //Mathf.Abs(ZAngDiff) > DirTolerance) { Debug.Log("Sending correction..."); player.LastCorrectionSent = lastControlApplied; // Send the current position // If we send the correction to the old position, it forces the client to apply more contorl commands on its own, creating a larger margin of error SceneCharacter3D scenechar = (SceneCharacter3D)player.InGameCharacter; GetComponent <NetworkView>().RPC("CorrectPosition", info.sender, player.LastControlNumApplied, player.InGameCharacter.state.pos, scenechar.state.momentum, player.InGameCharacter.state.angle, scenechar.state.velocity, scenechar.crouch_factor); } #endregion 11D }
public static string GenerateXdt(string newConfig) { var baseConfig = GetBaseConfig(); if (string.IsNullOrEmpty(baseConfig) || string.IsNullOrEmpty(newConfig)) { return(""); } var baseTree = BuildTree(baseConfig); var newTree = BuildTree(newConfig); XDiff.Diff(baseTree, newTree); var patch = new XdtDiffWriter().GetDiff(newTree); return(patch.ToFormattedString()); }
private static List <String> CompileXmlChanges(int fileVersion, string origPath, string newPath) { XmlDocument origDoc = new XmlDocument(); FileStream origFs = new FileStream(origPath, FileMode.Open); origDoc.Load(origFs); origFs.Dispose(); XmlDocument newDoc = new XmlDocument(); FileStream newFs = new FileStream(newPath, FileMode.Open); newDoc.Load(newFs); newFs.Dispose(); var tree1 = new XTree(origDoc); var tree2 = new XTree(newDoc); XDiff.Diff(tree1, tree2); var res = new List <String>(); List <string> missingFromNew = CompileXmlChangesForNode(Enumerable.Empty <string>().ToImmutableHashSet(), "", "", tree1.Root); if (missingFromNew.Any()) { res.Add("Missing nodes:"); res.AddRange(missingFromNew); } ImmutableHashSet <string> canIgnore = AddedFields.Where(kv => kv.Key >= fileVersion).SelectMany(kv => kv.Value).ToImmutableHashSet(); List <string> extra = CompileXmlChangesForNode(canIgnore, "", "", tree2.Root); if (extra.Any()) { res.Add("Additional nodes:"); res.AddRange(extra); } return(res); }
private XmlDocument GetPatch(string sourceXml, string targetXml) { var doc1 = new XmlDocument(); doc1.LoadXml(sourceXml); // reordered xml but same values var doc2 = new XmlDocument(); doc2.LoadXml(targetXml); var tree1 = new XTree(doc1); var tree2 = new XTree(doc2); XDiff.Diff(tree1, tree2); var writer = new XdtDiffWriter(); return(writer.GetDiff(tree2)); }