By Paul Chase - 4/11/2008
I wrote this add-in to save myself some time while working on a project I am doing that has lots of lookup tables and views. It took me a bit longer that I thought but it was interesting.I think it's a useful utility and add-in example to share with all of you. Hope it helpsI put this together LATE last night and finshed tonight so beware there might be a mosquito just waiting to sting. I added a few screenshots, a zip with the source andv a zip containing the addin and the .dll you can just unzip to your C:\Documents and Settings\[username]\My Documents\Visual Studio 2008\Addins or wherever you addins directory is. Gotta go Enjoy Paul Currently to set up a bo 1.Add each business object(s) to VisualStudio--- for 10 Bo's do this step 10 times 2.Launch the business object mapper 3.Configure the project 4.Configure the each Business Object--- for 10 Bo's do this step 10 times 5. Build the partial class(s). You would select the table and views you wich to create With Add In 1. Launch BoGenerator 2.Configure project (Same as step 3 above) 3.Select multiple Table(s) and View(s) from list. 4.Generate Business Object --- for 10 bo's it add's all 10 bo's to project and also configures the business object 5.Auto Launches the bo mapper then Build Partial Classes (Same as step 5)
|
By Trent L. Taylor - 4/12/2008
I will have to take a look, Paul. Thanks for the contribution!
|
By Edhy Rijo - 5/6/2008
Hi Paul,Thanks a lot for this contribution, this is a major tool specially for new SF developers. Trent L. Taylor (04/12/2008) I will have to take a look, Paul. Thanks for the contribution!Trent, have you look at this yet? I see a lot of benefits in adding this kind of automation to SF.
|
By Alex Luyando - 12/11/2008
Paul -
Awesome... Was just discussing yesterday how semi-tedious it can be to build multiple business objects, and how an add-in could save the day. Wish I had seen this posting about eight business objects ago!! LOL
Thanks a bunch!
|
By Alex Luyando - 12/11/2008
Ugh.... what a tease! LOL
Add-in installed and fires up nicely. Select the tables I want BOs for then click Generate Business Objects, hear a bong and see a Wait Window flash in upper right (too fast to even see text) and get the problem asking if I want to run the BOM. Looking at the solution and the BOM none of the business objects were built.
Any ideas?
Thanks.
|
By Paul Chase - 12/11/2008
Hi Alex,It has been awhile since I made the add-in I mainly made it for a project that had a lot of existing lookup tables and such. I think what is happening to you is you don't have a project selected in the solution, when the addin goes to create the business object it creates it in the project that is selected in soultion explorer. I had a look at the code and that is probably the problem.I checked for the possibility that the project wasnt selected but did not show the error and exit the sub like a I should have. To verify make sure you have the project you want to create the business objects in selected in solution explorer prior to generating business objects and it should work ok. I will fix the code and repost it if I get a chance later today or you can make the change it is in the following method. Private Sub CreateAndAddBusinessObjects() Paul
|
By Paul Chase - 12/11/2008
Actually here is the Corrected Code, figured might as well do it while i had it openPrivate Sub CreateAndAddBusinessObjects()'VariablesDim LcTableName, Lcfilename As StringIf Me.ListView_Views.CheckedItems.Count + Me.ListView1.CheckedItems.Count = 0 Then'nothing selectedExit SubEnd If'Make sure we have a project TryIf Not _Project Is Nothing Then' I could probably make this a bit more dynamic but it works For Each loitem As ListViewItem In Me.ListView1.CheckedItemsLcTableName = loitem.Text Me.SqlTableSchema.NavigateToPrimaryKey(LcTableName)Lcfilename = Me.TxtPreFix.Text & LcTableName & TxtSuffix.Text & ".vb"If GenerateBusinessObject(Lcfilename) ThenMe.WaitWindow1.ShowWaitWindow("Adding Table " & Lcfilename)CreateDTE_ProjectItems(SqlTableSchema) ElseMe.WaitWindow1.ShowWaitWindow("Failed to Add " & Lcfilename)End IfMe.WaitWindow1.HideWaitWindow()NextFor Each loitem As ListViewItem In Me.ListView_Views.CheckedItemsLcTableName = loitem.Text Lcfilename = Me.TxtPreFix.Text & LcTableName & TxtSuffix.Text & ".vb"Me.SqlViewSchema.NavigateToPrimaryKey(LcTableName)If GenerateBusinessObject(Me.TxtPreFix.Text & LcTableName & TxtSuffix.Text & ".vb") ThenMe.WaitWindow1.ShowWaitWindow("Adding View " & Lcfilename)CreateDTE_ProjectItems(SqlViewSchema) ElseEnd IfMe.WaitWindow1.HideWaitWindow()NextElse'Warn UserMessageBox.Show( "You must Select a Project in the Solution Explorer!!", "", MessageBoxButtons.OK, MessageBoxIcon.Error)'Make sure wait window is hiddenMe.WaitWindow1.HideWaitWindow()'get outta hereExit SubEnd IfIf MessageBox.Show("All Business Objects have been created " & vbCrLf & vbCrLf & "Would you like to run the business object mapper now?", "Business Object Generator", MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1) = System.Windows.Forms.DialogResult.Yes ThenMe.ShowBOMapper()End IfMe.Close()Catch ex As ExceptionFinallyMe.WaitWindow1.HideWaitWindow()End TryEnd Sub
|
By Alex Luyando - 12/11/2008
Hi Paul -
Thanks for the updated code. I rebuilt the Add-in but am getting the same error.
I started debugging the Add-in and I think the issue is inside GenerateBusinessObject(). An exception is being thrown by the loProjectItem = _Project.DTE.ItemOperations.AddNewItem("Common Items\SF Business Object", FileName) line. The exception message is:
Template 'Common Items\SF Business Object' is not valid for the selected project.
I am relatively new to .Net, so I'm not exactly sure where to go with this. I should, however, disclose the following though, just in case it's germane to this issue.
1.) My project is a C#.
2.) Due to the above I assumed (am I correct) that I needed to change the ".vb"s to ".cs"s in the Add-in. I did this before you provided the updated code, and again afterward.
3.) I do have a custom template (subclass of the StrataFrame business object class) that I am using for my business objects. I tried replacing the "Common Items\SF Business Object" reference with a fully-qualified path to my customized business object template, but that didn't work either.
Any help you can provide is much appreciated. I can see this Add-in being useful when dealing with new databases and projects where there are tons of tables and views to hit against.
Thanks!
|
By Paul Chase - 12/11/2008
Hi Alex,Here is a screenshot of the template that I am referencing in the line of code you mentioned, maybe it is named something different is C# ?
|
By Alex Luyando - 12/12/2008
Paul -
Good Morning!
Thanks... that was the clue I needed. I've got it working, after making a few additional adjustments to deal with VB v. C# differences (e.g., change to Inheritance).
Really appreciate your efforts in creating this BOB and in helping me get it operational in our environment. This baby will get some real use here, I anticipate.
Have a great weekend.
________________
_____/ Regards,
____/ al
|
By Paul Chase - 12/12/2008
Morning Alex,Godd to hear that you got it working ok I am glad that it might help you out. Have a good one Paul
|
By Alex Luyando - 12/15/2008
Hi all -
Thought I'd post the modified version of GenerateBusinessObject() which I am using for C# projects, so that anyone who may be able to benefit from this great Add-in can do so.
Hope this helps, and thanks again, Paul!
________________
_____/ Regards,
____/ al
Private Function GenerateBusinessObject(ByVal FileName As String) As Boolean
'-- Variables
Dim loStartEditPoint As EditPoint
Dim loEndEditPoint As EditPoint
Dim loTextDocument As TextDocument
Dim lodocument As Document
Dim loProjectItem As ProjectItem
'-- Make Sure We ar on the Correct Project
GotoProject(_Project.Name)
' Check to see if file exists
'---
If System.IO.File.Exists(_Project.FullName.Substring(0, _Project.FullName.LastIndexOf("\"c)) & "\" & FileName) Then
If ChkOverwrite.Checked Then
System.IO.File.Delete(_Project.FullName.Substring(0, _Project.FullName.LastIndexOf("\"c)) & "\" & FileName)
Else
Return False
End If
End If
'-
Try
loProjectItem = _Project.DTE.ItemOperations.AddNewItem("Visual C# Items\SF Business Object", FileName)
'// 12-11-2008 AEL: loProjectItem = _Project.DTE.ItemOperations.AddNewItem("Common Items\SF Business Object", FileName)
'Get Ref to New bus obj
lodocument = _Project.DTE.ActiveDocument
loTextDocument = DirectCast(lodocument.Object, TextDocument)
' Create edit point
loStartEditPoint = loTextdocument.CreateEditPoint()
'// [START] -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= AEL Mod. 12-12-2008 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= [START]
'//
'loStartEditPoint.MoveToLineAndOffset(7, 5)
'' Create edit point at the end of Document
'loEndEditPoint = loStartEditPoint.CreateEditPoint
'loEndEditPoint.EndOfLine()
'Delete Original Line and replace with the Inherits Statement on Text Box
'// 12-12-2008 AEL: loStartEditPoint.Delete(loEndEditPoint)
'// 12-12-2008 AEL: loStartEditPoint.Insert("Inherits " & Me.txtinherits.Text)
loStartEditPoint.MoveToLineAndOffset(13, 1) ' Start of partial class declaration for the new BO
If loStartEditPoint.FindPattern(":") = False Then
MsgBox("Error: Did not find ':' in partial class declaration! Could not change inheritance to custom BO class!!")
Return False
Else
'' Create edit point at the end of Document
loEndEditPoint = loStartEditPoint.CreateEditPoint
loEndEditPoint.EndOfLine()
'Delete Original Line and replace with the Inherits Statement on Text Box
loStartEditPoint.Delete(loEndEditPoint)
loStartEditPoint.Insert(": " & Me.txtinherits.Text)
End If
'//
'// [END] -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= AEL Mod. 12-12-2008 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= [END]
'Close The Document
lodocument.Close(vsSaveChanges.vsSaveChangesYes)
Return True
Catch ex As Exception
MessageBox.Show("Exception Thrown: " & ex.Message)
Return False
End Try
End Function
|
By Larry McIntosh - 12/15/2008
The BO Generator suddenly stopped working for me and eventually I tracked it down to DevExpress. I had installed an Evaluation copy after using the BO Generator successfully and it then would only create the first GO and gave an error for all the rest (Template not valid for project).A "Solution Items" folder was being created automatically when the BO Generator ran and it seemed to select this new folder somehow after the first BO was created and failed for every subsequent BO. I couldn't figure out how to stop the creation of the "Solution Items" folder so I un-installed DevExpress. Projects created when DevExpress was installed would still not work (kept creating the "Solution Items" folder). But if I re-created the project (without DevExpress installed), the BO Generator worked perfectly and the "Solution Items" folder did not appear. I'm a newbie to .Net so someone may know how to stop the creation of the "Solution Items" folder but I couldn't.
|
By Paul Chase - 12/16/2008
Hi Larry,That sounds strange I have and use Dev-Express and have not run into any issues like the one you describe. What version of Dev-Express are you using? Is it an Evaluation version ? Where is "Solution Items" folder you are talking about being created? is it in the project iself or what?
|
By Larry McIntosh - 12/16/2008
Yes, it was an Evaluation version of DevExpress and I have no idea what the Solution Items folder is used for. The Solution Items folder is a virtual folder that appeared directly under the Solution Title node at the top of the solution explorer when the BO Generator was running. I found references to it in the DevExpress forum about problems it was causing when converting VS2005 to VS2008. It also seemed to disappear when the solution was closed and re-opened. I assume that the BO Generator is linked to the project by PK and since the Solution Items folder was created about the real project, it got the project PK previously assigned to the real project.
|