/// <summary> /// Returns refreshed dependnecy node. There is a non trivial logic which is important: /// in order to find node at anypoint of time, we always fill live node instance children collection, /// which then could be found by recusrive search from RootNode. However we return always a new /// instance for requested node, to allow graph provider to compare old node instances to new ones /// when some thing changes in the dependent project and track changes. So in /// DependenciesGrpahProvider.TrackChangesOnGraphContextAsync we always remember old children /// collection for existing node, since for top level nodes (sent by CPS IProjectTree(s) we do update /// them here, which would make no difference between old and new nodes. For lower hierarchies below top /// nodes, new instances solve this problem. /// </summary> /// <param name="nodeId"></param> /// <returns></returns> public override IDependencyNode GetDependencyNode(DependencyNodeId nodeId) { if (nodeId == null) { return(null); } // normalize id to have regular paths (graph provider replaces \ with /. nodeId = nodeId.ToNormalizedId(); var node = RootNode.FindNode(nodeId, recursive: true); if (node == null) { return(null); } if (string.IsNullOrEmpty(nodeId.UniqueToken)) { return(node); } var projectPath = nodeId.UniqueToken; var projectContext = ProjectContextProvider.GetProjectContext(projectPath); if (projectContext == null) { return(node); } node.Children.Clear(); foreach (var subTreeProvider in projectContext.GetProviders()) { if (subTreeProvider.RootNode == null || !subTreeProvider.RootNode.HasChildren) { continue; } foreach (var child in subTreeProvider.RootNode.Children) { node.AddChild(child); } } // create a new instance of the node to allow graph provider to compare changes var newNode = CreateDependencyNode(node.Id, node.Priority, node.Properties, node.Resolved); newNode.Children.AddRange(node.Children); return(newNode); }
public void DependencyNodeId_ToNormalizedId(string providerType, string itemSpec, string itemType, string uniqueToken, string contextProject, string expectedResult) { var id = new DependencyNodeId(providerType, itemSpec, itemType, uniqueToken); if (!string.IsNullOrEmpty(contextProject)) { id.ContextProject = contextProject; } Assert.Equal(expectedResult, id.ToNormalizedId().ToString()); }