コード例 #1
0
        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 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);
 }
コード例 #3
0
        private void RefreshCache()
        {
            ICommonStructureService css    = tfs.GetService <ICommonStructureService>();
            WorkItemServer          server = tfs.GetService <WorkItemServer>();

            server.SyncExternalStructures(WorkItemServer.NewRequestId(), css.GetProjectFromName(projectName).Uri);
        }
コード例 #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;
                    }
                }
            }
        }
コード例 #5
0
        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);
        }
コード例 #6
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);
 }
コード例 #7
0
ファイル: VSConnectTest.cs プロジェクト: lopperman/VSUtility
        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)
//                        {
//
//                        }
                    }
                }
            }
        }
コード例 #8
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);
        }
コード例 #9
0
        /* 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 });
        }
コード例 #10
0
        public void GetProjectFromName()
        {
            // need TFS_ envvars for this test
            if (String.IsNullOrEmpty(tfsUrl))
            {
                return;
            }
            TeamFoundationServer tfs = new TeamFoundationServer(tfsUrl, credentials);

            ICommonStructureService css   = (ICommonStructureService)tfs.GetService(typeof(ICommonStructureService));
            ProjectInfo             pinfo = css.GetProjectFromName(Environment.GetEnvironmentVariable("TFS_PROJECT"));

            Assert.IsNotNull(pinfo.Name);
            Assert.IsNotNull(pinfo.Status);
            Assert.IsNotNull(pinfo.Uri);
        }
コード例 #11
0
        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);
            //////////////////////////////////////////////////
        }
コード例 #12
0
        /* 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 });
        }
コード例 #13
0
        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;
            }
        }
コード例 #14
0
        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);
            //////////////////////////////////////////////////
        }
コード例 #16
0
        public void GetProjectProperties()
        {
            // need TFS_ envvars for this test
            if (String.IsNullOrEmpty(tfsUrl))
            {
                return;
            }
            TeamFoundationServer tfs = new TeamFoundationServer(tfsUrl, credentials);

            ICommonStructureService css = (ICommonStructureService)tfs.GetService(typeof(ICommonStructureService));
            ProjectInfo             p1  = css.GetProjectFromName(Environment.GetEnvironmentVariable("TFS_PROJECT"));

            string projectName = "";
            string state       = "";
            int    templateId  = 0;

            ProjectProperty[] properties = null;

            css.GetProjectProperties(p1.Uri, out projectName, out state, out templateId, out properties);
            Assert.IsNotNull(projectName);
        }
コード例 #17
0
        /// <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);
        }
コード例 #18
0
        private void BtnBrowseSource_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                #region TextBox
                //This region Get the Source item from User which he would like to change or Compare in this utility
                Form     _chooseItemDialog = new Form();
                Assembly controlAssembly   = Assembly.GetAssembly(typeof(Microsoft.TeamFoundation.VersionControl.Controls.ControlAddItemsExclude));
                Type     vcChooseItem      = controlAssembly.GetType("Microsoft.TeamFoundation.VersionControl.Controls.DialogChooseItem");

                ConstructorInfo ci = vcChooseItem.GetConstructor(
                    BindingFlags.Instance | BindingFlags.NonPublic,
                    null,
                    new Type[] { typeof(VersionControlServer) },
                    null);

                _chooseItemDialog = (Form)ci.Invoke(new object[] { versionControlServer });
                _chooseItemDialog.ShowDialog();


                DialogResult DialogResult = _chooseItemDialog.DialogResult;

                var  fullpath     = vcChooseItem.GetProperty("SelectedItem", BindingFlags.Instance | BindingFlags.NonPublic);
                Item selecteditem = (Item)fullpath.GetValue(_chooseItemDialog, null);
                //objTFSSourceControlClient.frmSelectedItem = selecteditem;

                if (_chooseItemDialog.DialogResult == DialogResult.OK && string.Equals(selecteditem.ItemType.ToString(), "File", StringComparison.CurrentCultureIgnoreCase))
                {
                    txtSourceFile.Text = selecteditem.ServerItem;

                    sFromFullPath = selecteditem.ServerItem.ToString();

                    MakeTOFullPath();
                }
                else
                {
                    //if user has not selected anything and then again clicks the browse button then paths are added twice
                    return;
                }
                #endregion

                #region ComboBox
                //This region will fill the comboBox for target/Destination

                ICommonStructureService structureService = (ICommonStructureService)tfsTeamProjectCollection.GetService(typeof(ICommonStructureService));
                ProjectInfo             projects         = structureService.GetProjectFromName("Allscripts PM");

                Item[]  items       = null;
                string  path        = "$/" + projects.Name.ToString();
                ItemSet itemSetTemp = versionControlServer.GetItems(path, RecursionType.OneLevel);
                items = itemSetTemp.Items;

                foreach (var item in items)
                {
                    this.cmbDestinationFolders.SelectedValuePath = "Key";
                    this.cmbDestinationFolders.DisplayMemberPath = "Value";
                    if (item.ServerItem.Contains("Main"))
                    {
                        cmbDestinationFolders.Items.Add(new KeyValuePair <string, string>(item.ServerItem, item.ServerItem.Replace("$/Allscripts PM/", string.Empty)));
                    }

                    if (item.ServerItem.Contains("Development") || item.ServerItem.Contains("Release"))
                    {
                        path        = item.ServerItem;
                        itemSetTemp = versionControlServer.GetItems(path, RecursionType.OneLevel);
                        foreach (var item1 in itemSetTemp.Items)
                        {
                            if (item1 != itemSetTemp.Items[0])
                            {
                                cmbDestinationFolders.Items.Add(new KeyValuePair <string, string>(item1.ServerItem, item1.ServerItem.Replace("$/Allscripts PM/", string.Empty)));
                            }
                        }
                    }
                }
                #endregion
            }
            catch (Exception ex)
            {
                System.Windows.MessageBox.Show(string.Format("Error Occured \n Please review Log File"), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                LogFile.WriteLine(string.Format("{0} Exception :-  {1}", DateTime.Now.ToString(@"MM/dd/yyyy HH:mm:ss.ffff"), ex.Message), objVSTS);
            }
        }