Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DYN-6186: Clear any element binding data from DYN upon SaveAs #14394

Merged
merged 16 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/DynamoCoreWpf/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/DynamoCoreWpf/Properties/Resources.en-US.resx
Original file line number Diff line number Diff line change
Expand Up @@ -3720,4 +3720,10 @@ In certain complex graphs or host program scenarios, Automatic mode may cause in
<data name="PreferencesViewIncludeTimestampExportPathTooltip" xml:space="preserve">
<value>When toggled on, file names of exported images include date and time of export.</value>
</data>
<data name="ElementBindingWarningMessage" xml:space="preserve">
<value>A Save As command will create a workspace which is treated as a completely new file by Dynamo and existing element binding data will be lost. New element binding data will be created as normal as you run this file. Use the Save command instead if you wish to preserve element binding with the host document.</value>
</data>
<data name="ElementBindingWarningTitle" xml:space="preserve">
<value>Element Binding Warning</value>
</data>
</root>
6 changes: 6 additions & 0 deletions src/DynamoCoreWpf/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -3707,4 +3707,10 @@ In certain complex graphs or host program scenarios, Automatic mode may cause in
<data name="PreferencesViewIncludeTimestampExportPathTooltip" xml:space="preserve">
<value>When toggled on, file names of exported images include date and time of export.</value>
</data>
<data name="ElementBindingWarningMessage" xml:space="preserve">
<value>A Save As command will create a workspace which is treated as a completely new file by Dynamo and existing element binding data will be lost. New element binding data will be created as normal as you run this file. Use the Save command instead if you wish to preserve element binding with the host document.</value>
</data>
<data name="ElementBindingWarningTitle" xml:space="preserve">
<value>Element Binding Warning</value>
</data>
aparajit-pratap marked this conversation as resolved.
Show resolved Hide resolved
</root>
18 changes: 18 additions & 0 deletions src/DynamoCoreWpf/ViewModels/Core/WorkspaceViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using Dynamo.Graph.Workspaces;
using Dynamo.Models;
using Dynamo.Selection;
using Dynamo.UI.Prompts;
using Dynamo.Utilities;
using Dynamo.Wpf.ViewModels;
using Dynamo.Wpf.ViewModels.Core;
Expand Down Expand Up @@ -627,6 +628,23 @@ internal void Save(string filePath, bool isBackup = false, EngineController engi
{
// For intentional SaveAs either through UI or API calls, replace workspace elements' Guids and workspace Id
jo["Uuid"] = Guid.NewGuid().ToString();
if (jo["Bindings"] != JToken.Parse("[]"))
{
jo["Bindings"] = JToken.Parse("[]");

if (!DynamoModel.IsTestMode)
{
var result = DynamoMessageBox.Show(Wpf.Properties.Resources.ElementBindingWarningMessage,
Wpf.Properties.Resources.ElementBindingWarningTitle, MessageBoxButton.OKCancel,
MessageBoxImage.Warning);

if (result == MessageBoxResult.Cancel)
{
return;
}
}
}

saveContent = GuidUtility.UpdateWorkspaceGUIDs(jo.ToString());
}
else
Expand Down
44 changes: 44 additions & 0 deletions test/DynamoCoreWpfTests/DynamoViewTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
Expand All @@ -21,6 +22,7 @@
using Dynamo.Wpf.ViewModels.Core;
using Dynamo.Wpf.Views;
using DynamoCoreWpfTests.Utility;
using Newtonsoft.Json.Linq;
using NUnit.Framework;
using SharpDX.DXGI;

Expand Down Expand Up @@ -127,6 +129,48 @@ public void OpeningWorkspaceWithTclsrustWarning()
}

[Test]
public void ElementBinding_SaveAs()
{
var prebindingPathInTestDir = @"core\callsite\trace_test-prebinding.dyn";
var prebindingPath = Path.Combine(GetTestDirectory(ExecutingDirectory), prebindingPathInTestDir);

var pathInTestsDir = @"core\callsite\trace_test.dyn";
var filePath = Path.Combine(GetTestDirectory(ExecutingDirectory), pathInTestsDir);

// Always start with a fresh workspace with no binding data for this test.
File.Copy(prebindingPath, filePath);
OpenAndRun(pathInTestsDir);

// Assert that the node doesn't have trace data the first time it's run.
var hasTraceData = Model.CurrentWorkspace.Nodes.FirstOrDefault(x =>
x.Name == "IncrementerTracedClass.WasCreatedWithTrace");
Assert.AreEqual(false, hasTraceData.CachedValue.Data);

// Saving the workspace after a run serializes trace data to the DYN.
ViewModel.SaveCommand.Execute(null);

DynamoUtilities.PathHelper.isValidJson(filePath, out string fileContents, out Exception ex);
var obj = DSCore.Data.ParseJSON(fileContents) as Dictionary<string, object>;
Assert.AreEqual(1, (obj["Bindings"] as IEnumerable<object>).Count());

var saveAsPathInTestDir = @"core\callsite\trace_test2.dyn";
var saveAsPath = Path.Combine(GetTestDirectory(ExecutingDirectory), saveAsPathInTestDir);

// SaveAs current workspace, close workspace.
ViewModel.SaveAsCommand.Execute(saveAsPath);
ViewModel.CloseHomeWorkspaceCommand.Execute(null);

Open(saveAsPathInTestDir);

// Assert saved as file doesn't have binding data after open.
DynamoUtilities.PathHelper.isValidJson(filePath, out fileContents, out ex);
obj = DSCore.Data.ParseJSON(fileContents) as Dictionary<string, object>;
Assert.AreEqual(1, (obj["Bindings"] as IEnumerable<object>).Count());

File.Delete(filePath);
File.Delete(saveAsPath);
}

public void TestToastNotificationClosingBehavior()
{
var preferencesWindow = new PreferencesView(View);
Expand Down
186 changes: 186 additions & 0 deletions test/core/callsite/trace_test-prebinding.dyn
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
{
"Uuid": "92697b36-63f4-4e89-8814-4b1681342cf0",
"IsCustomNode": false,
"Description": "",
"Name": "trace_test",
"ElementResolver": {
"ResolutionMap": {}
},
"Inputs": [],
"Outputs": [],
"Nodes": [
{
"ConcreteType": "Dynamo.Graph.Nodes.ZeroTouch.DSFunction, DynamoCore",
"Id": "963b1305492e4741a2639848b37ba25f",
"NodeType": "FunctionNode",
"Inputs": [
{
"Id": "7d54983d59b2475486dbea82e4cd8234",
"Name": "x",
"Description": "int",
"UsingDefaultValue": false,
"Level": 2,
"UseLevels": false,
"KeepListStructure": false
}
],
"Outputs": [
{
"Id": "5fa2598e19d6478fb9134f42c2e4eb49",
"Name": "IncrementerTracedClass",
"Description": "IncrementerTracedClass",
"UsingDefaultValue": false,
"Level": 2,
"UseLevels": false,
"KeepListStructure": false
}
],
"FunctionSignature": "FFITarget.IncrementerTracedClass.IncrementerTracedClass@int",
"Replication": "Auto",
"Description": "Note that x is a dummy var here that is intended to force replicated dispatch it's not actually used\n\nIncrementerTracedClass.IncrementerTracedClass (x: int): IncrementerTracedClass"
},
{
"ConcreteType": "Dynamo.Graph.Nodes.CodeBlockNodeModel, DynamoCore",
"Id": "72fa79780443493faff475150a26c935",
"NodeType": "CodeBlockNode",
"Inputs": [],
"Outputs": [
{
"Id": "e63d799074504deb914e70ebb0d492d6",
"Name": "",
"Description": "Value of expression at line 1",
"UsingDefaultValue": false,
"Level": 2,
"UseLevels": false,
"KeepListStructure": false
}
],
"Replication": "Disabled",
"Description": "Allows for DesignScript code to be authored directly",
"Code": "12;"
},
{
"ConcreteType": "Dynamo.Graph.Nodes.ZeroTouch.DSFunction, DynamoCore",
"Id": "fca7f7004dec4c1aa7383ca0a722d5fa",
"NodeType": "FunctionNode",
"Inputs": [
{
"Id": "a91e903ed65e44b7b3f8b733d814e918",
"Name": "incrementerTracedClass",
"Description": "FFITarget.IncrementerTracedClass",
"UsingDefaultValue": false,
"Level": 2,
"UseLevels": false,
"KeepListStructure": false
}
],
"Outputs": [
{
"Id": "4f7a39b495454181a927247cfc2d045e",
"Name": "bool",
"Description": "bool",
"UsingDefaultValue": false,
"Level": 2,
"UseLevels": false,
"KeepListStructure": false
}
],
"FunctionSignature": "FFITarget.IncrementerTracedClass.WasCreatedWithTrace",
"Replication": "Auto",
"Description": "IncrementerTracedClass.WasCreatedWithTrace ( ): bool"
}
],
"Connectors": [
{
"Start": "5fa2598e19d6478fb9134f42c2e4eb49",
"End": "a91e903ed65e44b7b3f8b733d814e918",
"Id": "d68582a233564324926bd398c01905df",
"IsHidden": "False"
},
{
"Start": "e63d799074504deb914e70ebb0d492d6",
"End": "7d54983d59b2475486dbea82e4cd8234",
"Id": "6884d21efb704658b6902b11fdf87358",
"IsHidden": "False"
}
],
"Dependencies": [],
"NodeLibraryDependencies": [],
"Thumbnail": "",
"GraphDocumentationURL": null,
"ExtensionWorkspaceData": [
{
"ExtensionGuid": "28992e1d-abb9-417f-8b1b-05e053bee670",
"Name": "Properties",
"Version": "2.19",
"Data": {}
}
],
"Author": "",
"Linting": {
"activeLinter": "None",
"activeLinterId": "7b75fb44-43fd-4631-a878-29f4d5d8399a",
"warningCount": 0,
"errorCount": 0
},
"Bindings": [],
"View": {
"Dynamo": {
"ScaleFactor": 1.0,
"HasRunWithoutCrash": true,
"IsVisibleInDynamoLibrary": true,
"Version": "3.0.0.6191",
"RunType": "Automatic",
"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
},
"ConnectorPins": [],
"NodeViews": [
{
"Id": "963b1305492e4741a2639848b37ba25f",
"Name": "IncrementerTracedClass.IncrementerTracedClass",
"IsSetAsInput": false,
"IsSetAsOutput": false,
"Excluded": false,
"ShowGeometry": true,
"X": 440.79999999999995,
"Y": 204.80000000000007
},
{
"Id": "72fa79780443493faff475150a26c935",
"Name": "Code Block",
"IsSetAsInput": false,
"IsSetAsOutput": false,
"Excluded": false,
"ShowGeometry": true,
"X": 196.0,
"Y": 255.0
},
{
"Id": "fca7f7004dec4c1aa7383ca0a722d5fa",
"Name": "IncrementerTracedClass.WasCreatedWithTrace",
"IsSetAsInput": false,
"IsSetAsOutput": false,
"Excluded": false,
"ShowGeometry": true,
"X": 560.0000000000002,
"Y": 438.80000000000007
}
],
"Annotations": [],
"X": 0.0,
"Y": 0.0,
"Zoom": 1.0
}
}