Exemple #1
0
        /// <summary>
        /// Create and disable new custom work item type
        /// </summary>
        /// <param name="procId"></param>
        private static void CreateAndDiableWorkItemType(Guid procId)
        {
            CreateProcessWorkItemTypeRequest cpwit = new CreateProcessWorkItemTypeRequest();

            cpwit.Name        = "Child Task";
            cpwit.Icon        = wi_icons.asterisk;
            cpwit.Color       = "f6546a";
            cpwit.Description = "My new work item type to track child work";

            var newwit = ProcessHttpClient.CreateProcessWorkItemTypeAsync(cpwit, procId).Result;

            Console.WriteLine("New work item type: {0} - {1}", newwit.Name, newwit.ReferenceName);

            Console.ReadKey();

            UpdateProcessWorkItemTypeRequest upwit = new UpdateProcessWorkItemTypeRequest();

            upwit.Description = "Temporary disabled";
            upwit.IsDisabled  = true;
            upwit.Icon        = wi_icons.broken_lightbulb;

            newwit = ProcessHttpClient.UpdateProcessWorkItemTypeAsync(upwit, procId, newwit.ReferenceName).Result;

            Console.WriteLine("Disabled work item type: {0} - {1}", newwit.Name, newwit.ReferenceName);

            Console.ReadKey();
        }
        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 #3
0
        /// <summary>
        /// Create and remove custom work item type based on a defult type
        /// </summary>
        /// <param name="procId"></param>
        static private void ReCreateIssueWIT(Guid procId)
        {
            var issueRef = "Microsoft.VSTS.WorkItemTypes.Issue";

            CreateProcessWorkItemTypeRequest cpwit = new CreateProcessWorkItemTypeRequest();

            cpwit.Icon         = wi_icons.clipboard_issue;
            cpwit.Color        = "f6546a";
            cpwit.Description  = "My new work item type to track issues";
            cpwit.InheritsFrom = issueRef;

            var newwit = ProcessHttpClient.CreateProcessWorkItemTypeAsync(cpwit, procId).Result;

            Console.WriteLine("Updated work item type: {0} - {1}", newwit.Name, newwit.ReferenceName);

            Console.ReadKey();

            UpdateProcessWorkItemTypeRequest upwit = new UpdateProcessWorkItemTypeRequest();

            upwit.Icon = wi_icons.car;

            var iswit = ProcessHttpClient.UpdateProcessWorkItemTypeAsync(upwit, procId, newwit.ReferenceName).Result;

            Console.WriteLine("Updated work item type: {0} - {1}", iswit.Name, iswit.ReferenceName);

            Console.ReadKey();

            ProcessHttpClient.DeleteProcessWorkItemTypeAsync(procId, iswit.ReferenceName).Wait();

            Console.WriteLine("Work item type removed");

            Console.ReadKey();
        }
Exemple #4
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);
        }
Exemple #5
0
        /// <summary>
        /// Create a inherited work item type to make changes in the work flow
        /// </summary>
        /// <param name="procId"></param>
        /// <param name="parentRef"></param>
        /// <returns></returns>

        static private string CreateInheritedWIT(Guid procId, string parentRef)
        {
            var witDef = ProcessHttpClient.GetProcessWorkItemTypeAsync(procId, parentRef).Result;
            CreateProcessWorkItemTypeRequest cpwit = new CreateProcessWorkItemTypeRequest();

            cpwit.Color        = witDef.Color;
            cpwit.Icon         = witDef.Icon;
            cpwit.InheritsFrom = parentRef;

            var newwit = ProcessHttpClient.CreateProcessWorkItemTypeAsync(cpwit, procId).Result;

            return(newwit.ReferenceName);
        }
        private static ProcessWorkItemType CreateWorkItemType(VssConnection connection, Process process, WorkItemTypeModel workItemType)
        {
            var model = new CreateProcessWorkItemTypeRequest()
            {
                Name         = workItemType.Name,
                InheritsFrom = workItemType.Id,
                Color        = workItemType.Color,
                Icon         = workItemType.Icon,
                IsDisabled   = workItemType.IsDisabled ?? false
            };

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

            return(workClient.CreateProcessWorkItemTypeAsync(model, process.Id).Result);
        }
        public static void ProcessFile(VssConnection connection, string type, string fileContent)
        {
            switch (type)
            {
            case "project":
                var project       = JsonConvert.DeserializeObject <Project>(fileContent);
                var projectClient = connection.GetClient <ProjectHttpClient>();

                try
                {
                    var existingProject = projectClient.GetProject(project.Name).SyncResult();

                    if (existingProject != null)
                    {
                        //TODO: add capabilities or changes
                        return;
                    }
                }
                catch (Exception e)
                {
                    //this throws an exception if the project does not exists
                }


                var capabilities = new Dictionary <string, Dictionary <string, string> >();

                Dictionary <string, string> versionControlProperties = new Dictionary <string, string>();

                versionControlProperties[TeamProjectCapabilitiesConstants.VersionControlCapabilityAttributeName] =
                    SourceControlTypes.Git.ToString();

                // Setup process properties
                Dictionary <string, string> processProperaties = new Dictionary <string, string>();

                processProperaties[TeamProjectCapabilitiesConstants.ProcessTemplateCapabilityTemplateTypeIdAttributeName] =
                    ProcessMap["Basic"].ToString();

                capabilities[TeamProjectCapabilitiesConstants.VersionControlCapabilityName] =
                    versionControlProperties;
                capabilities[TeamProjectCapabilitiesConstants.ProcessTemplateCapabilityName] =
                    processProperaties;
                var newProject = new TeamProject()
                {
                    Name         = project.Name,
                    Description  = project.Description,
                    Visibility   = (ProjectVisibility)project.Visibility,
                    Capabilities = capabilities
                };
                projectClient.QueueCreateProject(newProject).SyncResult();
                break;

            case "process":
                var process       = JsonConvert.DeserializeObject <AzdoBoardsManager.Models.Process>(fileContent);
                var processClient = connection.GetClient <WorkItemTrackingProcessHttpClient>();

                if (ProcessMap.ContainsKey(process.ReferenceName ?? process.Name))
                {
                    return;
                }

                if (string.IsNullOrWhiteSpace(process.ReferenceName))
                {
                    return;
                }

                var createProcess = new CreateProcessModel()
                {
                    Name          = process.Name,
                    Description   = process.Description,
                    ReferenceName = process.ReferenceName,
                };

                if (!string.IsNullOrEmpty(process.ParentProcessId))
                {
                    createProcess.ParentProcessTypeId = ProcessMap[process.ParentProcessId];
                }

                var processInfo = processClient.CreateNewProcessAsync(createProcess).SyncResult();
                ProcessMap.Add(processInfo.ReferenceName ?? processInfo.Name, processInfo.TypeId);
                break;

            case "workitemtype":
                var workItemType = JsonConvert.DeserializeObject <AzdoBoardsManager.Models.WorkItemType>(fileContent);

                WorkItemTypes.Add(workItemType.Id, workItemType);

                var witClient = connection.GetClient <WorkItemTrackingProcessHttpClient>();

                try
                {
                    var types       = witClient.GetProcessWorkItemTypesAsync(ProcessMap[workItemType.ProcessId]).SyncResult();
                    var existingWit = witClient.GetProcessWorkItemTypeAsync(ProcessMap[workItemType.ProcessId], workItemType.Id).SyncResult();

                    if (existingWit != null)
                    {
                        //TODO: add capabilities or changes
                        return;
                    }
                }
                catch (Exception e)
                {
                    //this throws an exception if the project does not exists
                }

                var createWorkItemType = new CreateProcessWorkItemTypeRequest()
                {
                    Name         = workItemType.Name,
                    Description  = workItemType.Description,
                    Color        = workItemType.Color,
                    Icon         = workItemType.Icon,
                    InheritsFrom = workItemType.Inherits,
                    IsDisabled   = workItemType.IsDisabled
                };
                var processName = workItemType.ProcessId;

                witClient.CreateProcessWorkItemTypeAsync(createWorkItemType, ProcessMap[processName]).SyncResult();
                break;

            case "workitemtypestates":
                var witTrackingClient  = connection.GetClient <WorkItemTrackingProcessHttpClient>();
                var workItemTypeStates = JsonConvert.DeserializeObject <List <WorkItemTypeState> >(fileContent);

                if (workItemTypeStates.Count == 0)
                {
                    return;
                }

                var firstWorkItem    = workItemTypeStates[0];
                var workItemId       = firstWorkItem.WorkItemId;
                var processId        = ProcessMap[WorkItemTypes[firstWorkItem.WorkItemId].ProcessId];
                var stateDefinitions = witTrackingClient.GetStateDefinitionsAsync(
                    processId,
                    firstWorkItem.WorkItemId
                    ).SyncResult();
                var stateDefinitionsMap = new Dictionary <string, bool>();

                //We iterate to verify what is existing what needs to be created
                foreach (var workItemTypeState in workItemTypeStates)
                {
                    stateDefinitionsMap.Add(workItemTypeState.Name, false);

                    foreach (var def in stateDefinitions)
                    {
                        if (def.Name.Equals(workItemTypeState.Name))
                        {
                            stateDefinitionsMap[workItemTypeState.Name] = true;
                        }
                    }
                }

                //Extra will be deleted
                foreach (var def in stateDefinitions)
                {
                    if (!stateDefinitionsMap.ContainsKey(def.Name))
                    {
                        witTrackingClient.DeleteStateDefinitionAsync(
                            processId,
                            workItemId,
                            def.Id
                            ).SyncResult();
                    }
                }

                //We create the missing ones
                foreach (var workItemTypeState in workItemTypeStates)
                {
                    if (!stateDefinitionsMap[workItemTypeState.Name])
                    {
                        var workItemStateInputModel = new WorkItemStateInputModel()
                        {
                            Name          = workItemTypeState.Name,
                            Color         = workItemTypeState.Color,
                            StateCategory = workItemTypeState.StateCategory,
                            Order         = workItemTypeState.Order
                        };

                        var states = witTrackingClient.CreateStateDefinitionAsync(
                            workItemStateInputModel,
                            processId,
                            workItemTypeState.WorkItemId
                            ).SyncResult();
                    }
                }
                break;
            }
        }
        public async Task EnsureExceptionWorkItemType(Guid processId, string processName, string workItemTypeName)
        {
            var witReferenceName    = $"{processName}.{workItemTypeName}";
            var processWorkItemType = await GetWorkItemType(processId, witReferenceName);

            if (processWorkItemType == null)
            {
                var createWorkItemType = new CreateProcessWorkItemTypeRequest()
                {
                    Name        = workItemTypeName,
                    Description = "Used for tracking unhandled application exceptions",
                    Color       = "f6546a",
                    Icon        = "icon_airplane",
                    //InheritsFrom = "Microsoft.VSTS.WorkItemTypes.Bug"
                };
                processWorkItemType = await witProcessClient.CreateProcessWorkItemTypeAsync(createWorkItemType, processId);
            }

            await EnsureFieldExists("Custom.ExceptionApplication", "Application", "Application", processWorkItemType.ReferenceName, processId);


            //Add page
            var page = witProcessClient.AddPageAsync(new Page()
            {
                Label    = "Exception",
                PageType = PageType.Custom,

                Sections = new List <Section>()
                {
                    new Section()
                    {
                        Id     = "Section1",
                        Groups = new List <Group>()
                        {
                            new Group()
                            {
                                Label    = "MyGroup",
                                Controls = new List <Control>()
                                {
                                    new Control()
                                    {
                                        Id          = "Custom.ExceptionApplication",
                                        Label       = "Application",
                                        ControlType = "FieldControl",
                                        Name        = "Application",
                                        Visible     = true
                                    }
                                }
                            }
                        }
                    }
                }
            }, processId, processWorkItemType.ReferenceName).Result;

            ////Add fields
            //var fields = new string[]
            //{
            //            TfsStoreWithException.Application,
            //            TfsStoreWithException.AssignedToFieldName,
            //            TfsStoreWithException.CommentFieldName,
            //            TfsStoreWithException.RefCountFieldName,
            //            TfsStoreWithException.ExceptionReporterFieldName,
            //            TfsStoreWithException.BuildVersionFieldName,
            //            TfsStoreWithException.ExceptionMessageFieldName,
            //            TfsStoreWithException.ExceptionTypeFieldName,
            //            TfsStoreWithException.ClassFieldName,
            //            TfsStoreWithException.MethodFieldName,
            //            TfsStoreWithException.SourceFieldName,
            //            TfsStoreWithException.StackTraceFieldName,
            //            TfsStoreWithException.StackChecksumFieldName,
            //            TfsStoreWithException.AssemblyName
            //    };
        }