MyGeneration SharpDevelop Project Template

Template for MyGeneration that generates a project file for SharpDevelop, to be placed in the same directory as the generated dOOdads business entities. Also MyGeneration.dOOdads.dll has to be placed in the bin\Release subfolder - i.e. My Documents\SharpDevelop Projects\My Project\bin\Release

Interface Code:

Dim cmbDatabases
Dim lstTables

Sub setup()

 If Not input.Contains("lstTables") Or Not input.Contains("txtPath") Then

  ui.Title = "Generate SharpDevelop Project"
  ui.Width  = 330
  ui.Height = 400

  ' Grab default output path
  Dim sOutputPath
  sOutputPath = ""
  If input.Contains("defaultOutputPath") Then 
   sOutputPath = input.Item("defaultOutputPath")
  End If

  ui.AddLabel "lblPath", "Output file path: ",  "Select the output path."
  ui.AddTextBox "txtPath", sOutputPath, "Select the Output Path."
  ui.AddFilePicker "btnPath", "Select Path", "Select the Output Path.", "txtPath", true

  ' List Databases in a ComboBox
  ui.AddLabel "lblDatabases", "Select a database:", "Select a database in the dropdown below."
  Set cmbDatabases = ui.AddComboBox("cmbDatabase", "Select a database.")

  ' List Tables in a listbox
  ui.AddLabel "lblTables", "Select tables:", "Select tables from the listbox below."
  Set lstTables = ui.AddListBox ("lstTables", "Select tables:")
  lstTables.Height = 150

  ' Attach the onchange event to the cmbDatabases control.
  setupDatabaseDropdown cmbDatabases
  cmbDatabases.AttachEvent "onchange", "cmbDatabases_onchange"
  
  ui.ShowGUI = true
 Else 
  ui.ShowGUI = false
 End if

End Sub

Sub setupDatabaseDropdown(cmbDatabases)
 cmbDatabases.BindData MyMeta.Databases

 If Not MyMeta.DefaultDatabase Is Nothing Then
  cmbDatabases.SelectedValue = MyMeta.DefaultDatabase.Name
  bindTables cmbDatabases.SelectedValue
 End If
End Sub

Sub bindTables(sDatabase)
 Set db = MyMeta.Databases.Item(sDatabase)
 lstTables.BindData(db.Tables)
End Sub

' Event Handler
Sub cmbDatabases_onchange(control)
 Set cmbDatabases = ui.item("cmbDatabase")
 bindTables cmbDatabases.SelectedText
End Sub

Template Code:

<%
'------------------------------------------------------------------------------
' SharpDevelop.vbgen
' Last Updated: 13 May 2004
' Author: Sam Collett
' Creates SharpDevelop project file. Save to same directory as generated business entities
' Place MyGeneration.dOOdads.dll to bin\Release sub folder
'
'------------------------------------------------------------------------------

Dim objTable
Dim objColumn
Dim intLp
Dim bInFirst
Dim tableNames
Dim tableName
Dim buffer

Dim databaseName 
databaseName  = input.Item("cmbDatabase")
Set database = MyMeta.Databases.Item(databaseName)

Set tableNames = input.Item("lstTables")
%>
<Project name="<%=database.Alias%>" standardNamespace="<%=TrimSpaces(database.Alias)%>" description="" newfilesearch="OnLoadAutoInsert" enableviewstate="True" version="1.1" projecttype="VBNET">
 <Contents><%
' Loop through tables in db
For intLp = 0 To tableNames.Count - 1
 tableName = tableNames(intLp)
 Set objTable = database.Tables.Item(tableName)
 If objTable.Name = tableName Then
%>
  <File name=".\<%=objTable.Alias%>.vb" subtype="Code" buildaction="Compile" dependson="" data="" /><%
 End If
Next
%>
  <File name=".\AssemblyInfo.vb" subtype="Code" buildaction="Compile" dependson="" data="" />
 </Contents>
 <References>
  <Reference type="Assembly" refto=".\bin\Release\MyGeneration.dOOdads.dll" localcopy="True" />
 </References>
 <DeploymentInformation target="" script="" strategy="File" />
 <Configuration runwithwarnings="True" name="Release">
  <CodeGeneration includedebuginformation="False" optimize="True" generateoverflowchecks="False" rootnamespace="" mainclass="" target="Library" definesymbols="" generatexmldocumentation="False" win32Icon="" imports="" />
  <VBDOC outputfile="" enablevbdoc="False" filestoparse="" commentprefix="" />
  <Execution consolepause="True" commandlineparameters="" />
  <Output directory=".\bin\Release" assembly="<%=database.Alias%>" executeScript="" executeBeforeBuild="" executeAfterBuild="" />
 </Configuration>
 <Configurations active="Debug">
  <Configuration runwithwarnings="False" name="Debug">
   <CodeGeneration includedebuginformation="True" optimize="True" generateoverflowchecks="True" rootnamespace="" mainclass="" target="Library" definesymbols="" generatexmldocumentation="False" win32Icon="" imports="" />
   <VBDOC outputfile="" enablevbdoc="False" filestoparse="" commentprefix="" />
   <Execution consolepause="True" commandlineparameters="" />
   <Output directory=".\bin\Debug" assembly="<%=database.Alias%>" executeScript="" executeBeforeBuild="" executeAfterBuild="" />
  </Configuration>
  <Configuration runwithwarnings="True" name="Release">
   <CodeGeneration includedebuginformation="False" optimize="True" generateoverflowchecks="False" rootnamespace="" mainclass="" target="Library" definesymbols="" generatexmldocumentation="False" win32Icon="" imports="" />
   <VBDOC outputfile="" enablevbdoc="False" filestoparse="" commentprefix="" />
   <Execution consolepause="True" commandlineparameters="" />
   <Output directory=".\bin\Release" assembly="<%=database.Alias%>" executeScript="" executeBeforeBuild="" executeAfterBuild="" />
  </Configuration>
 </Configurations>
</Project>
<% 
' save project file
SaveOutput database.Alias, "prjx"
' assembly file %>
Imports System
Imports System.Reflection
Imports System.Runtime.InteropServices

' General Information about an assembly is controlled through the following 
' set of attributes. Change these attribute values to modify the information
' associated with an assembly.

' Review the values of the assembly attributes

<Assembly: AssemblyTitle("<%=database.Alias%>")> 
<Assembly: AssemblyDescription("VB.NET Class Library")> 
<Assembly: AssemblyCompany("")> 
<Assembly: AssemblyProduct("")> 
<Assembly: AssemblyCopyright("")> 
<Assembly: AssemblyTrademark("")> 
' Version information for an assembly consists of the following four values:
'
'      Major Version
'      Minor Version 
'      Build Number
'      Revision
'
' You can specify all the values or you can default the Build and Revision Numbers 
' by using the '*' as shown below:

<Assembly: AssemblyVersion("1.0.*")> 
<%
SaveOutput "AssemblyInfo", "vb"
' this function saves the output to disk
Function SaveOutput(filename, ext)
 ' Save the output file for this Table
 Dim filepath
 filepath = input.item("txtPath")
 ' length of file path
 Dim length
 ' position of last  Dim pos
 ' get length from input
 length = Len(filepath)
 ' get position of last  pos = InStrRev(filepath, "\")
 ' if last \ is not at the end of the file path, it needs adding
 If Not pos = length Then
  ' append \ to path
  filepath = filepath & "\"
 End If
 ' filename is generated from table alias, removing invalid filename characters
 filename = filepath & filename & "." & ext
 ' save output to file
 output.save filename, false
 buffer = buffer & output.text
 output.clear
End Function

output.write buffer

 %>

<%

Function TrimSpaces(str)

 Dim tname
 Dim name
 Dim char
 Dim l

 name = ""
 tname = str
 l = Len(tname)

 For j = 1 To l
  char = Mid(tname, j, 1)
  If Not char = " " Then
   name = name & char
  End If
 Next

 TrimSpaces = name
End Function
%>

Comments

Popular posts from this blog

Select box manipulation with jQuery

iTextSharp: Generating a Basic PDF file (ASP.NET/C#)

Popup Window Countdown (JavaScript)