예제 #1
0
        public Group Group_AddWithFields()
        {
            //get process id stored in cache so we don't have to load it each time
            System.Guid processId = Context.GetValue <Guid>("$processId");

            VssConnection connection = Context.Connection;
            WorkItemTrackingProcessHttpClient client = connection.GetClient <WorkItemTrackingProcessHttpClient>();

            Console.Write("Getting form layout to find all pages, sections, and groups...");

            FormLayout layout = client.GetFormLayoutAsync(processId, _witRefName).Result;

            //searching through the layout page to find the right page, section, and group
            Page  page  = ProcessHelper.getPage(layout, "Details");
            Group group = ProcessHelper.getGroup(layout, "Details", "Section2", "NewGroup");

            Console.WriteLine("done");

            if (group != null)
            {
                Console.WriteLine("Group '{0}' already exists on section '{1}' on page '{2}'", group.Label, "Section2", page.Label);
            }
            else
            {
                Console.Write("Creating new group 'NewGroup'...");

                List <Control> controlList = new List <Control>()
                {
                    new Control()
                    {
                        Id = _fieldRefName, Order = 1, Label = "Colors", Visible = true, Name = "Colors", Watermark = "Select a color"
                    },
                    new Control()
                    {
                        Id = "Microsoft.VSTS.Common.Activity", Order = 2, Label = "Activity", Visible = true
                    }
                };

                Group newGroup = new Group()
                {
                    Controls   = controlList,
                    Id         = null,
                    Label      = "NewGroup",
                    Overridden = false,
                    Visible    = true,
                    Order      = 1
                };

                group = client.AddGroupAsync(newGroup, processId, _witRefName, page.Id, "Section2").Result;

                Console.WriteLine("done");
            }

            return(group);
        }