From 4564b535a50a79abaf0aff4d555c519f2f43f841 Mon Sep 17 00:00:00 2001 From: anthony Date: Thu, 6 Nov 2014 17:10:17 +0000 Subject: [PATCH 1/4] fix for issue #4 - made export and import of nested process parameters work correctly --- .../ImportBuildDefinitions.xaml.cs | 13 +++++++++++-- .../ViewModels/BuildManagerViewModel.cs | 9 ++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Manager/TFSBuildManager.Views/ImportBuildDefinitions.xaml.cs b/Manager/TFSBuildManager.Views/ImportBuildDefinitions.xaml.cs index 9cd383d..9dd1047 100644 --- a/Manager/TFSBuildManager.Views/ImportBuildDefinitions.xaml.cs +++ b/Manager/TFSBuildManager.Views/ImportBuildDefinitions.xaml.cs @@ -132,8 +132,17 @@ private void ButtonImport_OnClick(object sender, RoutedEventArgs e) { Newtonsoft.Json.Linq.JArray arrayItem = param.Value as Newtonsoft.Json.Linq.JArray; if (arrayItem == null) - { - process.Add(param.Key, param.Value); + { + Newtonsoft.Json.Linq.JObject objectItem = param.Value as Newtonsoft.Json.Linq.JObject; + if (objectItem == null) + { + process.Add(param.Key, param.Value); + } + else + { + Microsoft.TeamFoundation.Build.Common.BuildParameter paramItem = new Microsoft.TeamFoundation.Build.Common.BuildParameter(param.Value.ToString()); + process.Add(param.Key, paramItem); + } } else { diff --git a/Manager/TFSBuildManager.Views/ViewModels/BuildManagerViewModel.cs b/Manager/TFSBuildManager.Views/ViewModels/BuildManagerViewModel.cs index b97aa8f..dd3189c 100644 --- a/Manager/TFSBuildManager.Views/ViewModels/BuildManagerViewModel.cs +++ b/Manager/TFSBuildManager.Views/ViewModels/BuildManagerViewModel.cs @@ -1057,7 +1057,14 @@ private static void ExportDefinition(BuildDefinitionViewModel b, string filePath } buildToExport.ProcessParameters = WorkflowHelpers.DeserializeProcessParameters(b.BuildDefinition.ProcessParameters); - + foreach (KeyValuePair item in processParameters) + { + if (item.Value.GetType() == typeof(Microsoft.TeamFoundation.Build.Common.BuildParameter)) + { + buildToExport.ProcessParameters[item.Key] = JsonConvert.DeserializeObject(item.Value.ToString()); + } + } + File.WriteAllText(Path.Combine(filePath, b.Name + ".json"), JsonConvert.SerializeObject(buildToExport, Formatting.Indented)); } From 12eb6867bccaa023dd4c386ff096899f25ad74e9 Mon Sep 17 00:00:00 2001 From: Anthony Brown Date: Wed, 20 May 2015 19:15:23 +0100 Subject: [PATCH 2/4] removed .orig file from merge --- .../ImportBuildDefinitions.xaml.cs.orig | 273 ------------------ 1 file changed, 273 deletions(-) delete mode 100644 Manager/TFSBuildManager.Views/ImportBuildDefinitions.xaml.cs.orig diff --git a/Manager/TFSBuildManager.Views/ImportBuildDefinitions.xaml.cs.orig b/Manager/TFSBuildManager.Views/ImportBuildDefinitions.xaml.cs.orig deleted file mode 100644 index 042ce37..0000000 --- a/Manager/TFSBuildManager.Views/ImportBuildDefinitions.xaml.cs.orig +++ /dev/null @@ -1,273 +0,0 @@ -//----------------------------------------------------------------------- -// (c) https://github.com/tfsbuildextensions/BuildManager. This source is subject to the Microsoft Permissive License. See http://www.microsoft.com/resources/sharedsource/licensingbasics/sharedsourcelicenses.mspx. All other rights reserved. -//----------------------------------------------------------------------- - -namespace TfsBuildManager.Views -{ - using System; - using System.Collections.ObjectModel; - using System.IO; - using System.Linq; - using System.Windows; - using Microsoft.TeamFoundation.Build.Client; - using Microsoft.TeamFoundation.Build.Workflow; - using Microsoft.TeamFoundation.Build.Workflow.Activities; - using Newtonsoft.Json; - - /// - /// Interaction logic for ImportBuildDefinitions - /// - public partial class ImportBuildDefinitions - { - private readonly ObservableCollection buildFiles = new ObservableCollection(); - private readonly IBuildServer buildServer; - - public ImportBuildDefinitions(string teamProjectName, IBuildServer server) - { - this.InitializeComponent(); - this.lableTeamProject.Content = teamProjectName; - this.buildServer = server; - } - - public ObservableCollection BuildFiles - { - get { return this.buildFiles; } - } - - private void ButtonSelectFiles_OnClick(object sender, RoutedEventArgs e) - { - Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog { DefaultExt = ".json", Filter = "json Files (*.json)|*.json", Multiselect = true }; - bool? result = dlg.ShowDialog(); - if (result == true) - { - foreach (string filename in dlg.FileNames) - { - this.BuildFiles.Add(new BuildImport { JsonFile = filename }); - } - - this.DataGridBuildsToImport.ItemsSource = this.buildFiles; - } - } - - private void ButtonImport_OnClick(object sender, RoutedEventArgs e) - { - foreach (var item in this.DataGridBuildsToImport.Items) - { - BuildImport bi = item as BuildImport; - try - { - if (bi == null) - { - return; - } - - if (!File.Exists(bi.JsonFile)) - { - bi.Status = "Failed"; - bi.StatusImage = "Graphics/Failed.png"; - bi.Message = "File not found"; - } - else - { - ExportedBuildDefinition exdef = JsonConvert.DeserializeObject(File.ReadAllText(bi.JsonFile)); - var newBuildDefinition = this.buildServer.CreateBuildDefinition(this.lableTeamProject.Content.ToString()); - newBuildDefinition.Name = exdef.Name; - newBuildDefinition.Description = exdef.Description; - newBuildDefinition.ContinuousIntegrationType = exdef.ContinuousIntegrationType; - newBuildDefinition.ContinuousIntegrationQuietPeriod = exdef.ContinuousIntegrationQuietPeriod; - - newBuildDefinition.QueueStatus = exdef.QueueStatus; - if (exdef.SourceProviders.All(s => s.Name != "TFGIT")) - { - foreach (var mapping in exdef.Mappings) - { - newBuildDefinition.Workspace.AddMapping(mapping.ServerItem, mapping.LocalItem, mapping.MappingType); - } - } - - newBuildDefinition.RetentionPolicyList.Clear(); - foreach (var ret in exdef.RetentionPolicyList) - { - newBuildDefinition.AddRetentionPolicy(ret.BuildReason, ret.BuildStatus, ret.NumberToKeep, ret.DeleteOptions); - } - - foreach (var sp in exdef.SourceProviders) - { - var provider = newBuildDefinition.CreateInitialSourceProvider(sp.Name); - if (exdef.SourceProviders.All(s => s.Name == "TFGIT")) - { - provider.Fields["RepositoryName"] = sp.Fields["RepositoryName"]; - provider.Fields["DefaultBranch"] = sp.Fields["DefaultBranch"]; - provider.Fields["CIBranches"] = sp.Fields["CIBranches"]; - provider.Fields["RepositoryUrl"] = sp.Fields["RepositoryUrl"]; - } - - newBuildDefinition.SetSourceProvider(provider); - } - - newBuildDefinition.BuildController = this.buildServer.GetBuildController(exdef.BuildController); - var x = this.buildServer.QueryProcessTemplates(this.lableTeamProject.Content.ToString()); - if (x.All(p => p.ServerPath != exdef.ProcessTemplate)) - { - bi.Status = "Failed"; - bi.StatusImage = "Graphics/Failed.png"; - bi.Message = "Process Template not found - " + exdef.ProcessTemplate; - continue; - } - - newBuildDefinition.Process = this.buildServer.QueryProcessTemplates(this.lableTeamProject.Content.ToString()).First(p => p.ServerPath == exdef.ProcessTemplate); - newBuildDefinition.DefaultDropLocation = exdef.DefaultDropLocation; - foreach (var sched in exdef.Schedules) - { - var newSched = newBuildDefinition.AddSchedule(); - newSched.DaysToBuild = sched.DaysToBuild; - newSched.StartTime = sched.StartTime; - newSched.TimeZone = sched.TimeZone; - } - - var process = WorkflowHelpers.DeserializeProcessParameters(newBuildDefinition.ProcessParameters); - - foreach (var param in exdef.ProcessParameters) - { - if (param.Key != "AgentSettings" && param.Key != "BuildSettings" && param.Key != "TestSpecs") - { - Newtonsoft.Json.Linq.JArray arrayItem = param.Value as Newtonsoft.Json.Linq.JArray; - if (arrayItem == null) -<<<<<<< HEAD - { - Newtonsoft.Json.Linq.JObject objectItem = param.Value as Newtonsoft.Json.Linq.JObject; - if (objectItem == null) - { - process.Add(param.Key, param.Value); - } - else - { - Microsoft.TeamFoundation.Build.Common.BuildParameter paramItem = new Microsoft.TeamFoundation.Build.Common.BuildParameter(param.Value.ToString()); - process.Add(param.Key, paramItem); -======= - { - Newtonsoft.Json.Linq.JObject objectItem = param.Value as Newtonsoft.Json.Linq.JObject; - if (objectItem == null) - { - if (param.Key == "CleanWorkspace") - { - process.Add(param.Key, (CleanWorkspaceOption)Enum.Parse(typeof(CleanWorkspaceOption), param.Value.ToString())); - } - else if (param.Key == "RunCodeAnalysis") - { - process.Add(param.Key, (CodeAnalysisOption)Enum.Parse(typeof(CodeAnalysisOption), param.Value.ToString())); - } - else - { - process.Add(param.Key, param.Value); - } - } - else - { - Microsoft.TeamFoundation.Build.Common.BuildParameter paramItem = new Microsoft.TeamFoundation.Build.Common.BuildParameter(param.Value.ToString()); - process.Add(param.Key, paramItem); ->>>>>>> upstream/master - } - } - else - { - string[] arrayItemList = new string[arrayItem.Count]; - for (int i = 0; i < arrayItem.Count; i++) - { - arrayItemList[i] = arrayItem[i].ToString(); - } - - process.Add(param.Key, arrayItemList); - } - } - } - - if (exdef.ProjectsToBuild != null) - { - process.Add("BuildSettings", new BuildSettings { ProjectsToBuild = exdef.ProjectsToBuild, PlatformConfigurations = exdef.ConfigurationsToBuild }); - } - - if (exdef.TfvcAgentSettings != null) - { - process.Add("AgentSettings", new AgentSettings { MaxExecutionTime = exdef.TfvcAgentSettings.MaxExecutionTime, MaxWaitTime = exdef.TfvcAgentSettings.MaxWaitTime, Name = exdef.TfvcAgentSettings.Name, TagComparison = exdef.TfvcAgentSettings.Comparison, Tags = exdef.TfvcAgentSettings.Tags }); - } - else if (exdef.GitAgentSettings != null) - { - process.Add("AgentSettings", exdef.GitAgentSettings); - } - - if (exdef.AgileTestSpecs != null) - { - TestSpecList tsl = new TestSpecList(); - foreach (var aitem in exdef.AgileTestSpecs) - { - AgileTestPlatformSpec agileSpec = new AgileTestPlatformSpec(); - agileSpec.AssemblyFileSpec = aitem.AssemblyFileSpec; - agileSpec.ExecutionPlatform = aitem.ExecutionPlatform; - agileSpec.FailBuildOnFailure = aitem.FailBuildOnFailure; - agileSpec.RunName = aitem.RunName; - agileSpec.TestCaseFilter = aitem.TestCaseFilter; - agileSpec.RunSettingsForTestRun = new RunSettings(); - agileSpec.RunSettingsForTestRun.ServerRunSettingsFile = aitem.RunSettingsFileName; - agileSpec.RunSettingsForTestRun.TypeRunSettings = aitem.TypeRunSettings; - tsl.Add(agileSpec); - } - - process.Add("TestSpecs", tsl); - } - - if (exdef.BuildReasons != null) - { - foreach (var key in exdef.BuildReasons.Keys) - { - if (process.ContainsKey(key)) - { - process[key] = exdef.BuildReasons[key]; - } - } - } - - if (exdef.IntegerParameters != null) - { - foreach (var key in exdef.IntegerParameters.Keys) - { - if (process.ContainsKey(key)) - { - process[key] = exdef.IntegerParameters[key]; - } - } - } - - if (exdef.BuildVerbosities != null) - { - foreach (var key in exdef.BuildVerbosities.Keys) - { - if (process.ContainsKey(key)) - { - process[key] = exdef.BuildVerbosities[key]; - } - } - } - - newBuildDefinition.ProcessParameters = WorkflowHelpers.SerializeProcessParameters(process); - newBuildDefinition.Save(); - bi.Status = "Succeeded"; - bi.StatusImage = "Graphics/Succeeded.png"; - bi.Message = string.Empty; - } - } - catch (Exception ex) - { - bi.Status = "Failed"; - bi.StatusImage = "Graphics/Failed.png"; - bi.Message = ex.Message; - } - finally - { - this.DataGridBuildsToImport.ItemsSource = null; - this.DataGridBuildsToImport.ItemsSource = this.buildFiles; - } - } - } - } -} From 7cae089e6662bdf7248d8845e66c8d52c707447b Mon Sep 17 00:00:00 2001 From: Anthony Brown Date: Wed, 20 May 2015 19:15:58 +0100 Subject: [PATCH 3/4] removed .orig file from merge --- .../ViewModels/BuildManagerViewModel.cs.orig | 1813 ----------------- 1 file changed, 1813 deletions(-) delete mode 100644 Manager/TFSBuildManager.Views/ViewModels/BuildManagerViewModel.cs.orig diff --git a/Manager/TFSBuildManager.Views/ViewModels/BuildManagerViewModel.cs.orig b/Manager/TFSBuildManager.Views/ViewModels/BuildManagerViewModel.cs.orig deleted file mode 100644 index ef344c9..0000000 --- a/Manager/TFSBuildManager.Views/ViewModels/BuildManagerViewModel.cs.orig +++ /dev/null @@ -1,1813 +0,0 @@ -//----------------------------------------------------------------------- -// (c) https://github.com/tfsbuildextensions/BuildManager. This source is subject to the Microsoft Permissive License. See http://www.microsoft.com/resources/sharedsource/licensingbasics/sharedsourcelicenses.mspx. All other rights reserved. -//----------------------------------------------------------------------- -namespace TfsBuildManager.Views -{ - using System; - using System.Collections.Generic; - using System.Collections.ObjectModel; - using System.Diagnostics; - using System.IO; - using System.Linq; - using System.Windows; - using System.Windows.Input; - using Microsoft.TeamFoundation.Build.Client; - using Microsoft.TeamFoundation.Build.Common; - using Microsoft.TeamFoundation.Build.Workflow; - using Microsoft.TeamFoundation.Build.Workflow.Activities; - using Newtonsoft.Json; - using TfsBuildManager.Repository; - using TfsBuildManager.Views.ViewModels; - - public class BuildManagerViewModel : ViewModelBase - { - public const string AllItem = "All"; - private readonly Window owner; - private readonly ITfsContext context; - private readonly ITfsClientRepository repository; - private readonly IMainView view; - private bool includeDisabledBuildDefinitions; - private string buildDefinitionFilter; - private DateFilter selectedBuildDateFilter; - private BuildFilter selectedBuildFilter; - private BuildView selectedBuildView; - - public BuildManagerViewModel(Window owner, ITfsClientRepository repository, IMainView view, IEnumerable controllers, IEnumerable teamProjects, ITfsContext context) - { - this.owner = owner; - this.repository = repository; - this.view = view; - this.context = context; - this.BuildDefinitions = new ObservableCollection(); - this.Builds = new ObservableCollection(); - this.BuildResources = new ObservableCollection(); - this.CleanDropsCommands = new DelegateCommand(this.OnCleanDrops); - this.DeleteCommand = new DelegateCommand(this.OnDelete); - this.OpenDropFolderCommand = new DelegateCommand(this.OnOpenDropfolder); - this.RetainIndefinitelyCommand = new DelegateCommand(this.OnRetainIndefinitely); - this.SetBuildQualityCommand = new DelegateCommand(this.OnSetBuildQuality); - this.BuildNotesCommand = new DelegateCommand(this.OnBuildNotes); - this.DeleteBuildCommand = new DelegateCommand(this.OnDeleteBuild); - this.ShowDetailsCommand = new DelegateCommand(this.OnShowDetails); - this.RetryCommand = new DelegateCommand(this.OnRetry); - this.ViewBuildLogsCommand = new DelegateCommand(this.OnViewBuildLogs); - this.ShowQueuedDetailsCommand = new DelegateCommand(this.OnShowQueuedDetails); - this.StopBuildCommand = new DelegateCommand(this.OnStopBuild); - this.DisabledQueuedDefinitionCommand = new DelegateCommand(this.OnDisabledQueuedDefinition); - this.PauseQueuedDefinitionCommand = new DelegateCommand(this.OnPauseQueuedDefinition); - this.SetHighPriorityCommand = new DelegateCommand(() => this.SetQueuedBuildPriority(QueuePriority.High)); - this.SetAboveNormalPriorityCommand = new DelegateCommand(() => this.SetQueuedBuildPriority(QueuePriority.AboveNormal)); - this.SetNormalPriorityCommand = new DelegateCommand(() => this.SetQueuedBuildPriority(QueuePriority.Normal)); - this.SetBelowNormalPriorityCommand = new DelegateCommand(() => this.SetQueuedBuildPriority(QueuePriority.BelowNormal)); - this.SetLowPriorityCommand = new DelegateCommand(() => this.SetQueuedBuildPriority(QueuePriority.Low)); - this.ResumeBuildCommand = new DelegateCommand(this.OnResumeBuild); - this.ChangeBuildTemplateCommand = new DelegateCommand(this.OnChangeBuildTemplate); - this.SetDefaultBuildTemplateCommand = new DelegateCommand(this.OnSetDefaultBuildTemplate, this.OnCanSetDefaultBuildTemplate); - this.AddBuildProcessTemplateCommand = new DelegateCommand(this.OnAddBuildProcessTemplate); - this.RemoveBuildProcessTemplateCommand = new DelegateCommand(this.OnRemoveBuildProcessTemplate); - this.EditControllerCommand = new DelegateCommand(this.OnEditController); - this.EnableBuildResourceCommand = new DelegateCommand(this.OnEnableBuildResource); - this.DisableBuildResourceCommand = new DelegateCommand(this.OnDisableBuildResource); - this.RemoveCommand = new DelegateCommand(this.OnRemove); - this.EnableCommand = new DelegateCommand(this.OnEnable); - this.DisableCommand = new DelegateCommand(this.OnDisable); - this.PauseCommand = new DelegateCommand(this.OnPause); - this.SetRetentionPoliciesCommand = new DelegateCommand(this.OnSetRetentionsPolicies); - this.ChangeProcessParameterCommand = new DelegateCommand(this.OnChangeProcessParameterCommand); - this.ChangeBuildControllerCommand = new DelegateCommand(this.OnChangeBuildController); - this.ChangeDefaultDropLocationCommand = new DelegateCommand(this.OnChangeDefaultDropLocation); - this.ChangeOutputLocationAsConfiguredCommand = new DelegateCommand(this.OnChangeOutputLocationAsConfiguredCommand); - this.ChangeOutputLocationPerProjectCommand = new DelegateCommand(this.OnChangeOutputLocationPerProjectCommand); - this.ChangeOutputLocationSingleFolderCommand = new DelegateCommand(this.OnChangeOutputLocationSingleFolderCommand); - this.ChangeTriggerCommand = new DelegateCommand(this.OnChangeTrigger); - this.ExportDefinitionCommand = new DelegateCommand(this.OnExportBuildDefinition); - this.CloneBuildsCommand = new DelegateCommand(this.OnCloneBuilds, this.OnCanCloneBuilds); - this.CloneGitBuildsCommand = new DelegateCommand(this.OnCloneGitBuilds, this.OnCanCloneBuilds); - this.CloneBuildToProjectCommand = new DelegateCommand(this.OnCloneBuildToProject, this.OnCanCloneBuilds); - this.RemapWorkspacesCommand = new DelegateCommand(this.OnRemapWorkspaces, this.OnCanRemapWorkspaces); - this.QueueBuildsCommand = new DelegateCommand(this.OnQueueBuilds, this.OnCanQueueBuilds); - this.QueueHighBuildsCommand = new DelegateCommand(this.OnQueueHighBuilds, this.OnCanQueueBuilds); - this.EditBuildDefinitionCommand = new DelegateCommand(this.OnEditBuildDefinition, this.OnCanEditBuildDefinition); - this.GenerateBuildResourcesCommand = new DelegateCommand(this.OnGenerateBuildResources); - this.Controllers = new ObservableCollection(controllers.Select(c => c.Name)); - this.Controllers.Sort(); - this.RefreshCurrentView = new DelegateCommand(this.OnRefreshCurrentView); - this.ImportBuildDefinition = new DelegateCommand(this.OnImportBuildDefinition); - this.Controllers.Insert(0, AllItem); - this.TeamProjects = new ObservableCollection(teamProjects.Select(tp => tp)); - this.TeamProjects.Sort(); - this.TeamProjects.Insert(0, AllItem); - this.SelectedBuildFilter = BuildFilter.Queued; - this.includeDisabledBuildDefinitions = false; - this.BuildViews = new ObservableCollection { new BuildViewItem { Name = "Build Definitions", Value = BuildView.BuildDefinitions }, new BuildViewItem { Name = "Builds", Value = BuildView.Builds }, new BuildViewItem { Name = "Build Process Templates", Value = BuildView.BuildProcessTemplates }, new BuildViewItem { Name = "Build Resources", Value = BuildView.BuildResources } }; - this.DateFilters = new DateFilterCollection(); - this.SelectedBuildView = BuildView.BuildDefinitions; - this.selectedBuildDateFilter = DateFilter.Today; - this.BuildProcessTemplatess = new ObservableCollection(); - } - - public event EventHandler Refresh; - - public ICommand CleanDropsCommands { get; private set; } - - public ICommand DeleteCommand { get; private set; } - - public ICommand DisableCommand { get; private set; } - - public ICommand PauseCommand { get; private set; } - - public ICommand EnableCommand { get; private set; } - - public ICommand ChangeBuildTemplateCommand { get; private set; } - - public ICommand SetDefaultBuildTemplateCommand { get; private set; } - - public ICommand AddBuildProcessTemplateCommand { get; private set; } - - public ICommand RemoveBuildProcessTemplateCommand { get; private set; } - - public ICommand EditControllerCommand { get; private set; } - - public ICommand EnableBuildResourceCommand { get; private set; } - - public ICommand DisableBuildResourceCommand { get; private set; } - - public ICommand RemoveCommand { get; private set; } - - public ICommand OpenDropFolderCommand { get; private set; } - - public ICommand DeleteBuildCommand { get; private set; } - - public ICommand ShowDetailsCommand { get; private set; } - - public ICommand RetryCommand { get; private set; } - - public ICommand ViewBuildLogsCommand { get; private set; } - - public ICommand ShowQueuedDetailsCommand { get; private set; } - - public ICommand ResumeBuildCommand { get; private set; } - - public ICommand StopBuildCommand { get; private set; } - - public ICommand DisabledQueuedDefinitionCommand { get; private set; } - - public ICommand PauseQueuedDefinitionCommand { get; private set; } - - public ICommand SetHighPriorityCommand { get; private set; } - - public ICommand SetAboveNormalPriorityCommand { get; private set; } - - public ICommand SetNormalPriorityCommand { get; private set; } - - public ICommand SetBelowNormalPriorityCommand { get; private set; } - - public ICommand SetLowPriorityCommand { get; private set; } - - public ICommand RetainIndefinitelyCommand { get; private set; } - - public ICommand SetBuildQualityCommand { get; private set; } - - public ICommand BuildNotesCommand { get; private set; } - - public ICommand ChangeBuildControllerCommand { get; private set; } - - public ICommand ChangeOutputLocationAsConfiguredCommand { get; private set; } - - public ICommand ChangeOutputLocationPerProjectCommand { get; private set; } - - public ICommand ChangeOutputLocationSingleFolderCommand { get; private set; } - - public ICommand ChangeDefaultDropLocationCommand { get; private set; } - - public ICommand ChangeTriggerCommand { get; private set; } - - public ICommand ExportDefinitionCommand { get; private set; } - - public ICommand SetRetentionPoliciesCommand { get; private set; } - - public ICommand ChangeProcessParameterCommand { get; private set; } - - public ICommand QueueBuildsCommand { get; private set; } - - public ICommand QueueHighBuildsCommand { get; private set; } - - public ICommand EditBuildDefinitionCommand { get; private set; } - - public ICommand CloneBuildsCommand { get; private set; } - - public ICommand CloneGitBuildsCommand { get; private set; } - - public ICommand CloneBuildToProjectCommand { get; private set; } - - public ICommand GenerateBuildResourcesCommand { get; private set; } - - public ICommand RemapWorkspacesCommand { get; private set; } - - public ICommand RefreshCurrentView { get; private set; } - - public ICommand ImportBuildDefinition { get; private set; } - - public ObservableCollection BuildDefinitions { get; private set; } - - public ObservableCollection Builds { get; private set; } - - public ObservableCollection BuildResources { get; private set; } - - public ObservableCollection BuildProcessTemplatess { get; private set; } - - public ObservableCollection Controllers { get; private set; } - - public ObservableCollection TeamProjects { get; private set; } - - public ObservableCollection BuildViews { get; private set; } - - public DateFilterCollection DateFilters { get; private set; } - - public BuildFilter SelectedBuildFilter - { - get - { - return this.selectedBuildFilter; - } - - set - { - var old = this.selectedBuildFilter; - this.selectedBuildFilter = value; - if (value != old) - { - this.NotifyPropertyChanged("SelectedBuildFilter"); - } - } - } - - public string BuildDefinitionFilter - { - get - { - return this.buildDefinitionFilter; - } - - set - { - var old = this.buildDefinitionFilter; - this.buildDefinitionFilter = value; - if (value != old) - { - this.NotifyPropertyChanged("BuildDefinitionFilter"); - } - } - } - - public bool IncludeDisabledBuildDefinitions - { - get - { - return this.includeDisabledBuildDefinitions; - } - - set - { - var old = this.includeDisabledBuildDefinitions; - this.includeDisabledBuildDefinitions = value; - if (value != old) - { - this.NotifyPropertyChanged("includeDisabledBuildDefinitions"); - } - } - } - - public BuildView SelectedBuildView - { - get - { - return this.selectedBuildView; - } - - set - { - var old = this.selectedBuildView; - this.selectedBuildView = value; - if (value != old) - { - this.NotifyPropertyChanged("SelectedBuildView"); - this.NotifyPropertyChanged("BuildDefinitionViewVisible"); - this.NotifyPropertyChanged("BuildsViewVisible"); - this.NotifyPropertyChanged("BuildProcessTemplateViewVisible"); - this.NotifyPropertyChanged("BuildResourcesViewVisible"); - } - } - } - - public DateFilter SelectedDateFilter - { - get - { - return this.selectedBuildDateFilter; - } - - set - { - var old = this.selectedBuildDateFilter; - this.selectedBuildDateFilter = value; - if (value != old) - { - this.OnRefresh(new EventArgs()); - } - } - } - - public Visibility BuildDefinitionViewVisible - { - get { return this.SelectedBuildView == BuildView.BuildDefinitions ? Visibility.Visible : Visibility.Collapsed; } - } - - public Visibility BuildsViewVisible - { - get { return this.SelectedBuildView == BuildView.Builds ? Visibility.Visible : Visibility.Collapsed; } - } - - public bool IsTfvcProject - { - get - { - if (this.view.SelectedItems.Count() != 1) - { - return false; - } - - return this.view.SelectedItems.First().IsTfvcProject; - } - } - - public bool IsGitProject - { - get - { - return !this.IsTfvcProject; - } - } - - public Visibility BuildProcessTemplateViewVisible - { - get { return this.SelectedBuildView == BuildView.BuildProcessTemplates ? Visibility.Visible : Visibility.Collapsed; } - } - - public Visibility BuildResourcesViewVisible - { - get { return this.SelectedBuildView == BuildView.BuildResources ? Visibility.Visible : Visibility.Collapsed; } - } - - public static void ExportDefinition(BuildDefinitionViewModel b, string filePath) - { - ExportedBuildDefinition buildToExport = new ExportedBuildDefinition { Name = b.BuildDefinition.Name, Description = b.BuildDefinition.Description }; - if (b.BuildDefinition.BuildController != null) - { - buildToExport.BuildController = b.BuildDefinition.BuildController.Name; - } - - buildToExport.ContinuousIntegrationType = b.BuildDefinition.ContinuousIntegrationType; - buildToExport.DefaultDropLocation = b.BuildDefinition.DefaultDropLocation; - buildToExport.Schedules = new List(); - - foreach (var schedule in b.BuildDefinition.Schedules) - { - buildToExport.Schedules.Add(new ExportedISchedule { StartTime = schedule.StartTime, DaysToBuild = schedule.DaysToBuild, TimeZone = schedule.TimeZone }); - } - - buildToExport.SourceProviders = new List(); - foreach (var provider in b.BuildDefinition.SourceProviders) - { - buildToExport.SourceProviders.Add(new ExportedIBuildDefinitionSourceProvider { Fields = provider.Fields, Name = provider.Name, SupportedTriggerTypes = provider.SupportedTriggerTypes }); - } - - buildToExport.QueueStatus = b.BuildDefinition.QueueStatus; - buildToExport.ContinuousIntegrationQuietPeriod = b.BuildDefinition.ContinuousIntegrationQuietPeriod; - - if (b.BuildDefinition.SourceProviders.All(s => s.Name != "TFGIT")) - { - buildToExport.Mappings = new List(); - foreach (var map in b.BuildDefinition.Workspace.Mappings) - { - buildToExport.Mappings.Add(new ExportedIWorkspaceMapping { Depth = map.Depth, LocalItem = map.LocalItem, MappingType = map.MappingType, ServerItem = map.ServerItem }); - } - } - - buildToExport.RetentionPolicyList = new List(); - foreach (var rp in b.BuildDefinition.RetentionPolicyList) - { - buildToExport.RetentionPolicyList.Add(new ExportedIRetentionPolicy { BuildDefinition = rp.BuildDefinition, BuildReason = rp.BuildReason, BuildStatus = rp.BuildStatus, NumberToKeep = rp.NumberToKeep, DeleteOptions = rp.DeleteOptions }); - } - - if (b.BuildDefinition.Process != null) - { - buildToExport.ProcessTemplate = b.BuildDefinition.Process.ServerPath; - } - - var processParameters = WorkflowHelpers.DeserializeProcessParameters(b.BuildDefinition.ProcessParameters); - if (processParameters.ContainsKey("AgentSettings")) - { - if (processParameters["AgentSettings"].GetType() == typeof(AgentSettings)) - { - AgentSettings ags = (AgentSettings)processParameters["AgentSettings"]; - AgentSettingsBuildParameter agentSet = new AgentSettingsBuildParameter(); - agentSet.MaxExecutionTime = ags.MaxExecutionTime; - agentSet.MaxWaitTime = ags.MaxWaitTime; - agentSet.Name = ags.Name; - agentSet.Comparison = ags.TagComparison; - agentSet.Tags = ags.Tags; - buildToExport.TfvcAgentSettings = agentSet; - } - else if (processParameters["AgentSettings"].GetType() == typeof(BuildParameter)) - { - BuildParameter ags = (BuildParameter)processParameters["AgentSettings"]; - { - buildToExport.GitAgentSettings = ags; - } - } - } - - if (processParameters.ContainsKey("BuildSettings")) - { - var buildSettings = processParameters["BuildSettings"] as BuildSettings; - if (buildSettings != null && buildSettings.HasProjectsToBuild) - { - buildToExport.ProjectsToBuild = buildSettings.ProjectsToBuild; - if (buildSettings.HasPlatformConfigurations) - { - buildToExport.ConfigurationsToBuild = buildSettings.PlatformConfigurations; - } - } - } - - if (processParameters.ContainsKey("TestSpecs")) - { - var testSpecs = processParameters["TestSpecs"] as TestSpecList; - if (testSpecs != null) - { - buildToExport.AgileTestSpecs = new List(); - foreach (var spec in testSpecs) - { - var agilespec = spec as AgileTestPlatformSpec; - if (agilespec != null) - { - ExportedAgileTestPlatformSpec expAgileSpec = new ExportedAgileTestPlatformSpec(); - expAgileSpec.AssemblyFileSpec = agilespec.AssemblyFileSpec; - expAgileSpec.ExecutionPlatform = agilespec.ExecutionPlatform; - expAgileSpec.FailBuildOnFailure = agilespec.FailBuildOnFailure; - expAgileSpec.RunName = agilespec.RunName; - expAgileSpec.TestCaseFilter = agilespec.TestCaseFilter; - expAgileSpec.RunSettingsFileName = agilespec.RunSettingsForTestRun.ServerRunSettingsFile; - expAgileSpec.TypeRunSettings = agilespec.RunSettingsForTestRun.TypeRunSettings; - buildToExport.AgileTestSpecs.Add(expAgileSpec); - } - } - } - } - - buildToExport.ProcessParameters = WorkflowHelpers.DeserializeProcessParameters(b.BuildDefinition.ProcessParameters); - foreach (KeyValuePair item in processParameters) - { - if (item.Value.GetType() == typeof(Microsoft.TeamFoundation.Build.Common.BuildParameter)) - { - buildToExport.ProcessParameters[item.Key] = JsonConvert.DeserializeObject(item.Value.ToString()); - } - else if (item.Value.GetType() == typeof(BuildReason)) - { - buildToExport.BuildReasons.Add(item.Key, (BuildReason)item.Value); - } - else if (item.Value is int) - { - buildToExport.IntegerParameters.Add(item.Key, (int)item.Value); - } - else if (item.Value.GetType() == typeof(BuildVerbosity)) - { - buildToExport.BuildVerbosities.Add(item.Key, (BuildVerbosity)item.Value); - } - } - - var jsonSerializerSettings = new JsonSerializerSettings - { - PreserveReferencesHandling = PreserveReferencesHandling.Objects, - ReferenceLoopHandling = ReferenceLoopHandling.Serialize - }; - - File.WriteAllText(Path.Combine(filePath, b.Name + ".json"), JsonConvert.SerializeObject(buildToExport, Formatting.Indented, jsonSerializerSettings)); - } - - public void OnCleanDrops() - { - try - { - var items = this.view.SelectedItems; - if (MessageBox.Show("Are you sure you want to delete drop folder of all deleted builds?", "Clean Drop Folders", MessageBoxButton.YesNo) == MessageBoxResult.Yes) - { - using (new WaitCursor()) - { - this.repository.CleanDropsFolders(items.Select(b => b.Uri)); - this.OnRefresh(new EventArgs()); - } - } - } - catch (Exception ex) - { - this.view.DisplayError(ex); - } - } - - public void OnDelete() - { - try - { - var items = this.view.SelectedItems; - DeleteOptions? options = this.PromptDeleteOptions(); - if (options.HasValue) - { - using (new WaitCursor()) - { - this.repository.DeleteBuildDefinitions(items.Select(b => b.Uri), options.Value); - this.OnRefresh(new EventArgs()); - } - } - } - catch (Exception ex) - { - this.view.DisplayError(ex); - } - } - - public void OnSetDefaultBuildTemplate() - { - try - { - var items = this.view.SelectedBuildProcessTemplates; - foreach (var item in items) - { - this.repository.SetDefaultBuildProcessTemplate(item.ServerPath, item.TeamProject); - } - - this.OnRefresh(new EventArgs()); - } - catch (Exception ex) - { - this.view.DisplayError(ex); - } - } - - public bool OnCanSetDefaultBuildTemplate() - { - var items = this.view.SelectedBuildProcessTemplates.ToList(); - return items.Count() == 1 && items.First().TemplateType != "Default"; - } - - public void OnAddBuildProcessTemplate() - { - try - { - var items = this.view.SelectedBuildProcessTemplates; - var projects = this.repository.AllTeamProjects.Select(tp => tp).ToList(); - var viewModel = new TeamProjectListViewModel(projects); - - var wnd = new SelectTeamProject(viewModel, null); - bool? res = wnd.ShowDialog(); - if (res.HasValue && res.Value) - { - using (new WaitCursor()) - { - this.repository.AddBuildProcessTemplates(items.Select(pt => pt.ServerPath), wnd.SelectedTeamProjects.Select(tp => tp.Name), wnd.SetAsDefault); - this.OnRefresh(new EventArgs()); - } - - this.OnRefresh(new EventArgs()); - } - } - catch (Exception ex) - { - this.view.DisplayError(ex); - } - } - - public void OnRemoveBuildProcessTemplate() - { - try - { - var items = this.view.SelectedBuildProcessTemplates.ToList(); - var projects = this.repository.AllTeamProjects.Select(tp => tp).ToList(); - var viewModel = new TeamProjectListViewModel(projects); - - var wnd = new SelectTeamProject(viewModel, this.view.SelectedTeamProject) { cbSetAsDefault = { Visibility = Visibility.Collapsed } }; - bool? res = wnd.ShowDialog(); - if (res.HasValue && res.Value) - { - using (new WaitCursor()) - { - this.repository.RemoveBuildProcessTemplates(items.Select(pt => pt.ServerPath), wnd.SelectedTeamProjects.Select(tp => tp.Name), this.ShouldRemove); - this.OnRefresh(new EventArgs()); - } - - this.OnRefresh(new EventArgs()); - } - } - catch (Exception ex) - { - this.view.DisplayError(ex); - } - } - - public void OnEditController() - { - try - { - this.context.ShowControllerManager(); - } - catch (Exception ex) - { - this.view.DisplayError(ex); - } - } - - public void OnEnableBuildResource() - { - try - { - var selectedBuildResources = this.view.SelectedBuildResources.ToList(); - if (!selectedBuildResources.Any()) - { - return; - } - - foreach (var res in selectedBuildResources) - { - res.OnEnable(this.repository); - } - - this.OnRefresh(new EventArgs()); - } - catch (Exception ex) - { - this.view.DisplayError(ex); - } - } - - public void OnDisableBuildResource() - { - try - { - var selectedBuildResources = this.view.SelectedBuildResources.ToList(); - if (!selectedBuildResources.Any()) - { - return; - } - - foreach (var res in selectedBuildResources) - { - res.OnDisable(this.repository); - } - - this.OnRefresh(new EventArgs()); - } - catch (Exception ex) - { - this.view.DisplayError(ex); - } - } - - public void OnRemove() - { - try - { - var selectedBuildResources = this.view.SelectedBuildResources.ToList(); - if (!selectedBuildResources.Any()) - { - return; - } - - if (MessageBox.Show("Are you sure you want to delete the selected item(s)?", "Community TFS Build Manager", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) - { - foreach (var res in selectedBuildResources) - { - res.OnRemove(this.repository); - } - - this.OnRefresh(new EventArgs()); - } - } - catch (Exception ex) - { - this.view.DisplayError(ex); - } - } - - public void OnDisable() - { - try - { - var items = this.view.SelectedItems; - using (new WaitCursor()) - { - this.repository.DisableBuildDefinitions(items.Select(b => b.Uri)); - this.OnRefresh(new EventArgs()); - } - } - catch (Exception ex) - { - this.view.DisplayError(ex); - } - } - - public void OnPause() - { - try - { - var items = this.view.SelectedItems; - using (new WaitCursor()) - { - this.repository.PauseBuildDefinitions(items.Select(b => b.Uri)); - this.OnRefresh(new EventArgs()); - } - } - catch (Exception ex) - { - this.view.DisplayError(ex); - } - } - - public void OnOpenDropfolder() - { - try - { - var items = this.view.SelectedBuilds; - using (new WaitCursor()) - { - if (!this.repository.OpenDropFolder(items.Select(b => b.DropLocation))) - { - MessageBox.Show("No valid drop folders were found for the selected builds", "Open Drop Folder", MessageBoxButton.OK, MessageBoxImage.Information); - } - } - } - catch (Exception ex) - { - this.view.DisplayError(ex); - } - } - - public void OnRetry() - { - try - { - var items = this.view.SelectedBuilds; - using (new WaitCursor()) - { - this.repository.RetryBuilds(items.Select(b => b.BuildDefinitionUri)); - } - } - catch (Exception ex) - { - this.view.DisplayError(ex); - } - } - - public void OnShowDetails() - { - foreach (var selectedBuild in this.view.SelectedBuilds) - { - this.context.ShowBuild(selectedBuild.Uri); - } - } - - public void OnViewBuildLogs() - { - var selectedBuild = this.view.SelectedBuilds.First(); - string logUrl = this.repository.GetBuildLogLocation(selectedBuild.FullBuildDetail); - Process.Start(logUrl); - } - - public void OnShowQueuedDetails() - { - foreach (var selectedBuild in this.view.SelectedActiveBuilds) - { - this.context.ShowBuild(selectedBuild.Uri); - } - } - - public void OnDisabledQueuedDefinition() - { - try - { - var items = this.view.SelectedActiveBuilds; - using (new WaitCursor()) - { - this.repository.DisableBuildDefinitions(items.Select(b => b.BuildDefinitionUri)); - this.OnRefresh(new EventArgs()); - } - } - catch (Exception ex) - { - this.view.DisplayError(ex); - } - } - - public void OnPauseQueuedDefinition() - { - try - { - var items = this.view.SelectedActiveBuilds; - using (new WaitCursor()) - { - this.repository.PauseBuildDefinitions(items.Select(b => b.BuildDefinitionUri)); - this.OnRefresh(new EventArgs()); - } - } - catch (Exception ex) - { - this.view.DisplayError(ex); - } - } - - public void SetQueuedBuildPriority(QueuePriority priority) - { - try - { - var items = this.view.SelectedActiveBuilds.ToList(); - - if (!items.Any()) - { - return; - } - - using (new WaitCursor()) - { - this.repository.SetQueuedBuildPriority(items.Select(b => b.BuildDefinitionUri), priority); - this.OnRefresh(new EventArgs()); - } - } - catch (Exception ex) - { - this.view.DisplayError(ex); - } - } - - public void OnDeleteBuild() - { - try - { - if (MessageBox.Show(this.owner, "Confirm Delete. ALL artefacts will be deleted.", "Delete", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) - { - var items = this.view.SelectedBuilds; - using (new WaitCursor()) - { - this.repository.DeleteBuilds(items.Select(b => b.FullBuildDetail)); - this.OnRefresh(new EventArgs()); - } - } - } - catch (Exception ex) - { - this.view.DisplayError(ex); - } - } - - public void OnResumeBuild() - { - try - { - var items = this.view.SelectedActiveBuilds; - using (new WaitCursor()) - { - this.repository.ResumeBuilds(items.Select(b => b.QueuedBuildDetail)); - this.OnRefresh(new EventArgs()); - } - } - catch (Exception ex) - { - this.view.DisplayError(ex); - } - } - - public void OnStopBuild() - { - try - { - if (MessageBox.Show(this.owner, "Confirm stop.", "Stop", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) - { - var items = this.view.SelectedActiveBuilds; - using (new WaitCursor()) - { - this.repository.StopBuilds(items.Select(b => b.QueuedBuildDetail)); - this.OnRefresh(new EventArgs()); - } - } - } - catch (Exception ex) - { - this.view.DisplayError(ex); - } - } - - public void OnBuildNotes() - { - try - { - var items = this.view.SelectedBuilds; - var options = this.PromptNotesOptions(); - if (options != null) - { - using (new WaitCursor()) - { - this.repository.GenerateBuildNotes(items.Select(b => b.FullBuildDetail), options); - this.OnRefresh(new EventArgs()); - } - } - } - catch (Exception ex) - { - this.view.DisplayError(ex); - } - } - - public void OnRetainIndefinitely() - { - try - { - var items = this.view.SelectedBuilds; - using (new WaitCursor()) - { - this.repository.RetainIndefinitely(items.Select(b => b.FullBuildDetail)); - this.OnRefresh(new EventArgs()); - } - } - catch (Exception ex) - { - this.view.DisplayError(ex); - } - } - - public void OnSetBuildQuality() - { - try - { - var items = this.view.SelectedBuilds.ToList(); - var buildQualities = this.repository.GetBuildQualities(items.Select(bd => bd.TeamProject).ToList().Distinct()); - var wnd = new SelectBuildQuality(new BuildQualityListViewModel(buildQualities)); - bool? res = wnd.ShowDialog(); - if (res.HasValue && res.Value) - { - using (new WaitCursor()) - { - this.repository.SetBuildQualities(items.Select(bd => bd.Uri), wnd.SelectedBuildQuality.Name); - this.OnRefresh(new EventArgs()); - } - } - } - catch (Exception ex) - { - this.view.DisplayError(ex); - } - } - - public void OnEnable() - { - try - { - var items = this.view.SelectedItems; - using (new WaitCursor()) - { - this.repository.EnableBuildDefinitions(items.Select(b => b.Uri)); - this.OnRefresh(new EventArgs()); - } - } - catch (Exception ex) - { - this.view.DisplayError(ex); - } - } - - public void AssignBuildDefinitions(IEnumerable builds) - { - try - { - this.BuildDefinitions.Clear(); - foreach (var b in builds.Select(b => new BuildDefinitionViewModel(b))) - { - this.BuildDefinitions.Add(b); - } - } - catch (Exception ex) - { - this.view.DisplayError(ex); - } - } - - public void AssignBuilds(IEnumerable builds) - { - try - { - this.Builds.Clear(); - foreach (var b in builds.Where(b => b != null).Select(b => new BuildViewModel(b))) - { - this.Builds.Add(b); - } - } - catch (Exception ex) - { - this.view.DisplayError(ex); - } - } - - public void AssignBuildProcessTemplates(IEnumerable buildProcessTemplates) - { - try - { - this.BuildProcessTemplatess.Clear(); - foreach (var b in buildProcessTemplates.Where(b => b != null).Select(b => new BuildTemplateViewModel(b))) - { - this.BuildProcessTemplatess.Add(b); - } - } - catch (Exception ex) - { - this.view.DisplayError(ex); - } - } - - public void AssignBuildResources(IEnumerable buildResources) - { - try - { - this.BuildResources.Clear(); - foreach (var c in buildResources) - { - this.BuildResources.Add(new BuildControllerResourceViewModel(c)); - foreach (var a in c.Agents) - { - this.BuildResources.Add(new BuildAgentViewModel(a)); - } - } - } - catch (Exception ex) - { - this.view.DisplayError(ex); - } - } - - public void AssignBuilds(IEnumerable queuedBuilds) - { - try - { - this.Builds.Clear(); - foreach (var b in queuedBuilds.Where(b => b != null).Select(b => new BuildViewModel(b))) - { - this.Builds.Add(b); - } - } - catch (Exception ex) - { - this.view.DisplayError(ex); - } - } - - private static string GetCommonString(List lst, bool caseSensitive = false) - { - string shortest = lst[0]; - for (int i = 0; i < lst.Count; i++) - { - string s = lst[i]; - if (s.Length < shortest.Length) - { - shortest = s; - } - - if (!caseSensitive) - { - lst[i] = lst[i].ToUpper(); - } - } - - for (int i = 0; i < shortest.Length; i++) - { - char c = lst[0].ElementAt(i); - - if (lst.Any(s => c != s.ElementAt(i))) - { - return shortest.Substring(0, i); - } - } - - return shortest; - } - -<<<<<<< HEAD - private static void ExportDefinition(BuildDefinitionViewModel b, string filePath) - { - ExportedBuildDefinition buildToExport = new ExportedBuildDefinition { Name = b.BuildDefinition.Name, Description = b.BuildDefinition.Description }; - if (b.BuildDefinition.BuildController != null) - { - buildToExport.BuildController = b.BuildDefinition.BuildController.Name; - } - - buildToExport.ContinuousIntegrationType = b.BuildDefinition.ContinuousIntegrationType; - buildToExport.DefaultDropLocation = b.BuildDefinition.DefaultDropLocation; - buildToExport.Schedules = new List(); - - foreach (var schedule in b.BuildDefinition.Schedules) - { - buildToExport.Schedules.Add(new ExportedISchedule { StartTime = schedule.StartTime, DaysToBuild = schedule.DaysToBuild, TimeZone = schedule.TimeZone }); - } - - buildToExport.SourceProviders = new List(); - foreach (var provider in b.BuildDefinition.SourceProviders) - { - buildToExport.SourceProviders.Add(new ExportedIBuildDefinitionSourceProvider { Fields = provider.Fields, Name = provider.Name, SupportedTriggerTypes = provider.SupportedTriggerTypes }); - } - - buildToExport.QueueStatus = b.BuildDefinition.QueueStatus; - buildToExport.ContinuousIntegrationQuietPeriod = b.BuildDefinition.ContinuousIntegrationQuietPeriod; - - if (b.BuildDefinition.SourceProviders.All(s => s.Name != "TFGIT")) - { - buildToExport.Mappings = new List(); - foreach (var map in b.BuildDefinition.Workspace.Mappings) - { - buildToExport.Mappings.Add(new ExportedIWorkspaceMapping { Depth = map.Depth, LocalItem = map.LocalItem, MappingType = map.MappingType, ServerItem = map.ServerItem }); - } - } - - buildToExport.RetentionPolicyList = new List(); - foreach (var rp in b.BuildDefinition.RetentionPolicyList) - { - buildToExport.RetentionPolicyList.Add(new ExportedIRetentionPolicy { BuildDefinition = rp.BuildDefinition, BuildReason = rp.BuildReason, BuildStatus = rp.BuildStatus, NumberToKeep = rp.NumberToKeep, DeleteOptions = rp.DeleteOptions }); - } - - if (b.BuildDefinition.Process != null) - { - buildToExport.ProcessTemplate = b.BuildDefinition.Process.ServerPath; - } - - var processParameters = WorkflowHelpers.DeserializeProcessParameters(b.BuildDefinition.ProcessParameters); - if (processParameters.ContainsKey("AgentSettings")) - { - if (processParameters["AgentSettings"].GetType() == typeof(AgentSettings)) - { - AgentSettings ags = (AgentSettings)processParameters["AgentSettings"]; - AgentSettingsBuildParameter agentSet = new AgentSettingsBuildParameter(); - agentSet.MaxExecutionTime = ags.MaxExecutionTime; - agentSet.MaxWaitTime = ags.MaxWaitTime; - agentSet.Name = ags.Name; - agentSet.Comparison = ags.TagComparison; - agentSet.Tags = ags.Tags; - buildToExport.TfvcAgentSettings = agentSet; - } - else if (processParameters["AgentSettings"].GetType() == typeof(BuildParameter)) - { - BuildParameter ags = (BuildParameter)processParameters["AgentSettings"]; - { - buildToExport.GitAgentSettings = ags; - } - } - } - - if (processParameters.ContainsKey("BuildSettings")) - { - var buildSettings = processParameters["BuildSettings"] as BuildSettings; - if (buildSettings != null && buildSettings.HasProjectsToBuild) - { - buildToExport.ProjectsToBuild = buildSettings.ProjectsToBuild; - if (buildSettings.HasPlatformConfigurations) - { - buildToExport.ConfigurationsToBuild = buildSettings.PlatformConfigurations; - } - } - } - - buildToExport.ProcessParameters = WorkflowHelpers.DeserializeProcessParameters(b.BuildDefinition.ProcessParameters); - foreach (KeyValuePair item in processParameters) - { - if (item.Value.GetType() == typeof(Microsoft.TeamFoundation.Build.Common.BuildParameter)) - { - buildToExport.ProcessParameters[item.Key] = JsonConvert.DeserializeObject(item.Value.ToString()); - } - } - - File.WriteAllText(Path.Combine(filePath, b.Name + ".json"), JsonConvert.SerializeObject(buildToExport, Formatting.Indented)); - } - -======= ->>>>>>> upstream/master - private void ShowNoBranchMessage(string project) - { - MessageBox.Show(this.owner, "Could not locate branch object for " + project, "Clone Build To Branch", MessageBoxButton.OK, MessageBoxImage.Stop); - } - - private void ShowInvalidActionMessage(string action, string message) - { - MessageBox.Show(this.owner, message, action, MessageBoxButton.OK, MessageBoxImage.Stop); - } - - private bool ShouldRemove() - { - return MessageBox.Show(this.owner, "One or more of the selected build process templates are used by build definitions. Do you want to proceed?", "Remove Build Process Template", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes; - } - - private IEnumerable PromptNotesOptions() - { - try - { - var wnd = new BuildNotesOptionWnd(); - bool? action = wnd.ShowDialog(); - if (action.HasValue && action.Value) - { - return wnd.Option; - } - } - catch (Exception ex) - { - this.view.DisplayError(ex); - } - - return null; - } - - private DeleteOptions? PromptDeleteOptions() - { - try - { - var wnd = new DeleteOptionsWindow(); - var action = wnd.ShowDialog(); - if (action.HasValue && action.Value) - { - return wnd.Option; - } - } - catch (Exception ex) - { - this.view.DisplayError(ex); - } - - return null; - } - - private bool OnCanCloneBuilds() - { - try - { - return this.view.SelectedItems.Any(); - } - catch (Exception ex) - { - this.view.DisplayError(ex); - } - - return false; - } - - private void OnRefreshCurrentView() - { - this.OnRefresh(new EventArgs()); - } - - private void OnImportBuildDefinition() - { - if (this.view.SelectedTeamProject == "All") - { - MessageBox.Show("Please select an individual Team Project.", "Error: Unable to import into All projects", MessageBoxButton.OK, MessageBoxImage.Error); - return; - } - - var wnd = new ImportBuildDefinitions(this.view.SelectedTeamProject, this.repository.GetBuildServer()); - wnd.ShowDialog(); - this.OnRefresh(new EventArgs()); - } - - private void OnGenerateBuildResources() - { - try - { - using (new WaitCursor()) - { - var dgml = this.repository.GenerateBuildResourcesDependencyGraph(); - string tempFile = Path.GetTempFileName(); - tempFile = Path.ChangeExtension(tempFile, ".dgml"); - using (var sw = new StreamWriter(tempFile)) - { - sw.Write(dgml); - } - - Process.Start(tempFile); - } - } - catch (Exception ex) - { - this.view.DisplayError(ex); - } - } - - private void OnCloneBuilds() - { - try - { - var items = this.view.SelectedItems.ToList(); - if (!items.Any()) - { - return; - } - - foreach (var item in items) - { - if (item.BuildDefinition.SourceProviders.Any(s => s.Name.ToUpperInvariant().Contains("GIT"))) - { - return; - } - - using (new WaitCursor()) - { - var projects = this.repository.GetProjectsToBuild(item.Uri).ToList(); - if (!projects.Any()) - { - this.ShowInvalidActionMessage("Clone Build to Branch", "Could not locate any projects in the selected build(s)"); - return; - } - - var project = projects.First(); - var branchObject = this.repository.GetBranchObjectForItem(project); - if (branchObject == null) - { - this.ShowNoBranchMessage(project); - return; - } - - var childBranches = this.repository.GetChildBranchObjectsForItem(branchObject.ServerPath).ToList(); - if (!childBranches.Any()) - { - MessageBox.Show(this.owner, "No branch exist for " + branchObject.ServerPath, "Clone Build To Branch", MessageBoxButton.OK, MessageBoxImage.Stop); - return; - } - - var dlg = new SelectTargetBranchWindow(item.Name, childBranches, item.TeamProject, this.repository); - bool? res = dlg.ShowDialog(); - if (res.HasValue && res.Value) - { - this.repository.CloneBuild(item.Uri, dlg.NewBuildDefinitionName, branchObject, dlg.SelectedTargetBranch); - } - else if (res.HasValue) - { - break; - } - - this.OnRefresh(new EventArgs()); - } - } - } - catch (Exception ex) - { - this.view.DisplayError(ex); - } - } - - private void OnCloneGitBuilds() - { - try - { - var items = this.view.SelectedItems.ToList(); - if (!items.Any()) - { - return; - } - - foreach (var item in items) - { - // check for corrupted builds caused by the TFS Power Tools Clone feature. - if (item.BuildDefinition.SourceProviders.Any(s => s.Name.ToUpperInvariant().Contains("TFVC"))) - { - MessageBox.Show(string.Format("{0} appears to be bound to TFVC rather than Git.\n\nIf you cloned this build using the TFS Power Tools Clone menu, it will have corrupted your definition. You should create a new definition and delete this one.", item.Name), "Error Exporting " + item.Name, MessageBoxButton.OK, MessageBoxImage.Error); - return; - } - - // Note that if a Git build pulls from a repo then its sourceprovider is TFGIT. If it does not, then its SourceProvider is GIT - if (!item.BuildDefinition.SourceProviders.All(s => s.Name.ToUpperInvariant().Contains("GIT"))) - { - return; - } - - using (new WaitCursor()) - { - this.repository.CloneGitBuild(item.Uri, item.Name + "_" + DateTime.Now.ToString("F").Replace(":", "-")); - this.OnRefresh(new EventArgs()); - } - } - } - catch (Exception ex) - { - this.view.DisplayError(ex); - } - } - - private void OnCloneBuildToProject() - { - try - { - var items = this.view.SelectedItems.ToList(); - if (!items.Any()) - { - return; - } - - foreach (var item in items) - { - using (new WaitCursor()) - { - var projects = this.repository.AllTeamProjects.Select(tp => tp).ToList(); - var viewModel = new TeamProjectListViewModel(projects); - - var wnd = new SelectTeamProject(viewModel, this.view.SelectedTeamProject) { cbSetAsDefault = { Visibility = Visibility.Collapsed } }; - bool? res = wnd.ShowDialog(); - if (res.HasValue && res.Value) - { - using (new WaitCursor()) - { - string targetProject = wnd.SelectedTeamProjects.Select(tp => tp.Name).First(); - if (item.BuildDefinition.TeamProject == targetProject) - { - item.Name = item.Name + "_" + DateTime.Now.ToString("F").Replace(":", "-"); - } - - this.repository.CloneBuildToProject(item.Uri, item.Name, targetProject); - } - - this.OnRefresh(new EventArgs()); - } - else if (res.HasValue) - { - break; - } - } - } - } - catch (Exception ex) - { - this.view.DisplayError(ex); - } - } - - private void OnRemapWorkspaces() - { - try - { - if (this.selectedBuildView == BuildView.BuildDefinitions) - { - var buildDefinition = this.view.SelectedItems.First().BuildDefinition; - this.context.RemapWorkspaces(buildDefinition); - } - else if (this.selectedBuildFilter == BuildFilter.Completed) - { - var buildDefinition = this.view.SelectedBuilds.First().FullBuildDefinition; - this.context.RemapWorkspaces(buildDefinition); - } - } - catch (Exception ex) - { - this.view.DisplayError(ex); - } - } - - private bool OnCanRemapWorkspaces() - { - try - { - return this.view.SelectedItems.Count() == 1 || this.view.SelectedBuilds.Count() == 1; - } - catch (Exception ex) - { - this.view.DisplayError(ex); - } - - return false; - } - - private void OnQueueHighBuilds() - { - try - { - var items = this.view.SelectedItems; - using (new WaitCursor()) - { - this.repository.QueueHighBuilds(items.Select(b => b.Uri)); - this.SelectedBuildView = BuildView.Builds; - this.SelectedBuildFilter = BuildFilter.Queued; - } - } - catch (Exception ex) - { - this.view.DisplayError(ex); - } - } - - private void OnQueueBuilds() - { - try - { - var items = this.view.SelectedItems; - using (new WaitCursor()) - { - this.repository.QueueBuilds(items.Select(b => b.Uri)); - this.SelectedBuildView = BuildView.Builds; - this.SelectedBuildFilter = BuildFilter.Queued; - } - } - catch (Exception ex) - { - this.view.DisplayError(ex); - } - } - - private void OnEditBuildDefinition() - { - try - { - if (this.selectedBuildView == BuildView.BuildDefinitions) - { - var buildDefinitionUri = this.view.SelectedItems.First().Uri; - this.context.EditBuildDefinition(buildDefinitionUri); - } - else if (this.selectedBuildFilter == BuildFilter.Completed) - { - var buildDefinitionUri = this.view.SelectedBuilds.First().BuildDefinitionUri; - this.context.EditBuildDefinition(buildDefinitionUri); - } - } - catch (Exception ex) - { - this.view.DisplayError(ex); - } - } - - private bool OnCanEditBuildDefinition() - { - try - { - return this.view.SelectedItems.Count() == 1 || this.view.SelectedBuilds.Count() == 1; - } - catch (Exception ex) - { - this.view.DisplayError(ex); - } - - return false; - } - - private bool OnCanQueueBuilds() - { - try - { - return this.view.SelectedItems.Any(s => !s.HasProcess); - } - catch (Exception ex) - { - this.view.DisplayError(ex); - } - - return false; - } - - private void OnSetRetentionsPolicies() - { - try - { - var items = this.view.SelectedItems; - var wnd = new RetentionPolicyWindow(); - bool? res = wnd.ShowDialog(); - if (res.HasValue && res.Value) - { - using (new WaitCursor()) - { - this.repository.SetRetentionPolicies(items.Select(bd => bd.Uri), wnd.BuildRetentionPolicy); - this.OnRefresh(new EventArgs()); - } - } - } - catch (Exception ex) - { - this.view.DisplayError(ex); - } - } - - private void OnChangeProcessParameterCommand() - { - try - { - var items = this.view.SelectedItems; - var wnd = new ProcessParameterWindow(); - bool? res = wnd.ShowDialog(); - if (res.HasValue && res.Value) - { - using (new WaitCursor()) - { - this.repository.ChangeProcessParameter(items.Select(bd => bd.Uri), wnd.ProcessParameter, wnd.BooleanParameter); - this.OnRefresh(new EventArgs()); - } - } - } - catch (Exception ex) - { - this.view.DisplayError(ex); - } - } - - private void OnRefresh(EventArgs e) - { - try - { - EventHandler handler = this.Refresh; - if (handler != null) - { - handler(this, e); - } - } - catch (Exception ex) - { - this.view.DisplayError(ex); - } - } - - private void OnChangeBuildTemplate() - { - try - { - var items = this.view.SelectedItems.ToList(); - var teamProjects = items.Select(i => i.TeamProject).Distinct(); - IEnumerable buildTemplates; - using (new WaitCursor()) - { - buildTemplates = this.repository.GetBuildProcessTemplates(teamProjects); - } - - var viewModel = new BuildTemplateListViewModel(buildTemplates); - var wnd = new SelectBuildProcessTemplateWindow(viewModel); - bool? res = wnd.ShowDialog(); - if (res.HasValue && res.Value) - { - using (new WaitCursor()) - { - this.repository.AssignBuildProcessTemplate(items.Select(bd => bd.Uri), wnd.SelectedBuildTemplate.ServerPath); - this.OnRefresh(new EventArgs()); - } - } - } - catch (Exception ex) - { - this.view.DisplayError(ex); - } - } - - private void OnExportBuildDefinition() - { - var items = this.view.SelectedItems; - using (new WaitCursor()) - { - System.Windows.Forms.FolderBrowserDialog saveFolder = new System.Windows.Forms.FolderBrowserDialog { Description = "Select a folder to export to..." }; - System.Windows.Forms.DialogResult result2 = saveFolder.ShowDialog(); - if (result2 == System.Windows.Forms.DialogResult.OK) - { - foreach (var b in items) - { - try - { - ExportDefinition(b, saveFolder.SelectedPath); - } - catch (Exception ex) - { - MessageBox.Show(ex.ToString(), "Error Exporting " + b.Name, MessageBoxButton.OK, MessageBoxImage.Error); - } - } - } - } - } - - private void OnChangeTrigger() - { - try - { - var items = this.view.SelectedItems; - var viewModel = new TriggerViewModel(); - - var wnd = new TriggerWindow(viewModel); - bool? res = wnd.ShowDialog(); - if (res.HasValue && res.Value) - { - using (new WaitCursor()) - { - if (wnd.Trigger.TriggerType == DefinitionTriggerType.Schedule || wnd.Trigger.TriggerType == DefinitionTriggerType.ScheduleForced) - { - this.repository.UpdateTrigger(items.Select(bd => bd.Uri), wnd.Trigger.TriggerType, wnd.Trigger.ScheduleDays, wnd.Trigger.ScheduleTime, wnd.Trigger.TimeZoneInfo); - } - else - { - this.repository.UpdateTrigger(items.Select(bd => bd.Uri), wnd.Trigger.Minutes, wnd.Trigger.Submissions, wnd.Trigger.TriggerType); - } - - this.OnRefresh(new EventArgs()); - } - } - } - catch (Exception ex) - { - this.view.DisplayError(ex); - } - } - - private void OnChangeOutputLocationAsConfiguredCommand() - { - var items = this.view.SelectedItems; - using (new WaitCursor()) - { - this.repository.UpdateOutputLocation(items.Select(bd => bd.Uri), "AsConfigured"); - this.OnRefresh(new EventArgs()); - } - } - - private void OnChangeOutputLocationPerProjectCommand() - { - var items = this.view.SelectedItems; - using (new WaitCursor()) - { - this.repository.UpdateOutputLocation(items.Select(bd => bd.Uri), "PerProject"); - this.OnRefresh(new EventArgs()); - } - } - - private void OnChangeOutputLocationSingleFolderCommand() - { - var items = this.view.SelectedItems; - using (new WaitCursor()) - { - this.repository.UpdateOutputLocation(items.Select(bd => bd.Uri), "SingleFolder"); - this.OnRefresh(new EventArgs()); - } - } - - private void OnChangeDefaultDropLocation() - { - try - { - var items = this.view.SelectedItems.ToList(); - var viewModel = new DropLocationViewModel(); - var lstDropLocations = from b in items orderby b.DefaultDropLocation.Length select b.DefaultDropLocation; - viewModel.SearchTxt = GetCommonString(lstDropLocations.ToList()); - viewModel.ReplaceTxt = viewModel.SearchTxt; - viewModel.SetDropLocation = string.Empty; - viewModel.AddMacro("$(TeamProject)", "TO BE SET"); - viewModel.AddMacro("$(BuildDefinition)", "TO BE SET"); - viewModel.AddMacro("$(BuildServer)", "TO BE SET"); - viewModel.AddMacro("$(BuildType)", "TO BE SET"); - - var wnd = new DropLocationWindow(viewModel); - bool? res = wnd.ShowDialog(); - if (res.HasValue && res.Value) - { - using (new WaitCursor()) - { - if (viewModel.ModeReplace) - { - this.repository.ChangeDefaultDropLocation(items.Select(bd => bd.Uri), viewModel.ReplaceTxt, viewModel.SearchTxt, viewModel.UpdateExistingBuilds); - this.OnRefresh(new EventArgs()); - } - else - { - this.repository.SetDefaultDropLocation(items.Select(bd => bd.Uri), viewModel.SetDropLocation, viewModel.Macros, viewModel.UpdateExistingBuilds); - this.OnRefresh(new EventArgs()); - } - } - } - } - catch (Exception ex) - { - this.view.DisplayError(ex); - } - } - - private void OnChangeBuildController() - { - try - { - var items = this.view.SelectedItems; - var controllers = this.repository.Controllers; - var viewModel = new BuildControllerListViewModel(controllers); - - var wnd = new BuildControllerWindow(viewModel); - bool? res = wnd.ShowDialog(); - if (res.HasValue && res.Value) - { - using (new WaitCursor()) - { - this.repository.ChangeBuildController(items.Select(bd => bd.Uri), wnd.SelectedBuildController.Name); - this.OnRefresh(new EventArgs()); - } - } - } - catch (Exception ex) - { - this.view.DisplayError(ex); - } - } - } -} From dd76ceeebf2a124adf76b27741127bc46f192b0a Mon Sep 17 00:00:00 2001 From: Anthony Brown Date: Wed, 20 May 2015 19:40:31 +0100 Subject: [PATCH 4/4] added username/password paramaters --- Manager/TFSBuildManager.Console/Program.cs | 59 ++++++++++++++++++++-- 1 file changed, 54 insertions(+), 5 deletions(-) diff --git a/Manager/TFSBuildManager.Console/Program.cs b/Manager/TFSBuildManager.Console/Program.cs index affd309..687696d 100644 --- a/Manager/TFSBuildManager.Console/Program.cs +++ b/Manager/TFSBuildManager.Console/Program.cs @@ -12,7 +12,8 @@ namespace TFSBuildManager.Console using System.Text.RegularExpressions; using Microsoft.TeamFoundation.Build.Client; using Microsoft.TeamFoundation.Client; - using TfsBuildManager.Views; + using TfsBuildManager.Views; + using System.Net; public class Program { @@ -101,8 +102,35 @@ internal static string ExportPath throw new ArgumentNullException("ExportPath"); } + } + + internal static string Username + { + get + { + string username; + if (Arguments.TryGetValue("Username", out username)) + { + return username; + } + + throw new ArgumentNullException("Username"); + } + } + + internal static string Password + { + get + { + string password; + if (Arguments.TryGetValue("Password", out password)) + { + return password; + } + + throw new ArgumentNullException("Password"); + } } - private static int Main(string[] args) { Console.WriteLine("Community TFS Build Manager Console - {0}\n", GetFileVersion(Assembly.GetExecutingAssembly())); @@ -116,9 +144,16 @@ private static int Main(string[] args) if (retval != 0) { return retval; - } - - TfsTeamProjectCollection collection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(ProjectCollection); + } + + NetworkCredential netCred = new NetworkCredential(Username, Password); + BasicAuthCredential basicCred = new BasicAuthCredential(netCred); + TfsClientCredentials tfsCred = new TfsClientCredentials(basicCred); + tfsCred.AllowInteractive = false; + + TfsTeamProjectCollection collection = new TfsTeamProjectCollection(ProjectCollection, tfsCred); + + collection.Authenticate(); IBuildServer buildServer = (IBuildServer)collection.GetService(typeof(IBuildServer)); @@ -221,6 +256,20 @@ private static int ProcessArguments(string[] args) if (propertiesargumentfound) { Arguments.Add("ExportPath", args.First(item => item.Contains("/ExportPath:")).Replace("/ExportPath:", string.Empty)); + } + + searchTerm = new Regex(@"/Username:.*"); + propertiesargumentfound = args.Select(arg => searchTerm.Match(arg)).Any(m => m.Success); + if (propertiesargumentfound) + { + Arguments.Add("Username", args.First(item => item.Contains("/Username:")).Replace("/Username:", string.Empty)); + } + + searchTerm = new Regex(@"/Password:.*"); + propertiesargumentfound = args.Select(arg => searchTerm.Match(arg)).Any(m => m.Success); + if (propertiesargumentfound) + { + Arguments.Add("Password", args.First(item => item.Contains("/Password:")).Replace("/Password:", string.Empty)); } Console.Write("...Success\n");