private static void RecurseIterations(NodeCollection sourceNodes, NodeInfo destinationRootNodeInfo, NodeCollection destinationRootNodes, Project destinationWitProject) { foreach (Node sourceIteration in sourceNodes) { NodeInfo destIterationNodeInfo = null; Node destIterationNode = null; if (destinationRootNodes.Cast <Node>().FirstOrDefault(n => n.Name == sourceIteration.Name) != null) { destIterationNode = destinationRootNodes.Cast <Node>().FirstOrDefault(n => n.Name == sourceIteration.Name); destIterationNodeInfo = _destinationStructureService.GetNode(destIterationNode.Uri.ToString()); _destinationIterationNodes.Add(destIterationNode); } if (destIterationNodeInfo == null) // node doesn't exist { string newAreaNodeUri = _destinationStructureService.CreateNode(sourceIteration.Name, destinationRootNodeInfo.Uri); destIterationNodeInfo = _destinationStructureService.GetNode(newAreaNodeUri); destIterationNode = FindIterationNode(destinationWitProject, destIterationNodeInfo.Path); _destinationIterationNodes.Add(destIterationNode); } if (sourceIteration.ChildNodes.Count > 0) { RecurseIterations(sourceIteration.ChildNodes, destIterationNodeInfo, destIterationNode.ChildNodes, destinationWitProject); } } }
public static Dictionary <int, int> GetNodeMap(NodeCollection sourceRootNodes, NodeCollection targetRootNodes, bool mapEverythingToRoot = false, int rootNode = 0) { if (mapEverythingToRoot && rootNode == 0) { rootNode = targetRootNodes[0].ParentNode.Id; } var iterationNodeMap = new Dictionary <int, int>(); foreach (Node node in sourceRootNodes) { if (mapEverythingToRoot) { iterationNodeMap.Add(node.Id, rootNode); if (node.HasChildNodes) { var r = Utils.GetNodeMap(node.ChildNodes, targetRootNodes, true, rootNode); foreach (var kvp in r) { iterationNodeMap.Add(kvp.Key, kvp.Value); } } } else { var targetNode = targetRootNodes.Cast <Node>().Where(n => n.Name == node.Name).First(); iterationNodeMap.Add(node.Id, targetNode.Id); if (node.HasChildNodes) { var r = Utils.GetNodeMap(node.ChildNodes, targetNode.ChildNodes, false, 0); foreach (var kvp in r) { iterationNodeMap.Add(kvp.Key, kvp.Value); } } } } return(iterationNodeMap); }
private static void RecurseIterations(NodeCollection sourceNodes, NodeInfo destinationRootNodeInfo, NodeCollection destinationRootNodes, Project destinationWitProject) { foreach (Node sourceIteration in sourceNodes) { NodeInfo destIterationNodeInfo = null; Node destIterationNode = null; if (destinationRootNodes.Cast<Node>().FirstOrDefault(n => n.Name == sourceIteration.Name) != null) { destIterationNode = destinationRootNodes.Cast<Node>().FirstOrDefault(n => n.Name == sourceIteration.Name); destIterationNodeInfo = _destinationStructureService.GetNode(destIterationNode.Uri.ToString()); _destinationIterationNodes.Add(destIterationNode); } if (destIterationNodeInfo == null) // node doesn't exist { string newAreaNodeUri = _destinationStructureService.CreateNode(sourceIteration.Name, destinationRootNodeInfo.Uri); destIterationNodeInfo = _destinationStructureService.GetNode(newAreaNodeUri); destIterationNode = FindIterationNode(destinationWitProject, destIterationNodeInfo.Path); _destinationIterationNodes.Add(destIterationNode); } if (sourceIteration.ChildNodes.Count > 0) { RecurseIterations(sourceIteration.ChildNodes, destIterationNodeInfo, destIterationNode.ChildNodes, destinationWitProject); } } }
public StarWarsQuery(StarWarsContext db) { Name = "Query"; Field <CharacterInterface>("hero", resolve: context => null); Field <HumanType>( "human", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <IntGraphType> > { Name = "id", Description = "id of the human" } ), resolve: context => { var id = context.GetArgument <int>("id"); Console.WriteLine("Loading human: " + id); var humans = db.Humans.Where(h => h.HumanId == id).ToList(); var collection = new NodeCollection <Human>(humans); return(collection.Single()); } ); Field <ListGraphType <HumanType> >( "humans", resolve: context => { Console.WriteLine("Loading all humans"); var humans = db.Humans.ToList(); var collection = new NodeCollection <Human>(humans); return(collection); } ); Field <DroidType>( "droid", arguments: new QueryArguments( new QueryArgument <NonNullGraphType <IntGraphType> > { Name = "id", Description = "id of the droid" } ), resolve: context => { var id = context.GetArgument <int>("id"); Console.WriteLine("Loading droid: " + id); var driods = db.Droids.Where(d => d.DroidId == id).ToList(); var collection = new NodeCollection <Droid>(driods); return(collection.Single()); } ); Field <ListGraphType <CharacterInterface> >( "characters", resolve: context => { Console.WriteLine("Loading all humans for characters"); var humans = new NodeCollection <Human>(db.Humans.ToList()); Console.WriteLine("Loading all droids for characters"); var droids = new NodeCollection <Droid>(db.Droids.ToList()); return(humans.Cast <object>().Union(droids)); } ); }