Team explorer的查询结果窗口的全局服务

时间:2015-09-02 18:13:13

标签: c# tfs

什么是查询结果窗口的全局服务(接口)?代码如下:

var dteService = Package.GetGlobalService(typeof(EnvDTE.DTE)) as EnvDTE.DTE;
if (dteService == null)
{
   Debug.WriteLine("");
   return;
}

var something=Package.GetGlobalService(typeof(???)) as ???;

编辑:目标是,当我按下上下文菜单按钮时,我希望函数回调能够访问选择工作项的服务(或结果列表

The goal is, when I press the context menu button, I want the function callback to be able to access the service where the work item is selected (or the results list

2 个答案:

答案 0 :(得分:1)

请在MSDN论坛中查看此案例,了解如何使其工作:https://social.msdn.microsoft.com/Forums/vstudio/en-US/2d158b9c-dec1-4c59-82aa-f1f2312d770b/sdk-packageget-selected-item-from-query-results-list

以下代码引自上面的链接,供您快速参考:

Document activeDocument = _applicationObject.ActiveDocument;
        if (activeDocument != null)
        {
            DocumentService globalService = (DocumentService)Package.GetGlobalService(typeof(DocumentService));
            if (globalService != null)
            {
                string fullName = activeDocument.FullName;
                IWorkItemTrackingDocument document2 = globalService.FindDocument(fullName, null);
                if ((document2 != null) && (document2 is IResultsDocument))
                {
                    int[] selectedItemIds = ((IResultsDocument)document2).SelectedItemIds;
                }
            }
        }

答案 1 :(得分:0)

var dteService = Package.GetGlobalService(typeof(EnvDTE.DTE)) as EnvDTE.DTE;
if (dteService == null)
{
   Debug.WriteLine("");
   return;
}

DocumentService documentService = Package.GetGlobalService(typeof(DocumentService)) as DocumentService;
if (documentService == null)
      return;

string fullName = dteService.ActiveDocument.FullName;

IWorkItemTrackingDocument activeDocument = documentService.FindDocument(fullName, null);

if (activeDocument == null || !(activeDocument is IResultsDocument))
             return;