Creating a Visual Studio Add-in for "Search"
Hello all!
We all know search is a problem in VSTS, each time we need to export the list to Excel and then use the Ctrl+F keys to search in a particular field.
OR
Creating a simple Query and modifying that query each time I need to search for another string.So I decided to create an Add-in in VSTS that simply asks for:
-Select Team Project : combobox
-Select Work Item Type: combobox
-Search For: textbox
-All Fields radio button #1
-Custom Fields radio button #2
-Search button and a Cancel button.
The Add-in works great, debugging and all the functionality is done but I'm missing something.
All I need now is how do I bind the result of my query(wilqQuery) to the existing grid in VSTS ?
As we speak, my Add-in is modal, so when I click the Search button, I would like to close the Add-in form and make the result appear in the existing VSTS grid.You know! the same one that's there when I double click "All Bugs" for example!
Or the result grid of a query!
How do I bind to it? Is it even possible?
Any help, code example, from you gurus out there is appreciated!
Thanks in advance
Sincerely
Vince.
[1341 byte] By [
Vlince] at [2007-12-20]
Can you host your plugin somethere. Or simply email it to me (tolyy@yandex.ru) I would like to try it.
Thanks
Hi tolyy the Add-in isn't finished yet, well its 90% done and I've stopped working on it for now.The only thing missing is, binding the result of the query to the existing grid in VSTS.
I could open my own new window and use the WorkItemResultGrid but I'd prefer using the grid in VSTS instead of opening a new window!
Perhaps, when I do get an asnwer or when I finish working on it I'll be posting a link to it, I'll probably make it available via ClickOnce!
Thanks
Vince
Hi Vince,
The add-in sounds great!
Assuming that your search is just a normal WIQL query, here is what you need to do:
private void ShowQueryResults(TeamFoundationServer s, string teamProject, string wiql)
{
DocumentService documentService = (DocumentService)m_applicationObject.DTE.GetObject("Microsoft.VisualStudio.TeamFoundation.WorkItemTracking.DocumentService");
// Create the query document for the wiql query
IQueryDocument query = documentService.CreateQuery(s, teamProject, false, wiql, this);
try
{
// Create the results document
IResultsDocument results = documentService.CreateResults(query, this);
try
{
// Show the results of the Query in VS
documentService.ShowResults(results);
}
finally
{
// Release my lock on the results
results.Release(this);
}
}
finally
{
// Release my lock on the query
query.Release(this);
}
}
The above function should work in your add-in. You need to change the reference to the application object and get the team foundation server object, but then you are ready to go.
Oh, if you need to get the TFServer object see the following post:
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=264040&SiteID=1
Wow this is amazing Jason! Thanks!
The Add-in is actually fun to make :)
I'm getting an error with the code snippet you've provided. The error occurs on line:
IQueryDocument query = documentService.CreateQuery(s, teamProject, false, wiql, this);Placing a breakpoint gives me the following error:
WrongServerContextException was unhandled by user code
The server context cannot be changed through a call to the DocumentService. Force a server context switch and then call the method.
I've search google and google groups, didn't find any link ? How come? lolll
Basically the Search button on my form invokes the click event in which I get an instance of our TFS server, get the Project Name from the dropdown box and create the wilQuery.
Then I pass these to the ShowQueryResults() you've provided me.
Perhaps I'm overlooking something...
Thanks again!
Sincerely
Vince
The WrongServerContextException is only thrown if the TFServer object provided is different that the one VS is already connected to. How are you getting the TFServer object?
Unfortunately, TeamFoundationServerFactory.GetServer may return you a new instance of the same server. This can happen if the URI passed in is not the same as the one we use internally. Try Tim's method of obtaining the TFServer (the link that I mentioned before). If that's not working, I will think of something else :)
Thanks,
Jason
Jason you are my new best friend and you are a GOD!
The reason why I was getting the error is imply because I was creating a new instance of our Team Foundation Server. I wasn't thinking about using the current one (the one used by the IDE).
Wow it works! its amazing! its Fun!
Initially the TFServer was always returning null. Then it hit me in the face!
FYI, when I open my IDE, it defaults to the "Solution Explorer" Pane so my IDE is not yet connected to TFS. Its only when I click on the "Team Explorer" Pane did my IDE started saying: Connecting to TFS...
When I was debugging, I was opening my Add-in right away hence why I was always getting a null back. So before opening my Add-in, I had to click on the "Team Explorer" Pane and made sure the IDE was connected to TFS.
Anyway...now my Add-in checks for that, basically if the instance is null a messagebox is prompted warning the user to make sure you are currently connected to TFS.
Still need to tweak a few things, then we are going to test it internally!
Many thanks Jason, can't wait for many more examples on Add-ins with VSTS.
Sincerely
Vince
PS: If your ever in the Montreal area, let me know, I'll buy you a beer!
I am not a diety by any means. I am glad I could help.
/Jason
I'd love to see a link to this too, including the source code if you'd like to share it. Thanks.
-Larry
I have the code ready if anyone is interested!
I'll zip the solution followed by a readme.
To get it, just click on my username and in my profile you'll have my email address.
Send me a mail and I'll foward the attachment cause I can't deploy it to URL as I initially thought :-(
Vince
Hi,
I have a related problem.
I'm trying to create an add-in which can get access to the currently active work item result query (document = "Work Item Tracking - Results View"). Then I want to get access to the currently selected SCRs in this document. I assume I can use WorkItemResultGrid for this. I know I can get access to the DocumentService but I have no idea how to link al this together.
- How do I know that in my add-in, _applicationObject.ActiveDocument references a "Work Item Tracking - Results View" document.
- And how to obtain the WorkItemResultGrid once I know it is an WIT result view.
I found some interesting info at the following location but this is not giving the answers I need.
http://blogs.msdn.com/edhintz/archive/2006/02/03/524312.aspx