コード例 #1
0
 public static void Export(ILogger logger, ApplicationTask task, IList <WorkItemConfigurationItemExport> workItemConfigurationItems)
 {
     if (workItemConfigurationItems.Count > 0)
     {
         var step = 0;
         foreach (var workItemConfigurationItem in workItemConfigurationItems)
         {
             task.SetProgress(step++, string.Format(CultureInfo.CurrentCulture, "Exporting {0} from Team Project \"{1}\"", workItemConfigurationItem.Item.DisplayName, workItemConfigurationItem.TeamProject.Name));
             try
             {
                 if (!string.IsNullOrEmpty(workItemConfigurationItem.SaveAsFileName))
                 {
                     Directory.CreateDirectory(Path.GetDirectoryName(workItemConfigurationItem.SaveAsFileName));
                     workItemConfigurationItem.Item.XmlDefinition.Save(workItemConfigurationItem.SaveAsFileName);
                 }
             }
             catch (Exception exc)
             {
                 var message = string.Format(CultureInfo.CurrentCulture, "An error occurred while exporting {0}", workItemConfigurationItem.Item.DisplayName);
                 logger.Log(message, exc);
                 task.SetError(message, exc);
             }
             if (task.IsCanceled)
             {
                 task.Status = "Canceled";
                 break;
             }
         }
     }
 }
コード例 #2
0
        private void ExportSelectedSecurityGroupPermissions(object argument)
        {
            var exportRequests = new List <SecurityGroupPermissionExportRequest>();
            var securityGroups = this.SelectedSecurityGroups;

            if (securityGroups.Count == 1)
            {
                // Export to a single file.
                var securityGroup = securityGroups.Single();
                var dialog        = new SaveFileDialog();
                dialog.FileName = securityGroup.Name + ".xml";
                dialog.Filter   = "XML Files (*.xml)|*.xml";
                var result = dialog.ShowDialog(Application.Current.MainWindow);
                if (result == true)
                {
                    exportRequests.Add(new SecurityGroupPermissionExportRequest(securityGroup, dialog.FileName));
                }
            }
            else
            {
                // Export to a directory structure.
                var dialog = new System.Windows.Forms.FolderBrowserDialog();
                dialog.Description = "Please select the path where to export the permission files (*.xml). They will be stored in a folder per Team Project.";
                var result = dialog.ShowDialog();
                if (result == System.Windows.Forms.DialogResult.OK)
                {
                    var rootFolder = dialog.SelectedPath;
                    foreach (var securityGroup in securityGroups)
                    {
                        var fileName = Path.Combine(rootFolder, securityGroup.TeamProject.Name, securityGroup.Name + ".xml");
                        exportRequests.Add(new SecurityGroupPermissionExportRequest(securityGroup, fileName));
                    }
                }
            }

            if (exportRequests.Any())
            {
                var task = new ApplicationTask("Exporting " + exportRequests.Count.ToCountString("security group permission"), exportRequests.Count, true);
                PublishStatus(new StatusEventArgs(task));
                var worker = new BackgroundWorker();
                worker.DoWork += (sender, e) =>
                {
                    SecurityManager.ExportPermissions(this.Logger, task, this.GetSelectedTfsTeamProjectCollection(), this.SelectedTeamProjectCollection.TeamFoundationServer.MajorVersion, exportRequests);
                };
                worker.RunWorkerCompleted += (sender, e) =>
                {
                    if (e.Error != null)
                    {
                        Logger.Log("An unexpected exception occurred while exporting security group permission", e.Error);
                        task.SetError(e.Error);
                        task.SetComplete("An unexpected exception occurred");
                    }
                    else
                    {
                        task.SetComplete("Exported " + exportRequests.Count.ToCountString("security group permission"));
                    }
                };
                worker.RunWorkerAsync();
            }
        }
コード例 #3
0
        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();
        }
コード例 #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ApplicationTaskViewModel"/> class.
 /// </summary>
 /// <param name="task">The task.</param>
 public ApplicationTaskViewModel(ApplicationTask task, ILogger logger)
 {
     if (task == null)
     {
         throw new ArgumentNullException("task");
     }
     this.Task   = task;
     this.logger = logger;
     this.taskId = Guid.NewGuid().ToString();
     Log(task.Name);
     task.StatusHistory.CollectionChanged += new NotifyCollectionChangedEventHandler(TaskStatusHistory_CollectionChanged);
     if (this.Task.StatusHistory != null)
     {
         var status = string.Empty;
         foreach (string item in this.Task.StatusHistory.ToList())
         {
             status += Environment.NewLine + item;
             Log(item);
         }
         this.StatusHistoryDescription = status.Trim();
     }
     this.ShowDetailsCommand   = new RelayCommand((o) => { this.DetailsVisible = true; }, (o) => this.DetailsAvailable);
     this.RequestCancelCommand = new RelayCommand((o) => { this.Task.RequestCancel(); }, (o) => this.Task.CanCancel && !this.Task.IsCanceled);
     this.DetailsAvailable     = (this.Task.StatusHistory.Count > 0);
 }
        private void GetBuildProcessTemplates(object argument)
        {
            var teamProjectNames = this.SelectedTeamProjects.Select(p => p.Name).ToList();
            var task             = new ApplicationTask("Retrieving build process templates", teamProjectNames.Count, true);

            PublishStatus(new StatusEventArgs(task));
            var worker = new BackgroundWorker();

            worker.DoWork += (sender, e) =>
            {
                var tfs         = GetSelectedTfsTeamProjectCollection();
                var buildServer = tfs.GetService <IBuildServer>();
                e.Result = Tasks.GetBuildProcessTemplates(task, buildServer, teamProjectNames);
            };
            worker.RunWorkerCompleted += (sender, e) =>
            {
                if (e.Error != null)
                {
                    Logger.Log("An unexpected exception occurred while retrieving build process templates", e.Error);
                    task.SetError(e.Error);
                    task.SetComplete("An unexpected exception occurred");
                }
                else
                {
                    var buildProcessTemplates = (IList <BuildProcessTemplateInfo>)e.Result;
                    this.BuildProcessTemplates = buildProcessTemplates;
                    RefreshBuildProcessHierarchy();
                    task.SetComplete("Retrieved " + buildProcessTemplates.Count().ToCountString("build process template"));
                }
            };
            worker.RunWorkerAsync();
        }
        private void DeleteSelectedBuildProcessTemplates(object argument)
        {
            var result = MessageBox.Show("This will unregister the selected build process templates. Are you sure you want to continue?" + Environment.NewLine + Environment.NewLine + "Note that the XAML files will not be deleted from Source Control, they will only be unregistered as build process templates.", "Confirm Unregister", MessageBoxButton.YesNo, MessageBoxImage.Warning);

            if (result == MessageBoxResult.Yes)
            {
                var buildProcessTemplates = this.SelectedBuildProcessTemplates.Select(p => p.ProcessTemplate).ToList();
                var task = new ApplicationTask("Unregistering build process templates", buildProcessTemplates.Count, true);
                PublishStatus(new StatusEventArgs(task));
                var worker = new BackgroundWorker();
                worker.DoWork += (sender, e) =>
                {
                    Tasks.UnregisterBuildProcessTemplates(task, buildProcessTemplates);
                };
                worker.RunWorkerCompleted += (sender, e) =>
                {
                    if (e.Error != null)
                    {
                        Logger.Log("An unexpected exception occurred while unregistering build process template", e.Error);
                        task.SetError(e.Error);
                        task.SetComplete("An unexpected exception occurred");
                    }
                    else
                    {
                        task.SetComplete("Unregistered " + buildProcessTemplates.Count.ToCountString("build process template"));
                    }

                    // Refresh the list.
                    GetBuildProcessTemplates(null);
                };
                worker.RunWorkerAsync();
            }
        }
コード例 #7
0
 private void RefreshTeamProjects(bool forceRefresh)
 {
     if (forceRefresh || (this.SelectedTeamProjectCollection != null && this.SelectedTeamProjectCollection.TeamFoundationServer == null && this.SelectedTeamProjectCollection.TeamProjects == null))
     {
         var teamProjectCollectionToRefresh = this.SelectedTeamProjectCollection;
         this.SelectedTeamProjectCollection = null;
         var task = new ApplicationTask(string.Format(CultureInfo.CurrentCulture, "Retrieving team projects for \"{0}\"", teamProjectCollectionToRefresh.Name));
         SetInfoMessage("Loading...", null);
         this.PublishStatus(new StatusEventArgs(task));
         this.IsTeamProjectsLoadComplete = false;
         this.TeamProjectsVisibility     = Visibility.Collapsed;
         var worker = new BackgroundWorker();
         worker.DoWork += (sender, e) =>
         {
             var tfs          = GetTfsTeamProjectCollection(teamProjectCollectionToRefresh.Uri);
             var tfsInfo      = GetTeamFoundationServerInfo(tfs, this.Logger);
             var store        = tfs.GetService <ICommonStructureService>();
             var teamProjects = store.ListAllProjects().Where(p => p.Status == Microsoft.TeamFoundation.Core.WebApi.ProjectState.WellFormed).Select(p => new TeamProjectInfo(teamProjectCollectionToRefresh, p.Name, new Uri(p.Uri), this.Logger)).OrderBy(p => p.Name).ToList();
             e.Result = new Tuple <TeamFoundationServerInfo, ICollection <TeamProjectInfo> >(tfsInfo, teamProjects);
         };
         worker.RunWorkerCompleted += (sender, e) =>
         {
             if (e.Error != null)
             {
                 this.Logger.Log("An unexpected exception occurred while retrieving team projects", e.Error);
                 SetInfoMessage("Could not connect", e.Error.Message);
                 task.SetError(e.Error);
                 task.SetComplete("An unexpected exception occurred");
             }
             else
             {
                 var result = (Tuple <TeamFoundationServerInfo, ICollection <TeamProjectInfo> >)e.Result;
                 teamProjectCollectionToRefresh.TeamFoundationServer = result.Item1;
                 teamProjectCollectionToRefresh.TeamProjects         = result.Item2;
                 this.SelectedTeamProjectCollection = teamProjectCollectionToRefresh;
                 task.SetComplete("Retrieved " + teamProjectCollectionToRefresh.TeamProjects.Count.ToCountString("team project"));
             }
             this.IsTeamProjectsLoadComplete = true;
             CommandManager.InvalidateRequerySuggested();
         };
         worker.RunWorkerAsync();
     }
     else
     {
         if (this.SelectedTeamProjectCollection == null)
         {
             SetInfoMessage(InfoMessageProperty.DefaultValue, null);
             this.TeamProjectsVisibility = Visibility.Collapsed;
         }
         else
         {
             var infoMessage = "Connected to {0}".FormatCurrent(this.SelectedTeamProjectCollection.TeamFoundationServer.ShortDisplayVersion);
             var toolTip     = "Connected to {0}".FormatCurrent(this.SelectedTeamProjectCollection.TeamFoundationServer.DisplayVersion);
             SetInfoMessage(infoMessage, toolTip);
             this.TeamProjectsVisibility = Visibility.Visible;
         }
         this.EventAggregator.GetEvent <TeamProjectCollectionSelectionChangedEvent>().Publish(new TeamProjectCollectionSelectionChangedEventArgs(this.SelectedTeamProjectCollection));
     }
     ShowAllTeamProjects(null);
 }
コード例 #8
0
ファイル: Program.cs プロジェクト: leearthur/BulkDataLoader
        public static async Task Main(string[] args)
        {
            try
            {
                Log.Logger = new LoggerConfiguration()
                             .WriteTo.Console()
                             .CreateLogger();

                var task = await ApplicationTask.GetTaskInstanceAsync(args);

                var timer = new Stopwatch();

                timer.Start();
                await task.ExecuteAsync();

                timer.Stop();

                if (task.DisplayExecutionTime)
                {
                    var executionTime = Math.Round((decimal)timer.ElapsedMilliseconds / 1000, 4);
                    Log.Information($"Execution Time: {executionTime} seconds");
                }
            }
            catch (RequestValidationException ex)
            {
                Log.Error($"Request Validation Exception:\n{ex.Message}");
            }
            catch (Exception ex)
            {
                Log.Error(ex, "System Error:");
            }
        }
 private void RegisterBuildProcessTemplate(object argument)
 {
     var result = MessageBoxResult.Yes;
     if (!this.Simulate)
     {
         result = MessageBox.Show("This will update all selected Team Projects. Are you sure you want to continue?", "Confirm Update", MessageBoxButton.YesNo, MessageBoxImage.Warning);
     }
     if (result == MessageBoxResult.Yes)
     {
         var teamProjectNames = this.SelectedTeamProjects.Select(p => p.Name).ToList();
         var task = new ApplicationTask((this.Simulate ? "Simulating registering build process template" : "Registering build process template"), teamProjectNames.Count, true);
         PublishStatus(new StatusEventArgs(task));
         var worker = new BackgroundWorker();
         worker.DoWork += (sender, e) =>
         {
             var tfs = GetSelectedTfsTeamProjectCollection();
             var buildServer = tfs.GetService<IBuildServer>();
             Tasks.RegisterBuildProcessTemplate(task, buildServer, teamProjectNames, this.TemplateServerPath, this.TemplateType, true, this.UnregisterAllOtherTemplates, this.UnregisterAllOtherTemplatesIncludesUpgradeTemplate, this.Simulate);
         };
         worker.RunWorkerCompleted += (sender, e) =>
         {
             if (e.Error != null)
             {
                 Logger.Log("An unexpected exception occurred while registering build process template", e.Error);
                 task.SetError(e.Error);
                 task.SetComplete("An unexpected exception occurred");
             }
             else
             {
                 task.SetComplete("Done");
             }
         };
         worker.RunWorkerAsync();
     }
 }
        private void PerformImport(Dictionary <TeamProjectInfo, List <WorkItemConfigurationItem> > teamProjectsWithProcessConfigurations, ImportOptions options)
        {
            var numberOfSteps = teamProjectsWithProcessConfigurations.Aggregate(0, (a, p) => a += p.Value.Count);
            var task          = new ApplicationTask("Importing process configurations", numberOfSteps, true);

            PublishStatus(new StatusEventArgs(task));
            var worker = new BackgroundWorker();

            worker.DoWork += (sender, e) =>
            {
                var tfs   = GetSelectedTfsTeamProjectCollection();
                var store = tfs.GetService <WorkItemStore>();
                WorkItemConfigurationItemImportExport.Import(this.Logger, task, true, store, teamProjectsWithProcessConfigurations, options);
            };
            worker.RunWorkerCompleted += (sender, e) =>
            {
                if (e.Error != null)
                {
                    Logger.Log("An unexpected exception occurred while importing process configurations", e.Error);
                    task.SetError(e.Error);
                    task.SetComplete("An unexpected exception occurred");
                }
                else
                {
                    task.SetComplete(task.IsError ? "Failed" : (task.IsWarning ? "Succeeded with warnings" : "Succeeded"));
                }
            };
            worker.RunWorkerAsync();
        }
コード例 #11
0
        private void ExportSelectedWorkItemTypes(object argument)
        {
            var workItemTypesToExport = new List <WorkItemConfigurationItemExport>();
            var workItemTypes         = this.SelectedWorkItemTypes;

            if (workItemTypes.Count == 1)
            {
                // Export to single file.
                var workItemType = workItemTypes.Single();
                var dialog       = new SaveFileDialog();
                dialog.FileName = workItemType.Name + ".xml";
                dialog.Filter   = "XML Files (*.xml)|*.xml";
                var result = dialog.ShowDialog(Application.Current.MainWindow);
                if (result == true)
                {
                    workItemTypesToExport.Add(new WorkItemConfigurationItemExport(workItemType.TeamProject, workItemType.WorkItemTypeDefinition, dialog.FileName));
                }
            }
            else
            {
                // Export to a directory structure.
                var dialog = new System.Windows.Forms.FolderBrowserDialog();
                dialog.Description = "Please select the path where to export the Work Item Type Definition files (*.xml). They will be stored in a folder per Team Project.";
                var result = dialog.ShowDialog();
                if (result == System.Windows.Forms.DialogResult.OK)
                {
                    var rootFolder = dialog.SelectedPath;
                    foreach (var workItemType in workItemTypes)
                    {
                        var fileName = Path.Combine(rootFolder, workItemType.TeamProject.Name, workItemType.Name + ".xml");
                        workItemTypesToExport.Add(new WorkItemConfigurationItemExport(workItemType.TeamProject, workItemType.WorkItemTypeDefinition, fileName));
                    }
                }
            }

            if (workItemTypesToExport.Any())
            {
                var task = new ApplicationTask("Exporting " + workItemTypesToExport.Count.ToCountString("work item type"), workItemTypesToExport.Count, true);
                PublishStatus(new StatusEventArgs(task));
                var worker = new BackgroundWorker();
                worker.DoWork += (sender, e) =>
                {
                    WorkItemConfigurationItemImportExport.Export(this.Logger, task, workItemTypesToExport);
                };
                worker.RunWorkerCompleted += (sender, e) =>
                {
                    if (e.Error != null)
                    {
                        Logger.Log("An unexpected exception occurred while exporting work item types", e.Error);
                        task.SetError(e.Error);
                        task.SetComplete("An unexpected exception occurred");
                    }
                    else
                    {
                        task.SetComplete("Exported " + workItemTypesToExport.Count.ToCountString("work item type"));
                    }
                };
                worker.RunWorkerAsync();
            }
        }
コード例 #12
0
 public RequiresAccessToAttribute(
     ApplicationTask task,
     ApplicationTaskAccessLevel level = ApplicationTaskAccessLevel.Execute)
 {
     Task  = task;
     Level = level;
 }
コード例 #13
0
        private async Task GetBuildDefinitions(object argument)
        {
            var teamProjects = this.SelectedTeamProjects.ToList();
            var task         = new ApplicationTask("Retrieving build definitions", teamProjects.Count, true);

            PublishStatus(new StatusEventArgs(task));
            try
            {
                var tfsVersion  = this.SelectedTeamProjectCollection.TeamFoundationServer.MajorVersion;
                var tfs         = GetSelectedTfsTeamProjectCollection();
                var buildServer = tfs.GetClient <BuildHttpClient>();

                var step             = 0;
                var buildDefinitions = new List <BuildDefinition>();
                foreach (var teamProject in teamProjects)
                {
                    task.SetProgress(step++, string.Format(CultureInfo.CurrentCulture, "Processing Team Project \"{0}\"", teamProject.Name));
                    try
                    {
                        if (tfsVersion == TfsMajorVersion.TeamServices)
                        {
                            // Use a single API call if available.
                            var projectBuildDefinitions = await buildServer.GetFullDefinitionsAsync(project : teamProject.Name);

                            buildDefinitions.AddRange(projectBuildDefinitions);
                        }
                        else
                        {
                            // Otherwise get the base info first and then individual details.
                            var baseBuildDefinitions = await buildServer.GetDefinitionsAsync(project : teamProject.Name);

                            foreach (var baseBuildDefinition in baseBuildDefinitions)
                            {
                                var buildDefinition = await buildServer.GetDefinitionAsync(teamProject.Guid, baseBuildDefinition.Id);

                                buildDefinitions.Add(buildDefinition);
                            }
                        }
                    }
                    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;
                    }
                }
                this.BuildDefinitions = buildDefinitions;
                task.SetComplete("Retrieved " + this.BuildDefinitions.Count.ToCountString("build definition"));
            }
            catch (Exception exc)
            {
                Logger.Log("An unexpected exception occurred while retrieving build definitions", exc);
                task.SetError(exc);
                task.SetComplete("An unexpected exception occurred");
            }
        }
コード例 #14
0
ファイル: Actor.cs プロジェクト: MikeHanson/SpecSalad
        void see_how_i_do(TaskRole something)
        {
            if (something is ApplicationTask)
                _current_task = (ApplicationTask)something;

            if (something is ApplicationRole)
                _currentApplicationRole = (ApplicationRole) something;
        }
コード例 #15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="StatusEventArgs"/> class.
 /// </summary>
 /// <param name="message">The status message.</param>
 /// <param name="details">The status details.</param>
 /// <param name="exception">The exception that occurred, if any.</param>
 /// <param name="eventType">The type of event.</param>
 /// <param name="task">The application task that can be used to track further progress of the status event.</param>
 private StatusEventArgs(string message, string details, Exception exception, TraceEventType eventType, ApplicationTask task)
 {
     this.Message   = message;
     this.Details   = details;
     this.Exception = exception;
     this.EventType = eventType;
     this.Task      = task;
 }
コード例 #16
0
        private void DeleteSelectedSecurityGroups(object argument)
        {
            var result = MessageBox.Show("This will delete the selected security groups. Are you sure you want to continue?", "Confirm Delete", MessageBoxButton.YesNo, MessageBoxImage.Warning);

            if (result == MessageBoxResult.Yes)
            {
                var securityGroupsToDelete = this.SelectedSecurityGroups.ToList();
                var task = new ApplicationTask("Deleting security groups", securityGroupsToDelete.Count, true);
                PublishStatus(new StatusEventArgs(task));
                var worker = new BackgroundWorker();
                worker.DoWork += (sender, e) =>
                {
                    var tfs             = GetSelectedTfsTeamProjectCollection();
                    var securityService = tfs.GetService <IIdentityManagementService>();

                    var step  = 0;
                    var count = 0;
                    foreach (var securityGroup in securityGroupsToDelete)
                    {
                        task.SetProgress(step++, string.Format(CultureInfo.CurrentCulture, "Deleting security group \"{0}\" in Team Project \"{1}\"", securityGroup.Name, securityGroup.TeamProject.Name));
                        try
                        {
                            securityService.DeleteApplicationGroup(IdentityHelper.CreateTeamFoundationDescriptor(securityGroup.Sid));
                            count++;
                        }
                        catch (Exception exc)
                        {
                            task.SetWarning(string.Format(CultureInfo.CurrentCulture, "An error occurred while deleting security group \"{0}\" in Team Project \"{1}\"", securityGroup.Name, securityGroup.TeamProject.Name), exc);
                        }
                        if (task.IsCanceled)
                        {
                            task.Status = "Canceled";
                            break;
                        }
                    }

                    e.Result = count;
                };
                worker.RunWorkerCompleted += (sender, e) =>
                {
                    if (e.Error != null)
                    {
                        Logger.Log("An unexpected exception occurred while deleting security groups", e.Error);
                        task.SetError(e.Error);
                        task.SetComplete("An unexpected exception occurred");
                    }
                    else
                    {
                        var count = (int)e.Result;
                        task.SetComplete("Deleted " + count.ToCountString("security group"));
                    }

                    // Refresh the list.
                    GetSecurityGroups(null);
                };
                worker.RunWorkerAsync();
            }
        }
コード例 #17
0
        private async Task ImportTaskGroups(object argument)
        {
            var result = MessageBox.Show("This will import the selected task groups. Are you sure you want to continue?", "Confirm Import", MessageBoxButton.YesNo, MessageBoxImage.Warning);

            if (result != MessageBoxResult.Yes)
            {
                return;
            }
            var teamProjects = this.SelectedTeamProjects.ToList();
            var taskGroups   = this.TaskGroupsToImport.ToArray();
            var task         = new ApplicationTask("Importing task groups", teamProjects.Count * taskGroups.Length, true);

            PublishStatus(new StatusEventArgs(task));
            try
            {
                var tfs             = GetSelectedTfsTeamProjectCollection();
                var taskAgentClient = tfs.GetClient <TaskAgentHttpClient>();

                var step = 0;
                foreach (var teamProject in teamProjects)
                {
                    task.Status = "Processing Team Project \"{0}\"".FormatCurrent(teamProject.Name);
                    foreach (var taskGroup in taskGroups)
                    {
                        try
                        {
                            task.SetProgress(step++, string.Format(CultureInfo.CurrentCulture, "Importing task group \"{0}\" into Team Project \"{1}\"", taskGroup.Name, teamProject.Name));
                            await taskAgentClient.AddTaskGroupAsync(teamProject.Guid, taskGroup);
                        }
                        catch (MetaTaskDefinitionExistsException)
                        {
                            task.SetWarning(string.Format(CultureInfo.CurrentCulture, "The task group \"{0}\" already exists in Team Project \"{1}\"", taskGroup.Name, teamProject.Name));
                        }
                        catch (Exception exc)
                        {
                            task.SetWarning(string.Format(CultureInfo.CurrentCulture, "An error occurred while importing task group \"{0}\" into Team Project \"{1}\"", taskGroup.Name, teamProject.Name), exc);
                        }
                        if (task.IsCanceled)
                        {
                            break;
                        }
                    }
                    if (task.IsCanceled)
                    {
                        task.Status = "Canceled";
                        break;
                    }
                }
                task.SetComplete("Imported " + taskGroups.Length.ToCountString("task group"));
            }
            catch (Exception exc)
            {
                Logger.Log("An unexpected exception occurred while importing task groups", exc);
                task.SetError(exc);
                task.SetComplete("An unexpected exception occurred");
            }
        }
コード例 #18
0
        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();
        }
コード例 #19
0
        private async Task Import(object argument)
        {
            var result = MessageBox.Show("This will import the specified build templates. Are you sure you want to continue?", "Confirm Import", MessageBoxButton.YesNo, MessageBoxImage.Warning);

            if (result != MessageBoxResult.Yes)
            {
                return;
            }
            var teamProjects   = this.SelectedTeamProjects.ToList();
            var buildTemplates = this.BuildTemplatesToImport.ToArray();
            var task           = new ApplicationTask("Importing build templates", teamProjects.Count * buildTemplates.Length, true);

            PublishStatus(new StatusEventArgs(task));
            try
            {
                var tfs         = GetSelectedTfsTeamProjectCollection();
                var buildServer = tfs.GetClient <BuildHttpClient>();

                var step = 0;
                foreach (var teamProject in teamProjects)
                {
                    task.Status = "Processing Team Project \"{0}\"".FormatCurrent(teamProject.Name);
                    foreach (var buildTemplate in buildTemplates)
                    {
                        try
                        {
                            task.SetProgress(step++, string.Format(CultureInfo.CurrentCulture, "Importing build template \"{0}\" into Team Project \"{1}\"", buildTemplate.Name, teamProject.Name));
                            buildTemplate.Template.Project = new TeamProjectReference {
                                Name = teamProject.Name, Id = teamProject.Guid
                            };
                            await buildServer.SaveTemplateAsync(buildTemplate, teamProject.Name, buildTemplate.Id);
                        }
                        catch (Exception exc)
                        {
                            task.SetWarning(string.Format(CultureInfo.CurrentCulture, "An error occurred while importing build template \"{0}\" into Team Project \"{1}\"", buildTemplate.Name, teamProject.Name), exc);
                        }
                        if (task.IsCanceled)
                        {
                            break;
                        }
                    }
                    if (task.IsCanceled)
                    {
                        task.Status = "Canceled";
                        break;
                    }
                }
                task.SetComplete("Imported " + buildTemplates.Length.ToCountString("build template"));
            }
            catch (Exception exc)
            {
                Logger.Log("An unexpected exception occurred while importing build templates", exc);
                task.SetError(exc);
                task.SetComplete("An unexpected exception occurred");
            }
        }
コード例 #20
0
        private void AddOrUpdateSecurityGroup(object argument)
        {
            var result = MessageBox.Show("This will add a new security group to all selected Team Projects, or update the existing group if it already exists. Are you sure you want to continue?", "Confirm Add", MessageBoxButton.YesNo, MessageBoxImage.Warning);

            if (result == MessageBoxResult.Yes)
            {
                var teamProjects = this.SelectedTeamProjects.ToList();
                var task         = new ApplicationTask("Adding / updating security groups", teamProjects.Count, true);
                PublishStatus(new StatusEventArgs(task));
                var worker = new BackgroundWorker();
                worker.DoWork += (sender, e) =>
                {
                    var tfs        = GetSelectedTfsTeamProjectCollection();
                    var tfsVersion = this.SelectedTeamProjectCollection.TeamFoundationServer.MajorVersion;

                    var step  = 0;
                    var count = 0;
                    foreach (var teamProject in teamProjects)
                    {
                        task.SetProgress(step++, string.Format(CultureInfo.CurrentCulture, "Adding / updating security group \"{0}\" for Team Project \"{1}\"", this.SecurityGroupChange.Name, teamProject.Name));
                        try
                        {
                            SecurityManager.Apply(task, tfs, tfsVersion, teamProject.Name, this.SecurityGroupChange);
                            count++;
                        }
                        catch (Exception exc)
                        {
                            task.SetWarning(string.Format(CultureInfo.CurrentCulture, "An error occurred while adding / updating security group \"{0}\" for Team Project \"{1}\"", this.SecurityGroupChange.Name, teamProject.Name), exc);
                        }
                        if (task.IsCanceled)
                        {
                            task.Status = "Canceled";
                            break;
                        }
                    }

                    e.Result = count;
                };
                worker.RunWorkerCompleted += (sender, e) =>
                {
                    if (e.Error != null)
                    {
                        Logger.Log("An unexpected exception occurred while adding / updating security groups", e.Error);
                        task.SetError(e.Error);
                        task.SetComplete("An unexpected exception occurred");
                    }
                    else
                    {
                        var count = (int)e.Result;
                        task.SetComplete("Added / updated " + count.ToCountString("security group"));
                    }
                };
                worker.RunWorkerAsync();
            }
        }
        private void GetBuildDefinitions(object argument)
        {
            var teamProjects = this.SelectedTeamProjects.ToList();
            var task         = new ApplicationTask("Retrieving build definitions", teamProjects.Count, true);

            PublishStatus(new StatusEventArgs(task));
            var worker = new BackgroundWorker();

            worker.DoWork += (sender, e) =>
            {
                var tfs         = GetSelectedTfsTeamProjectCollection();
                var buildServer = tfs.GetService <IBuildServer>();

                var step             = 0;
                var buildDefinitions = new List <BuildDefinitionInfo>();
                foreach (var teamProject in teamProjects)
                {
                    task.SetProgress(step++, string.Format(CultureInfo.CurrentCulture, "Processing Team Project \"{0}\"", teamProject.Name));
                    try
                    {
                        foreach (var buildDefinition in buildServer.QueryBuildDefinitions(teamProject.Name, QueryOptions.All))
                        {
                            buildDefinitions.Add(new BuildDefinitionInfo(teamProject.Name, buildDefinition));
                        }
                    }
                    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 = buildDefinitions;
            };
            worker.RunWorkerCompleted += (sender, e) =>
            {
                if (e.Error != null)
                {
                    Logger.Log("An unexpected exception occurred while retrieving build definitions", e.Error);
                    task.SetError(e.Error);
                    task.SetComplete("An unexpected exception occurred");
                }
                else
                {
                    this.BuildDefinitions = (ICollection <BuildDefinitionInfo>)e.Result;
                    task.SetComplete("Retrieved " + this.BuildDefinitions.Count.ToCountString("build definition"));
                }
            };
            worker.RunWorkerAsync();
        }
コード例 #22
0
        private void ImportWorkItemCategoryList(object argument)
        {
            var result = MessageBox.Show("This will import the work item category list to all selected Team Projects. Certain applications like Microsoft Test Manager rely on categories so modifying them can reduce their functionality. Are you sure you want to continue?", "Confirm Import", MessageBoxButton.YesNo, MessageBoxImage.Warning);

            if (result != MessageBoxResult.Yes)
            {
                return;
            }

            var task = new ApplicationTask("Importing work item category list", this.SelectedTeamProjects.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 categoriesXml = this.SelectedWorkItemCategoryList.Save();
                foreach (var teamProject in this.SelectedTeamProjects)
                {
                    try
                    {
                        task.SetProgress(step++, string.Format(CultureInfo.CurrentCulture, "Importing work item category list in Team Project \"{0}\"", teamProject.Name));
                        var project = store.Projects[teamProject.Name];
                        WorkItemConfigurationItemImportExport.SetCategories(project, categoriesXml);
                    }
                    catch (Exception exc)
                    {
                        task.SetError(string.Format(CultureInfo.CurrentCulture, "An error occurred while importing the work item category list for Team Project \"{0}\"", teamProject.Name), exc);
                    }
                    if (task.IsCanceled)
                    {
                        task.Status = "Canceled";
                        break;
                    }
                }
            };
            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
                {
                    task.SetComplete(task.IsError ? "Failed" : (task.IsWarning ? "Succeeded with warnings" : "Succeeded"));
                }
            };
            worker.RunWorkerAsync();
        }
コード例 #23
0
        public void Update(ApplicationTask task, IBuildDefinition buildDefinition, ICollection <IBuildController> availableBuildControllers, ICollection <IProcessTemplate> availableProcessTemplates)
        {
            if (buildDefinition == null)
            {
                return;
            }

            // General Properties
            if (UpdateBuildControllerName)
            {
                var selectedBuildController = availableBuildControllers.FirstOrDefault(c => string.Equals(c.Name, this.BuildControllerName, StringComparison.OrdinalIgnoreCase));
                if (selectedBuildController == null)
                {
                    task.SetWarning(string.Format(CultureInfo.CurrentCulture, "The build controller could not be set to \"{0}\" because a build controller with this name is not registered.", this.BuildControllerName));
                }
                else
                {
                    buildDefinition.BuildController = selectedBuildController;
                }
            }
            if (UpdateDefaultDropLocation)
            {
                // To disable the drop location, do not set to null but always use an empty string (null only works for TFS 2010 and before, an empty string always works).
                buildDefinition.DefaultDropLocation = this.DefaultDropLocation ?? string.Empty;
            }
            if (UpdateTriggerType)
            {
                buildDefinition.TriggerType = this.TriggerType;
            }
            if (UpdateQueueStatus)
            {
                buildDefinition.QueueStatus = this.QueueStatus;
            }
            if (UpdateProcessTemplate)
            {
                var selectedProcessTemplate = availableProcessTemplates.FirstOrDefault(p => string.Equals(p.ServerPath, this.ProcessTemplate, StringComparison.OrdinalIgnoreCase));
                if (selectedProcessTemplate == null)
                {
                    task.SetWarning(string.Format(CultureInfo.CurrentCulture, "The process template could not be set to \"{0}\" because a process template with this server path is not registered.", this.ProcessTemplate));
                }
                else
                {
                    buildDefinition.Process = selectedProcessTemplate;
                }
            }
            if (UpdateContinuousIntegrationQuietPeriod)
            {
                buildDefinition.ContinuousIntegrationQuietPeriod = this.ContinuousIntegrationQuietPeriod;
            }
            if (UpdateBatchSize)
            {
                buildDefinition.BatchSize = this.BatchSize;
            }
        }
コード例 #24
0
        private void UpdateSourceControlSettings(object argument)
        {
            var result = MessageBox.Show("This will update the source control settings in all selected Team Projects. Are you sure you want to continue?", "Confirm Update", MessageBoxButton.YesNo, MessageBoxImage.Warning);

            if (result == MessageBoxResult.Yes)
            {
                var teamProjectNames = this.SelectedTeamProjects.Select(p => p.Name).ToList();
                var settings         = this.SelectedSourceControlSettings;
                var task             = new ApplicationTask("Updating source control settings", teamProjectNames.Count, true);
                this.PublishStatus(new StatusEventArgs(task));
                var worker = new BackgroundWorker();
                worker.DoWork += (sender, e) =>
                {
                    var step = 0;
                    var tfs  = GetSelectedTfsTeamProjectCollection();
                    var vcs  = tfs.GetService <VersionControlServer>();
                    foreach (var teamProjectName in teamProjectNames)
                    {
                        task.SetProgress(step++, string.Format(CultureInfo.CurrentCulture, "Processing Team Project \"{0}\"", teamProjectName));
                        try
                        {
                            var project = vcs.GetTeamProject(teamProjectName);
                            project.ExclusiveCheckout   = !settings.EnableMultipleCheckout;
                            project.GetLatestOnCheckout = settings.EnableGetLatestOnCheckout;
                            var checkinNoteFields = settings.CheckinNoteFields.Select(f => new CheckinNoteFieldDefinition(f.Name, f.Required, f.DisplayOrder)).ToArray();
                            project.SetCheckinNoteFields(checkinNoteFields);
                        }
                        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 updating source control settings", e.Error);
                        task.SetError(e.Error);
                        task.SetComplete("An unexpected exception occurred");
                    }
                    else
                    {
                        task.SetComplete("Done");
                    }
                };
                worker.RunWorkerAsync();
            }
        }
コード例 #25
0
ファイル: Actor.cs プロジェクト: DuncanButler/SpecSalad
        void see_how_i_do(TaskRole something)
        {
            if (something is ApplicationTask)
            {
                _current_task = (ApplicationTask)something;
            }

            if (something is ApplicationRole)
            {
                _currentApplicationRole = (ApplicationRole)something;
            }
        }
コード例 #26
0
        private async Task DeleteSelectedServiceEndpoints(object argument)
        {
            var result = MessageBox.Show("This will delete the selected service endpoints. Are you sure you want to continue?", "Confirm Delete", MessageBoxButton.YesNo, MessageBoxImage.Warning);

            if (result != MessageBoxResult.Yes)
            {
                return;
            }

            var serviceEndpointsToDelete = this.SelectedServiceEndpoints;
            var task = new ApplicationTask("Deleting service endpoints", serviceEndpointsToDelete.Count, true);

            PublishStatus(new StatusEventArgs(task));
            try
            {
                var tfs             = GetSelectedTfsTeamProjectCollection();
                var taskAgentClient = tfs.GetClient <TaskAgentHttpClient>();

                var step  = 0;
                var count = 0;
                foreach (var serviceEndpointToDelete in serviceEndpointsToDelete)
                {
                    task.SetProgress(step++, string.Format(CultureInfo.CurrentCulture, "Deleting service endpoint \"{0}\" in Team Project \"{1}\"", serviceEndpointToDelete.ServiceEndpoint.Name, serviceEndpointToDelete.TeamProject.Name));
                    try
                    {
                        // Delete the service endpoints one by one to avoid one failure preventing the other ones from being deleted.
                        await taskAgentClient.DeleteServiceEndpointAsync(serviceEndpointToDelete.TeamProject.Guid, serviceEndpointToDelete.ServiceEndpoint.Id);

                        count++;
                    }
                    catch (Exception exc)
                    {
                        task.SetWarning(string.Format(CultureInfo.CurrentCulture, "An error occurred while deleting service endpoints \"{0}\" in Team Project \"{1}\"", serviceEndpointToDelete.ServiceEndpoint.Name, serviceEndpointToDelete.TeamProject.Name), exc);
                    }
                    if (task.IsCanceled)
                    {
                        task.Status = "Canceled";
                        break;
                    }
                }
                task.SetComplete("Deleted " + count.ToCountString("service endpoint"));

                // Refresh the list.
                await GetServiceEndpoints(null);
            }
            catch (Exception exc)
            {
                Logger.Log("An unexpected exception occurred while deleting service endpoints", exc);
                task.SetError(exc);
                task.SetComplete("An unexpected exception occurred");
            }
        }
コード例 #27
0
        private static void PerformUserAction(ApplicationTask task, IIdentityManagementService ims, string userName, Action <TeamFoundationIdentity> action)
        {
            // Look up the user by account name.
            var userIdentity = ims.ReadIdentity(IdentitySearchFactor.AccountName, userName, MembershipQuery.None, ReadIdentityOptions.IncludeReadFromSource);

            if (userIdentity == null)
            {
                task.SetWarning("The requested user was not found: \"{0}\". Please make sure to use the account name, not the display name (which can be ambiguous).".FormatCurrent(userName));
            }
            else
            {
                action(userIdentity);
            }
        }
コード例 #28
0
        private void GetSourceControlSettings(object argument)
        {
            var teamProjectNames = this.SelectedTeamProjects.Select(p => p.Name).ToList();
            var task             = new ApplicationTask("Retrieving source control settings", teamProjectNames.Count, true);

            this.PublishStatus(new StatusEventArgs(task));
            var worker = new BackgroundWorker();

            worker.DoWork += (sender, e) =>
            {
                var settings = new ObservableCollection <SourceControlSettings>();
                var step     = 0;
                var tfs      = GetSelectedTfsTeamProjectCollection();
                var vcs      = tfs.GetService <VersionControlServer>();
                foreach (var teamProjectName in teamProjectNames)
                {
                    task.SetProgress(step++, string.Format(CultureInfo.CurrentCulture, "Processing Team Project \"{0}\"", teamProjectName));
                    try
                    {
                        var projectSettings = GetSourceControlSettings(vcs, teamProjectName);
                        settings.Add(projectSettings);
                    }
                    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 = settings;
            };
            worker.RunWorkerCompleted += (sender, e) =>
            {
                if (e.Error != null)
                {
                    Logger.Log("An unexpected exception occurred while retrieving source control settings", e.Error);
                    task.SetError(e.Error);
                    task.SetComplete("An unexpected exception occurred");
                }
                else
                {
                    this.SourceControlSettings = (ObservableCollection <SourceControlSettings>)e.Result;
                    task.SetComplete("Done");
                }
            };
            worker.RunWorkerAsync();
        }
コード例 #29
0
        private async Task AddServiceEndpoint(object argument)
        {
            var result = MessageBox.Show("This will add the service endpoint to all selected Team Projects. Are you sure you want to continue?", "Confirm Service Endpoint", MessageBoxButton.YesNo, MessageBoxImage.Warning);

            if (result != MessageBoxResult.Yes)
            {
                return;
            }

            var teamProjects = this.SelectedTeamProjects.ToList();
            var task         = new ApplicationTask("Adding service endpoint", teamProjects.Count, true);

            PublishStatus(new StatusEventArgs(task));
            try
            {
                var tfs             = GetSelectedTfsTeamProjectCollection();
                var taskAgentClient = tfs.GetClient <TaskAgentHttpClient>();
                var serviceEndpoint = this.GenericServiceEndpoint.ToServiceEndpoint();

                var step  = 0;
                var count = 0;
                foreach (var teamProject in teamProjects)
                {
                    task.SetProgress(step++, string.Format(CultureInfo.CurrentCulture, "Processing Team Project \"{0}\"", teamProject.Name));
                    try
                    {
                        await taskAgentClient.CreateServiceEndpointAsync(teamProject.Guid, serviceEndpoint);

                        count++;
                    }
                    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;
                    }
                }
                task.SetComplete("Added service endpoint to " + count.ToCountString("Team Project"));
            }
            catch (Exception exc)
            {
                Logger.Log("An unexpected exception occurred while adding service endpoint", exc);
                task.SetError(exc);
                task.SetComplete("An unexpected exception occurred");
            }
        }
コード例 #30
0
 public ApplicationTaskViewModel(ApplicationTask task)
 {
     this.Task = task;
     this.Task.ObservablePropertyChanged       += Task_ObservablePropertyChanged;
     this.Task.StatusHistory.CollectionChanged += TaskStatusHistory_CollectionChanged;
     if (this.Task.StatusHistory != null)
     {
         var status = string.Empty;
         foreach (string item in this.Task.StatusHistory.ToList())
         {
             status += Environment.NewLine + item;
         }
         this.StatusHistoryDescription = status.Trim();
     }
     RefreshState();
 }
コード例 #31
0
        private void ViewBranchHierarchies(object argument)
        {
            var teamProjectNames = this.SelectedTeamProjects.Select(p => p.Name).ToList();
            var task             = new ApplicationTask("Retrieving branch hierarchies", null, true);

            this.PublishStatus(new StatusEventArgs(task));
            var worker = new BackgroundWorker();

            worker.DoWork += (sender, e) =>
            {
                var tfs = GetSelectedTfsTeamProjectCollection();
                var vcs = tfs.GetService <VersionControlServer>();
                var teamProjectRootPaths = teamProjectNames.Select(t => string.Concat("$/", t, "/")).ToArray();
                var branchHierarchies    = new List <BranchInfo>();
                foreach (var rootBranch in vcs.QueryRootBranchObjects(RecursionType.OneLevel).Where(b => !teamProjectRootPaths.Any() || teamProjectRootPaths.Any(t => (b.Properties.RootItem.Item + "/").StartsWith(t, StringComparison.OrdinalIgnoreCase))).OrderBy(b => b.Properties.RootItem.Item))
                {
                    branchHierarchies.Add(GetBranchInfo(rootBranch, null, vcs, task));
                    if (task.IsCanceled)
                    {
                        task.Status = "Canceled";
                        break;
                    }
                }
                e.Result = branchHierarchies;
            };
            worker.RunWorkerCompleted += (sender, e) =>
            {
                if (e.Error != null)
                {
                    Logger.Log("An unexpected exception occurred while retrieving branch hierarchies", e.Error);
                    task.SetError(e.Error);
                    task.SetComplete("An unexpected exception occurred");
                    this.BranchHierarchiesInfoMessage = null;
                }
                else
                {
                    this.BranchHierarchies = (IList <BranchInfo>)e.Result;
                    var totalBranchCount = this.BranchHierarchies.Count + this.BranchHierarchies.Sum(b => b.RecursiveChildCount);
                    var maxTreeDepth     = this.BranchHierarchies.Any() ? this.BranchHierarchies.Max(b => b.MaxTreeDepth) : 0;
                    var infoMessage      = "Retrieved {0} with a total of {1} and a maximum depth of {2}".FormatCurrent(this.BranchHierarchies.Count.ToCountString("branch hierarchy"), totalBranchCount.ToCountString("branch"), maxTreeDepth);
                    task.SetComplete(infoMessage);
                    this.BranchHierarchiesInfoMessage = infoMessage;
                }
            };
            worker.RunWorkerAsync();
        }
コード例 #32
0
 public object do_action(ApplicationTask task_to_perform, object details)
 {
     throw new NotImplementedException();
 }