コード例 #1
0
        public override IDependencyNode GetDependencyNode(DependencyNodeId id)
        {
            lock (_snapshotLock)
            {
                IDependencyNode node = null;
                if (CurrentSnapshot.NodesCache.TryGetValue(id, out node))
                {
                    return(node);
                }

                DependencyMetadata dependencyMetadata = null;
                if (!CurrentSnapshot.DependenciesWorld.TryGetValue(id.ItemSpec, out dependencyMetadata))
                {
                    return(null);
                }

                // create node and it's direct children
                node = CreateDependencyNode(dependencyMetadata, id);
                CurrentSnapshot.NodesCache.Add(id, node);

                var frameworkAssemblies = new List <DependencyMetadata>();
                foreach (var childItemSpec in dependencyMetadata.DependenciesItemSpecs)
                {
                    DependencyMetadata childDependencyMetadata = null;
                    if (!CurrentSnapshot.DependenciesWorld.TryGetValue(childItemSpec, out childDependencyMetadata))
                    {
                        continue;
                    }

                    if (childDependencyMetadata.DependencyType == DependencyType.FrameworkAssembly)
                    {
                        frameworkAssemblies.Add(childDependencyMetadata);
                        continue;
                    }

                    node.AddChild(CreateDependencyNode(childDependencyMetadata, topLevel: false));
                }

                if (frameworkAssemblies.Count > 0)
                {
                    var frameworkAssembliesNode = CreateFrameworkAssembliesFolder();
                    node.AddChild(frameworkAssembliesNode);

                    foreach (var fxAssemblyMetadata in frameworkAssemblies)
                    {
                        frameworkAssembliesNode.AddChild(CreateDependencyNode(fxAssemblyMetadata, topLevel: false));
                    }
                }

                return(node);
            }
        }
コード例 #2
0
        /// <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);
                }
            }
        }
        public static INuGetPackagesDataProvider ImplementUpdateNodeChildren(string itemSpec,
                                                                             IDependencyNode node,
                                                                             IDependencyNode[] childrenToAdd,
                                                                             MockBehavior?mockBehavior = null)
        {
            var behavior = mockBehavior ?? MockBehavior.Default;
            var mock     = new Mock <INuGetPackagesDataProvider>(behavior);

            mock.Setup(x => x.UpdateNodeChildren(itemSpec, node));

            childrenToAdd.ToList().ForEach(x => node.AddChild(x));

            return(mock.Object);
        }