public WorkItemClassificationNode CreateIteration()
        {
            Guid   projectId        = ClientSampleHelpers.FindAnyProject(this.Context).Id;
            string newIterationName = "New iteration " + Guid.NewGuid();

            WorkItemClassificationNode node = new WorkItemClassificationNode()
            {
                Name          = newIterationName,
                StructureType = TreeNodeStructureType.Iteration,
                Attributes    = new Dictionary <string, Object>()
                {
                    { "startDate", DateTime.Today },
                    { "finishDate", DateTime.Today.AddDays(7) },
                }
            };

            // Get a client
            VssConnection connection = Context.Connection;
            WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient <WorkItemTrackingHttpClient>();

            // Create the new iteration
            WorkItemClassificationNode result = workItemTrackingClient.CreateOrUpdateClassificationNodeAsync(
                node,
                projectId.ToString(),
                TreeStructureGroup.Iterations).Result;

            // Show the new node
            ShowNodeTree(result);

            // Save the new iteration for use in a later sample
            Context.SetValue <string>("$newIterationName", node.Name);
            Context.SetValue <Guid>("$newIterationProjectId", projectId);

            return(result);
        }
 public static void SetStartDate(this WorkItemClassificationNode source, DateTime?value)
 {
     if (value != null)
     {
         SetValue(source, "startDate", value);
     }
 }
        public WorkItemClassificationNode RenameIteration()
        {
            Guid   projectId;
            string currentName;

            // Get values from previous sample method that created a sample iteration
            Context.TryGetValue <Guid>("$newIterationProjectId", out projectId);
            Context.TryGetValue <string>("$newIterationName", out currentName);

            string newName = currentName + " (renamed)";

            WorkItemClassificationNode node = new WorkItemClassificationNode()
            {
                Name          = newName,
                StructureType = TreeNodeStructureType.Iteration
            };

            // Get a client
            VssConnection connection = Context.Connection;
            WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient <WorkItemTrackingHttpClient>();

            WorkItemClassificationNode result = workItemTrackingClient.UpdateClassificationNodeAsync(
                node,
                projectId.ToString(),
                TreeStructureGroup.Iterations,
                currentName).Result;

            // Save the new name for a later sample
            Context.SetValue <string>("$newIterationName", newName);

            // Show the new node
            ShowNodeTree(result);

            return(result);
        }
        private void ProcessNode(string path, WorkItemClassificationNode node, ISet <string> pathList, IDictionary <string, WorkItemClassificationNode> pathListLookup)
        {
            if (node == null)
            {
                return;
            }
            string currentpath;

            if (path != null)
            {
                currentpath = $"{path}\\{node.Name}";
            }
            else
            {
                //very first node will have null path, so it will be just a node name
                currentpath = node.Name;
            }

            pathList.Add(currentpath);
            pathListLookup.Add(currentpath, node);


            if (node.Children != null)
            {
                foreach (var child in node.Children)
                {
                    ProcessNode(currentpath, child, pathList, pathListLookup);
                }
            }
        }
Ejemplo n.º 5
0
 internal ClassificationNode(WorkItemClassificationNode n,
                             string projectName, WorkItemTrackingHttpClient client) : base(n)
 {
     ProjectName = projectName;
     _client     = client;
     FixNodePath();
 }
Ejemplo n.º 6
0
        static void ManageIterations(string TeamProjectName)
        {
            WorkItemClassificationNode newNode = CreateIteration(TeamProjectName, @"R2"); //Add iteraion R2

            PrintNodeInfo(newNode);
            newNode = CreateIteration(TeamProjectName, @"R2.1", ParentIterationPath: @"R2");                                       //Add iteraion R2\R2.1
            PrintNodeInfo(newNode);
            newNode = CreateIteration(TeamProjectName, @"Ver1", new DateTime(2019, 1, 1), new DateTime(2019, 1, 7), @"R2\R2.1");   //Add iteraion R2\R2.1\Ver1
            PrintNodeInfo(newNode);
            newNode = CreateIteration(TeamProjectName, @"Ver2", new DateTime(2019, 1, 7), new DateTime(2019, 1, 14), @"R2\R2.1");  //Add iteraion R2\R2.1\Ver2
            PrintNodeInfo(newNode);
            newNode = CreateIteration(TeamProjectName, @"Ver3", new DateTime(2019, 1, 14), new DateTime(2019, 1, 21), @"R2\R2.1"); //Add iteraion R2\R2.1\Ver3
            PrintNodeInfo(newNode);
            newNode = CreateIteration(TeamProjectName, @"R2.2", ParentIterationPath: @"R2");                                       //Add iteraion R2\R2.2
            PrintNodeInfo(newNode);
            newNode = CreateIteration(TeamProjectName, @"Ver1", new DateTime(2019, 2, 1), new DateTime(2019, 2, 7), @"R2\R2.2");   //Add iteraion R2\R2.2\Ver1
            PrintNodeInfo(newNode);

            newNode = RenameClassificationNode(TeamProjectName, @"R2\R2.2\Ver1", @"Ver1.1", TreeStructureGroup.Iterations); //Rename iteration R2\R2.2\Ver1 to R2\R2.2\Ver1.1
            PrintNodeInfo(newNode);

            newNode = MoveClassificationNode(TeamProjectName, @"R2\R2.1\Ver3", @"R2\R2.2", TreeStructureGroup.Iterations); //Move iteration R2\R2.1\Ver3 to R2\R2.2\Ver3
            PrintNodeInfo(newNode);

            newNode = ReplanIteration(TeamProjectName, @"R2\R2.2\Ver1.1", new DateTime(2019, 3, 1), new DateTime(2019, 3, 7)); //Update dates for R2\R2.2\Ver1.1
            PrintNodeInfo(newNode);

            DeleteClassificationNode(TeamProjectName, @"R2\R2.2", @"R2", TreeStructureGroup.Iterations); // Delete iteration tree R2\R2.2 and move work items to iteration R2
        }
Ejemplo n.º 7
0
        protected override ClassificationNode DoSetItem()
        {
            var nodeToSet      = GetItem <ClassificationNode>();
            var startDate      = GetParameter <DateTime?>(nameof(SetIteration.StartDate));
            var finishDate     = GetParameter <DateTime?>(nameof(SetIteration.FinishDate));
            var structureGroup = GetParameter <TreeStructureGroup>("StructureGroup");

            ErrorUtil.ThrowIfNotFound(nodeToSet, nameof(SetIteration.Node), GetParameter <string>(nameof(SetIteration.Node)));

            var(_, tp) = GetCollectionAndProject();

            var client = GetClient <WorkItemTrackingHttpClient>();

            if (!ShouldProcess(tp, $"Set dates on iteration '{nodeToSet.RelativePath}'"))
            {
                return(null);
            }

            var patch = new WorkItemClassificationNode()
            {
                Attributes = new Dictionary <string, object>()
                {
                    ["startDate"]  = startDate,
                    ["finishDate"] = finishDate
                }
            };

            var result = client.UpdateClassificationNodeAsync(patch, tp.Name, structureGroup, nodeToSet.RelativePath.Substring(1))
                         .GetResult($"Error setting dates on iteration '{nodeToSet.FullPath}'");

            return(new ClassificationNode(result, tp.Name, client));
        }
Ejemplo n.º 8
0
        public static async Task <WorkItemClassificationNode> CreateAreaAsync(this WorkItemTrackingHttpClient source, NodePath areaPath, CancellationToken cancellationToken)
        {
            //Get the parent area, if any
            if (areaPath.Parent != null)
            {
                var parentArea = await source.GetAreaAsync(areaPath.Parent, false, cancellationToken).ConfigureAwait(false);

                cancellationToken.ThrowIfCancellationRequested();

                if (parentArea == null)
                {
                    parentArea = await source.CreateAreaAsync(areaPath.Parent, cancellationToken).ConfigureAwait(false);
                }
            }
            ;

            var newArea = new WorkItemClassificationNode()
            {
                Name = areaPath.Name
            };

            newArea = await source.CreateOrUpdateClassificationNodeAsync(newArea, areaPath.Project, TreeStructureGroup.Areas, path : areaPath.Parent?.RelativePath, cancellationToken : cancellationToken).ConfigureAwait(false);

            Logger.Debug($"Created area '{areaPath}' with Id {newArea.Id}");

            return(newArea);
        }
Ejemplo n.º 9
0
        public string UpdateIterationDates(string project, string name, DateTime startDate, DateTime finishDate)
        {
            IDictionary <string, Object> dict = new Dictionary <string, Object>();

            dict.Add("startDate", startDate);
            dict.Add("finishDate", finishDate);

            WorkItemClassificationNode node = new WorkItemClassificationNode()
            {
                StructureType = TreeNodeStructureType.Iteration,
                Attributes    = dict
            };

            using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials))
            {
                try
                {
                    WorkItemClassificationNode result = workItemTrackingHttpClient.UpdateClassificationNodeAsync(node, project, TreeStructureGroup.Iterations, name).Result;
                }
                catch (System.AggregateException ex)
                {
                    return(ex.InnerException.ToString());
                }

                return("success");
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Update iteration dates
        /// </summary>
        /// <param name="TeamProjectName"></param>
        /// <param name="NodePath"></param>
        /// <param name="StartDate"></param>
        /// <param name="FinishDate"></param>
        /// <returns></returns>
        static WorkItemClassificationNode ReplanIteration(string TeamProjectName, string NodePath, DateTime StartDate, DateTime FinishDate)
        {
            WorkItemClassificationNode node = WitClient.GetClassificationNodeAsync(
                TeamProjectName,
                TreeStructureGroup.Iterations,
                NodePath, 4).Result;

            if (node.Attributes == null)
            {
                node.Attributes = new Dictionary <string, object>();
            }

            if (!node.Attributes.ContainsKey("startDate"))
            {
                node.Attributes.Add("startDate", StartDate);
            }
            else
            {
                node.Attributes["startDate"] = StartDate;
            }
            if (!node.Attributes.ContainsKey("finishDate"))
            {
                node.Attributes.Add("finishDate", FinishDate);
            }
            else
            {
                node.Attributes["finishDate"] = FinishDate;
            }

            return(UpdateClassificationNode(TeamProjectName, node, GetParentNodePath(NodePath, node.Name)));
        }
Ejemplo n.º 11
0
        private void SaveClassificationNodesRecursive(Guid projectId, WorkItemClassificationNode classificationNode, TreeStructureGroup structureGroup, string pathToParent = null)
        {
            try
            {
                var result = workClient.CreateOrUpdateClassificationNodeAsync(
                    classificationNode,
                    projectId.ToString(),
                    structureGroup,
                    pathToParent).Result;

                Logger.Info($"{GetType()} Saved type {structureGroup} '{pathToParent}\\{classificationNode.Name}'");
            }
            catch (Exception)
            {
                // Intentionally eating the e
                Logger.Error($"{GetType()} Failed saving type {structureGroup} '{pathToParent}\\{classificationNode.Name}', does it already exist?");
            }

            if (classificationNode.HasChildren != true)
            {
                return;
            }

            var newPathToParent = $"{pathToParent}\\{classificationNode.Name}";

            foreach (var classificationNodeChild in classificationNode.Children)
            {
                SaveClassificationNodesRecursive(projectId, classificationNodeChild, structureGroup, newPathToParent);
            }
        }
Ejemplo n.º 12
0
        public WorkItemClassificationNode CreateIteration(string TeamProjectName, string IterationName, DateTime StartDate, DateTime FinishDate, string ParentIteration = "")
        {
            var project = ProjectClient.GetProject(TeamProjectName).Result;

            WorkItemClassificationNode newIteration = new WorkItemClassificationNode();

            newIteration.Name          = IterationName;
            newIteration.StructureType = TreeNodeStructureType.Iteration;

            if (StartDate != DateTime.MinValue && FinishDate != DateTime.MinValue)
            {
                newIteration.Attributes = new Dictionary <string, object>();
                newIteration.Attributes.Add("startDate", StartDate);
                newIteration.Attributes.Add("finishDate", FinishDate);
            }

            var result = WitClient.CreateOrUpdateClassificationNodeAsync(newIteration, project.Id, TreeStructureGroup.Iterations).Result;

            if (ParentIteration != "")
            {
                result = MoveIteration(TeamProjectName, result, ParentIteration);
            }

            return(result);
        }
Ejemplo n.º 13
0
        private void GetIterations(
            List <IterationItem> list,
            WorkItemClassificationNode node,
            string path = "")
        {
            var item = new IterationItem();

            if (path.Length > 0)
            {
                item.Path = path + @"\";
                path      = path + @"\" + node.Name;
            }
            else
            {
                path = node.Name;
            }

            item.Name = path;

            if (node.Attributes != null && node.Attributes.Any(a => a.Key == "startDate"))
            {
                item.StartDate = Convert.ToDateTime(node.Attributes["startDate"]);
            }

            list.Add(item);

            if (node.Children != null)
            {
                foreach (var child in node.Children)
                {
                    GetIterations(list, child, path);
                }
            }
        }
Ejemplo n.º 14
0
        public WorkItemClassificationNode GetIteration(string project, string path)
        {
            VssConnection connection = new VssConnection(_uri, _credentials);
            WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient <WorkItemTrackingHttpClient>();
            WorkItemClassificationNode result = workItemTrackingHttpClient.GetClassificationNodeAsync(project, TreeStructureGroup.Iterations, path, 0).Result;

            return(result);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Create new area
        /// </summary>
        /// <param name="TeamProjectName"></param>
        /// <param name="AreaName"></param>
        /// <param name="ParentAreaPath"></param>
        /// <returns></returns>
        static WorkItemClassificationNode CreateArea(string TeamProjectName, string AreaName, string ParentAreaPath = null)
        {
            WorkItemClassificationNode newArea = new WorkItemClassificationNode();

            newArea.Name = AreaName;

            return(WitClient.CreateOrUpdateClassificationNodeAsync(newArea, TeamProjectName, TreeStructureGroup.Areas, ParentAreaPath).Result);
        }
Ejemplo n.º 16
0
        public WorkItemClassificationNode GetAreas(string project, int depth)
        {
            VssConnection connection = new VssConnection(_uri, _credentials);
            WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient <WorkItemTrackingHttpClient>();
            WorkItemClassificationNode result = workItemTrackingHttpClient.GetClassificationNodeAsync(project, TreeStructureGroup.Areas, null, depth).Result;

            return(result);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Move area or iteration to new path
        /// </summary>
        /// <param name="TeamProjectName"></param>
        /// <param name="NodePath"></param>
        /// <param name="NewParentNodePath"></param>
        /// <param name="treeStructureGroup"></param>
        /// <returns></returns>
        static WorkItemClassificationNode MoveClassificationNode(string TeamProjectName, string NodePath, string NewParentNodePath, TreeStructureGroup treeStructureGroup)
        {
            WorkItemClassificationNode node = WitClient.GetClassificationNodeAsync(
                TeamProjectName,
                treeStructureGroup,
                NodePath, 4).Result;

            return(UpdateClassificationNode(TeamProjectName, node, NewParentNodePath));
        }
        private static T GetValue <T> (WorkItemClassificationNode node, string key)
        {
            if (node.Attributes != null)
            {
                return(node.Attributes.TryGetValue <T>(key));
            }

            return(default(T));
        }
Ejemplo n.º 19
0
 public async virtual Task CreateIterationPath(string iterationPath, WorkItemClassificationNode sourceIterationNode)
 {
     await WorkItemTrackingHelpers.CreateIterationAsync(
         context.TargetClient.WorkItemTrackingHttpClient,
         context.Config.TargetConnection.Project,
         iterationPath,
         sourceIterationNode.Attributes == null?null : (DateTime?)sourceIterationNode.Attributes?["startDate"],
         sourceIterationNode.Attributes == null?null : (DateTime?)sourceIterationNode.Attributes["finishDate"]);
 }
Ejemplo n.º 20
0
        public string GetIterations(string project, int depth)
        {
            using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials))
            {
                WorkItemClassificationNode result = workItemTrackingHttpClient.GetClassificationNodeAsync(project, TreeStructureGroup.Iterations, null, depth).Result;
            }

            return("success");
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Remove area or iteration
        /// </summary>
        /// <param name="TeamProjectName"></param>
        /// <param name="NodePath"></param>
        /// <param name="NewNodePath"></param>
        /// <param name="treeStructureGroup"></param>
        static void DeleteClassificationNode(string TeamProjectName, string NodePath, string NewNodePath, TreeStructureGroup treeStructureGroup)
        {
            WorkItemClassificationNode node = WitClient.GetClassificationNodeAsync(
                TeamProjectName,
                treeStructureGroup,
                NewNodePath, 4).Result;

            WitClient.DeleteClassificationNodeAsync(TeamProjectName, treeStructureGroup, NodePath, node.Id).SyncResult();
        }
Ejemplo n.º 22
0
 public IEnumerable <WorkItemClassificationNode> GetAreas(string project, int depth = 100)
 {
     using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(_uri, _credentials))
     {
         WorkItemClassificationNode result             = workItemTrackingHttpClient.GetClassificationNodeAsync(project, TreeStructureGroup.Areas, null, depth).Result;
         IEnumerable <WorkItemClassificationNode> tree = result.Children;
         return(result != null?result.GetAllNodes() : null);
     }
 }
        public void TestGetAreaListWith2LevelDepth()
        {
            WorkItemClassificationNode areaNode = this.GetContext().ListAreas();

            Assert.IsNotNull(areaNode);
            Assert.IsNotNull(areaNode.Children);
            Assert.AreEqual(2, areaNode.Children.Count());
            Assert.AreEqual("area-1", areaNode.Children.FirstOrDefault().Name);
        }
        private static void SetValue <T> (WorkItemClassificationNode node, string key, T value)
        {
            if (node.Attributes == null)
            {
                node.Attributes = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase);
            }

            node.Attributes[key] = value;
        }
Ejemplo n.º 25
0
        public WorkItemClassificationNode MoveIteration(string TeamProjectName, string IterationName, string ParentIteration)
        {
            WorkItemClassificationNode iteration = WitClient.GetClassificationNodeAsync(
                TeamProjectName,
                TreeStructureGroup.Iterations,
                IterationName, 4).Result;

            return(MoveIteration(TeamProjectName, iteration, ParentIteration));
        }
 private void CreateIterationPathList(WorkItemClassificationNode headnode)
 {
     //node is the headnode
     if (headnode == null)
     {
         return;
     }
     //path for the headnode is null
     ProcessNode(null, headnode, this.IterationPathList, this.IterationPathListLookup);
 }
 /// <summary>
 /// Gets all nodes of a <see cref="WorkItemClassificationNode"/> recursively.
 /// </summary>
 /// <param name="root">The root node.</param>
 private void GetAllNodes(WorkItemClassificationNode root)
 {
     if (root.Children != null)
     {
         foreach (var child in root.Children)
         {
             this.iterations.Add(child);
             this.GetAllNodes(child);
         }
     }
 }
 public void walkTreeNode(WorkItemClassificationNode t, List <string> list, string node)
 {
     if (t.Children != null)
     {
         foreach (WorkItemClassificationNode child in t.Children)
         {
             list.Add(node + "/" + child.Name);
             walkTreeNode(child, list, node + "/" + child.Name);
         }
     }
 }
Ejemplo n.º 29
0
        private IEnumerable <string> ListNodeTree(WorkItemClassificationNode node)
        {
            yield return(node.Name);

            if (node.Children != null)
            {
                foreach (var child in node.Children)
                {
                    yield return(child.Name);
                }
            }
        }
        private void ShowNodeTree(WorkItemClassificationNode node, string path = "")
        {
            path = path + "/" + node.Name;
            Console.WriteLine(path);

            if (node.Children != null)
            {
                foreach (var child in node.Children)
                {
                    ShowNodeTree(child, path);
                }
            }
        }