diff --git a/src/DynamoCore/Core/CustomNodeDefinition.cs b/src/DynamoCore/Core/CustomNodeDefinition.cs
index b9a574d15c1..3dcf2cbccac 100644
--- a/src/DynamoCore/Core/CustomNodeDefinition.cs
+++ b/src/DynamoCore/Core/CustomNodeDefinition.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.IO;
using System.Linq;
using Dynamo.Engine;
using Dynamo.Engine.CodeGeneration;
@@ -7,6 +8,8 @@
using Dynamo.Graph.Nodes.CustomNodes;
using Dynamo.Graph.Workspaces;
using Dynamo.Library;
+using Newtonsoft.Json;
+using Newtonsoft.Json.Linq;
using ProtoCore;
using ProtoCore.AST.AssociativeAST;
@@ -302,6 +305,9 @@ public CustomNodeInfo(Guid functionId, string name, string category, string desc
if (String.IsNullOrWhiteSpace(Category))
Category = Dynamo.Properties.Resources.DefaultCustomNodeCategory;
}
+
+ [JsonConstructor] public CustomNodeInfo() { }
+
///
/// Returns custom node unique ID
///
@@ -337,7 +343,7 @@ public CustomNodeInfo(Guid functionId, string name, string category, string desc
/// Indicates if custom node is part of the library search.
/// If true, then custom node is part of library search.
///
- public bool IsVisibleInDynamoLibrary { get; private set; }
+ public bool IsVisibleInDynamoLibrary { get; set; }
///
/// Only valid if IsPackageMember is true.
@@ -345,5 +351,72 @@ public CustomNodeInfo(Guid functionId, string name, string category, string desc
/// requested this CustomNode to load.
///
public PackageInfo PackageInfo { get; internal set; }
+
+
+ private static readonly string[] topLevelJsonKeys = { "Uuid", "Category", "Description", "Name" };
+ private static readonly Dictionary propertyLookup = [];
+ private static object isVisibleInDynamoLibraryProp = null;
+ private static DefaultJsonNameTable propertyTable = null;
+
+ internal static bool GetFromJsonDocument(string path, out CustomNodeInfo info, out Exception ex)
+ {
+ if (propertyTable == null)
+ {
+ propertyTable = new DefaultJsonNameTable();
+ foreach (var pn in topLevelJsonKeys)
+ {
+ propertyLookup[pn] = propertyTable.Add(pn);
+ }
+ isVisibleInDynamoLibraryProp = propertyTable.Add(nameof(IsVisibleInDynamoLibrary));
+ }
+
+ try
+ {
+ var data = new JObject();
+ // JsonTextRead will automatically dispose of the stream reader
+ using (var fs = new FileStream(path, FileMode.Open, FileAccess.Read))
+ using (var jr = new JsonTextReader(new StreamReader(fs)) { PropertyNameTable = propertyTable })
+ {
+ while (jr.Read())
+ {
+ if (data.Count == topLevelJsonKeys.Length + 1)
+ {
+ break; // we have all of the
+ }
+
+ if (jr.TokenType == JsonToken.PropertyName)
+ {
+ if (jr.Depth == 1)
+ {
+ foreach (var prop in propertyLookup)
+ {
+ if (jr.Value == prop.Value)
+ {
+ data[prop.Key] = jr.ReadAsString() ?? "";
+ break;
+ }
+ }
+ }
+ else if (jr.Value == isVisibleInDynamoLibraryProp)
+ {
+ data[nameof(IsVisibleInDynamoLibrary)] = jr.ReadAsBoolean();
+ }
+ }
+ }
+ }
+
+ ex = null;
+ data["FunctionId"] = data.GetValue("Uuid");
+ data["Path"] = path;
+ info = data.ToObject();
+ return true;
+ }
+ catch (Exception e)
+ {
+ ex = e;
+ info = null;
+ return false;
+ }
+ }
}
}
diff --git a/src/DynamoCore/Core/CustomNodeManager.cs b/src/DynamoCore/Core/CustomNodeManager.cs
index 8dabe1ec45b..9172c2561cb 100644
--- a/src/DynamoCore/Core/CustomNodeManager.cs
+++ b/src/DynamoCore/Core/CustomNodeManager.cs
@@ -678,39 +678,33 @@ internal bool IsInitialized(Guid guid)
/// The custom node info object - null if we failed
internal bool TryGetInfoFromPath(string path, bool isTestMode, out CustomNodeInfo info)
{
- WorkspaceInfo header = null;
- XmlDocument xmlDoc;
- string jsonDoc;
Exception ex;
try
{
- if (DynamoUtilities.PathHelper.isValidJson(path, out jsonDoc, out ex))
+ //if (DynamoUtilities.PathHelper.isValidJson(path, out jsonDoc, out ex))
+ if (CustomNodeInfo.GetFromJsonDocument(path, out info, out ex))
{
- if (!WorkspaceInfo.FromJsonDocument(jsonDoc, path, isTestMode, false, AsLogger(), out header))
- {
- Log(String.Format(Properties.Resources.FailedToLoadHeader, path));
- info = null;
- return false;
- }
+ return true;
}
- else if (DynamoUtilities.PathHelper.isValidXML(path, out xmlDoc, out ex))
+ else if (DynamoUtilities.PathHelper.isValidXML(path, out var xmlDoc, out ex))
{
- if (!WorkspaceInfo.FromXmlDocument(xmlDoc, path, isTestMode, false, AsLogger(), out header))
+ if (!WorkspaceInfo.FromXmlDocument(xmlDoc, path, isTestMode, false, AsLogger(), out var header))
{
Log(String.Format(Properties.Resources.FailedToLoadHeader, path));
info = null;
return false;
}
+
+ info = new CustomNodeInfo(
+ Guid.Parse(header.ID),
+ header.Name,
+ header.Category,
+ header.Description,
+ path,
+ header.IsVisibleInDynamoLibrary);
+ return true;
}
else throw ex;
- info = new CustomNodeInfo(
- Guid.Parse(header.ID),
- header.Name,
- header.Category,
- header.Description,
- path,
- header.IsVisibleInDynamoLibrary);
- return true;
}
catch (Exception e)
{