/// <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> public bool TryGetInfoFromPath(string path, bool isTestMode, out CustomNodeInfo info) { try { var xmlDoc = new XmlDocument(); xmlDoc.Load(path); WorkspaceHeader header; if (!WorkspaceHeader.FromXmlDocument(xmlDoc, path, isTestMode, 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); return(true); } catch (Exception e) { Log(String.Format(Properties.Resources.FailedToLoadHeader, path)); Log(e.ToString()); info = null; return(false); } }
private bool InitializeCustomNode( Guid functionId, WorkspaceHeader workspaceInfo, XmlDocument xmlDoc, out CustomNodeWorkspaceModel workspace) { // Add custom node definition firstly so that a recursive // custom node won't recursively load itself. SetPreloadFunctionDefinition(functionId); var nodeGraph = NodeGraph.LoadGraphFromXml(xmlDoc, nodeFactory); var newWorkspace = new CustomNodeWorkspaceModel( workspaceInfo.Name, workspaceInfo.Category, workspaceInfo.Description, nodeFactory, nodeGraph.Nodes, nodeGraph.Notes, workspaceInfo.X, workspaceInfo.Y, functionId, nodeGraph.ElementResolver, workspaceInfo.FileName); RegisterCustomNodeWorkspace(newWorkspace); workspace = newWorkspace; return(true); }
/// <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> public bool TryGetInfoFromPath(string path, bool isTestMode, out CustomNodeInfo info) { try { var xmlDoc = new XmlDocument(); xmlDoc.Load(path); WorkspaceHeader header; if (!WorkspaceHeader.FromXmlDocument(xmlDoc, path, isTestMode, AsLogger(), out header)) { Log( "ERROR: The header for the custom node at " + path + " failed to load. It will be left out of search."); info = null; return(false); } info = new CustomNodeInfo( Guid.Parse(header.ID), header.Name, header.Category, header.Description, path); return(true); } catch (Exception e) { Log( "ERROR: The header for the custom node at " + path + " failed to load. It will be left out of search."); Log(e.ToString()); info = null; return(false); } }
public void CanRecognizeHomeWorkspace() { var examplePath = Path.Combine(GetTestDirectory(), @"core\combine", "combine-with-three.dyn"); var workspaceInfo = WorkspaceHeader.FromPath(examplePath); Assert.AreEqual("Home", workspaceInfo.Name); Assert.IsTrue(String.IsNullOrEmpty(workspaceInfo.ID)); Assert.IsFalse(workspaceInfo.IsCustomNodeWorkspace()); }
public void CanRecognizeCustomNodeWorkspace() { var examplePath = Path.Combine(GetTestDirectory(), @"core\combine", "Sequence2.dyf"); var workspaceInfo = WorkspaceHeader.FromPath(examplePath); Assert.AreEqual(workspaceInfo.Name, "Sequence2"); Assert.AreEqual(workspaceInfo.ID, "6aecda57-7679-4afb-aa02-05a75cc3433e"); Assert.IsTrue(workspaceInfo.IsCustomNodeWorkspace()); }
public void CanRecognizeHomeWorkspace() { var examplePath = Path.Combine(GetTestDirectory(), @"core\combine", "combine-with-three.dyn"); var doc = new XmlDocument(); doc.Load(examplePath); WorkspaceHeader workspaceInfo; Assert.IsTrue(WorkspaceHeader.FromXmlDocument(doc, examplePath, true, ViewModel.Model.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(GetTestDirectory(), @"core\combine", "Sequence2.dyf"); var doc = new XmlDocument(); doc.Load(examplePath); WorkspaceHeader workspaceInfo; Assert.IsTrue(WorkspaceHeader.FromXmlDocument(doc, examplePath, true, ViewModel.Model.Logger, out workspaceInfo)); Assert.AreEqual(workspaceInfo.Name, "Sequence2"); Assert.AreEqual(workspaceInfo.ID, "6aecda57-7679-4afb-aa02-05a75cc3433e"); Assert.IsTrue(workspaceInfo.IsCustomNodeWorkspace); }
/// <summary> /// Opens a Custom Node workspace from an XmlDocument, given a pre-constructed WorkspaceHeader. /// </summary> /// <param name="xmlDoc">XmlDocument representing the parsed custom node file.</param> /// <param name="workspaceInfo">Workspace header describing the custom node file.</param> /// <param name="isTestMode"> /// Flag specifying whether or not this should operate in "test mode". /// </param> /// <param name="workspace"></param> /// <returns></returns> public bool OpenCustomNodeWorkspace( XmlDocument xmlDoc, WorkspaceHeader workspaceInfo, bool isTestMode, out WorkspaceModel workspace) { CustomNodeWorkspaceModel customNodeWorkspace; if (InitializeCustomNode( Guid.Parse(workspaceInfo.ID), workspaceInfo, xmlDoc, out customNodeWorkspace)) { workspace = customNodeWorkspace; return(true); } workspace = 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); WorkspaceHeader header; if (WorkspaceHeader.FromXmlDocument( xmlDoc, xmlPath, isTestMode, AsLogger(), out header) && header.IsCustomNodeWorkspace) { if (migrationManager.ProcessWorkspace(header, xmlDoc, isTestMode, nodeFactory)) { return(InitializeCustomNode(functionId, header, 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); } }
/// <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("Loading node definition for \"" + customNodeInfo + "\" from: " + xmlPath); var xmlDoc = new XmlDocument(); xmlDoc.Load(xmlPath); WorkspaceHeader header; if (WorkspaceHeader.FromXmlDocument( xmlDoc, xmlPath, isTestMode, AsLogger(), out header) && header.IsCustomNodeWorkspace) { if (migrationManager.ProcessWorkspace(header, xmlDoc, isTestMode, nodeFactory)) { return(InitializeCustomNode(functionId, header, xmlDoc, out workspace)); } } Log(string.Format("Custom node \"{0}\" could not be initialized.", customNodeInfo.Name)); workspace = null; return(false); } catch (Exception ex) { Log("There was an error opening the workspace."); Log(ex); if (isTestMode) { throw; // Rethrow for NUnit. } workspace = null; return(false); } }