コード例 #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);
        }
コード例 #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);
                }
            }
        }
コード例 #3
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;
                }
            }
        }
コード例 #4
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);
        }
コード例 #6
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);
        }
コード例 #7
0
ファイル: Utils.cs プロジェクト: garora/Tfs2Git
        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);
                }
            }
        }
コード例 #8
0
        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);
        }
コード例 #10
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);
     }
 }