From e21a95a8a51f7ca72007fbe9ee7b1ef00ee09d3d Mon Sep 17 00:00:00 2001 From: aparajit-pratap Date: Wed, 22 Jan 2020 19:57:08 -0500 Subject: [PATCH 1/3] fix for crash upon unresolved node undo --- src/DynamoCore/Graph/Nodes/DummyNode.cs | 28 ++++++++++++++++++------- src/DynamoCore/Graph/Nodes/NodeModel.cs | 27 +++++++++++++++++++++--- 2 files changed, 44 insertions(+), 11 deletions(-) diff --git a/src/DynamoCore/Graph/Nodes/DummyNode.cs b/src/DynamoCore/Graph/Nodes/DummyNode.cs index dd39bd2a542..79490411034 100644 --- a/src/DynamoCore/Graph/Nodes/DummyNode.cs +++ b/src/DynamoCore/Graph/Nodes/DummyNode.cs @@ -10,6 +10,7 @@ using System; using System.Collections.Generic; using System.Globalization; +using System.Linq; using System.Xml; namespace Dynamo.Graph.Nodes @@ -250,11 +251,10 @@ private void LoadNode(XmlNode nodeElement) OutputCount = Int32.Parse(outputCount.Value); LegacyNodeName = legacyName.Value; - if (nodeElement.ChildNodes != null) + foreach (XmlNode childNode in nodeElement.ChildNodes) { - foreach (XmlNode childNode in nodeElement.ChildNodes) - if (childNode.Name.Equals("OriginalNodeContent")) - OriginalNodeContent = (XmlElement)nodeElement.FirstChild.FirstChild; + if (childNode.Name.Equals("OriginalNodeContent")) + OriginalNodeContent = (XmlElement) nodeElement.FirstChild.FirstChild; } if (originalElement != null) @@ -292,18 +292,30 @@ private void LoadNode(XmlNode nodeElement) private void UpdatePorts() { + var guids = InPorts.Select(x => x.GUID).ToArray(); InPorts.Clear(); for (int input = 0; input < InputCount; input++) { - var name = string.Format("Port {0}", input + 1); - InPorts.Add(new PortModel(PortType.Input, this, new PortData(name, ""))); + var name = $"Port {input + 1}"; + var pm = new PortModel(PortType.Input, this, new PortData(name, "")); + InPorts.Add(pm); + if (guids.Length == InputCount) + { + pm.GUID = guids[input]; + } } + guids = OutPorts.Select(x => x.GUID).ToArray(); OutPorts.Clear(); for (int output = 0; output < OutputCount; output++) { - var name = string.Format("Port {0}", output + 1); - OutPorts.Add(new PortModel(PortType.Output, this, new PortData(name, ""))); + var name = $"Port {output + 1}"; + var pm = new PortModel(PortType.Output, this, new PortData(name, "")); + OutPorts.Add(pm); + if (guids.Length == OutputCount) + { + pm.GUID = guids[output]; + } } RegisterAllPorts(); diff --git a/src/DynamoCore/Graph/Nodes/NodeModel.cs b/src/DynamoCore/Graph/Nodes/NodeModel.cs index eab36b87b51..05b092f4f1b 100644 --- a/src/DynamoCore/Graph/Nodes/NodeModel.cs +++ b/src/DynamoCore/Graph/Nodes/NodeModel.cs @@ -1610,10 +1610,31 @@ public void NotifyAstBuildBroken(string p) internal int GetPortModelIndex(PortModel portModel) { + int index; if (portModel.PortType == PortType.Input) - return InPorts.IndexOf(portModel); - else - return OutPorts.IndexOf(portModel); + { + index = InPorts.IndexOf(portModel); + if (index == -1) + { + var pm = InPorts.FirstOrDefault(x => x.GUID == portModel.GUID); + if (pm != null) + { + index = InPorts.IndexOf(pm); + } + } + return index; + } + + index = OutPorts.IndexOf(portModel); + if (index == -1) + { + var pm = OutPorts.FirstOrDefault(x => x.GUID == portModel.GUID); + if (pm != null) + { + index = InPorts.IndexOf(pm); + } + } + return index; } /// From 4ebc70f8847bc03cf7098f7ed4c97d4e7a5dd963 Mon Sep 17 00:00:00 2001 From: aparajit-pratap Date: Wed, 22 Jan 2020 20:33:37 -0500 Subject: [PATCH 2/3] override Equals in PortModel --- src/DynamoCore/Graph/Nodes/NodeModel.cs | 27 +++---------------------- src/DynamoCore/Graph/Nodes/PortModel.cs | 19 ++++++++++++++++- 2 files changed, 21 insertions(+), 25 deletions(-) diff --git a/src/DynamoCore/Graph/Nodes/NodeModel.cs b/src/DynamoCore/Graph/Nodes/NodeModel.cs index 05b092f4f1b..eab36b87b51 100644 --- a/src/DynamoCore/Graph/Nodes/NodeModel.cs +++ b/src/DynamoCore/Graph/Nodes/NodeModel.cs @@ -1610,31 +1610,10 @@ public void NotifyAstBuildBroken(string p) internal int GetPortModelIndex(PortModel portModel) { - int index; if (portModel.PortType == PortType.Input) - { - index = InPorts.IndexOf(portModel); - if (index == -1) - { - var pm = InPorts.FirstOrDefault(x => x.GUID == portModel.GUID); - if (pm != null) - { - index = InPorts.IndexOf(pm); - } - } - return index; - } - - index = OutPorts.IndexOf(portModel); - if (index == -1) - { - var pm = OutPorts.FirstOrDefault(x => x.GUID == portModel.GUID); - if (pm != null) - { - index = InPorts.IndexOf(pm); - } - } - return index; + return InPorts.IndexOf(portModel); + else + return OutPorts.IndexOf(portModel); } /// diff --git a/src/DynamoCore/Graph/Nodes/PortModel.cs b/src/DynamoCore/Graph/Nodes/PortModel.cs index 110cebacce1..9bd3b3baaf2 100644 --- a/src/DynamoCore/Graph/Nodes/PortModel.cs +++ b/src/DynamoCore/Graph/Nodes/PortModel.cs @@ -22,7 +22,7 @@ public enum PortType { Input, Output }; /// /// PortModel represents Dynamo ports. /// - public class PortModel : ModelBase + public class PortModel : ModelBase, IEquatable { #region private fields ObservableCollection connectors = new ObservableCollection(); @@ -369,6 +369,23 @@ protected override void DeserializeCore(XmlElement nodeElement, SaveContext cont } #endregion + + public bool Equals(PortModel other) + { + if (other == null) return false; + + if (this == other) return true; + + if (GUID == other.GUID) return true; + + return false; + } + + public override int GetHashCode() + { + return GUID.GetHashCode(); + } + } /// From 4ae9814bbadd8f86bdfed9c4ae9428cf2b8c7308 Mon Sep 17 00:00:00 2001 From: aparajit-pratap Date: Thu, 23 Jan 2020 13:19:14 -0500 Subject: [PATCH 3/3] add recorded test --- test/DynamoCoreWpfTests/RecordedTests.cs | 30 +++++ .../TestUnresolvedCodeBlockNodeUndo.dyn | 94 +++++++++++++++ .../TestUnresolvedCodeBlockNodeUndo.xml | 108 ++++++++++++++++++ 3 files changed, 232 insertions(+) create mode 100644 test/core/recorded/TestUnresolvedCodeBlockNodeUndo.dyn create mode 100644 test/core/recorded/TestUnresolvedCodeBlockNodeUndo.xml diff --git a/test/DynamoCoreWpfTests/RecordedTests.cs b/test/DynamoCoreWpfTests/RecordedTests.cs index 7eb800fff92..6d6872ffc36 100644 --- a/test/DynamoCoreWpfTests/RecordedTests.cs +++ b/test/DynamoCoreWpfTests/RecordedTests.cs @@ -1563,6 +1563,36 @@ public void RedoDeletedNodeShowsConnector() }); } + [Test, RequiresSTA] + public void TestUnresolvedCodeBlockNodeUndo() + { + bool undo_1 = false; + bool undo_2 = false; + bool undo_3 = false; + RunCommandsFromFile("TestUnresolvedCodeBlockNodeUndo.xml", (commandTag) => + { + var workspace = ViewModel.Model.CurrentWorkspace; + Assert.IsNotNull(workspace); + + if (commandTag == "Undo_1") + { + undo_1 = true; + } + else if (commandTag == "Undo_2") + { + undo_2 = true; + } + else if (commandTag == "Undo_3") + { + undo_3 = true; + } + }); + + Assert.IsTrue(undo_1); + Assert.IsTrue(undo_2); + Assert.IsTrue(undo_3); + } + /// /// Creates a Code Block Node with a single line comment and multi line comment /// checks if the ports are created properly and at the correct height diff --git a/test/core/recorded/TestUnresolvedCodeBlockNodeUndo.dyn b/test/core/recorded/TestUnresolvedCodeBlockNodeUndo.dyn new file mode 100644 index 00000000000..e5bd004d58e --- /dev/null +++ b/test/core/recorded/TestUnresolvedCodeBlockNodeUndo.dyn @@ -0,0 +1,94 @@ +{ + "Uuid": "0e5aec87-f0db-46dc-a7a0-e13d05b74a76", + "IsCustomNode": false, + "Description": null, + "Name": "TestUnresolvedCodeBlockNodeUndo", + "ElementResolver": { + "ResolutionMap": {} + }, + "Inputs": [], + "Outputs": [], + "Nodes": [ + { + "ConcreteType": "Dynamo.Graph.Nodes.ZeroTouch.DSFunction, DynamoCore", + "NodeType": "FunctionNode", + "FunctionSignature": "Lists.Manage.ReplaceNulls@var,var", + "Id": "50580245505a483b994b14d1b38d691c", + "Inputs": [ + { + "Id": "45071948e0ca4de7b7e7854a11256693", + "Name": "Data", + "Description": "var", + "UsingDefaultValue": false, + "Level": 2, + "UseLevels": false, + "KeepListStructure": false + }, + { + "Id": "c1a7e3f5ed9f43a6ab26c6d6f59f74fa", + "Name": "ReplaceWith", + "Description": "var", + "UsingDefaultValue": false, + "Level": 2, + "UseLevels": false, + "KeepListStructure": false + } + ], + "Outputs": [ + { + "Id": "3dca242246fd45048bb743b957909984", + "Name": "var[]..[]", + "Description": "var[]..[]", + "UsingDefaultValue": false, + "Level": 2, + "UseLevels": false, + "KeepListStructure": false + } + ], + "Replication": "Auto", + "Description": "Manage.ReplaceNulls (Data: var, ReplaceWith: var): var[]..[]" + } + ], + "Connectors": [], + "Dependencies": [], + "NodeLibraryDependencies": [], + "Bindings": [], + "View": { + "Dynamo": { + "ScaleFactor": 1.0, + "HasRunWithoutCrash": true, + "IsVisibleInDynamoLibrary": true, + "Version": "2.6.0.7481", + "RunType": "Manual", + "RunPeriod": "1000" + }, + "Camera": { + "Name": "Background Preview", + "EyeX": -17.0, + "EyeY": 24.0, + "EyeZ": 50.0, + "LookX": 12.0, + "LookY": -13.0, + "LookZ": -58.0, + "UpX": 0.0, + "UpY": 1.0, + "UpZ": 0.0 + }, + "NodeViews": [ + { + "ShowGeometry": true, + "Name": "Manage.ReplaceNulls", + "Id": "50580245505a483b994b14d1b38d691c", + "IsSetAsInput": false, + "IsSetAsOutput": false, + "Excluded": false, + "X": 1465.785850242029, + "Y": 338.9393205772858 + } + ], + "Annotations": [], + "X": -790.23067822776329, + "Y": 4.6725830650765374, + "Zoom": 1.0 + } +} \ No newline at end of file diff --git a/test/core/recorded/TestUnresolvedCodeBlockNodeUndo.xml b/test/core/recorded/TestUnresolvedCodeBlockNodeUndo.xml new file mode 100644 index 00000000000..e6dd1c12f26 --- /dev/null +++ b/test/core/recorded/TestUnresolvedCodeBlockNodeUndo.xml @@ -0,0 +1,108 @@ + + + + 00000000-0000-0000-0000-000000000000 + + + 739d4254-1347-421e-bf14-c146f60ac45b + + + + + + + 739d4254-1347-421e-bf14-c146f60ac45b + + + 00000000-0000-0000-0000-000000000000 + + + 4fcc7262-5953-4e3c-8186-0a60f523c542 + + + + + + 4fcc7262-5953-4e3c-8186-0a60f523c542 + + + 00000000-0000-0000-0000-000000000000 + + + 83063f49-2d6c-4f05-b370-0cf03d60cb09 + + + + + + + 00000000-0000-0000-0000-000000000000 + + + 83063f49-2d6c-4f05-b370-0cf03d60cb09 + + + 50580245-505a-483b-994b-14d1b38d691c + + + 83063f49-2d6c-4f05-b370-0cf03d60cb09 + + + 739d4254-1347-421e-bf14-c146f60ac45b + + + 50580245-505a-483b-994b-14d1b38d691c + + + 4fcc7262-5953-4e3c-8186-0a60f523c542 + + + 50580245-505a-483b-994b-14d1b38d691c + + + 50580245-505a-483b-994b-14d1b38d691c + + + + + + 83063f49-2d6c-4f05-b370-0cf03d60cb09 + + + + + + + 50580245-505a-483b-994b-14d1b38d691c + + + 00000000-0000-0000-0000-000000000000 + + + + 50580245-505a-483b-994b-14d1b38d691c + + + + + + 4fcc7262-5953-4e3c-8186-0a60f523c542 + + + + + + + 50580245-505a-483b-994b-14d1b38d691c + + + + + + 739d4254-1347-421e-bf14-c146f60ac45b + + + + + + \ No newline at end of file