/// <summary> /// Get a guid from a specific path, internally this first calls GetDefinitionFromPath /// </summary> /// <param name="path">The path from which to get the guid</param> /// <param name="isTestMode"> /// Flag specifying whether or not this should operate in "test mode". /// </param> /// <param name="info"></param> /// <returns>The custom node info object - null if we failed</returns> internal bool TryGetInfoFromPath(string path, bool isTestMode, out CustomNodeInfo info) { try { var xmlDoc = new XmlDocument(); xmlDoc.Load(path); WorkspaceInfo header; if (!WorkspaceInfo.FromXmlDocument(xmlDoc, path, isTestMode, false, AsLogger(), out 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); } catch (Exception e) { Log(String.Format(Properties.Resources.FailedToLoadHeader, path)); Log(e.ToString()); info = null; return(false); } }
internal static MdFileInfo FromCustomNode(string path) { WorkspaceInfo header = null; ILogger log = new DummyConsoleLogger(); if (DynamoUtilities.PathHelper.isValidXML(path, out XmlDocument xmlDoc, out Exception ex)) { WorkspaceInfo.FromXmlDocument(xmlDoc, path, true, false, log, out header); }
public void CanRecognizeHomeWorkspace() { var examplePath = Path.Combine(TestDirectory, @"core\combine", "combine-with-three.dyn"); var doc = new XmlDocument(); doc.Load(examplePath); WorkspaceInfo workspaceInfo; Assert.IsTrue(WorkspaceInfo.FromXmlDocument(doc, examplePath, true, false, CurrentDynamoModel.Logger, out workspaceInfo)); Assert.AreEqual("Home", workspaceInfo.Name); Assert.IsTrue(String.IsNullOrEmpty(workspaceInfo.ID)); Assert.IsFalse(workspaceInfo.IsCustomNodeWorkspace); }
public void CanRecognizeCustomNodeWorkspace() { var examplePath = Path.Combine(TestDirectory, @"core\combine", "Sequence2.dyf"); var doc = new XmlDocument(); doc.Load(examplePath); WorkspaceInfo workspaceInfo; Assert.IsTrue(WorkspaceInfo.FromXmlDocument(doc, examplePath, true, false, CurrentDynamoModel.Logger, out workspaceInfo)); Assert.AreEqual(workspaceInfo.Name, "Sequence2"); Assert.AreEqual(workspaceInfo.ID, "6aecda57-7679-4afb-aa02-05a75cc3433e"); Assert.IsTrue(workspaceInfo.IsCustomNodeWorkspace); }
/// <summary> /// Deserialize a function definition from a given path. A side effect of this function is that /// the node is added to the dictionary of loadedNodes. /// </summary> /// <param name="functionId">The function guid we're currently loading</param> /// <param name="workspace">The resultant function definition</param> /// <returns>Boolean indicating if Custom Node initialized.</returns> private bool InitializeCustomNode( Guid functionId, out CustomNodeWorkspaceModel workspace) { try { var customNodeInfo = NodeInfos[functionId]; var path = customNodeInfo.Path; Log(String.Format(Properties.Resources.LoadingNodeDefinition, customNodeInfo, path)); WorkspaceInfo info; XmlDocument xmlDoc; string strInput; Exception ex; if (DynamoUtilities.PathHelper.isValidXML(path, out xmlDoc, out ex)) { if (WorkspaceInfo.FromXmlDocument(xmlDoc, path, false, AsLogger(), out info)) { info.ID = functionId.ToString(); if (migrationManager.ProcessWorkspace(info, xmlDoc, nodeFactory)) { return(InitializeCustomNode(info, xmlDoc, out workspace)); } } } else if (DynamoUtilities.PathHelper.isValidJson(path, out strInput, out ex)) { // TODO: Skip Json migration for now WorkspaceInfo.FromJsonDocument(strInput, path, false, AsLogger(), out info); info.ID = functionId.ToString(); return(InitializeCustomNode(info, null, out workspace)); } else { throw ex; } Log(string.Format(Properties.Resources.CustomNodeCouldNotBeInitialized, customNodeInfo.Name)); workspace = null; return(false); } catch (Exception ex) { Log(Properties.Resources.OpenWorkspaceError); Log(ex); workspace = null; return(false); } }
/// <summary> /// Returns a boolean indicating if successfully get a CustomNodeInfo object from a workspace path /// </summary> /// <param name="path">The path from which to get the guid</param> /// <param name="info"></param> /// <returns>The custom node info object - null if we failed</returns> internal bool TryGetInfoFromPath(string path, out CustomNodeInfo info) { WorkspaceInfo header = null; XmlDocument xmlDoc; string jsonDoc; Exception ex; try { if (DynamoUtilities.PathHelper.isValidXML(path, out xmlDoc, out ex)) { if (!WorkspaceInfo.FromXmlDocument(xmlDoc, path, false, AsLogger(), out header)) { Log(String.Format(Properties.Resources.FailedToLoadHeader, path)); info = null; return(false); } } else if (DynamoUtilities.PathHelper.isValidJson(path, out jsonDoc, out ex)) { if (!WorkspaceInfo.FromJsonDocument(jsonDoc, path, false, AsLogger(), out header)) { Log(String.Format(Properties.Resources.FailedToLoadHeader, path)); info = null; return(false); } } else { throw ex; } info = new CustomNodeInfo( Guid.Parse(header.ID), header.Name, header.Category, header.Description, path, header.IsVisibleInDynamoLibrary); return(true); } catch (Exception e) { Log(String.Format(Properties.Resources.FailedToLoadHeader, path)); Log(e.ToString()); info = null; return(false); } }
/// <summary> /// Deserialize a function definition from a given path. A side effect of this function is that /// the node is added to the dictionary of loadedNodes. /// </summary> /// <param name="functionId">The function guid we're currently loading</param> /// <param name="isTestMode"></param> /// <param name="workspace">The resultant function definition</param> /// <returns></returns> private bool InitializeCustomNode(Guid functionId, bool isTestMode, out CustomNodeWorkspaceModel workspace) { try { var customNodeInfo = NodeInfos[functionId]; var xmlPath = customNodeInfo.Path; Log(String.Format(Properties.Resources.LoadingNodeDefinition, customNodeInfo, xmlPath)); var xmlDoc = new XmlDocument(); xmlDoc.Load(xmlPath); WorkspaceInfo info; if (WorkspaceInfo.FromXmlDocument( xmlDoc, xmlPath, isTestMode, false, AsLogger(), out info) && info.IsCustomNodeWorkspace) { info.ID = functionId.ToString(); if (migrationManager.ProcessWorkspace(info, xmlDoc, isTestMode, nodeFactory)) { return(InitializeCustomNode(info, xmlDoc, out workspace)); } } Log(string.Format(Properties.Resources.CustomNodeCouldNotBeInitialized, customNodeInfo.Name)); workspace = null; return(false); } catch (Exception ex) { Log(Properties.Resources.OpenWorkspaceError); Log(ex); if (isTestMode) { throw; // Rethrow for NUnit. } workspace = null; return(false); } }