Esempio n. 1
0
        private NodeInfo CreateNode(string name, NodeInfo parent)
        {
            string   nodePath = string.Format(@"{0}\{1}", parent.Path, name);
            NodeInfo node     = null;

            Trace.Write(string.Format("--CreateNode: {0}", nodePath));
            try
            {
                node = _targetCommonStructureService.GetNodeFromPath(nodePath);
                Trace.Write("...found");
            }
            catch (CommonStructureSubsystemException ex)
            {
                try
                {
                    string newPathUri = _targetCommonStructureService.CreateNode(name, parent.Uri);
                    Trace.Write("...created");
                    node = _targetCommonStructureService.GetNode(newPathUri);
                }
                catch
                {
                    Log.Error(ex, "Creating Node");
                    Trace.Write("...missing");
                    throw;
                }
            }

            Trace.WriteLine(String.Empty);
            return(node);
        }
Esempio n. 2
0
        private static void RecurseAreas(NodeCollection sourceNodes, NodeInfo destinationRootNodeInfo, NodeCollection destinationRootNodes, Project destinationWitProject)
        {
            foreach (Node sourceArea in sourceNodes)
            {
                NodeInfo destAreaNodeInfo = null;
                Node     destAreaNode     = null;

                if (destinationRootNodes.Cast <Node>().FirstOrDefault(n => n.Name == sourceArea.Name) != null)
                {
                    destAreaNode     = destinationRootNodes.Cast <Node>().FirstOrDefault(n => n.Name == sourceArea.Name);
                    destAreaNodeInfo = _destinationStructureService.GetNode(destAreaNode.Uri.ToString());

                    _destinationAreaNodes.Add(destAreaNode);
                }

                if (destAreaNodeInfo == null) // node doesn't exist
                {
                    string newAreaNodeUri = _destinationStructureService.CreateNode(sourceArea.Name, destinationRootNodeInfo.Uri);
                    destAreaNodeInfo = _destinationStructureService.GetNode(newAreaNodeUri);
                    destAreaNode     = FindAreaNode(destinationWitProject, destAreaNodeInfo.Path);

                    _destinationAreaNodes.Add(destAreaNode);
                }

                if (sourceArea.ChildNodes.Count > 0)
                {
                    RecurseAreas(sourceArea.ChildNodes, destAreaNodeInfo, destAreaNode.ChildNodes, destinationWitProject);
                }
            }
        }
Esempio n. 3
0
        private void GenerateSubAreas(XmlNode tree, string nodePath, ICommonStructureService css)
        {
            var path      = css.GetNodeFromPath(nodePath);
            int nodeCount = tree.FirstChild.ChildNodes.Count;

            for (int i = 0; i < nodeCount; i++)
            {
                XmlNode Node = tree.ChildNodes[0].ChildNodes[i];
                try
                {
                    css.CreateNode(Node.Attributes["Name"].Value, path.Uri);
                }
                catch (Exception ex)
                {
                    logger.Error(string.Format("{0}", path.Uri), ex);
                    //node already exists
                    continue;
                }
                if (Node.FirstChild != null)
                {
                    string newPath = nodePath + "\\" + Node.Attributes["Name"].Value;
                    GenerateSubAreas(Node, newPath, css);
                }
            }
        }
Esempio n. 4
0
        public void GenerateAreas(XmlNode tree, string sourceProjectName)
        {
            ICommonStructureService css = (ICommonStructureService)tfs.GetService(typeof(ICommonStructureService));
            string rootNodePath         = string.Format("\\{0}\\Area", projectName);
            var    pathRoot             = css.GetNodeFromPath(rootNodePath);

            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 ex)
                    {
                        logger.Error(string.Format("{0}", pathRoot.Uri), ex);
                        //node already exists
                        continue;
                    }
                    if (Node.FirstChild != null)
                    {
                        string nodePath = rootNodePath + "\\" + Node.Attributes["Name"].Value;
                        GenerateSubAreas(Node, nodePath, css);
                    }
                }
            }
            RefreshCache();
        }
Esempio n. 5
0
        public static NodeInfo AddNode(ICommonStructureService commonStructureService, string elementPath, string projectName, eStructureType nodeType)
        {
            NodeInfo retVal;
            string   rootNodePath = "\\" + projectName + "\\" + nodeType.ToString();

            if (CheckIfPathAlreadyExists(commonStructureService, elementPath, rootNodePath))
            {
                return(null);
            }

            int      backSlashIndex = GetBackSlashIndex(elementPath);
            string   newpathname    = GetNewPathName(elementPath, backSlashIndex);
            string   path           = GetActualNodePath(elementPath, backSlashIndex);
            string   pathRoot       = rootNodePath + path;
            NodeInfo previousPath   = GetPreviousPath(commonStructureService, pathRoot);

            if (previousPath == null)
            {
                // call this method to create the parent paths.
                previousPath = AddNode(commonStructureService, path, projectName, nodeType);
            }

            string newPathUri = commonStructureService.CreateNode(newpathname, previousPath.Uri);

            return(commonStructureService.GetNode(newPathUri));
        }
        private NodeInfo CreateNode(ICommonStructureService css, string name, NodeInfo parent, DateTime?startDate, DateTime?finishDate)
        {
            string   nodePath = string.Format(@"{0}\{1}", parent.Path, name);
            NodeInfo node     = null;

            Trace.Write(string.Format("--CreateNode: {0}, start date: {1}, finish date: {2}", nodePath, startDate, finishDate));
            try
            {
                node = css.GetNodeFromPath(nodePath);
                Trace.Write("...found");
            }
            catch (CommonStructureSubsystemException ex)
            {
                Telemetry.Current.TrackException(ex);
                Trace.Write("...missing");
                string newPathUri = css.CreateNode(name, parent.Uri);
                Trace.Write("...created");
                node = css.GetNode(newPathUri);
                ((ICommonStructureService4)css).SetIterationDates(node.Uri, startDate, finishDate);
                Trace.Write("...dates assigned");
            }

            Trace.WriteLine(String.Empty);
            return(node);
        }
        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 static NodeInfo AddNode(ICommonStructureService commonStructureService, string elementPath, string projectName, eStructureType nodeType)
        {
            NodeInfo retVal;
            string rootNodePath = "\\" + projectName + "\\" + nodeType.ToString();

            if (CheckIfPathAlreadyExists(commonStructureService, elementPath, rootNodePath))
            {
                return null;
            }

            int backSlashIndex = GetBackSlashIndex(elementPath);
            string newpathname = GetNewPathName(elementPath, backSlashIndex);
            string path = GetActualNodePath(elementPath, backSlashIndex);
            string pathRoot = rootNodePath + path;
            NodeInfo previousPath = GetPreviousPath(commonStructureService, pathRoot);

            if (previousPath == null)
            {
                // call this method to create the parent paths.
                previousPath = AddNode(commonStructureService, path, projectName, nodeType);
            }

            string newPathUri = commonStructureService.CreateNode(newpathname, previousPath.Uri);
            return commonStructureService.GetNode(newPathUri);
        }
Esempio n. 9
0
        /// <summary>
        /// Creates path.
        /// </summary>
        /// <param name="type">Type of the node to be created</param>
        /// <param name="parentUri">Parent node</param>
        /// <param name="nodes">Node names</param>
        /// <param name="first">Index of the first node to create</param>
        /// <returns>Id of the node</returns>
        private int CreatePath(
            Node.TreeType type,
            string parentUri,
            string[] nodes,
            int first)
        {
            Debug.Assert(first < nodes.Length, "Nothing to create!");

            // Step 1: create in CSS
            ICommonStructureService css = Css;

            for (int i = first; i < nodes.Length; i++)
            {
                string node = nodes[i];
                if (!string.IsNullOrEmpty(node))
                {
                    try
                    {
                        parentUri = css.CreateNode(node, parentUri);
                    }
                    catch (CommonStructureSubsystemException cssEx)
                    {
                        if (cssEx.Message.Contains("TF200020"))
                        {
                            // TF200020 may be thrown if the tree node metadata has been propagated
                            // from css to WIT cache. In this case, we will wait for the node id
                            //   Microsoft.TeamFoundation.Server.CommonStructureSubsystemException:
                            //   TF200020: The parent node already has a child node with the following name: {0}.
                            //   Child nodes must have unique names.
                            Node existingNode = WaitForTreeNodeId(type, new string[] { node });
                            if (existingNode == null)
                            {
                                throw;
                            }
                            else
                            {
                                parentUri = existingNode.Uri.AbsoluteUri;
                            }
                        }
                    }
                }
            }

            // Step 2: locate in the cache
            // Syncing nodes into WIT database is an asynchronous process, and there's no way to tell
            // the exact moment.
            Node newNode = WaitForTreeNodeId(type, nodes);

            if (newNode == null)
            {
                return(-1);
            }
            else
            {
                return(newNode.Id);
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Create the CSS path (Area Path or Iteration Path)
        /// </summary>
        /// <param name="css">Handle to ICommonStructureService</param>
        /// <param name="cssPath">Path to be created</param>
        /// <param name="defaultUri">URI for the root node</param>
        private static void CreateCSSPath(ICommonStructureService css, string cssPath, string defaultUri)
        {
            string[] cssPathFragments = cssPath.Split('\\');
            int      pathLength       = 0;
            string   tempPath         = String.Empty;
            NodeInfo rootNode         = css.GetNode(defaultUri);
            NodeInfo parentNode       = rootNode; // parent is root for now

            Logger.Write(LogSource.WorkItemTracking, TraceLevel.Verbose, "Creating CSS path [{0}]", cssPath);

            // for each fraction of path, see if it exists
            for (pathLength = 0; pathLength < cssPathFragments.Length; pathLength++)
            {
                tempPath = String.Concat(parentNode.Path, "\\", cssPathFragments[pathLength]);
                NodeInfo childNode = null;
                try
                {
                    if (NodeInfoCache.ContainsKey(tempPath))
                    {
                        childNode = NodeInfoCache[tempPath];
                    }
                    else
                    {
                        childNode = css.GetNodeFromPath(tempPath);
                        NodeInfoCache.Add(tempPath, childNode);
                    }
                }
                catch (SoapException)
                {
                    // node does not exist.. ignore the exception
                }
                catch (ArgumentException)
                {
                    // node does not exist.. ignore the exception
                }

                if (childNode == null)
                {
                    // given node does not exist.. create it
                    for (int restCSSPath = pathLength; restCSSPath < cssPathFragments.Length; restCSSPath++)
                    {
                        string nodeUri = css.CreateNode(cssPathFragments[restCSSPath], parentNode.Uri);
                        // once a node is created, all the subsequent nodes can be created without any lookup
                        // set the parent node
                        parentNode = css.GetNode(nodeUri);
                    }
                    break;  // out of for loop
                }
                else
                {
                    // set the parent node to current node
                    parentNode = childNode;
                }
            }
        }
Esempio n. 11
0
        private static void CopyNodes(NodeCollection sourceNodes, NodeInfo targetRootNode, ICommonStructureService css)
        {
            foreach (Node sourceNode in sourceNodes)
            {
                string newNodePath = css.CreateNode(sourceNode.Name, targetRootNode.Uri);
                var    targetNode  = css.GetNode(newNodePath);

                if (sourceNode.HasChildNodes)
                {
                    CopyNodes(sourceNode.ChildNodes, targetNode, css);
                }
            }
        }
        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();
        }
        private NodeInfo CreateNode(ICommonStructureService css, string name, NodeInfo parent)
        {
            string   nodePath = string.Format(@"{0}\{1}", parent.Path, name);
            NodeInfo node     = null;

            Trace.Write(string.Format("--CreateNode: {0}", nodePath));
            try
            {
                node = css.GetNodeFromPath(nodePath);
                Trace.Write("...found");
            }
            catch (CommonStructureSubsystemException ex)
            {
                Telemetry.Current.TrackException(ex);
                Trace.Write("...missing");
                string newPathUri = css.CreateNode(name, parent.Uri);
                Trace.Write("...created");
                node = css.GetNode(newPathUri);
            }
            return(node);
        }
        private NodeInfo CreateNode(string name, NodeInfo parent, DateTime?startDate, DateTime?finishDate)
        {
            string   nodePath = string.Format(@"{0}\{1}", parent.Path, name);
            NodeInfo node     = null;

            Log.LogInformation(" Processing Node: {0}, start date: {1}, finish date: {2}", nodePath, startDate, finishDate);
            try
            {
                node = _targetCommonStructureService.GetNodeFromPath(nodePath);
                Log.LogDebug("  Node {node} already exists", nodePath);
                Log.LogTrace("{node}", node);
            }
            catch (CommonStructureSubsystemException ex)
            {
                try
                {
                    string newPathUri = _targetCommonStructureService.CreateNode(name, parent.Uri);
                    Log.LogDebug("  Node {newPathUri} has been created", newPathUri);
                    node = _targetCommonStructureService.GetNode(newPathUri);
                }
                catch
                {
                    Log.LogError(ex, "Creating Node");
                    throw;
                }
            }
            if (startDate != null && finishDate != null)
            {
                try
                {
                    ((ICommonStructureService4)_targetCommonStructureService).SetIterationDates(node.Uri, startDate, finishDate);
                    Log.LogDebug("  Node {node} has been assigned {startDate} / {finishDate}", nodePath, startDate, finishDate);
                }
                catch (CommonStructureSubsystemException ex)
                {
                    Log.LogWarning(ex, " Unable to set {node}dates of {startDate} / {finishDate}", nodePath, startDate, finishDate);
                }
            }
            return(node);
        }
Esempio n. 15
0
 /// <summary>
 /// Create test cycle
 /// </summary>
 /// <param name="projName"></param>
 /// <param name="rootName"></param>
 /// <returns>if cycle was be create successfully, return true; or return false</returns>
 private static bool CreateCycle(string[] folder)
 {
     // we haven't permission to create project and root folder
     try
     {
         ICommonStructureService css = teamProjectCollection.GetService <ICommonStructureService>();
         Project proj = workItemStore.Projects[folder[0]];
         iterNode = proj.IterationRootNodes[folder[1]];
         NodeInfo ni = css.GetNode(iterNode.Uri.ToString());
         if (ni.StructureType.Equals("ProjectLifecycle"))
         {
             for (int a = 2; a < folder.Length; a++)
             {
                 if (!IsNodeExist(iterNode, folder[a]))
                 {
                     parentNodeUris    = new string[folder.Length - a + 1];
                     parentNodeUris[0] = strUri;
                     for (int i = a; i < folder.Length; i++)
                     {
                         parentNodeUris[i - a + 1] = css.CreateNode(folder[i], parentNodeUris[i - a]);
                     }
                     break;
                 }
                 else
                 {
                     iterNode = iterNode.FindNodeInSubTree(folder[a]);
                 }
             }
         }
         return(true);
     }
     catch (Exception e)
     {
         return(false);
     }
 }
 private void GenerateSubAreas(XmlNode tree, string nodePath, ICommonStructureService css)
 {
     var path = css.GetNodeFromPath(nodePath);
     int nodeCount = tree.FirstChild.ChildNodes.Count;
     for (int i = 0; i < nodeCount; i++)
     {
         XmlNode node = tree.ChildNodes[0].ChildNodes[i];
         try
         {
             css.CreateNode(node.Attributes["Name"].Value, path.Uri);
         }
         catch (Exception ex)
         {
             //node already exists
             continue;
         }
         if (node.FirstChild != null)
         {
             string newPath = nodePath + "\\" + node.Attributes["Name"].Value;
             GenerateSubAreas(node, newPath, css);
         }
     }
 }