public static ProcessWorkItemType CloneWorkItemType(VssConnection connection, string witRefName, Guid processId)
        {
            ProcessWorkItemType wit = Process.GetWorkItemType(connection, processId, witRefName);

            if (wit == null)
            {
                return(null);
            }

            WorkItemTrackingProcessHttpClient client = connection.GetClient <WorkItemTrackingProcessHttpClient>();

            CreateProcessWorkItemTypeRequest createWitRequest = new CreateProcessWorkItemTypeRequest()
            {
                Color        = wit.Color,
                Description  = wit.Description,
                Name         = wit.Name,
                Icon         = wit.Icon,
                InheritsFrom = wit.Inherits,
                IsDisabled   = false
            };

            ProcessWorkItemType results = client.CreateProcessWorkItemTypeAsync(createWitRequest, processId).Result;

            return(results);
        }
Exemple #2
0
        public ProcessWorkItemType WorkItemTypes_Create()
        {
            //get process id stored in cache so we don't have to load it each time
            System.Guid processId = Context.GetValue <Guid>("$processId");

            ProcessWorkItemType processWorkItemType = null;

            CreateProcessWorkItemTypeRequest createWorkItemType = new CreateProcessWorkItemTypeRequest()
            {
                Name        = "Change Request",
                Description = "Change request to track requests for changes :)",
                Color       = "f6546a",
                Icon        = "icon_airplane"
                              //InheritsFrom = "Microsoft.VSTS.WorkItemTypes.UserStory"
            };

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

            Console.Write("Does work item type '{0}' already exists? ... ", createWorkItemType.Name);

            //get list of work item types and see if wit exists
            List <ProcessWorkItemType> list = client.GetProcessWorkItemTypesAsync(processId).Result;

            processWorkItemType = list.Find(x => x.Name == "Change Request");

            if (processWorkItemType == null)
            {
                Console.WriteLine("No");
                Console.WriteLine("");
                Console.Write("Creating new work item type '" + createWorkItemType.Name + "'...");

                try
                {
                    //create new work item type
                    processWorkItemType = client.CreateProcessWorkItemTypeAsync(createWorkItemType, processId).Result;

                    Console.WriteLine("success");
                    Console.WriteLine("{0} : {1}", processWorkItemType.Name, processWorkItemType.ReferenceName);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("failed");
                    Console.WriteLine("Error creating work item type: " + ex.InnerException.Message);
                }
            }
            else
            {
                Console.WriteLine("Yes");
                Console.WriteLine("{0} : {1}", processWorkItemType.Name, processWorkItemType.ReferenceName);
            }

            Context.SetValue <ProcessWorkItemType>("$newWorkItemType", processWorkItemType);

            return(processWorkItemType);
        }
        public async Task GetWorkItemType()
        {
            var pt      = new ProcessTemplate("https://whateveryousay.visualstudio.com", "gvdiglh3bcvi3silg5hgkqhqia5b6635ff6ek64vcubullzfldvq");
            var process = await pt.GetProcessByName("AgileWithExceptions");

            ProcessWorkItemType wit = await pt.GetWorkItemType(process.TypeId, "AgileWithExceptions.Bug");

            ProcessWorkItemType witBug = await pt.GetWorkItemType(process.TypeId, "AgileWithExceptions.Bug");

//            FormLayout layout = witProcessClient.GetFormLayoutAsync(processId, workItemTypeReferenceName).Result;
        }
        public static ProcessWorkItemType GetWorkItemType(VssConnection connection, System.Guid processId, string witRefName)
        {
            WorkItemTrackingProcessHttpClient client = connection.GetClient <WorkItemTrackingProcessHttpClient>();

            try
            {
                ProcessWorkItemType result = client.GetProcessWorkItemTypeAsync(processId, witRefName).Result;

                return(result);
            }
            catch (Exception)
            {
                return(null);
            }
        }
        public ProcessWorkItemType WorkItemType_Get()
        {
            ProcessWorkItemType processWorkItemType = null;

            //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>();

            //load the process by id
            processWorkItemType = client.GetProcessWorkItemTypeAsync(processId, _witRefName).Result;

            Console.WriteLine("Getting work item type for " + _refName);

            return(processWorkItemType);
        }
Exemple #6
0
        public ProcessWorkItemType WorkItemTypes_Update()
        {
            //get process id stored in cache so we don't have to load it each time
            System.Guid processId = Context.GetValue <Guid>("$processId");

            //create UpdateProcessWorkItemTypeRequest object and set properties for whatever you want to change
            UpdateProcessWorkItemTypeRequest updateWorkItemType = new UpdateProcessWorkItemTypeRequest()
            {
                Description = "This is my description"
            };

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

            Console.Write("Updating description for 'Change Request' work item type...");
            ProcessWorkItemType result = client.UpdateProcessWorkItemTypeAsync(updateWorkItemType, processId, _witRefName).Result;

            Console.WriteLine("success");

            return(result);
        }
        static void Main(string[] args)
        {
            var result = Parser.Default.ParseArguments <Options>(args);

            string accountUrl  = null;
            string projectName = null;

            result.WithParsed((options) =>
            {
                accountUrl  = options.AccountUrl;
                projectName = options.ProjectName;
            });

            result.WithNotParsed((e) =>
            {
                ConsoleLogger.LogError("Usage: WorkItemCustomizationSample.exe -a yourAccountUrl -p yourPojectName -c yourAreaPathName -g yourGroupName", true);
            });

            ConsoleLogger.Log("You might see a login screen if you have never signed in to your account using this app.");

            VssConnection connection = new VssConnection(new Uri(accountUrl), new VssClientCredentials());

            string workItemTypeName = "Task";
            string fieldName        = "StringField";

            // todo add sample for picklist field

            ConsoleLogger.Log("Getting team project");
            // Get the team project
            TeamProject project = GetProject(connection, projectName);

            ConsoleLogger.Log($"Getting process for team project {project.Name}");
            Process process = GetProcess(connection, project);

            if (process.Type != ProcessType.Inherited)
            {
                ConsoleLogger.LogError("The process is not an inherited process.", true);
            }

            List <WorkItemTypeModel> workItemTypes = GetProcessWorkItemTypes(connection, process);

            if (!TryGetWorkItemType(workItemTypes, workItemTypeName, out WorkItemTypeModel workItemType))
            {
                ConsoleLogger.LogError("The work item type does not exist.", true);
            }

            string systemTypeRefName  = null;
            string derivedTypeRefName = null;

            if (workItemType.Class == WorkItemTypeClass.Derived)
            {
                systemTypeRefName  = workItemType.Inherits;
                derivedTypeRefName = workItemType.Id;
            }
            else
            {
                systemTypeRefName = workItemType.Id;
            }

            // since the derived type doesnt exists in the process. Lets add one.
            if (string.IsNullOrEmpty(derivedTypeRefName))
            {
                ConsoleLogger.Log("Derived work item type does not exit. Creating a new derived work item type");
                ProcessWorkItemType type = CreateWorkItemType(connection, process, workItemType);

                derivedTypeRefName = type.ReferenceName;
            }

            WorkItemField field = new WorkItemField()
            {
                Name = fieldName,
                Type = Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models.FieldType.String
            };

            // add the field to the derived type
            var processWorkItemTypeField = AddFieldToWorkItemType(connection, field, process, derivedTypeRefName);

            ConsoleLogger.Log("Adding field as a control to the layout");
            // add the field as a control on the layout
            AddFieldToWorkItemTypeLayout(connection, process, processWorkItemTypeField, derivedTypeRefName);

            ConsoleLogger.LogSuccess("Field was successfully added to the work item type and layout");
        }