Skip to content

Commit

Permalink
DYN-6394: Add legacy trace warning when opening workspace (#14628)
Browse files Browse the repository at this point in the history
* remove coreclr-ncalc references

* show legacy trace warning

* cleanup

* get workspace version correctly

* update warning

* add warning for xml DYNs

* add unit test

* cleanup

* review comments

* update tests

* revert test fixture change

* refactor, add test

* cleanup

* rename

* review comments

* update tests

* update tests

* revert unchanged test file
  • Loading branch information
aparajit-pratap authored Nov 28, 2023
1 parent 1d14d57 commit 5bbdd8b
Show file tree
Hide file tree
Showing 16 changed files with 633 additions and 196 deletions.
9 changes: 8 additions & 1 deletion src/DynamoCore/Engine/EngineController.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using Dynamo.Engine.CodeCompletion;
using Dynamo.Engine.CodeGeneration;
using Dynamo.Engine.NodeToCode;
Expand All @@ -10,6 +9,7 @@
using Dynamo.Graph.Workspaces;
using Dynamo.Logging;
using Dynamo.Scheduler;
using Dynamo.Utilities;
using ProtoCore.AST.AssociativeAST;
using ProtoCore.DSASM.Mirror;
using ProtoCore.Mirror;
Expand Down Expand Up @@ -44,6 +44,11 @@ public class EngineController : LogSourceBase, IAstNodeContainer, IDisposable
/// </summary>
internal static event Action VMLibrariesReset;

/// <summary>
/// Dynamo version in which the current workspace was last created or modified.
/// </summary>
internal Version CurrentWorkspaceVersion { get; set; }

/// <summary>
/// This event is fired when <see cref="UpdateGraphAsyncTask"/> is completed.
/// </summary>
Expand Down Expand Up @@ -153,6 +158,8 @@ public EngineController(LibraryServices libraryServices, string geometryFactoryF
syncDataManager = new SyncDataManager();

VerboseLogging = verboseLogging;

CurrentWorkspaceVersion = AssemblyHelper.GetDynamoVersion();
}

/// <summary>
Expand Down
16 changes: 8 additions & 8 deletions src/DynamoCore/Graph/Nodes/NodeCategories.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand All @@ -7,7 +7,6 @@
using System.Xml;
using Dynamo.Configuration;
using Dynamo.Engine;
using Dynamo.Graph.Nodes.CustomNodes;
using Dynamo.Library;
using ProtoCore;

Expand Down Expand Up @@ -282,7 +281,7 @@ internal static string GetDocumentXmlPath(XmlDocument document)
/// <returns>Returns a dictionary of deserialized node-data-list pairs
/// loaded from the given XmlDocument.</returns>
internal static IEnumerable<KeyValuePair<Guid, List<CallSite.RawTraceData>>>
LoadTraceDataFromXmlDocument(XmlDocument document)
LoadTraceDataFromXmlDocument(XmlDocument document, out bool containsLegacyTraceData)
{
if (document == null)
throw new ArgumentNullException("document");
Expand All @@ -301,7 +300,10 @@ where childNode.Name.Equals(sessionXmlTagName)

var loadedData = new Dictionary<Guid, List<CallSite.RawTraceData>>();
if (!query.Any()) // There's no data, return empty dictionary.
{
containsLegacyTraceData = false;
return loadedData;
}

XmlElement sessionElement = query.ElementAt(0);
foreach (XmlElement nodeElement in sessionElement.ChildNodes)
Expand All @@ -313,14 +315,12 @@ where childNode.Name.Equals(sessionXmlTagName)
var callsiteId = string.Empty;
if (child.HasAttribute(Configurations.CallSiteID))
{
callsiteId = child.GetAttribute(Configurations.CallSiteID);
containsLegacyTraceData = true;
return loadedData;
}
var traceData = child.InnerText;
callsiteTraceData.Add(new CallSite.RawTraceData(callsiteId, traceData));
}
loadedData.Add(guid, callsiteTraceData);
}

containsLegacyTraceData = false;
return loadedData;
}

Expand Down
19 changes: 0 additions & 19 deletions src/DynamoCore/Graph/Workspaces/CustomNodeWorkspaceModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Xml;
using Dynamo.Engine;
using Dynamo.Graph.Annotations;
using Dynamo.Graph.Nodes;
Expand Down Expand Up @@ -315,23 +314,5 @@ public override void Save(string newPath, bool isBackup = false, EngineControlle

base.Save(newPath, isBackup, engine);
}

[Obsolete("Method will be deprecated in Dynamo 3.0.")]
protected override bool PopulateXmlDocument(XmlDocument document)
{
if (!base.PopulateXmlDocument(document))
return false;

var root = document.DocumentElement;
if (root == null)
return false;

var guid = CustomNodeDefinition != null ? CustomNodeDefinition.FunctionId : Guid.NewGuid();
root.SetAttribute("ID", guid.ToString());
root.SetAttribute("Description", Description);
root.SetAttribute("Category", Category);

return true;
}
}
}
22 changes: 1 addition & 21 deletions src/DynamoCore/Graph/Workspaces/HomeWorkspaceModel.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Runtime.Serialization;
using System.Xml;
using Dynamo.Core;
using Dynamo.Engine;
using Dynamo.Events;
Expand Down Expand Up @@ -664,24 +661,7 @@ internal void StopPeriodicEvaluation()
}

#endregion

[Obsolete("Method will be deprecated in Dynamo 3.0.")]
protected override bool PopulateXmlDocument(XmlDocument document)
{
if (!base.PopulateXmlDocument(document))
return false;

var root = document.DocumentElement;
if (root == null)
return false;

root.SetAttribute("RunType", RunSettings.RunType.ToString());
root.SetAttribute("RunPeriod", RunSettings.RunPeriod.ToString(CultureInfo.InvariantCulture));
root.SetAttribute("HasRunWithoutCrash", HasRunWithoutCrash.ToString(CultureInfo.InvariantCulture));

return true;
}


private void PulseMakerRunStarted()
{
var nodesToUpdate = Nodes.Where(n => n.CanUpdatePeriodically);
Expand Down
44 changes: 29 additions & 15 deletions src/DynamoCore/Graph/Workspaces/SerializationConverters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -679,27 +679,38 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
#region Restore trace data
// Trace Data
Dictionary<Guid, List<CallSite.RawTraceData>> loadedTraceData = new Dictionary<Guid, List<CallSite.RawTraceData>>();
bool containsLegacyTraceData = false;
// Restore trace data if bindings are present in json
if (obj["Bindings"] != null && obj["Bindings"].Children().Count() > 0)
{
JEnumerable<JToken> bindings = obj["Bindings"].Children();
var wrc = serializer.Converters.First(c => c is WorkspaceReadConverter) as WorkspaceReadConverter;

// Iterate through bindings to extract nodeID's and bindingData (callsiteId & traceData)
foreach (JToken entity in bindings)
if (wrc.engine.CurrentWorkspaceVersion < new Version(3, 0, 0))
{
Guid nodeId = Guid.Parse(entity["NodeId"].ToString());
string bindingString = entity["Binding"].ToString();

// Key(callsiteId) : Value(traceData)
Dictionary<string, string> bindingData = JsonConvert.DeserializeObject<Dictionary<string, string>>(bindingString);
List<CallSite.RawTraceData> callsiteTraceData = new List<CallSite.RawTraceData>();
containsLegacyTraceData = true;
}
else
{
JEnumerable<JToken> bindings = obj["Bindings"].Children();

foreach (KeyValuePair<string, string> pair in bindingData)
// Iterate through bindings to extract nodeID's and bindingData (callsiteId & traceData)
foreach (JToken entity in bindings)
{
callsiteTraceData.Add(new CallSite.RawTraceData(pair.Key, pair.Value));
}
Guid nodeId = Guid.Parse(entity["NodeId"].ToString());
string bindingString = entity["Binding"].ToString();

// Key(callsiteId) : Value(traceData)
Dictionary<string, string> bindingData =
JsonConvert.DeserializeObject<Dictionary<string, string>>(bindingString);
List<CallSite.RawTraceData> callsiteTraceData = new List<CallSite.RawTraceData>();

loadedTraceData.Add(nodeId, callsiteTraceData);
foreach (KeyValuePair<string, string> pair in bindingData)
{
callsiteTraceData.Add(new CallSite.RawTraceData(pair.Key, pair.Value));
}

loadedTraceData.Add(nodeId, callsiteTraceData);
}
}
}
#endregion
Expand All @@ -725,7 +736,7 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
if (obj.TryGetValue(nameof(HomeWorkspaceModel.Thumbnail), StringComparison.OrdinalIgnoreCase, out JToken thumbnail))
homeWorkspace.Thumbnail = thumbnail.ToString();

// GraphDocumentaionLink
// GraphDocumentationLink
if (obj.TryGetValue(nameof(HomeWorkspaceModel.GraphDocumentationURL), StringComparison.OrdinalIgnoreCase, out JToken helpLink))
{
if (Uri.TryCreate(helpLink.ToString(), UriKind.Absolute, out Uri uri))
Expand All @@ -738,6 +749,7 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
// If there is a active linter serialized in the graph we set it to the active linter else set the default None.
SetActiveLinter(obj);


ws = homeWorkspace;
}

Expand All @@ -746,7 +758,9 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
ws.ExternalFiles = externalFiles;
if (obj.TryGetValue(nameof(WorkspaceModel.Author), StringComparison.OrdinalIgnoreCase, out JToken author))
ws.Author = author.ToString();


ws.ContainsLegacyTraceData = containsLegacyTraceData;

return ws;
}

Expand Down
98 changes: 5 additions & 93 deletions src/DynamoCore/Graph/Workspaces/WorkspaceModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using System.Reflection;
using System.Threading;
using System.Xml;
using Dynamo.Configuration;
using Dynamo.Core;
using Dynamo.Engine;
using Dynamo.Engine.CodeGeneration;
Expand Down Expand Up @@ -233,6 +232,11 @@ internal int CurrentPasteOffset
}
}

/// <summary>
/// This is true only if the workspace contains legacy SOAP formatted binding data.
/// </summary>
internal bool ContainsLegacyTraceData { get; set; }

internal bool ScaleFactorChanged = false;

/// <summary>
Expand Down Expand Up @@ -1280,9 +1284,6 @@ public Rect2D Rect
get { return new Rect2D(x, y, width, height); }
}

//TODO(Steve): This probably isn't needed inside of WorkspaceModel -- MAGN-5714
internal Version WorkspaceVersion { get; set; }

/// <summary>
/// Implements <see cref="ILocatable.CenterX"/> property.
/// </summary>
Expand Down Expand Up @@ -1372,7 +1373,6 @@ protected WorkspaceModel(
IsReadOnly = DynamoUtilities.PathHelper.IsReadOnlyPath(fileName);
LastSaved = DateTime.Now;

WorkspaceVersion = AssemblyHelper.GetDynamoVersion();
undoRecorder = new UndoRedoRecorder(this);

NodeFactory = factory;
Expand Down Expand Up @@ -2062,94 +2062,6 @@ private void SerializeElementResolver(XmlDocument xmlDoc)
root.AppendChild(mapElement);
}

[Obsolete("Method will be deprecated in Dynamo 3.0.")]
protected virtual bool PopulateXmlDocument(XmlDocument xmlDoc)
{
try
{
var root = xmlDoc.DocumentElement;
root.SetAttribute("Version", WorkspaceVersion.ToString());
root.SetAttribute("X", X.ToString(CultureInfo.InvariantCulture));
root.SetAttribute("Y", Y.ToString(CultureInfo.InvariantCulture));
root.SetAttribute("ScaleFactor", ScaleFactor.ToString(CultureInfo.InvariantCulture));
root.SetAttribute("Name", Name);
root.SetAttribute("Description", Description);

SerializeElementResolver(xmlDoc);

var elementList = xmlDoc.CreateElement("Elements");
//write the root element
root.AppendChild(elementList);

foreach (var dynEl in Nodes.Select(el => el.Serialize(xmlDoc, SaveContext.Save)))
elementList.AppendChild(dynEl);

//write only the output connectors
var connectorList = xmlDoc.CreateElement("Connectors");
//write the root element
root.AppendChild(connectorList);

foreach (var el in Nodes)
{
foreach (var port in el.OutPorts)
{
foreach (
var c in
port.Connectors.Where(c => c.Start != null && c.End != null))
{
var connector = xmlDoc.CreateElement(c.GetType().ToString());
connectorList.AppendChild(connector);
connector.SetAttribute("start", c.Start.Owner.GUID.ToString());
connector.SetAttribute("start_index", c.Start.Index.ToString());
connector.SetAttribute("end", c.End.Owner.GUID.ToString());
connector.SetAttribute("end_index", c.End.Index.ToString());
connector.SetAttribute(nameof(ConnectorModel.IsHidden), c.IsHidden.ToString());

if (c.End.PortType == PortType.Input)
connector.SetAttribute("portType", "0");
}
}
}

//save the notes
var noteList = xmlDoc.CreateElement("Notes"); //write the root element
root.AppendChild(noteList);
foreach (var n in Notes)
{
var note = n.Serialize(xmlDoc, SaveContext.Save);
noteList.AppendChild(note);
}

//save the annotation
var annotationList = xmlDoc.CreateElement("Annotations");
root.AppendChild(annotationList);
foreach (var n in annotations)
{
var annotation = n.Serialize(xmlDoc, SaveContext.Save);
annotationList.AppendChild(annotation);
}

//save the presets into the dyn file as a seperate element on the root
var presetsElement = xmlDoc.CreateElement("Presets");
root.AppendChild(presetsElement);
foreach (var preset in Presets)
{
var presetState = preset.Serialize(xmlDoc, SaveContext.Save);
presetsElement.AppendChild(presetState);
}

OnSaving(xmlDoc);

return true;
}
catch (Exception ex)
{
Log(ex.Message);
Log(ex.StackTrace);
return false;
}
}

internal void SendModelEvent(Guid modelGuid, string eventName, int value)
{
var retrievedModel = GetModelInternal(modelGuid);
Expand Down
18 changes: 0 additions & 18 deletions src/DynamoCore/Migration/Migration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -517,24 +517,6 @@ internal static Version VersionFromString(string version)
return new Version(ver.Major, ver.Minor, ver.Build, 0);
}

/// <summary>
/// Call this method to obtain the version of current WorkspaceModel.
/// Note that the revision number is dropped as both "0.7.0.1234"
/// should be treated as the same version as "0.7.0.5678", and no file
/// migration should take place.
/// </summary>
/// <param name="workspace">The WorkspaceModel to get the Version from.
/// </param>
/// <returns>Returns the Version object representing the workspace
/// version with the revision set to 0.</returns>
///
internal static Version VersionFromWorkspace(WorkspaceModel workspace)
{
// Ignore revision number.
var ver = workspace.WorkspaceVersion;
return new Version(ver.Major, ver.Minor, ver.Build, 0);
}

/// <summary>
/// Call this method to determine if migration should take place
/// for the input DYN/DYF file based on the given version numbers.
Expand Down
Loading

0 comments on commit 5bbdd8b

Please sign in to comment.