示例#1
0
        /// <summary>
        /// Create Area and Iteration path recursively
        /// </summary>
        /// <param name="elementPath"></param>
        /// <param name="projectName"></param>
        /// <param name="nodeType"></param>
        /// <returns></returns>
        private NodeInfo AddNode(string elementPath, string projectName, string nodeType)
        {
            NodeInfo retVal;

            //Check if this path already exsist
            try
            {
                retVal = _commonStructureService4.GetNodeFromPath(elementPath);
                if (retVal != null)
                {
                    Console.WriteLine($"Node '{elementPath}' already exists.");
                    return(null);
                }
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("The following node does not exist"))
                {
                    //just means that this path is not exist and we can continue.
                }
                else
                {
                    throw ex;
                }
            }

            int      backSlashIndex = elementPath.LastIndexOf("\\");
            string   newPathName    = elementPath.Substring(backSlashIndex + 1);
            string   newPath        = (backSlashIndex == 0 ? string.Empty : elementPath.Substring(0, backSlashIndex));
            NodeInfo previousPath   = null;

            try
            {
                previousPath = _commonStructureService4.GetNodeFromPath(newPath);
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("Invalid path."))
                {
                    //just means that this path is not exist and we can continue.
                    previousPath = null;
                }
                else
                {
                    throw ex;
                }
            }
            if (previousPath == null)
            {
                //call this method to create the parent paths.
                previousPath = AddNode(newPath, projectName, nodeType);
            }
            string newPathUri = _commonStructureService4.CreateNode(newPathName, previousPath.Uri);

            Console.WriteLine($"Node '{newPathName}' in '{elementPath}' created.");

            return(_commonStructureService4.GetNode(newPathUri));
        }
示例#2
0
        // source tree, target tfs
        public void GenerateIterations(XmlNode tree, string sourceProjectName)
        {
            ICommonStructureService4 css = (ICommonStructureService4)tfs.GetService(typeof(ICommonStructureService4));
            string rootNodePath          = string.Format("\\{0}\\Iteration", projectName);
            var    pathRoot = css.GetNodeFromPath(rootNodePath);

            string firstReleaseName = tree.FirstChild.FirstChild.Attributes["Name"].Value;

            css.CreateNode(firstReleaseName, pathRoot.Uri, DateTime.Parse(tree.FirstChild.FirstChild.Attributes["StartDate"].Value), DateTime.Parse(tree.FirstChild.FirstChild.Attributes["FinishDate"].Value));

            string firstReleaseNodePath = string.Format("\\{0}\\Iteration\\{1}", projectName, firstReleaseName);
            var    firstReleasePathRoot = css.GetNodeFromPath(firstReleaseNodePath);

            if (tree.FirstChild != null)
            {
                int myNodeCount = tree.FirstChild.FirstChild.ChildNodes[0].ChildNodes.Count;
                for (int i = 0; i < myNodeCount; i++)
                {
                    XmlNode Node = tree.FirstChild.FirstChild.ChildNodes[0].ChildNodes[i];
                    try
                    {
                        css.CreateNode(Node.Attributes["Name"].Value, firstReleasePathRoot.Uri, DateTime.Parse(Node.Attributes["StartDate"].Value), DateTime.Parse(Node.Attributes["FinishDate"].Value));
                    }
                    catch (Exception ex)
                    {
                        //node already exists
                        logger.Info("RK: Iteration already exists: " + ex);
                        continue;
                    }
                }
            }
            else
            {
                try
                {
                    logger.Info("RK: " + tree.Name);
                }
                catch (Exception ex)
                {
                    logger.Info("RK: " + ex);
                }
                try
                {
                    logger.Info("RK2: " + tree.Attributes["Name"].Value);
                }
                catch (Exception ex)
                {
                    logger.Info("RK: " + ex);
                }
            }
            RefreshCache();
        }
        private string CreateNodeIfMissing(Node node, NodeInfo rootNode)
        {
            // we should never account for Root node, as it has a fixed name project dependant
            string nodePathWithoutRoot = node.Path.Remove(0, node.Path.IndexOf("\\") + 1);
            string nodePathOnDest      = rootNode.Path + "\\" + nodePathWithoutRoot;
            string destNodeUri         = string.Empty;
            var    destNode            = GetNodeIfExists(nodePathOnDest);

            if (destNode == null)
            {
                if (!nodePathWithoutRoot.Contains("\\"))
                {
                    // first level nodes
                    if (!this.testMode)
                    {
                        destNodeUri = destCSS.CreateNode(nodePathWithoutRoot, rootNode.Uri);
                        if (node.IsAreaNode)
                        {
                            this.ChangeLog.AddEntry(new AreaChangeEntry(node.Name, destNodeUri, NodeChangeEntry.Change.Add));
                        }
                        else if (node.IsIterationNode)
                        {
                            this.ChangeLog.AddEntry(new IterationChangeEntry(node.Name, destNodeUri, NodeChangeEntry.Change.Add));
                        }
                    }
                }
                else
                {
                    int      lastBackslash = nodePathWithoutRoot.LastIndexOf("\\");
                    NodeInfo parentNode    = destCSS.GetNodeFromPath(rootNode.Path + "\\" + nodePathWithoutRoot.Substring(0, lastBackslash));
                    // TODO test mode!
                    if (!this.testMode)
                    {
                        destNodeUri = destCSS.CreateNode(nodePathWithoutRoot.Substring(lastBackslash + 1), parentNode.Uri);
                        if (node.IsAreaNode)
                        {
                            this.ChangeLog.AddEntry(new AreaChangeEntry(node.Name, destNodeUri, NodeChangeEntry.Change.Add));
                        }
                        else if (node.IsIterationNode)
                        {
                            this.ChangeLog.AddEntry(new IterationChangeEntry(node.Name, destNodeUri, NodeChangeEntry.Change.Add));
                        }
                    }
                }//if
            }
            else
            {
                destNodeUri = destNode.Uri;
            }//if
            return(destNodeUri);
        }
示例#4
0
        public IEnumerable <TimeSheetItem> GetWorkItems(DateTime iterationDay, string userName)
        {
            if (!IsAuthenticated)
            {
                throw new InvalidOperationException("User not authenticated.");
            }

            var result = new List <TimeSheetItem>();

            var parameters = new Hashtable {
                { "project", _project }, { "me", userName }
            };
            var wiCollection = _workItemStore.Query(_workitemQueryText, parameters);

            // Add only workitems from an iteration that has the given iterationDay
            result.AddRange(from WorkItem workItem in wiCollection
                            let fullPath                       = workItem.IterationPath.Replace(_project, _project + @"\Iteration")
                                                      let node = _commonStructureService.GetNodeFromPath(fullPath)
                                                                 where node.StartDate <= iterationDay && node.FinishDate >= iterationDay
                                                                 select new TimeSheetItem
            {
                WorkItemId    = workItem.Id,
                Name          = workItem.Title,
                WorkRemaining = Convert.ToDateTime(TimeSpan.FromHours(Convert.ToDouble(workItem["Remaining work"])).ToString()),
                Project       = _project,
                ServerUrl     = _url
            });

            return(result);
        }
        private static void CreateIterationNodes(XmlNode node, ICommonStructureService4 css, NodeInfo pathRoot)
        {
            int myNodeCount = node.ChildNodes.Count;

            for (int i = 0; i < myNodeCount; i++)
            {
                XmlNode  childNode = node.ChildNodes[i];
                NodeInfo createdNode;
                var      name = childNode.Attributes["Name"].Value;
                try
                {
                    var uri = css.CreateNode(name, pathRoot.Uri);
                    Console.WriteLine("NodeCreated:" + uri);
                    createdNode = css.GetNode(uri);
                }
                catch (Exception)
                {
                    //node already exists
                    createdNode = css.GetNodeFromPath(pathRoot.Path + @"\" + name);

                    //continue;
                }

                DateTime?startDateToUpdate = null;
                if (!createdNode.StartDate.HasValue)
                {
                    var      startDate = childNode.Attributes["StartDate"];
                    DateTime startDateParsed;
                    if (startDate != null && DateTime.TryParse(startDate.Value, out startDateParsed))
                    {
                        startDateToUpdate = startDateParsed;
                    }
                }
                DateTime?finishDateToUpdate = null;
                if (!createdNode.FinishDate.HasValue)
                {
                    DateTime finishDateParsed;
                    var      finishDate = childNode.Attributes["FinishDate"];
                    if (finishDate != null && DateTime.TryParse(finishDate.Value, out finishDateParsed))
                    {
                        finishDateToUpdate = finishDateParsed;
                    }
                }
                if (startDateToUpdate.HasValue || finishDateToUpdate.HasValue)
                {
                    css.SetIterationDates(createdNode.Uri, startDateToUpdate, finishDateToUpdate);
                }
                if (createdNode != null && node.HasChildNodes)
                {
                    foreach (XmlNode subChildNode in childNode.ChildNodes)
                    {
                        CreateIterationNodes(subChildNode, css, createdNode);
                    }
                }
            }
        }
        private NodeInfo CreateNode(string name, NodeInfo parent, DateTime?startDate, DateTime?finishDate)
        {
            string   nodePath = string.Format(@"{0}\{1}", parent.Path, name);
            NodeInfo node;

            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
                {
                    _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);
        }
        public void GenerateIterations(XmlNode tree, string sourceProjectName)
        {
            ICommonStructureService4 css = (ICommonStructureService4)tfs.GetService(typeof(ICommonStructureService4));
            string rootNodePath          = string.Format("\\{0}\\Iteration", projectName);
            var    pathRoot = css.GetNodeFromPath(rootNodePath);

            if (tree.FirstChild != null)
            {
                var firstChild = tree.FirstChild;
                CreateIterationNodes(firstChild, css, pathRoot);
            }
            RefreshCache();
        }
示例#8
0
        private void CreateNode(ICommonStructureService4 css, string nodeName, NodeInfo rootNode)
        {
            char _delimeter = '|';

            var      name      = String.Empty;
            DateTime?startDate = null;
            DateTime?endDate   = null;

            if (nodeName.Contains(_delimeter))
            {
                var parts = nodeName.Split(_delimeter);

                name      = parts[0];
                startDate = DateTime.Parse(parts[1]);
                endDate   = DateTime.Parse(parts[2]);
            }
            else
            {
                name = nodeName;
            }

            if (!name.Contains("\\"))
            {
                try
                {
                    var iterationUri = css.CreateNode(name, rootNode.Uri);
                    css.SetIterationDates(iterationUri, startDate, endDate);
                }
                catch (Exception ex) when(ex.ToString().Contains("TF200020"))
                {
                    Console.WriteLine("Node Exists. Skipping...");
                }
            }
            else
            {
                int      lastBackslash = name.LastIndexOf("\\");
                NodeInfo info          = css.GetNodeFromPath(rootNode.Path + "\\" + name.Substring(0, lastBackslash));
                var      iterationUri  = css.CreateNode(name.Substring(lastBackslash + 1), info.Uri);
                css.SetIterationDates(iterationUri, startDate, endDate);
            }
        }
示例#9
0
        public IterationModel GetIteration(Guid collectionId, int projectId, string iterationPath)
        {
            using (var server = GetServer())
            {
                TfsTeamProjectCollection collection = server.GetTeamProjectCollection(collectionId);
                WorkItemStore            wiStore    = collection.GetService <WorkItemStore>();
                string query = @"SELECT * " +
                               "FROM WorkItems " +
                               "WHERE ([System.WorkItemType] = 'Bug' OR [System.WorkItemType] = 'Product Backlog Item' OR [System.WorkItemType] = 'Task') " +
                               "AND [System.IterationPath] = '@IterationPath' " +
                               "ORDER BY [System.WorkItemType]";
                query = query.Replace("@IterationPath", iterationPath);
                var items = wiStore.Query(query);

                ICommonStructureService4 css = collection.GetService <ICommonStructureService4>();
                var      path     = GetFullIterationPath(iterationPath);
                NodeInfo pathRoot = css.GetNodeFromPath(path);

                IterationModel model = Map(pathRoot);
                model.WorkItems = Map(items);
                return(model);
            }
        }
 private static void CreateIterationNodes(XmlNode node, ICommonStructureService4 css,
     NodeInfo pathRoot)
 {
     int myNodeCount = node.ChildNodes.Count;
     for (int i = 0; i < myNodeCount; i++)
     {
         XmlNode childNode = node.ChildNodes[i];
         NodeInfo createdNode;
         var name = childNode.Attributes["Name"].Value;
         try
         {
             var uri = css.CreateNode(name, pathRoot.Uri);
             Console.WriteLine("NodeCreated:" + uri);
             createdNode = css.GetNode(uri);
         }
         catch (Exception)
         {
             //node already exists
             createdNode = css.GetNodeFromPath(pathRoot.Path + @"\" + name);
             //continue;
         }
         DateTime? startDateToUpdate = null;
         if (!createdNode.StartDate.HasValue)
         {
             var startDate = childNode.Attributes["StartDate"];
             DateTime startDateParsed;
             if (startDate != null && DateTime.TryParse(startDate.Value, out startDateParsed))
                 startDateToUpdate = startDateParsed;
         }
         DateTime? finishDateToUpdate = null;
         if (!createdNode.FinishDate.HasValue)
         {
             DateTime finishDateParsed;
             var finishDate = childNode.Attributes["FinishDate"];
             if (finishDate != null && DateTime.TryParse(finishDate.Value, out finishDateParsed))
                 finishDateToUpdate = finishDateParsed;
         }
         if (startDateToUpdate.HasValue || finishDateToUpdate.HasValue)
             css.SetIterationDates(createdNode.Uri, startDateToUpdate, finishDateToUpdate);
         if (createdNode != null && node.HasChildNodes)
         {
             foreach (XmlNode subChildNode in childNode.ChildNodes)
             {
                 CreateIterationNodes(subChildNode, css, createdNode);
             }
         }
     }
 }
        private void CreateNode(ICommonStructureService4 css, string nodeName, NodeInfo rootNode)
        {
            char _delimeter = '|';

            var name = String.Empty;
            DateTime? startDate = null;
            DateTime? endDate = null;

            if (nodeName.Contains(_delimeter))
            {
                var parts = nodeName.Split(_delimeter);

                name = parts[0];
                startDate = DateTime.Parse(parts[1]);
                endDate = DateTime.Parse(parts[2]);
            }
            else
            {
                name = nodeName;
            }

            if (!name.Contains("\\"))
            {
                try
                {
                    var iterationUri = css.CreateNode(name, rootNode.Uri);
                    css.SetIterationDates(iterationUri, startDate, endDate);
                }
                catch(Exception ex) when (ex.ToString().Contains("TF200020"))
                {
                    Console.WriteLine("Node Exists. Skipping...");
                }
            }
            else
            {
                int lastBackslash = name.LastIndexOf("\\");
                NodeInfo info = css.GetNodeFromPath(rootNode.Path + "\\" + name.Substring(0, lastBackslash));
                var iterationUri = css.CreateNode(name.Substring(lastBackslash + 1), info.Uri);
                css.SetIterationDates(iterationUri, startDate, endDate);
            }
        }