2013-05-09 96 views
0

我正在編寫一個擴展構建資源管理器的Visual Studio 2012加載項 - 基本上,我爲每個構建(已完成或正在運行,但未排隊)添加一個上下文菜單選項。在a blog post about doing this in VS2010之後,我設法爲Builder資源管理器中出現的構建做好了準備 - 萬歲!查找在團隊資源管理器的「我的構建」

現在,我的上下文菜單也出現在團隊資源管理器的Builds頁面,My Builds部分。但是,當我收到回調時,我無法在任何地方找到實際的構建版本!

這裏是我的beforeQueryStatus事件處理程序,在這裏我試着找出我是否生成以顯示或不:

private void OpenCompletedInBuildExplorerBeforeQueryStatus(object sender, EventArgs e) 
{ 
    var cmd = (OleMenuCommand)sender; 
    var vsTfBuild = (IVsTeamFoundationBuild)GetService(typeof(IVsTeamFoundationBuild)); 

    // This finds builds in Build Explorer window 
    cmd.Enabled = (vsTfBuild.BuildExplorer.CompletedView.SelectedBuilds.Length == 1 
       && vsTfBuild.BuildExplorer.QueuedView.SelectedBuilds.Length == 0); // No build _requests_ are selected 

    // This tries to find builds in Team Explorer's Builds page, My Builds section 
    var teamExplorer = (ITeamExplorer)GetService(typeof(ITeamExplorer)); 
    var page = teamExplorer.CurrentPage as Microsoft.TeamFoundation.Controls.WPF.TeamExplorer.TeamExplorerPageBase; 
    var vm = page.ViewModel; 
    // does not compile: 'Microsoft.TeamFoundation.Build.Controls.BuildsPageViewModel' is inaccessible due to its protection level 
    var vm_private = vm as Microsoft.TeamFoundation.Build.Controls.BuildsPageViewModel; 
    // But debugger shows that if it did, my builds would be here: 
    var builds = vm_private.MyBuilds; 
} 
  1. 有沒有辦法讓生成的列表?
  2. 更一般地說,有沒有辦法得到一些「這個上下文菜單所屬的窗口」?目前,我只是隨便看看在VS的部分我認爲將有建立...

回答

0

我設法使用反射來獲取編譯:

var teamExplorer = (ITeamExplorer)GetService(typeof(ITeamExplorer)); 

var BuildsPage = teamExplorer.CurrentPage as Microsoft.TeamFoundation.Controls.WPF.TeamExplorer.TeamExplorerPageBase; 
var PageViewModel = BuildsPage.ViewModel as Microsoft.TeamFoundation.Controls.WPF.TeamExplorer.TeamExplorerPageViewModelBase; 
    // PageViewModel is actually Microsoft.TeamFoundation.Build.Controls.BuildsPageViewModel. But, it's private, so get SelectedBuilds through reflection 
var SelectedBuilds = PageViewModel.GetType().GetProperty("SelectedBuilds").GetValue(PageViewModel) as System.Collections.IList; 
if (SelectedBuilds.Count != 1) 
{ 
    cmd.Enabled = false; 
    return; 
} 

object BuildModel = SelectedBuilds[0]; 
    // BuildModel is actually Microsoft.TeamFoundation.Build.Controls.BuildModel. But, it's private, so get UriToOpen through reflection 
var BuildUri = BuildModel.GetType().GetProperty("UriToOpen").GetValue(BuildModel) as Uri; 
// TODO: Use BuildUri... 

cmd.Enabled = true; 
相關問題