public TfsNodeStructureEnricher(IMigrationEngine engine, ILogger <TfsNodeStructureEnricher> logger) : base(engine, logger)
 {
     _sourceCommonStructureService = (ICommonStructureService)Engine.Source.GetService <ICommonStructureService>();
     _targetCommonStructureService = (ICommonStructureService)Engine.Target.GetService <ICommonStructureService4>();
     _sourceProjectInfo            = _sourceCommonStructureService.GetProjectFromName(Engine.Source.Config.AsTeamProjectConfig().Project);
     _sourceRootNodes = _sourceCommonStructureService.ListStructures(_sourceProjectInfo.Uri);
 }
        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);
        }
示例#3
0
        /// <summary>
        /// Initializes URI of root area and iteration nodes.
        /// </summary>
        private void GetRootNodes()
        {
            if (!m_hasRootNodes)
            {
                ICommonStructureService css = Css;
                NodeInfo[] nodes            = css.ListStructures(m_store.Projects[m_cfg.Project].Uri.ToString());
                string     areaUri          = null;
                string     iterationUri     = null;

                for (int i = 0; i < nodes.Length; i++)
                {
                    NodeInfo n = nodes[i];

                    if (TFStringComparer.CssStructureType.Equals(n.StructureType, "ProjectLifecycle"))
                    {
                        iterationUri = n.Uri;
                    }
                    else if (TFStringComparer.CssStructureType.Equals(n.StructureType, "ProjectModelHierarchy"))
                    {
                        areaUri = n.Uri;
                    }
                }

                m_areaNodeUri      = areaUri;
                m_iterationNodeUri = iterationUri;
                m_hasRootNodes     = true;
            }
        }
示例#4
0
        /// <summary>
        /// Set the root node URI for Area Path and Iteration Path
        /// </summary>
        /// <param name="css">Handle to Common Structure Services</param>
        /// <param name="projectName">Team Foundation Project Name</param>
        private static void SetDefaultCSSUri(ICommonStructureService css, string projectName)
        {
            if (RootAreaNodeUri == null &&
                RootIterationNodeUri == null)
            {
                ProjectInfo m_project       = css.GetProjectFromName(projectName);
                NodeInfo[]  nodes           = css.ListStructures(m_project.Uri);
                bool        fFoundArea      = false;
                bool        fFoundIteration = false;
                for (int i = 0; (fFoundArea == false || fFoundIteration == false) && i < nodes.Length; i++)
                {
                    if (!fFoundArea &&
                        string.Equals(nodes[i].StructureType, VSTSConstants.AreaRoot, StringComparison.OrdinalIgnoreCase))
                    {
                        RootAreaNodeUri = nodes[i].Uri;
                        fFoundArea      = true;
                    }

                    if (!fFoundIteration &&
                        string.Equals(nodes[i].StructureType, VSTSConstants.IterationRoot, StringComparison.OrdinalIgnoreCase))
                    {
                        RootIterationNodeUri = nodes[i].Uri;
                        fFoundIteration      = true;
                    }
                }
            }
        }
        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
            {
            }
        }
示例#6
0
        internal static string GetAreaRootNodeUri(string projectUri)
        {
            string nodeUri = String.Empty;

            ICommonStructureService cssProxy = (ICommonStructureService)GetProxy(m_teamSystemName, typeof(ICommonStructureService));

            NodeInfo[] nodeInfos = cssProxy.ListStructures(projectUri);

            if (nodeInfos == null)
            {
                throw new ConverterException(VSTSResource.InvalidStructureNode);
            }

            foreach (NodeInfo nodeInfo in nodeInfos)
            {
                if (TFStringComparer.StructureType.Equals(nodeInfo.StructureType, StructureType.ProjectModelHierarchy))
                {
                    nodeUri = nodeInfo.Uri;
                    break;
                }
            }

            if (String.IsNullOrEmpty(nodeUri))
            {
                throw new ConverterException(VSTSResource.InvalidStructureNode);
            }

            return(nodeUri);
        }
示例#7
0
 public NodeStructureEnricher(IMigrationEngine engine)
 {
     Engine = engine;
     _sourceCommonStructureService = (ICommonStructureService)Engine.Source.GetService <ICommonStructureService>();
     _targetCommonStructureService = (ICommonStructureService)Engine.Target.GetService <ICommonStructureService4>();
     _sourceProjectInfo            = _sourceCommonStructureService.GetProjectFromName(Engine.Source.Config.Project);
     _sourceRootNodes = _sourceCommonStructureService.ListStructures(_sourceProjectInfo.Uri);
 }
示例#8
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)
//                        {
//
//                        }
                    }
                }
            }
        }
示例#9
0
        /// <summary>
        /// Feed project properties
        /// </summary>
        /// <remarks>keep in the source code for futur use</remarks>
        /// <param name="tpc"></param>
        /// <param name="teamProjectNodes"></param>
        private static void FeedProjectPropertiesData(TfsTeamProjectCollection tpc, string projectUri)
        {
            ICommonStructureService css = tpc.GetService <ICommonStructureService3>();
            string projectName2;
            int    templateId;
            string state;

            ProjectProperty[] properties;
            css.GetProjectProperties(projectUri, out projectName2, out state, out templateId, out properties);
            ProjectInfo projectInfo = css.GetProject(projectUri);

            NodeInfo[] nodeInfo = css.ListStructures(projectUri);
        }
示例#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);
        }
        /* 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 });
        }
        internal override void InternalExecute()
        {
            //////////////////////////////////////////////////
            ICommonStructureService sourceCss         = (ICommonStructureService)me.Source.Collection.GetService(typeof(ICommonStructureService));
            ProjectInfo             sourceProjectInfo = sourceCss.GetProjectFromName(me.Source.Name);

            NodeInfo[] sourceNodes = sourceCss.ListStructures(sourceProjectInfo.Uri);
            //////////////////////////////////////////////////
            ICommonStructureService targetCss = (ICommonStructureService)me.Target.Collection.GetService(typeof(ICommonStructureService4));

            //////////////////////////////////////////////////
            ProcessCommonStructure("Area", sourceNodes, targetCss, sourceCss);
            //////////////////////////////////////////////////
            ProcessCommonStructure("Iteration", sourceNodes, targetCss, sourceCss);
            //////////////////////////////////////////////////
        }
        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;
            }
        }
        /* 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 GenerateAreas(XmlNode tree, string sourceProjectName)
        {
            ICommonStructureService css = (ICommonStructureService)tfs.GetService(typeof(ICommonStructureService));
            // get project info
            ProjectInfo projectInfo = css.GetProjectFromName(projectName);

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

            // find ProjectModelHierarchy (contains path for area node)
            var node = nodes.FirstOrDefault(n => n.StructureType == "ProjectModelHierarchy");

            if (node == null)
            {
                return;
            }

            var pathRoot = css.GetNodeFromPath(node.Path);

            if (tree.FirstChild != null)
            {
                int myNodeCount = tree.FirstChild.ChildNodes.Count;
                for (int i = 0; i < myNodeCount; i++)
                {
                    XmlNode Node = tree.ChildNodes[0].ChildNodes[i];
                    try
                    {
                        css.CreateNode(Node.Attributes["Name"].Value, pathRoot.Uri);
                    }
                    catch (Exception)
                    {
                        //node already exists
                        continue;
                    }
                    if (Node.FirstChild != null)
                    {
                        string nodePath = node.Path + "\\" + Node.Attributes["Name"].Value;
                        GenerateSubAreas(Node, nodePath, css);
                    }
                }
            }
            RefreshCache();
        }
        internal override void InternalExecute()
        {
            if (_config == null)
            {
                throw new Exception("You must call Configure() first");
            }
            //////////////////////////////////////////////////
            ICommonStructureService sourceCss         = (ICommonStructureService)me.Source.Collection.GetService(typeof(ICommonStructureService));
            ProjectInfo             sourceProjectInfo = sourceCss.GetProjectFromName(me.Source.Config.Project);

            NodeInfo[] sourceNodes = sourceCss.ListStructures(sourceProjectInfo.Uri);
            //////////////////////////////////////////////////
            ICommonStructureService targetCss = (ICommonStructureService)me.Target.Collection.GetService(typeof(ICommonStructureService4));

            //////////////////////////////////////////////////
            ProcessCommonStructure(me.Source.Config.LanguageMaps.AreaPath, me.Target.Config.LanguageMaps.AreaPath, sourceNodes, targetCss, sourceCss);
            //////////////////////////////////////////////////
            ProcessCommonStructure(me.Source.Config.LanguageMaps.IterationPath, me.Target.Config.LanguageMaps.IterationPath, sourceNodes, targetCss, sourceCss);
            //////////////////////////////////////////////////
        }
        /// <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);
        }