private void AddArea(TfsTeamProjectCollection tpc, string teamProject, string nodeValue, string parentValue = "")
        {
            try
            {
                // Get service and hierarchy

                ICommonStructureService css     = tpc.GetService <ICommonStructureService>();
                ProjectInfo             project = css.GetProjectFromName(teamProject);
                NodeInfo[] hierarchy            = css.ListStructures(project.Uri);
                XmlElement tree;
                if (hierarchy[0].Name.ToLower() == "area")
                {
                    tree = css.GetNodesXml(new string[] { hierarchy[0].Uri }, true);
                }
                else
                {
                    tree = css.GetNodesXml(new string[] { hierarchy[1].Uri }, true);
                }

                string parentUri = "";
                if (parentValue == "")
                {
                    parentUri = tree.FirstChild.Attributes["NodeID"].Value;
                }
                else
                {
                    parentUri = tree.SelectSingleNode("//Children/Node[@Name='" + parentValue + "']").Attributes["NodeID"].Value;
                }
                css.CreateNode(nodeValue, parentUri);
            }
            catch
            {
            }
        }
        public Dictionary <string, string> PopulateIterations()
        {
            ICommonStructureService css = (ICommonStructureService)tfs.GetService(typeof(ICommonStructureService));
            //Gets Area/Iteration base Project
            ProjectInfo projectInfo = css.GetProjectFromName(projectName);

            NodeInfo[]      nodes          = css.ListStructures(projectInfo.Uri);
            XmlElement      areaTree       = css.GetNodesXml(new[] { nodes.Single(n => n.StructureType == "ProjectModelHierarchy").Uri }, true);
            XmlElement      iterationsTree = css.GetNodesXml(new[] { nodes.Single(n => n.StructureType == "ProjectLifecycle").Uri }, true);
            XmlNode         areaNodes      = areaTree.ChildNodes[0];
            Queue <XmlNode> nodesToDo      = new Queue <XmlNode>();

            nodesToDo.Enqueue(iterationsTree.ChildNodes[0]);

            var map = new Dictionary <string, string>();

            while (nodesToDo.Any())
            {
                var current = nodesToDo.Dequeue();

                var path   = current.Attributes["Path"].Value;
                var nodeId = current.Attributes["NodeID"].Value;

                map.Add(path, nodeId);
                foreach (XmlNode item in current.ChildNodes)
                {
                    foreach (XmlNode child in ((XmlNode)item).ChildNodes)
                    {
                        nodesToDo.Enqueue(child);
                    }
                }
            }

            return(map);
        }
Example #3
0
        public void TestGetListOfIterationPaths()
        {
            ICommonStructureService css = connect.ProjectCollection.GetService <ICommonStructureService>();

            ProjectInfo projectInfo = css.GetProjectFromName("MARKETING TEMP");

            NodeInfo[] nodes = css.ListStructures(projectInfo.Uri);



            //GetNodes can use with:

            //Area = 1

            //Iteration = 0

            XmlElement AreaTree = css.GetNodesXml(new string[] { nodes[1].Uri }, true);

            XmlElement IterationsTree = css.GetNodesXml(new string[] { nodes[0].Uri }, true);

            XmlNode AreaNodes = AreaTree.ChildNodes[0];

            XmlNode IterationsNodes = IterationsTree.ChildNodes[0];

            int myNodeCount = IterationsNodes.FirstChild.ChildNodes.Count;

            List <string> list = new List <string>();

            for (int i = 0; i < myNodeCount; i++)
            {
                XmlNode Node = IterationsNodes.ChildNodes[0].ChildNodes[i];


                var x = AddNodeItem(Node);

                list.Add(Node.Attributes["Name"].Value);

                if (Node.HasChildNodes)
                {
                    foreach (XmlNodeList childNode in Node.ChildNodes)
                    {
                        //list.AddRange(AddNodeItem(Node, childNode.Item(0)));


//                        foreach (XmlNode n in childNode)
//                        {
//
//                        }
                    }
                }
            }
        }
        /* Return Areas and Iterations of the project */
        public XmlNode[] PopulateIterations()
        {
            ICommonStructureService css = (ICommonStructureService)tfs.GetService(typeof(ICommonStructureService));
            //Gets Area/Iteration base Project
            ProjectInfo projectInfo = css.GetProjectFromName(projectName);

            NodeInfo[] nodes           = css.ListStructures(projectInfo.Uri);
            XmlElement areaTree        = css.GetNodesXml(new[] { nodes.Single(n => n.StructureType == "ProjectModelHierarchy").Uri }, true);
            XmlElement iterationsTree  = css.GetNodesXml(new[] { nodes.Single(n => n.StructureType == "ProjectLifecycle").Uri }, true);
            XmlNode    areaNodes       = areaTree.ChildNodes[0];
            XmlNode    iterationsNodes = iterationsTree.ChildNodes[0];

            return(new XmlNode[] { areaNodes, iterationsNodes });
        }
        private void ProcessCommonStructure(string treeTypeSource, string treeTypeTarget)
        {
            Log.LogDebug("NodeStructureEnricher.ProcessCommonStructure({treeTypeSource}, {treeTypeTarget})", treeTypeSource, treeTypeTarget);
            NodeInfo sourceNode = (from n in _sourceRootNodes where n.Path.Contains(treeTypeSource) select n).Single();

            if (sourceNode == null) // May run into language problems!!! This is to try and detect that
            {
                Exception ex = new Exception(string.Format("Unable to load Common Structure for Source. This is usually due to diferent language versions. Validate that '{0}' is the correct name in your version. ", treeTypeSource));
                Log.LogError(ex, "Unable to load Common Structure for Source.");
                throw ex;
            }
            XmlElement sourceTree = _sourceCommonStructureService.GetNodesXml(new string[] { sourceNode.Uri }, true);
            NodeInfo   structureParent;

            try // May run into language problems!!! This is to try and detect that
            {
                structureParent = _targetCommonStructureService.GetNodeFromPath(string.Format("\\{0}\\{1}", Engine.Target.Config.AsTeamProjectConfig().Project, treeTypeTarget));
            }
            catch (Exception ex)
            {
                Exception ex2 = new Exception(string.Format("Unable to load Common Structure for Target.This is usually due to diferent language versions. Validate that '{0}' is the correct name in your version. ", treeTypeTarget), ex);
                Log.LogError(ex2, "Unable to load Common Structure for Target.");
                throw ex2;
            }
            if (_prefixProjectToNodes)
            {
                structureParent = CreateNode(Engine.Source.Config.AsTeamProjectConfig().Project, structureParent, null, null);
            }
            if (sourceTree.ChildNodes[0].HasChildNodes)
            {
                CreateNodes(sourceTree.ChildNodes[0].ChildNodes[0].ChildNodes, structureParent, treeTypeTarget);
            }
        }
        private void ProcessCommonStructure(string treeTypeSource, string treeTypeTarget, NodeInfo[] sourceNodes, ICommonStructureService targetCss, ICommonStructureService sourceCss)
        {
            NodeInfo sourceNode = (from n in sourceNodes where n.Path.Contains(treeTypeSource) select n).Single();

            if (sourceNode == null) // May run into language problems!!! This is to try and detect that
            {
                Exception ex = new Exception(string.Format("Unable to load Common Structure for Source. This is usually due to diferent language versions. Validate that '{0}' is the correct name in your version. ", treeTypeSource));
                Log.Error(ex, "Unable to load Common Structure for Source.");
                throw ex;
            }
            XmlElement sourceTree = sourceCss.GetNodesXml(new string[] { sourceNode.Uri }, true);
            NodeInfo   structureParent;

            try // May run into language problems!!! This is to try and detect that
            {
                structureParent = targetCss.GetNodeFromPath(string.Format("\\{0}\\{1}", me.Target.Config.Project, treeTypeTarget));
            }
            catch (Exception ex)
            {
                Exception ex2 = new Exception(string.Format("Unable to load Common Structure for Target.This is usually due to diferent language versions. Validate that '{0}' is the correct name in your version. ", treeTypeTarget), ex);
                Log.Error(ex2, "Unable to load Common Structure for Target.");
                throw ex2;
            }
            if (_config.PrefixProjectToNodes)
            {
                structureParent = CreateNode(targetCss, me.Source.Config.Project, structureParent);
            }
            if (sourceTree.ChildNodes[0].HasChildNodes)
            {
                CreateNodes(sourceTree.ChildNodes[0].ChildNodes[0].ChildNodes, targetCss, structureParent, treeTypeTarget);
            }
        }
Example #7
0
        private void ProcessCommonStructure(string treeType, NodeInfo[] sourceNodes, ICommonStructureService targetCss, ICommonStructureService sourceCss)
        {
            NodeInfo sourceNode = null;

            sourceNode = (from n in sourceNodes where n.Path.Contains(treeType) select n)?.SingleOrDefault();
            if (sourceNode == null && treeType == "Iteration")
            {
                sourceNode = (from n in sourceNodes where n.Name.Equals("Milestone", StringComparison.OrdinalIgnoreCase) select n)?.SingleOrDefault();
            }
            if (sourceNode == null)
            {
                throw new Exception($"No elements found in the sequence for the tree type {treeType}. Please check the process template and project details.");
            }

            XmlElement sourceTree      = sourceCss.GetNodesXml(new string[] { sourceNode.Uri }, true);
            NodeInfo   structureParent = targetCss.GetNodeFromPath(string.Format("\\{0}\\{1}", me.Target.Name, treeType));

            if (config.PrefixProjectToNodes)
            {
                structureParent = CreateNode(targetCss, me.Source.Name, structureParent);
            }
            if (sourceTree.ChildNodes[0].HasChildNodes)
            {
                CreateNodes(sourceTree.ChildNodes[0].ChildNodes[0].ChildNodes, targetCss, structureParent, treeType);
            }
        }
        /* Return Areas and Iterations of the project */
        public XmlNode[] PopulateIterations()
        {
            ICommonStructureService css = (ICommonStructureService)tfs.GetService(typeof(ICommonStructureService));
            //Gets Area/Iteration base Project
            ProjectInfo projectInfo = css.GetProjectFromName(projectName);

            NodeInfo[] nodes = css.ListStructures(projectInfo.Uri);

            //GetNodes can use with:
            //Area = 0
            //Iteration = 1
            XmlElement AreaTree       = css.GetNodesXml(new string[] { nodes[0].Uri }, true);
            XmlElement IterationsTree = css.GetNodesXml(new string[] { nodes[1].Uri }, true);

            XmlNode AreaNodes       = AreaTree.ChildNodes[0];
            XmlNode IterationsNodes = IterationsTree.ChildNodes[0];

            return(new XmlNode[] { AreaNodes, IterationsNodes });
        }
        public void RemoveAreas()
        {
            try
            {
                TfsTeamProjectCollection tpc = TfsConnect();
                ICommonStructureService  css = tpc.GetService <ICommonStructureService>();
                ProjectInfo project          = css.GetProjectFromName(TeamProject);
                NodeInfo[]  hierarchy        = css.ListStructures(project.Uri);
                XmlElement  tree;
                if (hierarchy[0].Name.ToLower() == "area")
                {
                    tree = css.GetNodesXml(new string[] { hierarchy[0].Uri }, true);
                }
                else
                {
                    tree = css.GetNodesXml(new string[] { hierarchy[1].Uri }, true);
                }
                string parentUri = tree.FirstChild.Attributes["NodeID"].Value;

                // Enumerate nodes

                if (tree.HasChildNodes)
                {
                    XmlNode childrenNode = tree.FirstChild;
                    if (childrenNode.HasChildNodes && childrenNode.FirstChild.HasChildNodes)
                    {
                        string[] nodes = new string[childrenNode.ChildNodes[0].ChildNodes.Count];
                        for (int i = 0; i < childrenNode.ChildNodes[0].ChildNodes.Count; i++)
                        {
                            XmlNode node = childrenNode.ChildNodes[0].ChildNodes[i];
                            nodes[i] = node.Attributes["NodeID"].Value;
                        }
                        css.DeleteBranches(nodes, parentUri);
                    }
                }
                Console.WriteLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.Message);
                throw;
            }
        }
Example #10
0
        /// <summary>
        /// Initializes a new instance of Iteration class for a TFS projet name.
        /// </summary>
        /// <param name="tfs"></param>
        /// <param name="projectName"></param>
        internal Iterations(TfsTeamProjectCollection tfs, string projectName)
        {
            this._projectName = projectName;

            ICommonStructureService css         = (ICommonStructureService)tfs.GetService(typeof(ICommonStructureService));
            ProjectInfo             projectInfo = css.GetProjectFromName(projectName);

            NodeInfo[] nodes          = css.ListStructures(projectInfo.Uri);
            NodeInfo   node           = nodes.Where(item => item.StructureType == "ProjectLifecycle").Single();
            XmlElement IterationsTree = css.GetNodesXml(new string[] { node.Uri }, true);

            this.FillItemsList(IterationsTree.FirstChild);
        }
        private void ProcessCommonStructure(string treeType, NodeInfo[] sourceNodes, ICommonStructureService targetCss, ICommonStructureService sourceCss)
        {
            NodeInfo   sourceNode      = (from n in sourceNodes where n.Path.Contains(treeType) select n).Single();
            XmlElement sourceTree      = sourceCss.GetNodesXml(new string[] { sourceNode.Uri }, true);
            NodeInfo   structureParent = targetCss.GetNodeFromPath(string.Format("\\{0}\\{1}", me.Target.Name, treeType));

            if (config.PrefixProjectToNodes)
            {
                structureParent = CreateNode(targetCss, me.Source.Name, structureParent);
            }
            if (sourceTree.ChildNodes[0].HasChildNodes)
            {
                CreateNodes(sourceTree.ChildNodes[0].ChildNodes[0].ChildNodes, targetCss, structureParent, treeType);
            }
        }
        /// <summary>
        /// Gets the project areas.
        /// </summary>
        /// <returns>list of areas names as string list</returns>
        private List <string> GetProjectAreas()
        {
            List <string>           areas = new List <string>();
            ICommonStructureService css   = (ICommonStructureService)TestCaseManagerCore.ExecutionContext.TfsTeamProjectCollection.GetService(typeof(ICommonStructureService));

            log.InfoFormat("Get All Areas for Project= {0}", TestCaseManagerCore.ExecutionContext.Preferences.TestProjectName);
            ProjectInfo projectInfo = css.GetProjectFromName(TestCaseManagerCore.ExecutionContext.Preferences.TestProjectName);

            NodeInfo[] nodes = css.ListStructures(projectInfo.Uri);
            foreach (NodeInfo currentNode in nodes)
            {
                if (currentNode.Name.Equals("Area"))
                {
                    XmlElement areaTree = css.GetNodesXml(new string[] { currentNode.Uri }, true);
                    areas.Clear();
                    XmlNode areaNodes = areaTree.ChildNodes[0];
                    this.CreateAreasList(areaNodes, areas);
                }
            }

            return(areas);
        }