/// <summary> /// For given node tries to find matching nuget package and adds direct package dependencies /// nodes to given node's children collection. Use case is, when other provider has a node, /// that is actually a package, it would call this method when GraphProvider is about to /// check if node has children or not. /// </summary> /// <param name="packageItemSpec">Package reference items spec that is supposed to be associated /// with the given node</param> /// <param name="originalNode">Node to fill children for, if it's is a package</param> public void UpdateNodeChildren(string packageItemSpec, IDependencyNode originalNode) { lock (_snapshotLock) { originalNode.RemoveAllChildren(); if (!CurrentSnapshot.NodesCache.TryGetValue(originalNode.Id, out IDependencyNode node)) { if (!CurrentSnapshot.DependenciesWorld.TryGetValue(packageItemSpec, out DependencyMetadata dependencyMetadata)) { return; } node = GetDependencyNode(originalNode.Id, dependencyMetadata); } if (node == null) { return; } var nodeChildren = node.Children; foreach (var child in nodeChildren) { originalNode.AddChild(child); } } }
private void AddIntoDAG(IDependencyNode node, DAG <IDependencyNode> dag) { if (Excluded(node)) { return; } dag.Add(node); var projectNode = node as ProjectNode; if (null == projectNode) { return; } var referenceNodes = context.LoadAssemblyNodes(projectNode.AssemblyReferences) .Where(n => !Excluded(n)).ToArray(); Array.ForEach(referenceNodes, p => AddReferenceIntoDAG(p, dag, projectNode)); var projectReferences = projectNode.ProjectReferences .Where(n => !Excluded(n.Node)).ToArray(); Array.ForEach(projectReferences, p => AddProjectReferenceIntoDAG(dag, p.Node, projectNode)); var runtimeReferenceNodes = context.LoadAssemblyNodes(projectNode.RuntimeReferences) .Where(n => !Excluded(n)).ToArray(); Array.ForEach(runtimeReferenceNodes, p => AddReferenceIntoDAG(p, dag, projectNode)); }
private GraphNode DoAddGraphNode(GraphNodeId graphNodeId, IGraphContext graphContext, string projectPath, IProjectDependenciesSubTreeProvider subTreeProvider, GraphNode parentNode, IDependencyNode nodeInfo) { var newNode = graphContext.Graph.Nodes.GetOrCreate(graphNodeId, nodeInfo.Caption, null); newNode.SetValue(DgmlNodeProperties.Icon, GetIconStringName(nodeInfo.Icon)); newNode.SetValue(DependenciesGraphSchema.DependencyNodeProperty, nodeInfo); // priority sets correct order among peers newNode.SetValue(CodeNodeProperties.SourceLocation, new SourceLocation(projectPath, new Position(nodeInfo.Priority, 0))); newNode.SetValue(DependenciesGraphSchema.ProviderProperty, subTreeProvider); newNode.AddCategory(DependenciesGraphSchema.CategoryDependency); graphContext.OutputNodes.Add(newNode); if (parentNode != null) { graphContext.Graph.Links.GetOrCreate(parentNode, newNode, /*label*/ null, CodeLinkCategories.Contains); } return(newNode); }
private GraphNodeId GetTopLevelGraphNodeId(string projectPath, IDependencyNode nodeInfo) { var partialValues = new List <GraphNodeId> { GraphNodeId.GetPartial(CodeGraphNodeIdName.Assembly, new Uri(projectPath, UriKind.RelativeOrAbsolute)) }; var projectFolder = Path.GetDirectoryName(projectPath)?.ToLowerInvariant(); if (nodeInfo.Flags.Contains(DependencyNode.CustomItemSpec)) { if (nodeInfo.Name != null) { partialValues.Add(GraphNodeId.GetPartial( CodeGraphNodeIdName.File, new Uri(Path.Combine(projectFolder, nodeInfo.Name.ToLowerInvariant()), UriKind.RelativeOrAbsolute))); } } else { var fullItemSpecPath = MakeRooted(projectFolder, nodeInfo.Id.ItemSpec); if (!string.IsNullOrEmpty(fullItemSpecPath)) { partialValues.Add(GraphNodeId.GetPartial(CodeGraphNodeIdName.File, new Uri(fullItemSpecPath.ToLowerInvariant(), UriKind.RelativeOrAbsolute))); } } return(GraphNodeId.GetNested(partialValues.ToArray())); }
public override Task <IEnumerable <IDependencyNode> > SearchAsync(IDependencyNode node, string searchTerm) { lock (_snapshotLock) { DependencyMetadata rootDependency = null; if (!CurrentSnapshot.DependenciesWorld.TryGetValue(node.Id.ItemSpec, out rootDependency)) { return(Task.FromResult <IEnumerable <IDependencyNode> >(null)); } var flatMatchingDependencies = new HashSet <DependencyMetadata>(); foreach (var kvp in CurrentSnapshot.DependenciesWorld) { if (kvp.Value.Name.ToLowerInvariant().Contains(searchTerm) || kvp.Value.Version.ToLowerInvariant().Contains(searchTerm)) { flatMatchingDependencies.Add(kvp.Value); } } if (flatMatchingDependencies.Count <= 0) { return(Task.FromResult <IEnumerable <IDependencyNode> >(null)); } return(Task.FromResult <IEnumerable <IDependencyNode> >( SearchRecursive(rootDependency, flatMatchingDependencies))); } }
public static void GetTemplateTypeDependencies(ref DependencyList dependencies, NodeFactory factory, TypeDesc type) { if (!factory.MetadataManager.SupportsReflection) { return; } TypeDesc templateType = ConvertArrayOfTToRegularArray(factory, type); if (!IsEligibleToHaveATemplate(templateType)) { return; } if ((factory.Target.Abi == TargetAbi.ProjectN) && !ProjectNDependencyBehavior.EnableFullAnalysis) { // If the type does not have fully constructed type, don't track its dependencies. // TODO: Remove the workaround once we stop using the STS dependency analysis. IDependencyNode node = factory.MaximallyConstructableType(templateType); if (!node.Marked) { return; } } dependencies = dependencies ?? new DependencyList(); dependencies.Add(new DependencyListEntry(factory.NecessaryTypeSymbol(templateType), "Template type")); dependencies.Add(new DependencyListEntry(factory.NativeLayout.TemplateTypeLayout(templateType), "Template Type Layout")); }
/// <summary> /// Discovers if there any changes to apply for existing node, after it's context changed. /// </summary> private bool AnyChangesToTrack(IDependencyNode node, IDependencyNode updatedNode, IDependenciesChangeDiff diff, out IEnumerable <IDependencyNode> nodesToAdd, out IEnumerable <IDependencyNode> nodesToRemove) { var existingChildren = node.Children; if (node.Flags.Contains(DependencyNode.DependsOnOtherProviders)) { var remove = new HashSet <IDependencyNode>(diff.RemovedNodes); var add = new HashSet <IDependencyNode>(diff.AddedNodes); foreach (var changedNode in diff.UpdatedNodes) { remove.Add(changedNode); add.Add(changedNode); } nodesToAdd = add; nodesToRemove = remove; } else { var updatedChildren = updatedNode.Children; var comparer = new DependencyNodeResolvedStateComparer(); nodesToRemove = existingChildren.Except(updatedChildren, comparer).ToList(); nodesToAdd = updatedChildren.Except(existingChildren, comparer).ToList(); } return(nodesToAdd.Any() || nodesToRemove.Any()); }
/// <summary> /// Finds IProjectTree node in the top level children of a given parent IProjectTree node. /// Depending on the type of IDependencyNode search method is different: /// - if dependency node has custom ItemSpec, we only can find it by caption. /// - if dependency node has normal ItemSpec, we first try to find it by path and then /// by caption if path was not found (since unresolved and resolved items can have /// different items specs). /// </summary> private IProjectTree FindProjectTreeNode(IProjectTree parentNode, IDependencyNode nodeInfo, string projectFolder) { IProjectTree treeNode = null; if (nodeInfo.Flags.Contains(DependencyNode.CustomItemSpec)) { treeNode = parentNode.FindNodeByCaption(nodeInfo.Caption); } else { var itemSpec = nodeInfo.Id.ItemSpec; if (!ManagedPathHelper.IsRooted(itemSpec)) { itemSpec = ManagedPathHelper.TryMakeRooted(projectFolder, itemSpec); } if (!string.IsNullOrEmpty(itemSpec)) { treeNode = parentNode.FindNodeByPath(itemSpec); } if (treeNode == null) { treeNode = parentNode.FindNodeByCaption(nodeInfo.Caption); } } return(treeNode); }
private IEnumerable <Registration> ConvertNodeToRegistration(IDependencyNode node) { var implementationType = node.Node as Type; var attrs = implementationType.CustomAttribute(RegistrationType, false).OfType <RegistrationAttribute>(); return(attrs.Select(r => new Registration(r, implementationType))); }
private int Compare(IDependencyNode n1, IDependencyNode n2) { if (n1.Kind == DependencyNodeKind.Normal) { if (n2.Kind == DependencyNodeKind.Cyclic) { return(-1); } return(resourceComparer(n1.Resource, n2.Resource)); } else if (n2.Kind == DependencyNodeKind.Normal) { if (n1.Kind == DependencyNodeKind.Cyclic) { return(1); } return(resourceComparer(n1.Resource, n2.Resource)); } Contract.Assert(sccs != null); Contract.Assert(n1.InternalNodes.Count > 0 && n2.InternalNodes.Count > 0); return(resourceComparer(n1.InternalNodes.GetSomeElement().Resource, n2.InternalNodes.GetSomeElement().Resource)); }
private IDependencyNode CreateDependencyNode(DependencyMetadata dependencyMetadata, DependencyNodeId id = null, bool topLevel = true) { if (id == null) { var uniqueToken = topLevel ? null : Guid.NewGuid().ToString(); id = new DependencyNodeId(ProviderType, dependencyMetadata.ItemSpec, ResolvedPackageReference.PrimaryDataSourceItemType, uniqueToken); } // here based on DependencyType we create a corresponding node IDependencyNode dependencyNode = null; switch (dependencyMetadata.DependencyType) { case DependencyType.Package: dependencyNode = new PackageDependencyNode( id, name: dependencyMetadata.Name, caption: dependencyMetadata.FriendlyName, flags: NuGetSubTreeNodeFlags, properties: dependencyMetadata.Properties, resolved: dependencyMetadata.Resolved); break; case DependencyType.Assembly: case DependencyType.FrameworkAssembly: dependencyNode = new PackageAssemblyDependencyNode( id, caption: dependencyMetadata.Name, flags: NuGetSubTreeNodeFlags, properties: dependencyMetadata.Properties, resolved: dependencyMetadata.Resolved); break; case DependencyType.AnalyzerAssembly: dependencyNode = new PackageAnalyzerAssemblyDependencyNode( id, caption: dependencyMetadata.Name, flags: NuGetSubTreeNodeFlags, properties: dependencyMetadata.Properties, resolved: dependencyMetadata.Resolved); break; default: dependencyNode = new PackageUnknownDependencyNode( id, caption: dependencyMetadata.Name, flags: NuGetSubTreeNodeFlags, properties: dependencyMetadata.Properties, resolved: dependencyMetadata.Resolved); break; } return(dependencyNode); }
private void AddProjectReferenceIntoDAG(DAG <IDependencyNode> dag, IDependencyNode p, IDependencyNode project) { if (!dag.Contains(p)) { AddIntoDAG(p, dag); } dag.AddMergePath(project, p); }
private void AddProjectReferenceIntoDAG(DAG<IDependencyNode> dag, IDependencyNode p, IDependencyNode project) { if (!dag.Contains(p)) { AddIntoDAG(p, dag); } dag.AddMergePath(project, p); }
public void AddDependencyNode(IDependencyNode node) { _nodes.Add(node); if (_isStarted) { node.OnDependencyStart(this); } }
/// <summary> /// Adds a child to the node /// </summary> /// <param name="childNode">child node to be added. Should not be null.</param> public void AddChild(IDependencyNode childNode) { Requires.NotNull(childNode, nameof(childNode)); lock (_childrenLock) { _children = _children.Add(childNode); } }
public void RemoveChild(IDependencyNode childNode) { Requires.NotNull(childNode, nameof(childNode)); if (_children.Contains(childNode)) { _children.Remove(childNode); } }
public bool Equals(IDependencyNode other) { if (other != null && other.Id.Equals(Id)) { return(true); } return(false); }
public void AddCompilationDiscoveredDependency(IDependencyNode <NodeFactory> node, string reason) { Debug.Assert(!_dependenciesQueried); if (_compilationDiscoveredDependencies == null) { _compilationDiscoveredDependencies = new List <DependencyListEntry>(); } _compilationDiscoveredDependencies.Add(new DependencyNodeCore <NodeFactory> .DependencyListEntry(node, reason)); }
public void NameNotNull(IDependencyNode node) { if (node is null) { throw new ArgumentNullException(nameof(node)); } Assert.NotNull(node.Name); }
public void SetRootNode(IDependencyNode node) { RootNode = node; if (node.Children != null) { SetCurrentSnapshot(node.Children); } }
public static void SetRequireNodes(this IDependencyNode node, IEnumerable <NodeProfile> requireNodes) { node.Sources.Clear(); node.Destinations.Clear(); foreach (var d in requireNodes) { node.Destinations.Add(d); } }
private GraphNode AddTopLevelGraphNode(IGraphContext graphContext, string projectPath, IProjectDependenciesSubTreeProvider subTreeProvider, IDependencyNode nodeInfo) { var newNodeId = GetTopLevelGraphNodeId(projectPath, nodeInfo); return(DoAddGraphNode(newNodeId, graphContext, projectPath, subTreeProvider, null, nodeInfo)); }
public DependencyNode(ModuleFactory factory, Type moduleType, IDependencyNode root) { _factory = factory; ModuleType = moduleType; Root = root; Dependencies = new DependencyTree(factory, Root); }
public override Task <IEnumerable <IDependencyNode> > SearchAsync(IDependencyNode node, string searchTerm) { if (!IsImplicit(node, out string packageItemSpec)) { return(base.SearchAsync(node, searchTerm)); } return(NuGetPackagesDataProvider.SearchAsync(packageItemSpec, searchTerm)); }
private void RemoveNodeFromCacheRecursive(IDependencyNode node) { NodesCache.Remove(node.Id); foreach (var childNode in node.Children) { RemoveNodeFromCacheRecursive(childNode); } }
private GraphNode AddGraphNode(IGraphContext graphContext, string projectPath, IProjectDependenciesSubTreeProvider subTreeProvider, GraphNode parentNode, IDependencyNode nodeInfo) { var newNodeId = GetGraphNodeId(projectPath, nodeInfo); return(DoAddGraphNode(newNodeId, graphContext, projectPath, subTreeProvider, parentNode, nodeInfo)); }
public void SharedStateTest(IDependencyNode node) { if (node is null) { throw new ArgumentNullException(nameof(node)); } Assert.NotNull(node.SharedState); Assert.Equal(node.SharedState, SharedState); }
private GraphNodeId GetGraphNodeId(string projectPath, IDependencyNode nodeInfo) { var partialValues = new List <GraphNodeId>(); partialValues.Add(GraphNodeId.GetPartial(CodeGraphNodeIdName.Assembly, new Uri(projectPath, UriKind.RelativeOrAbsolute))); partialValues.Add(GraphNodeId.GetPartial(CodeGraphNodeIdName.File, new Uri(nodeInfo.Id.ToString().ToLowerInvariant(), UriKind.RelativeOrAbsolute))); return(GraphNodeId.GetNested(partialValues.ToArray())); }
public override bool Equals(object obj) { IDependencyNode other = obj as IDependencyNode; if (other != null) { return(Equals(other)); } return(false); }
public void AddChildToNodeInCache(string itemSpec, IDependencyNode childNode) { var node = CurrentSnapshot.NodesCache.FirstOrDefault( x => x.Key.ItemSpec.Equals(itemSpec, StringComparison.OrdinalIgnoreCase)).Value; if (node == null) { return; } node.AddChild(childNode); }
/// <summary> /// Checks if given node has children and adds corresponding IDependencyDescription to the node. /// </summary> private async Task CheckChildrenAsync(IGraphContext graphContext) { foreach (var inputGraphNode in graphContext.InputNodes) { if (graphContext.CancelToken.IsCancellationRequested) { return; } // All graph nodes generated here will have this unique node id, root node will have it equal to null var nodeIdString = GetPartialValueFromGraphNodeId(inputGraphNode.Id, CodeGraphNodeIdName.File); var nodeId = DependencyNodeId.FromString(nodeIdString); if (nodeId == null) { continue; } var projectPath = GetPartialValueFromGraphNodeId(inputGraphNode.Id, CodeGraphNodeIdName.Assembly); if (string.IsNullOrEmpty(projectPath)) { continue; } var subTreeProvider = await GetSubTreeProviderAsync(graphContext, inputGraphNode, projectPath, nodeId).ConfigureAwait(false); if (subTreeProvider == null) { continue; } IDependencyNode nodeInfo = subTreeProvider.GetDependencyNode(nodeId); if (nodeInfo == null) { continue; } using (var scope = new GraphTransactionScope()) { inputGraphNode.SetValue(DependenciesGraphSchema.ProviderProperty, subTreeProvider); inputGraphNode.SetValue(DependenciesGraphSchema.DependencyNodeProperty, nodeInfo); if (nodeInfo.HasChildren) { inputGraphNode.SetValue(DgmlNodeProperties.ContainsChildren, true); } scope.Complete(); } } }
private void AddReferenceIntoDAG(IDependencyNode child, DAG<IDependencyNode> dag, IDependencyNode parent) { var project = child as ProjectNode; if (project != null) { if (!dag.Contains(project)) { AddIntoDAG(project, dag); } dag.AddPath(parent, child); } var assemblyReference = child as AssemblyNode; if (assemblyReference != null) { dag.AddMergePath(parent, child); } }
private void AddIntoDAG(IDependencyNode node, DAG<IDependencyNode> dag) { if (Excluded(node)) { return; } dag.Add(node); var projectNode = node as ProjectNode; if (null == projectNode) { return; } var referenceNodes = context.LoadAssemblyNodes(projectNode.AssemblyReferences) .Where(n => !Excluded(n)).ToArray(); Array.ForEach(referenceNodes, p => AddReferenceIntoDAG(p, dag, projectNode)); var projectReferences = projectNode.ProjectReferences .Where(n => !Excluded(n.Node)).ToArray(); Array.ForEach(projectReferences, p => AddProjectReferenceIntoDAG(dag, p.Node, projectNode)); var runtimeReferenceNodes = context.LoadAssemblyNodes(projectNode.RuntimeReferences) .Where(n => !Excluded(n)).ToArray(); Array.ForEach(runtimeReferenceNodes, p => AddReferenceIntoDAG(p, dag, projectNode)); }
public void AddDependencyNode(IDependencyNode node) { _nodes.Add (node); if (_isStarted) node.OnDependencyStart (this); }
private static bool MatchEnd(IDependencyNode dependencyNode, IEnumerable<string> endPaths) { return endPaths.Any(p => p == dependencyNode.GetPath()); }
private bool Excluded(IDependencyNode node) { var path = node.GetPath(); return Excluded(path); }