예제 #1
0
        public ProcessWorkItemTypeField Field_AddSystemFieldToWorkItemType()
        {
            string fieldName = "Microsoft.VSTS.Common.Activity";

            ProcessWorkItemTypeField processWorkItemTypeField = null;

            System.Guid processId = Context.GetValue <Guid>("$processId");

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

            //get the list of fields on the work item item
            Console.Write("Loading list of fields on the work item and checking to see if field '{0}' already exists...", fieldName);

            List <ProcessWorkItemTypeField> list = client.GetAllWorkItemTypeFieldsAsync(processId, _witRefName).Result;

            //check to see if the field already exists on the work item
            processWorkItemTypeField = list.Find(x => x.ReferenceName == fieldName);

            //field is already on the work item, so just return it
            if (processWorkItemTypeField != null)
            {
                Console.WriteLine("field found");
                return(processWorkItemTypeField);
            }
            else
            {
                //the field is not on the work item, so we best add it
                Console.WriteLine("field not found");
                Console.Write("Adding field to work item...");

                AddProcessWorkItemTypeFieldRequest fieldRequest = new AddProcessWorkItemTypeFieldRequest()
                {
                    AllowGroups   = false,
                    DefaultValue  = String.Empty,
                    ReadOnly      = false,
                    ReferenceName = fieldName,
                    Required      = false
                };

                processWorkItemTypeField = client.AddFieldToWorkItemTypeAsync(fieldRequest, processId, _witRefName).Result;

                Console.WriteLine("done");

                return(processWorkItemTypeField);
            }
        }
        public async Task EnsureFieldExists(string fieldRefName, string name, string description, string workItemType, Guid processId)
        {
            var field = await witClient.GetFieldAsync(fieldRefName);

            if (field == null)
            {
                field = await witClient.CreateFieldAsync(new WorkItemField()
                {
                    Name          = name,
                    Description   = description,
                    ReferenceName = fieldRefName
                });
            }
            await witProcessClient.AddFieldToWorkItemTypeAsync(
                new AddProcessWorkItemTypeFieldRequest()
            {
                ReferenceName = field.ReferenceName
            }, processId, workItemType);
        }