private void Import(object argument) { var options = ImportOptions.None; if (this.Simulate) { options |= ImportOptions.Simulate; } if (this.SaveCopy) { options |= ImportOptions.SaveCopy; } var workItemTypes = new List <WorkItemConfigurationItem>(); foreach (var workItemTypeFile in this.WorkItemTypeFiles) { try { workItemTypes.Add(WorkItemTypeDefinition.FromFile(workItemTypeFile)); } catch (Exception exc) { this.Logger.Log(string.Format(CultureInfo.CurrentCulture, "An error occurred while loading the work item type from \"{0}\"", workItemTypeFile), exc); MessageBox.Show(string.Format(CultureInfo.CurrentCulture, "An error occurred while loading the work item type from \"{0}\". See the log file for details", workItemTypeFile), "Error", MessageBoxButton.OK, MessageBoxImage.Warning); } } var teamProjectsWithWorkItemTypes = this.SelectedTeamProjects.ToDictionary(p => p, p => workItemTypes); if (!options.HasFlag(ImportOptions.Simulate)) { var result = MessageBox.Show("This will import the selected work item types. Are you sure you want to continue?", "Confirm Import", MessageBoxButton.YesNo, MessageBoxImage.Warning); if (result != MessageBoxResult.Yes) { return; } } PerformImport(options, teamProjectsWithWorkItemTypes); }
public static WorkItemConfiguration FromProcessTemplate(string processTemplateFileName) { // Load the process template XML. if (!File.Exists(processTemplateFileName)) { throw new FileNotFoundException("The process template file does not exist: " + processTemplateFileName); } var processTemplate = new XmlDocument(); processTemplate.Load(processTemplateFileName); var baseDir = Path.GetDirectoryName(processTemplateFileName); var items = new List <WorkItemConfigurationItem>(); string processTemplateName = null; var processTemplateNameNode = processTemplate.SelectSingleNode("/ProcessTemplate/metadata/name"); if (processTemplateNameNode != null) { processTemplateName = processTemplateNameNode.InnerText; } // Find the work item tracking XML file. var workItemFileNameAttribute = processTemplate.SelectSingleNode("/ProcessTemplate/groups/group[@id='WorkItemTracking']/taskList/@filename"); if (workItemFileNameAttribute != null) { // Load the work item tracking XML. var workItemConfigurationTemplateFileName = Path.Combine(baseDir, workItemFileNameAttribute.InnerText); if (!File.Exists(workItemConfigurationTemplateFileName)) { throw new FileNotFoundException("The work item configuration file defined in the process template file does not exist: " + workItemConfigurationTemplateFileName); } var workItemConfigurationTemplate = new XmlDocument(); workItemConfigurationTemplate.Load(workItemConfigurationTemplateFileName); // Find all work item type definition XML files. foreach (XmlAttribute witFileNameAttribute in workItemConfigurationTemplate.SelectNodes("/tasks/task[@id='WITs']/taskXml/WORKITEMTYPES/WORKITEMTYPE/@fileName")) { var witFileName = Path.Combine(baseDir, witFileNameAttribute.InnerText); items.Add(WorkItemTypeDefinition.FromFile(witFileName)); } // Find the categories XML file. var categoriesFileNameAttribute = workItemConfigurationTemplate.SelectSingleNode("/tasks/task[@id='Categories']/taskXml/CATEGORIES/@fileName"); if (categoriesFileNameAttribute != null) { var categoriesFileName = Path.Combine(baseDir, categoriesFileNameAttribute.InnerText); items.Add(WorkItemConfigurationItem.FromFile(categoriesFileName)); } else { // If the process template doesn't specify any categories (typically because it's an old // process template from before Work Item Categories existed), load an empty list anyway. // This will improve comparisons because a Team Project will always have a Work Item // Categories configuration item (even if it's empty). items.Add(WorkItemConfigurationItem.FromXml("<cat:CATEGORIES xmlns:cat=\"http://schemas.microsoft.com/VisualStudio/2008/workitemtracking/categories\"/>")); } // Find the common configuration XML file. var commonConfigurationFileNameAttribute = workItemConfigurationTemplate.SelectSingleNode("/tasks/task[@id='ProcessConfiguration']/taskXml/PROCESSCONFIGURATION/CommonConfiguration/@fileName"); if (commonConfigurationFileNameAttribute != null) { var commonConfigurationFileName = Path.Combine(baseDir, commonConfigurationFileNameAttribute.InnerText); items.Add(WorkItemConfigurationItem.FromFile(commonConfigurationFileName)); } // Find the agile configuration XML file. var agileConfigurationFileNameAttribute = workItemConfigurationTemplate.SelectSingleNode("/tasks/task[@id='ProcessConfiguration']/taskXml/PROCESSCONFIGURATION/AgileConfiguration/@fileName"); if (agileConfigurationFileNameAttribute != null) { var agileConfigurationFileName = Path.Combine(baseDir, agileConfigurationFileNameAttribute.InnerText); items.Add(WorkItemConfigurationItem.FromFile(agileConfigurationFileName)); } // Find the process configuration XML file. var processConfigurationFileNameAttribute = workItemConfigurationTemplate.SelectSingleNode("/tasks/task[@id='ProcessConfiguration']/taskXml/PROCESSCONFIGURATION/ProjectConfiguration/@fileName"); if (processConfigurationFileNameAttribute != null) { var processConfigurationFileName = Path.Combine(baseDir, processConfigurationFileNameAttribute.InnerText); items.Add(WorkItemConfigurationItem.FromFile(processConfigurationFileName)); } } return(new WorkItemConfiguration(processTemplateName, items)); }