public ProcessInfo Process_Create() { ProcessInfo processInfo = Process_Get(); if (processInfo != null) { return(processInfo); } //create process model record object that will be used to create the process CreateProcessModel processModel = new CreateProcessModel { Name = "MyNewAgileProcess", ParentProcessTypeId = new System.Guid("adcc42ab-9882-485e-a3ed-7678f01f66bc"), ReferenceName = _refName, Description = "My new process" }; Console.Write("Creating new processes '" + _refName + "'..."); VssConnection connection = Context.Connection; WorkItemTrackingProcessHttpClient client = connection.GetClient <WorkItemTrackingProcessHttpClient>(); try { //save type id for later use processInfo = client.CreateNewProcessAsync(processModel).Result; Console.WriteLine("success"); Console.WriteLine("Process Id: {0}", processInfo.TypeId); Context.SetValue <Guid>("$processId", processInfo.TypeId); } catch (Exception ex) //exception will be thrown if process already exists { Console.WriteLine("failed"); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(ex.InnerException.Message); } finally { Console.ForegroundColor = ConsoleColor.White; } return(processInfo); }
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; } }