Skip to content

Commit

Permalink
Deserialize More View level properties for DynamoPlayer clients (#10071)
Browse files Browse the repository at this point in the history
* Initial Commit

* Comments and add unit tests

* Typos

* Unit Test
  • Loading branch information
QilongTang authored Oct 31, 2019
1 parent 51ff553 commit dab7e14
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 40 deletions.
51 changes: 17 additions & 34 deletions src/DynamoCore/Graph/Workspaces/SerializationConverters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
var nodes = obj["Nodes"].ToObject<IEnumerable<NodeModel>>(serializer);

// Setting Inputs
// Required in headless mode by Dynamo Player that NodeModel.Name and NodeModel.IsSetAsInput are set
// Required in headless mode by Dynamo Player that certain view properties are set back to NodeModel
var inputsToken = obj["Inputs"];
if (inputsToken != null)
{
Expand Down Expand Up @@ -532,45 +532,28 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
// TODO: It is currently duplicating the effort with Input Block parsing which should be cleaned up once
// Dynamo supports both selection and drop down nodes in Inputs block
var view = obj["View"];
if (view != null)
if (view != null && view["NodeViews"] != null)
{
var nodesView = view["NodeViews"];
if (nodesView != null)
var nodeViews = view["NodeViews"].ToList();
foreach (var nodeview in nodeViews)
{
var inputsView = nodesView.ToArray().Select(x => x.ToObject<Dictionary<string, string>>()).ToList();
foreach (var inputViewData in inputsView)
Guid nodeGuid;
try
{
string isSetAsInput = "";
if (!inputViewData.TryGetValue("IsSetAsInput", out isSetAsInput) || isSetAsInput == bool.FalseString)
nodeGuid = Guid.Parse(nodeview["Id"].Value<string>());
var matchingNode = nodes.Where(x => x.GUID == nodeGuid).FirstOrDefault();
if (matchingNode != null)
{
continue;
}

string inputId = "";
if (inputViewData.TryGetValue("Id", out inputId))
{
Guid inputGuid;
try
{
inputGuid = Guid.Parse(inputId);
}
catch
{
continue;
}

var matchingNode = nodes.Where(x => x.GUID == inputGuid).FirstOrDefault();
if (matchingNode != null)
{
matchingNode.IsSetAsInput = true;
string inputName = "";
if (inputViewData.TryGetValue("Name", out inputName))
{
matchingNode.Name = inputName;
}
}
matchingNode.IsSetAsInput = nodeview["IsSetAsInput"].Value<bool>();
matchingNode.IsSetAsOutput = nodeview["IsSetAsOutput"].Value<bool>();
matchingNode.IsFrozen = nodeview["Excluded"].Value<bool>();
matchingNode.Name = nodeview["Name"].Value<string>();
}
}
catch
{
continue;
}
}
}
#endregion
Expand Down
50 changes: 49 additions & 1 deletion test/DynamoCoreTests/SerializationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ public void NodeDescriptionDeserilizationTest()
{
// This test is in reference to this task: https://jira.autodesk.com/browse/DYN-2002
// The description of the node in the below graph has been updated to a different value.
// We continue to serilize the description property to the json file but we do not want to
// We continue to serialize the description property to the json file but we do not want to
// read this value back while deserializing. This test will make sure that the description is
// not read from the json file and it gets the value from the node's config.
var testFile = Path.Combine(TestDirectory, @"core\serialization\NodeDescriptionDeserilizationTest.dyn");
Expand All @@ -631,6 +631,54 @@ public void NodeDescriptionDeserilizationTest()
Assert.AreEqual(node.Description, "Makes a new list out of the given inputs");
}

[Test]
public void NodeFreezeStateDeserilizationTest()
{
// The freeze state of the node is saved in node view block. However the property on node model
// will impact headless Dynamo clients graph run, e.g. DynamoPlayer, Refinery.
// This test will make sure that the isFrozenExplicitly is read from the node view block in Json file.
var testFile = Path.Combine(TestDirectory, @"core\serialization\NodeDescriptionDeserilizationTest.dyn");
OpenModel(testFile);
var node = this.CurrentDynamoModel.CurrentWorkspace.Nodes.First();
Assert.AreEqual(node.isFrozenExplicitly, true);
}

[Test]
public void NodeIsSetAsInputStateDeserilizationTest()
{
// The IsSetAsInput state of the node is saved in node view block. However the property on node model
// will impact headless Dynamo clients graph run, e.g. DynamoPlayer, Refinery.
// This test will make sure that the IsSetAsInput is read from the node view block in Json file.
var testFile = Path.Combine(TestDirectory, @"core\serialization\NodeDescriptionDeserilizationTest.dyn");
OpenModel(testFile);
var node = this.CurrentDynamoModel.CurrentWorkspace.Nodes.ToList()[1];
Assert.AreEqual(node.IsSetAsInput, true);
}

[Test]
public void NodeIsSetAsOutputStateDeserilizationTest()
{
// The IsSetAsOutput state of the node is saved in node view block. However the property on node model
// will impact headless Dynamo clients graph run, e.g. DynamoPlayer, Refinery.
// This test will make sure that the IsSetAsOutput is read from the node view block in Json file.
var testFile = Path.Combine(TestDirectory, @"core\serialization\NodeDescriptionDeserilizationTest.dyn");
OpenModel(testFile);
var node = this.CurrentDynamoModel.CurrentWorkspace.Nodes.First();
Assert.AreEqual(node.IsSetAsOutput, true);
}

[Test]
public void NodeNameDeserilizationTest()
{
// The name of the node is saved in node view block. However the property on node model
// will impact headless Dynamo clients graph run, e.g. DynamoPlayer, Refinery.
// This test will make sure that the name is read from the node view block in Json file.
var testFile = Path.Combine(TestDirectory, @"core\serialization\NodeDescriptionDeserilizationTest.dyn");
OpenModel(testFile);
var node = this.CurrentDynamoModel.CurrentWorkspace.Nodes.First();
Assert.AreEqual(node.Name, "List Create");
}

[Test, Category("JsonTestExclude")]
public void FunctionNodeLoadsWhenSignatureChanges()
{
Expand Down
41 changes: 36 additions & 5 deletions test/core/serialization/NodeDescriptionDeserilizationTest.dyn
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,27 @@
],
"Replication": "Disabled",
"Description": "Bad Description. This value should not be read."
},
{
"ConcreteType": "CoreNodeModels.Input.DoubleInput, CoreNodeModels",
"NodeType": "NumberInputNode",
"NumberType": "Double",
"InputValue": 0.0,
"Id": "867142a3c67e4d66a6c9bbf90e0b5145",
"Inputs": [],
"Outputs": [
{
"Id": "6e61229f418b48358a8c3d44902779b1",
"Name": "",
"Description": "Double",
"UsingDefaultValue": false,
"Level": 2,
"UseLevels": false,
"KeepListStructure": false
}
],
"Replication": "Disabled",
"Description": "Creates a number."
}
],
"Connectors": [],
Expand Down Expand Up @@ -71,15 +92,25 @@
"Name": "List Create",
"Id": "5b193e6856cf440a9d31bd85d16545aa",
"IsSetAsInput": false,
"IsSetAsOutput": false,
"Excluded": false,
"IsSetAsOutput": true,
"Excluded": true,
"X": 281.0,
"Y": 258.0
},
{
"ShowGeometry": true,
"Name": "Number",
"Id": "867142a3c67e4d66a6c9bbf90e0b5145",
"IsSetAsInput": true,
"IsSetAsOutput": false,
"Excluded": false,
"X": 282.16414686825055,
"Y": 360.88768898488127
}
],
"Annotations": [],
"X": 0.0,
"Y": 0.0,
"Zoom": 1.0
"X": -53.707499999999982,
"Y": -29.609999999999985,
"Zoom": 1.1575
}
}

0 comments on commit dab7e14

Please sign in to comment.