/// <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); } }