In my previous post on writing a SSMS Add-in for Denali I detailed the steps that you would need to take to get the Add-in loaded and running but it didn’t do a great deal.
Now we take it a step further. But not too far(!)
I’ve done a number of things;
- Hooked up to the events class in DTE, so we can get a view on what’s happening inside the Add-in.
- Added some T-SQL code formatting functionality, to show how to access the contents of a query window.
- Added a context menu to the Object Explorer
- Put all the source on Codeplex under a new project called ‘’SQL Server Management Studio Add-in for Denali (SSMS Addin)” Url: http://ssmsaddindenali.codeplex.com/ Feel free to download or/and join the project and contribute.
1) As we all know, SSMS Add-in’s only work because of a deep dark magic, but there are a few ways we can peek inside to see what’s happening.
The DTE object we get during the OnConnection method has a class full of events – so lets hook them up and see what happens.
EnvDTE.TextDocument doc = (EnvDTE.TextDocument)ServiceCache.ExtensibilityModel.Application.ActiveDocument.Object(null);
Returns a TextDocument object from which you can get the contents of the window (SQL).
3) Just like previous versions add-ins, you use the same code to pick up Object Explorer events.
1: objExplorerService = (ObjectExplorerService)ServiceCache.ServiceProvider.GetService(typeof(IObjectExplorerService));
2: cs = (ContextService)objExplorerService.Container.Components[0];
3: cs.ObjectExplorerContext.CurrentContextChanged += new NodesChangedEventHandler(ObjectExplorerContext_CurrentContextChanged);
Download the source from codeplex, check it out, play with it, check it in!
I am having problem when i downloaded your source code and trying to use it please assist thank you.
ReplyDeleteHere is the screen shot
https://picasaweb.google.com/109227880271946894828/April82012
I've got the same problem. Did You solve it?
DeleteExcellent post. I'm implementing something similar to what you have in the Source Controled version. I'm adding a pair of items to the object explorer for databases. So far it is kind of working there is one segment that is giving me trouble in two ways. This is also in SQL Sever 2012
ReplyDeleteBelow is the problem code.
INodeInformation node = objectExplorer.FindNode(navigationContext.Context);
if(node.Parent.InvariantName.Equals("Databases"))
{
if (_databaseMenu == null)
{
string value = typeof(IMenuHandler).ToString();
_databaseMenu = (HierarchyObject)node.GetService(typeof(IMenuHandler));
String wtf = _databaseMenu.ToString();
RestoreMenuItem rst = new RestoreMenuItem();
_databaseMenu.AddChild(string.Empty, rst);
}
}
This works but it gives me two entries in the context menu because I think the call is being made aschynchronously twice to the change method. This is a nuisance but I do have a way around it. The other problem is more severe the FindNode method depending on how you are clicking around in management studio can seemingly randomly take forever. It does finish eventually but much later. Do you know of any work arounds for those problems?
I am also having major issues trying to compile a working addin. I believe I have referenced the proper libraries but when I try to implement ObjectExplorerService, It throws an error "Unable to cast object of Type Microsoft.SqlServer.Management.SqlStudio.Explorer.ObjectExplorerService to type Microsoft.SqlServer.Management.SqlStudio.Explorer.ContextService"
DeleteI am hoping the community will share info on a working Explorer interface!
Did you solve FindNode problem ?
Delete