index > Visual Studio Guidance Automation Toolkit > Type of Document objects retrieved from DTE

Type of Document objects retrieved from DTE

I'm working on a guidance package for a DSL, and one of the recipies concerns code generation.
I have associated the recipie with the appropriate ProjectItems and everything is working perfectly. I can get the ProjectItem, load the referenced file as a DSL model and continue into the code generation.

Then it strikes me that most often the user is going to have the file open already, so I can avoid the overhead of loading the model by simply finding a reference to the open file and using that as the source for the code gen.

So I have the code below (the Execute method of an Action). It locates the correct open document, but I cannot cast it to the correct type. The type of the object I get is System.__ComObject, and there is no obvious way to marshall that into a ModelingDocData.
Can you give me any pointers on how to get a reference to the document as the type I need?

Thanks,
Brian.

public override void Execute()
{
DTE vs = GetService<DTE>(true);
IAssetReferenceService referenceService = GetService<IAssetReferenceService>(true);
object item = DteHelper.GetTarget(vs);

ProjectItem projectItem = item as ProjectItem;
foreach (Document doc in vs.Documents)
{
if (doc.ProjectItem.Equals(item))
{
MessageBox.Show("Found open document " + doc.Path, "Code Generation", MessageBoxButtons.OK, MessageBoxIcon.Information);
Microsoft.VisualStudio.EnterpriseTools.Shell.ModelingDocData docData = doc as Microsoft.VisualStudio.EnterpriseTools.Shell.ModelingDocData;
if (docData != null)
{
MessageBox.Show("Document is ModelingDocData " + docData.RootElement.MetaClass.Name, "Code Generation", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("Document type " + doc.GetType().AssemblyQualifiedName, "Code Generation", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}

if (projectItem == null)
throw new InvalidOperationException("There is no valid model from which to generate code.");

MessageBox.Show("Generating code for " + projectItem.Name, "Code Generation",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}

Brian OByrne
This question is related to the DSL tools and not specifically to GAT.
You should try asking in their forum instead: http://forums.microsoft.com/msdn/showforum.aspx?forumid=61&siteid=1

Thanks!



Daniel Cazzulino [Solutions Architect MVP]
kzu
No, this problem is related to the types returned from the DTE objects.

I might accept that it is related to VS SDK more than to GAT, but it is not a DSL question.

Brian OByrne
More over, it's not a VSSDK but an VS extensibility (DTE/addins) question, as you're accessing the document from the DTE solution object.

The reason I pointed you to the DSL forum, is that you're talking specifically about getting the modelling document, and they may have a preferred way for you to do that, which may or may not involve the DTE (i.e. there are VSIP interfaces to get to the same information, i.e. IVsMonitorSelection and IVsWindowFrame, using __VSFPROPID.VSFPROPID_DocView).





Daniel Cazzulino [Solutions Architect MVP]
kzu
And by the way, as you acknowledge yourself, this is a DTE question, so you should also try the VS extensibility forum: http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=57&SiteID=1

Thanks



Daniel Cazzulino [Solutions Architect MVP]
kzu
reply 5

You can use google to search for other answers

 

More Articles

• Uninstall Failure
• classname value
• How to execute actions after solution template was unfolded
• How is GAT Package information persisted?
• Is there any way to run an action when a project with my guidance...
• Where is the Recipe History stored?
• TechEd Hands On Lab 2005 - Exercise 2 - Code Snippet Issue
• Can you build a guidance package in VB?
• Guidance Automation Extensions and Toolkit: June 2006 Release
• Fail to register Guidance Package from Solution Manager
Bookmark and Share
Welcome to Bokebb   New Update  
 

New Articles

• GAT on Visual Studio Release Candidate
• Slow Wizard Input using MonitorArgument
• IExtenderProvider the GAT way...
• Reality Check?
• GAT fails to install, claims GAX is miss
• UIPAB
• enable GAT for existing projects
• Download not available
• Installation error
• Is there any way to run an action when a
• TechEd Hands On Lab 2005 - Exercise 2 -
• GAT is VS Solution Centric
• How should I deploy additional binaries?
• How can you skip the UI when you run a r
• How to get SysListView32 of hiding objec

Hot Articles

• uninstall of HoLPackageSetup.msi failed
• Register Guidance Package fails
• How do you enable delay signing on a web
• How to get SysListView32 of hiding objec
• Error 1001: Item has already been added.
• Loading solution verty slow
• Debugging your packages.
• Loosing Item Template Information
• Access Denied (On Windows XP SP2)
• Creating projects in a subdirectory
• Project reference problem
• Guidance actions are gone
• HoL Registration failed
• Changes to the ProjectName from a Wizard
• How to use Generic List in T3

Recommend Articles

• uninstall of HoLPackageSetup.msi failed
• Register Guidance Package fails
• configured attribute T3 - no property o
• How to Add Fixed Assets in GAT?
• Trusted Assembly referenace Problem
• Use AddEntity recipe form HoL on existin
• Loading solution verty slow
• trouble installing the Web Service Softw
• Microsoft.Jet.OLEDB.4.0
• How to create a local method in a T3 scr
• Tools.GenerateLocalResource
• Uninstalling Missing Packages
• Error installing GAX
• Problem with Specifying Command Bars
• June GAT Installation Issues