/// <summary> /// Get all of the dependencies from a workspace /// </summary> /// <param name="workspace">The workspace to read the dependencies from</param> /// <param name="customNodeManager">A custom node manager to look up dependencies</param> /// <returns>A WorkspaceDependencies object containing the workspace and its CustomNodeWorkspaceModel dependencies</returns> public static WorkspaceDependencies Collect(HomeWorkspaceModel workspace, ICustomNodeManager customNodeManager) { if (workspace == null) throw new ArgumentNullException("workspace"); if (customNodeManager == null) throw new ArgumentNullException("customNodeManager"); // collect all dependencies var dependencies = new HashSet<CustomNodeDefinition>(); foreach (var node in workspace.Nodes.OfType<Function>()) { dependencies.Add(node.Definition); foreach (var dep in node.Definition.Dependencies) { dependencies.Add(dep); } } var customNodeWorkspaces = new List<ICustomNodeWorkspaceModel>(); foreach (var dependency in dependencies) { ICustomNodeWorkspaceModel customNodeWs; var workspaceExists = customNodeManager.TryGetFunctionWorkspace(dependency.FunctionId, false, out customNodeWs); if (!workspaceExists) { throw new InvalidOperationException(String.Format(Resources.CustomNodeDefinitionNotFoundErrorMessage, dependency.FunctionName)); } if (!customNodeWorkspaces.Contains(customNodeWs)) { customNodeWorkspaces.Add(customNodeWs); } } return new WorkspaceDependencies(workspace, customNodeWorkspaces); }
/// <summary> /// This recursive function returns true if any of the custom nodes in the input list has an IronPython dependency. /// Any custom nodes in the input list traversed during evalution have their dependencies cached in <see cref="CustomNodePythonDependencyMap"/>. /// Custom nodes are found to depend on IronPython if the parent custom node or any of its child custom nodes contain an IronPython dependency. /// </summary> /// <param name="customNodes">The custom nodes to evaluate.</param> /// <param name="customNodeManager">The custom node manager.</param> /// <returns>True if any IronPython depencies are found, false otherwise.</returns> private static bool CustomNodesHaveIronPythonDependency(IEnumerable <Function> customNodes, ICustomNodeManager customNodeManager) { var hasIronPythonDependency = false; foreach (var customNode in customNodes) { if (!customNodeManager.TryGetFunctionWorkspace(customNode.FunctionSignature, false, out ICustomNodeWorkspaceModel customNodeWS)) { continue; } // If a custom node workspace is already checked for IronPython dependencies, // check the CustomNodePythonDependency dictionary instead of processing it again. if (CustomNodePythonDependencyMap.TryGetValue(customNodeWS.CustomNodeId, out CNPythonDependencyType dependency)) { if (dependency == CNPythonDependencyType.DirectDependency || dependency == CNPythonDependencyType.NestedDependency) { hasIronPythonDependency = true; } continue; } var hasPythonNodesInCustomNodeWorkspace = customNodeWS.Nodes.Any(n => IsIronPythonNode(n)); if (hasPythonNodesInCustomNodeWorkspace) { CustomNodePythonDependencyMap.Add(customNodeWS.CustomNodeId, CNPythonDependencyType.DirectDependency); hasIronPythonDependency = true; } else { CustomNodePythonDependencyMap.Add(customNodeWS.CustomNodeId, CNPythonDependencyType.NoDependency); } // Recursively check for IronPython dependencies in the nested custom nodes. var nestedCustomNodes = customNodeWS.Nodes.OfType <Function>(); if (nestedCustomNodes.Any()) { hasPythonNodesInCustomNodeWorkspace = CustomNodesHaveIronPythonDependency(nestedCustomNodes, customNodeManager); // If a custom node contains an IronPython dependency in its sub-tree, // update its corresponding value to 'NestedDependency' in CustomNodePythonDependency. if (hasPythonNodesInCustomNodeWorkspace && CustomNodePythonDependencyMap[customNodeWS.CustomNodeId] != CNPythonDependencyType.DirectDependency) { CustomNodePythonDependencyMap[customNodeWS.CustomNodeId] = CNPythonDependencyType.NestedDependency; hasIronPythonDependency = true; } } } return(hasIronPythonDependency); }
public bool SetPath(string originalPath, string newDirectoryPath) { var id = customNodeManager.GuidFromPath(originalPath); CustomNodeWorkspaceModel def; var res = customNodeManager.TryGetFunctionWorkspace(id, this.isTestMode, out def); if (!res) { return(false); } var newPath = Path.Combine(newDirectoryPath, Path.GetFileName(def.FileName)); def.FileName = newPath; return(true); }
/// <summary> /// Get all of the dependencies from a workspace /// </summary> /// <param name="workspace">The workspace to read the dependencies from</param> /// <param name="customNodeManager">A custom node manager to look up dependencies</param> /// <returns>A WorkspaceDependencies object containing the workspace and its CustomNodeWorkspaceModel dependencies</returns> public static WorkspaceDependencies Collect(HomeWorkspaceModel workspace, ICustomNodeManager customNodeManager) { if (workspace == null) { throw new ArgumentNullException("workspace"); } if (customNodeManager == null) { throw new ArgumentNullException("customNodeManager"); } // collect all dependencies var dependencies = new HashSet <CustomNodeDefinition>(); foreach (var node in workspace.Nodes.OfType <Function>()) { dependencies.Add(node.Definition); foreach (var dep in node.Definition.Dependencies) { dependencies.Add(dep); } } var customNodeWorkspaces = new List <ICustomNodeWorkspaceModel>(); foreach (var dependency in dependencies) { ICustomNodeWorkspaceModel customNodeWs; var workspaceExists = customNodeManager.TryGetFunctionWorkspace(dependency.FunctionId, false, out customNodeWs); if (!workspaceExists) { throw new InvalidOperationException(String.Format(Resources.CustomNodeDefinitionNotFoundErrorMessage, dependency.FunctionName)); } if (!customNodeWorkspaces.Contains(customNodeWs)) { customNodeWorkspaces.Add(customNodeWs); } } return(new WorkspaceDependencies(workspace, customNodeWorkspaces)); }
public bool SetPath(string originalPath, string newDirectoryPath) { var id = customNodeManager.GuidFromPath(originalPath); ICustomNodeWorkspaceModel def; var res = customNodeManager.TryGetFunctionWorkspace(id, this.isTestMode, out def); if (!res) { return(false); } var newPath = Path.Combine(newDirectoryPath, Path.GetFileName(def.FileName)); // TODO: http://adsk-oss.myjetbrains.com/youtrack/issue/MAGN-7989 var cdef = def as CustomNodeWorkspaceModel; cdef.FileName = newPath; return(true); }
/// <summary> /// Sends workspace and its' dependencies to Flood. /// </summary> /// <returns>String which is response from server.</returns> internal string Send(IEnumerable <IWorkspaceModel> workspaces, WorkspaceProperties workspaceProperties = null) { if (String.IsNullOrWhiteSpace(serverUrl)) { Error = UploadErrorType.ServerNotFound; return(Resources.FailedMessage); } if (String.IsNullOrWhiteSpace(authenticationProvider.Username)) { Error = UploadErrorType.AuthenticationFailed; return(Resources.FailedMessage); } if (authenticationProvider == null) { Error = UploadErrorType.AuthProviderNotFound; return(Resources.FailedMessage); } if (reachClient == null) { reachClient = new WorkspaceStorageClient(authenticationProvider, serverUrl); } HomeWorkspace = workspaces.OfType <HomeWorkspaceModel>().First(); var functionNodes = HomeWorkspace.Nodes.OfType <Function>(); List <CustomNodeDefinition> dependencies = new List <CustomNodeDefinition>(); foreach (var node in functionNodes) { dependencies.AddRange(node.Definition.Dependencies); } CustomNodeWorkspaces = new List <ICustomNodeWorkspaceModel>(); foreach (var dependency in dependencies) { ICustomNodeWorkspaceModel customNodeWs; var isWorkspaceCreated = customNodeManager.TryGetFunctionWorkspace(dependency.FunctionId, false, out customNodeWs); if (isWorkspaceCreated && !CustomNodeWorkspaces.Contains(customNodeWs)) { CustomNodeWorkspaces.Add(customNodeWs); } } string result; try { result = reachClient.Send( HomeWorkspace, CustomNodeWorkspaces.OfType <CustomNodeWorkspaceModel>(), workspaceProperties); InvalidNodeNames = null; } catch (InvalidNodesException ex) { InvalidNodeNames = ex.InvalidNodeNames; result = Resources.FailedMessage; } catch { result = Resources.FailedMessage; } return(result); }