private void importFromProcessTemplateButton_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         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);
             }
         }
     }
     catch (Exception exc)
     {
         ShowException(exc);
     }
 }
Ejemplo n.º 2
0
        private void importFromRegisteredProcessTemplateButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                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 ItemsPickerDialog();
                        processTemplatePicker.Title                 = "Please select a Process Template";
                        processTemplatePicker.SelectionMode         = SelectionMode.Single;
                        processTemplatePicker.AvailableItems        = registeredTemplates;
                        processTemplatePicker.ItemDisplayMemberPath = nameof(TemplateHeader.Name);
                        processTemplatePicker.Owner                 = this;
                        if (processTemplatePicker.ShowDialog() == true)
                        {
                            var selectedProcessTemplate = (TemplateHeader)processTemplatePicker.SelectedItem;
                            if (selectedProcessTemplate != null)
                            {
                                var downloadedTemplateZipFileName = processTemplateService.GetTemplateData(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);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception exc)
            {
                ShowException(exc);
            }
        }