| | | 
StrataFrame User
       
Group: StrataFrame Users Last Login: 07/03/2008 3:22:13 PM Posts: 329, Visits: 1,991 |
| | I am trying to create an VS add in for my reporting engine. I need to be able to loop through each project and then loop through the project and find reports by type. (Like you do with the Bo Mapper) .. i am trying something like below just cannot figure out how to load or just get at the assembly. thanks for any helpDim LoProject As ProjectDim loAssembly As Reflection.AssemblyTry'Check to see if Solution is open, I forget everytime debugging this If Not _appobject.Solution.IsOpen Then MessageBox.Show( "Please load solution")ElseFor Each LoProject In _appobject.Solution.Projects'show what projects we have MessageBox.Show( "Project Name: " & LoProject.FullName)'-- Here i need to be able to load the assembly and then do through the types' loAssembly = Reflection.Assembly.LoadFor Each loType As Type In loAssembly.GetTypes()If loType.IsSubclassOf(GetType(DevExpress.XtraReports.UI.XtraReport)) ThenMe.ListView1.Items.Add(loType.FullName)End IfNextNextEnd IfCatch objException As System.ExceptionMessageBox.Show(objException.ToString) End Try |
| | | | 
StrataFrame Developer

Group: StrataFrame Developers Last Login: Yesterday @ 9:47:36 PM Posts: 4,115, Visits: 4,185 |
| | You are going to have to use the EnvDTE name space, you will then wan to get a DTE object and once you have that, you will be able to get the ActiveSolution, and enumerate the Projects with the solution: You will want to create a class and implement the IDTExtensibility2 implemention on your class. This will require that a method called OnConnection be created. This method has a parameter called Application which can be typed as a DTE or DTE2 object, and this will be your entry point: Imports EnvDTE Imports EnvDTE80 Public Class MyAddIn Implements IDTExtensibility2 Private _DTE As DTE2 Public Sub OnConnection(ByVal application As Object, ByVal connectMode As ext_ConnectMode, ByVal addInInst As Object, ByRef custom As Array) Implements IDTExtensibility2.OnConnection _DTE = CTYpe(application, DTE2) End Sub End Class You can also create a wizard class that implements the IWizard interface which will give you a similar starting point and you can tie into template that shows up under (New Item). This will allow you to provide additional functionality when creating a new item. This class has a RunStarted method on that implemention and the automationObject is the DTE object in this case. Once you have the DTE object, you can then get the active solution and project items: For Each proj As EnvDTE.Project In _DTE.Solution.Projects '-- You can access the project and pretty much everything associated with that project For each item as ProjectItem in proj.ProjectItems Next Next |
| | | | 
StrataFrame User
       
Group: StrataFrame Users Last Login: 07/03/2008 3:22:13 PM Posts: 329, Visits: 1,991 |
| Hi Trent I got the reference but am still having trouble trying to find objects of a certain type. hopefully the code below makes sense. For whatever reason I am missing something and it is driving me nuts Thanks for your helpPaul Public Sub New(ByVal AppObject As EnvDTE80.DTE2)' This call is required by the Windows Form Designer.InitializeComponent() ' Add any initialization after the InitializeComponent() call._appobject = AppObject End Sub'-- Form Variables Private _appobject As DTE2'-- Build Report List Private Sub BuildReportList() '-- Local Variables Dim loType As TypeDim LoProject As ProjectTry'Check to see if Solution is open, I forget everytime debugging this If Not _appobject.Solution.IsOpen ThenMessageBox.Show( "Please load solution dummy")ElseFor Each LoProject In _appobject.Solution.Projects'-- Here i need to be able find type that are subclassed from dev ex report' For Each item As ProjectItem In LoProject.ProjectItems'- Code below doesnt work but should illustrate what i am trying to doloType = item.GetType '--check the type and see if it is a subclass of a dev ex reportIf loType.IsSubclassOf(GetType(DevExpress.XtraReports.UI.XtraReport)) Then'add it to the list Me.ListView2.Items.Add(loType.FullName, 0)End IfNextNextEnd IfCatch objException As System.ExceptionMessageBox.Show(objException.ToString) End Try This code would work normally but as an add in I guess the solution is in a seperate app domain. For Each loAssembly As Reflection.Assembly In AppDomain.CurrentDomain.GetAssemblies'-- Check the assembly if the name starts with ActionLabor then it is all mineIf loAssembly.FullName.StartsWith("ActionLabor") Then'-- Cycle through all of the types...For Each loType As Type In loAssembly.GetTypes()' only get types that inherite from dev ex reportIf loType.IsSubclassOf(GetType(DevExpress.XtraReports.UI.XtraReport)) Then'---- We found one now do something with itEnd IfNextEnd IfNext |
| | | | 
StrataFrame Developer

Group: StrataFrame Developers Last Login: Yesterday @ 9:47:36 PM Posts: 4,115, Visits: 4,185 |
| That won't work in most cases. You will have to use the ITypeDiscoveryService to search for the object types. Using the IsSubClassOf will work under cetain conditions, but you will miss a lot of classes or types. You can get the ITypeDiscoveryService reference through the GetService method on a provider (IServiceProvider):Dim disc As ITypeDiscoveryService Dim loList As ICollection disc = CType(Provider.GetService(GetType(ITypeDiscoveryService)), ITypeDiscoveryService) loList = disc.GetTypes(MyBaseType, False) For each i as Type in loList Next |
| | | | 
StrataFrame User
       
Group: StrataFrame Users Last Login: 07/03/2008 3:22:13 PM Posts: 329, Visits: 1,991 |
| Thanks alot Trent I'll try that, so much for "It will probably be faster to make a small add in to generate report metadata" Aw well nothing is ever easy is it? Thanks again for the help |
| | | | 
StrataFrame Developer

Group: StrataFrame Developers Last Login: Yesterday @ 9:47:36 PM Posts: 4,115, Visits: 4,185 |
| Aw well nothing is ever easy is it? No...add-ins are a MAJOR commitment. Once you get one going, and have an understanding of the DTE it gets better, but it is a very deep, complex, and painful environment to develop for. But once you get it integrated and helping you out, then it becomes worth the pain  |
| |
|
|