private void GetWorkItemCategories(object argument) { var teamProjectNames = this.SelectedTeamProjects.Select(p => p.Name).ToList(); var task = new ApplicationTask("Retrieving work item categories", teamProjectNames.Count, true); PublishStatus(new StatusEventArgs(task)); var step = 0; var worker = new BackgroundWorker(); worker.DoWork += (sender, e) => { var tfs = GetSelectedTfsTeamProjectCollection(); var store = tfs.GetService <WorkItemStore>(); var results = new List <WorkItemCategoryInfo>(); foreach (var teamProjectName in teamProjectNames) { task.SetProgress(step++, string.Format(CultureInfo.CurrentCulture, "Processing Team Project \"{0}\"", teamProjectName)); try { var project = store.Projects[teamProjectName]; var categoriesXml = WorkItemConfigurationItemImportExport.GetCategoriesXml(project); var categoryList = WorkItemCategoryList.Load(categoriesXml); foreach (var category in categoryList.Categories) { results.Add(new WorkItemCategoryInfo(teamProjectName, categoryList, category)); } } catch (Exception exc) { task.SetWarning(string.Format(CultureInfo.CurrentCulture, "An error occurred while processing Team Project \"{0}\"", teamProjectName), exc); } if (task.IsCanceled) { task.Status = "Canceled"; break; } } e.Result = results; }; worker.RunWorkerCompleted += (sender, e) => { if (e.Error != null) { Logger.Log("An unexpected exception occurred while retrieving work item categories", e.Error); task.SetError(e.Error); task.SetComplete("An unexpected exception occurred"); } else { this.WorkItemCategories = (ICollection <WorkItemCategoryInfo>)e.Result; task.SetComplete("Retrieved " + this.WorkItemCategories.Count.ToCountString("work item category")); } }; worker.RunWorkerAsync(); }
private void LoadWorkItemCategoryList(object argument) { using (var dialog = new TeamProjectPicker(TeamProjectPickerMode.SingleProject, false)) { var result = dialog.ShowDialog(Application.Current.MainWindow.GetIWin32Window()); if (result == System.Windows.Forms.DialogResult.OK && dialog.SelectedProjects != null && dialog.SelectedProjects.Length > 0) { var teamProjectCollection = dialog.SelectedTeamProjectCollection; var teamProject = dialog.SelectedProjects.First(); var task = new ApplicationTask("Loading work item category list"); PublishStatus(new StatusEventArgs(task)); var worker = new BackgroundWorker(); worker.DoWork += (sender, e) => { var tfs = GetTfsTeamProjectCollection(teamProjectCollection.Uri); var store = tfs.GetService <WorkItemStore>(); var project = store.Projects[teamProject.Name]; var categoriesXml = WorkItemConfigurationItemImportExport.GetCategoriesXml(project); var selectedWorkItemCategoryList = WorkItemCategoryList.Load(categoriesXml); var availableWorkItemTypeReferences = project.WorkItemTypes.Cast <WorkItemType>().Select(w => new WorkItemTypeReference { Name = w.Name }).ToList(); e.Result = new Tuple <WorkItemCategoryList, ICollection <WorkItemTypeReference> >(selectedWorkItemCategoryList, availableWorkItemTypeReferences); }; worker.RunWorkerCompleted += (sender, e) => { if (e.Error != null) { Logger.Log("An unexpected exception occurred while importing the work item category list", e.Error); task.SetError(e.Error); task.SetComplete("An unexpected exception occurred"); } else { var loadResult = (Tuple <WorkItemCategoryList, ICollection <WorkItemTypeReference> >)e.Result; this.SelectedWorkItemCategoryList = loadResult.Item1; this.AvailableWorkItemTypeReferences = loadResult.Item2; this.SelectedWorkItemCategory = this.SelectedWorkItemCategoryList.Categories.FirstOrDefault(); task.SetComplete("Done"); } }; worker.RunWorkerAsync(); } } }
private void GetWorkItemTypes(object argument) { var teamProjects = this.SelectedTeamProjects.ToList(); var task = new ApplicationTask("Retrieving work item types", teamProjects.Count, true); PublishStatus(new StatusEventArgs(task)); var step = 0; var worker = new BackgroundWorker(); worker.DoWork += (sender, e) => { var tfs = GetSelectedTfsTeamProjectCollection(); var store = tfs.GetService <WorkItemStore>(); var results = new List <WorkItemTypeInfo>(); foreach (var teamProject in teamProjects) { task.SetProgress(step++, string.Format(CultureInfo.CurrentCulture, "Processing Team Project \"{0}\"", teamProject.Name)); try { var project = store.Projects[teamProject.Name]; var categoriesXml = WorkItemConfigurationItemImportExport.GetCategoriesXml(project); var categoryList = WorkItemCategoryList.Load(categoriesXml); foreach (WorkItemType workItemType in project.WorkItemTypes) { var parameters = new Dictionary <string, object>() { { "WorkItemType", workItemType.Name }, { "TeamProject", workItemType.Project.Name } }; var workItemCount = store.QueryCount("SELECT [System.Id] FROM WorkItems WHERE [System.WorkItemType] = @WorkItemType AND [System.TeamProject] = @TeamProject", parameters); var referencingCategories = categoryList.Categories.Where(c => c.WorkItemTypes.Concat(new WorkItemTypeReference[] { c.DefaultWorkItemType }).Any(w => string.Equals(w.Name, workItemType.Name, StringComparison.OrdinalIgnoreCase))).Select(c => c.Name); var workItemTypeDefinition = WorkItemTypeDefinition.FromXml(workItemType.Export(false)); results.Add(new WorkItemTypeInfo(teamProject, workItemType.Name, workItemType.Description, workItemCount, referencingCategories.ToList(), workItemTypeDefinition)); } } catch (Exception exc) { task.SetWarning(string.Format(CultureInfo.CurrentCulture, "An error occurred while processing Team Project \"{0}\"", teamProject.Name), exc); } if (task.IsCanceled) { task.Status = "Canceled"; break; } } e.Result = results; }; worker.RunWorkerCompleted += (sender, e) => { if (e.Error != null) { Logger.Log("An unexpected exception occurred while retrieving work item types", e.Error); task.SetError(e.Error); task.SetComplete("An unexpected exception occurred"); } else { this.WorkItemTypes = (ICollection <WorkItemTypeInfo>)e.Result; task.SetComplete("Retrieved " + this.WorkItemTypes.Count.ToCountString("work item type")); } }; worker.RunWorkerAsync(); }
private void DeleteSelectedWorkItemCategories(object argument) { var workItemCategoriesToDelete = this.SelectedWorkItemCategories; var result = MessageBox.Show("This will delete the selected work item categories. Certain applications like Microsoft Test Manager rely on categories so deleting them can reduce their functionality. Are you sure you want to continue?", "Confirm Delete", MessageBoxButton.YesNo, MessageBoxImage.Warning); if (result != MessageBoxResult.Yes) { return; } var task = new ApplicationTask("Deleting " + workItemCategoriesToDelete.Count.ToCountString("work item category"), workItemCategoriesToDelete.Count, true); PublishStatus(new StatusEventArgs(task)); var step = 0; var worker = new BackgroundWorker(); worker.DoWork += (sender, e) => { var tfs = GetSelectedTfsTeamProjectCollection(); var store = tfs.GetService <WorkItemStore>(); foreach (var categoriesByTeamProject in workItemCategoriesToDelete.GroupBy(c => c.TeamProject).ToList()) { var teamProjectName = categoriesByTeamProject.Key; try { var project = store.Projects[teamProjectName]; var categoriesXml = WorkItemConfigurationItemImportExport.GetCategoriesXml(project); var categoryList = WorkItemCategoryList.Load(categoriesXml); foreach (var workItemCategoryToDelete in categoriesByTeamProject) { try { task.SetProgress(step++, string.Format(CultureInfo.CurrentCulture, "Deleting work item category \"{0}\" from Team Project \"{1}\"", workItemCategoryToDelete.WorkItemCategory.Name, workItemCategoryToDelete.TeamProject)); var category = categoryList.Categories.FirstOrDefault(c => string.Equals(c.RefName, workItemCategoryToDelete.WorkItemCategory.RefName, StringComparison.OrdinalIgnoreCase)); if (category != null) { categoryList.Categories.Remove(category); } } catch (Exception exc) { task.SetError(string.Format(CultureInfo.CurrentCulture, "An error occurred while deleting the work item category \"{0}\" for Team Project \"{1}\"", workItemCategoryToDelete.WorkItemCategory.Name, workItemCategoryToDelete.TeamProject), exc); } } categoriesXml = categoryList.Save(); WorkItemConfigurationItemImportExport.SetCategories(project, categoriesXml); } catch (Exception exc) { task.SetError(string.Format(CultureInfo.CurrentCulture, "An error occurred while processing Team Project \"{0}\"", teamProjectName), exc); } if (task.IsCanceled) { task.Status = "Canceled"; break; } } }; worker.RunWorkerCompleted += (sender, e) => { if (e.Error != null) { Logger.Log("An unexpected exception occurred while deleting work item categories", e.Error); task.SetError(e.Error); task.SetComplete("An unexpected exception occurred"); } else { task.SetComplete("Deleted " + workItemCategoriesToDelete.Count.ToCountString("work item category")); } // Refresh the list. GetWorkItemCategories(null); }; worker.RunWorkerAsync(); }