private void importFromTeamProjectButton_Click(object sender, RoutedEventArgs e) { 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) { try { this.IsEnabled = false; var teamProjectCollection = dialog.SelectedTeamProjectCollection; var teamProject = dialog.SelectedProjects.First(); var tfs = TfsTeamProjectCollectionCache.GetTfsTeamProjectCollection(teamProjectCollection.Uri); var store = tfs.GetService <WorkItemStore>(); var project = store.Projects[teamProject.Name]; this.Configuration = WorkItemConfiguration.FromTeamProject(tfs, project); } finally { this.IsEnabled = true; } } } }
public WorkItemConfigurationComparisonResult(WorkItemConfiguration source, WorkItemConfiguration target, ICollection <WorkItemConfigurationItemComparisonResult> itemResults) { this.Source = source; this.Target = target; this.ItemResults = itemResults ?? new WorkItemConfigurationItemComparisonResult[0]; this.PercentMatch = this.ItemResults.Count == 0 ? 1.0 : this.ItemResults.Average(r => r.PercentMatch); }
private void Compare(object argument) { var teamProjectNames = this.SelectedTeamProjects.Select(p => p.Name).ToList(); var sources = this.ComparisonSources.ToList(); var ignoreCase = this.IgnoreCase; var task = new ApplicationTask("Comparing work item configurations", 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 <TeamProjectComparisonResult>(); foreach (var teamProjectName in teamProjectNames) { task.SetProgress(step++, string.Format(CultureInfo.CurrentCulture, "Processing Team Project \"{0}\"", teamProjectName)); try { var project = store.Projects[teamProjectName]; var target = WorkItemConfiguration.FromTeamProject(tfs, project); var sourceComparisonResults = new List <WorkItemConfigurationComparisonResult>(); foreach (var source in sources) { sourceComparisonResults.Add(WorkItemConfigurationComparer.Compare(this.SelectedTeamProjectCollection.TeamFoundationServer.MajorVersion, source, target, ignoreCase)); } results.Add(new TeamProjectComparisonResult(teamProjectName, sourceComparisonResults)); } 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 comparing work item configurations", e.Error); task.SetError(e.Error); task.SetComplete("An unexpected exception occurred"); } else { this.ComparisonResults = (ICollection <TeamProjectComparisonResult>)e.Result; task.SetComplete("Done"); } }; worker.RunWorkerAsync(); }
private void importFromProcessTemplateButton_Click(object sender, RoutedEventArgs e) { var dialog = new OpenFileDialog(); dialog.Title = "Please select the Process Template file that defines the configuration files to compare with."; dialog.Filter = "Process Template XML Files (ProcessTemplate.xml)|ProcessTemplate.xml"; var result = dialog.ShowDialog(Application.Current.MainWindow); if (result == true) { try { this.Configuration = WorkItemConfiguration.FromProcessTemplate(dialog.FileName); } catch (Exception exc) { MessageBox.Show("An error occurred while loading the process template: " + exc.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Warning); } } }
private void importFromRegisteredProcessTemplateButton_Click(object sender, RoutedEventArgs e) { using (var dialog = new TeamProjectPicker(TeamProjectPickerMode.NoProject, false)) { var result = dialog.ShowDialog(Application.Current.MainWindow.GetIWin32Window()); if (result == System.Windows.Forms.DialogResult.OK) { var projectCollection = dialog.SelectedTeamProjectCollection; var processTemplateService = projectCollection.GetService <IProcessTemplates>(); var registeredTemplates = processTemplateService.TemplateHeaders().OrderBy(t => t.Rank).ToArray(); var processTemplatePicker = new ProcessTemplatePickerDialog(registeredTemplates); processTemplatePicker.Owner = this; if (processTemplatePicker.ShowDialog() == true) { var downloadedTemplateZipFileName = processTemplateService.GetTemplateData(processTemplatePicker.SelectedProcessTemplate.TemplateId); var unzipPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); try { ZipFile.ExtractToDirectory(downloadedTemplateZipFileName, unzipPath); var processTemplateXmlFile = Path.Combine(unzipPath, "ProcessTemplate.xml"); if (!File.Exists(processTemplateXmlFile)) { MessageBox.Show("The selected Process Template did not contain a \"ProcessTemplate.xml\" file in its root directory.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } else { this.Configuration = WorkItemConfiguration.FromProcessTemplate(processTemplateXmlFile); } } finally { File.Delete(downloadedTemplateZipFileName); Directory.Delete(unzipPath, true); } } } } }
private WorkItemConfigurationEditorDialog(WorkItemConfiguration configuration, bool canCancel) { InitializeComponent(); this.Configuration = configuration; this.cancelButton.IsEnabled = canCancel; }
public WorkItemConfigurationEditorDialog(WorkItemConfiguration configuration) : this(configuration, false) { }
public static WorkItemConfigurationComparisonResult Compare(TfsMajorVersion tfsMajorVersion, WorkItemConfiguration source, WorkItemConfiguration target, bool ignoreCase) { var itemResults = new List <WorkItemConfigurationItemComparisonResult>(); var sourceItems = source.Items.ToList(); var targetItems = target.Items.ToList(); // Ignore TFS 2012 agile/common config when both source and target have TFS 2013 process config. if (sourceItems.Any(i => i.Type == WorkItemConfigurationItemType.ProcessConfiguration) && targetItems.Any(i => i.Type == WorkItemConfigurationItemType.ProcessConfiguration)) { sourceItems.RemoveAll(i => i.Type == WorkItemConfigurationItemType.CommonConfiguration || i.Type == WorkItemConfigurationItemType.AgileConfiguration); targetItems.RemoveAll(i => i.Type == WorkItemConfigurationItemType.CommonConfiguration || i.Type == WorkItemConfigurationItemType.AgileConfiguration); } // If the source doesn't have categories or agile/common/process config, ignore them in the target as well. if (!sourceItems.Any(i => i.Type == WorkItemConfigurationItemType.Categories)) { targetItems.RemoveAll(i => i.Type == WorkItemConfigurationItemType.Categories); } if (!sourceItems.Any(i => i.Type == WorkItemConfigurationItemType.AgileConfiguration)) { targetItems.RemoveAll(i => i.Type == WorkItemConfigurationItemType.AgileConfiguration); } if (!sourceItems.Any(i => i.Type == WorkItemConfigurationItemType.CommonConfiguration)) { targetItems.RemoveAll(i => i.Type == WorkItemConfigurationItemType.CommonConfiguration); } if (!sourceItems.Any(i => i.Type == WorkItemConfigurationItemType.ProcessConfiguration)) { targetItems.RemoveAll(i => i.Type == WorkItemConfigurationItemType.ProcessConfiguration); } foreach (var itemOnlyInSource in sourceItems.Where(s => !targetItems.Any(t => s.Type == t.Type && string.Equals(s.Name, t.Name, StringComparison.OrdinalIgnoreCase)))) { itemResults.Add(new WorkItemConfigurationItemComparisonResult(itemOnlyInSource.XmlDefinition, null, itemOnlyInSource.Name, itemOnlyInSource.Type, ComparisonStatus.ExistsOnlyInSource)); } var comparisonType = ignoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal; foreach (var targetItem in targetItems) { var sourceItem = sourceItems.FirstOrDefault(s => s.Type == targetItem.Type && string.Equals(s.Name, targetItem.Name, StringComparison.OrdinalIgnoreCase)); if (sourceItem == null) { itemResults.Add(new WorkItemConfigurationItemComparisonResult(null, targetItem.XmlDefinition, targetItem.Name, targetItem.Type, ComparisonStatus.ExistsOnlyInTarget)); } else { // To allow better comparisons between source XML files from Process Templates // and the actual exported work item configuration item, normalize and process some special cases. var sourceNormalizedXmlDefinition = XmlNormalizer.GetNormalizedXmlDefinition(sourceItem, tfsMajorVersion); var targetNormalizedXmlDefinition = XmlNormalizer.GetNormalizedXmlDefinition(targetItem, tfsMajorVersion); var partResults = new List <WorkItemConfigurationItemPartComparisonResult>(); var sourceParts = sourceItem.GetParts(sourceNormalizedXmlDefinition); var targetParts = targetItem.GetParts(targetNormalizedXmlDefinition); var totalSize = sourceParts.Sum(p => p.NormalizedXmlDefinition == null ? 0 : p.NormalizedXmlDefinition.OuterXml.Length); foreach (WorkItemConfigurationItemPart sourcePart in sourceParts) { var targetPart = targetParts.SingleOrDefault(p => p.Name == sourcePart.Name); ComparisonStatus status; if (targetPart == null) { status = ComparisonStatus.ExistsOnlyInSource; } else { status = string.Equals(XmlNormalizer.GetValue(sourcePart.NormalizedXmlDefinition), XmlNormalizer.GetValue(targetPart.NormalizedXmlDefinition), comparisonType) ? ComparisonStatus.AreEqual : ComparisonStatus.AreDifferent; } var relativeSize = (sourcePart.NormalizedXmlDefinition == null ? 0 : sourcePart.NormalizedXmlDefinition.OuterXml.Length) / (double)totalSize; partResults.Add(new WorkItemConfigurationItemPartComparisonResult(sourcePart.Name, status, relativeSize)); } itemResults.Add(new WorkItemConfigurationItemComparisonResult(sourceNormalizedXmlDefinition, targetNormalizedXmlDefinition, sourceItem.Name, sourceItem.Type, partResults)); } } return(new WorkItemConfigurationComparisonResult(source, target, itemResults)); }
public WorkItemConfigurationPersistenceData(WorkItemConfiguration source) { this.Name = source.Name; this.WorkItemConfigurationItems = source.Items.Select(w => w.XmlDefinition.OuterXml).ToList(); }