MyGeneration SharpDevelop Project Template (C# version)
C# version of my previous template for MyGeneration. Save in the same directory as generated C# dOOdads entities. Set namespace to same one that was used to generate the dOOdads 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 C# SharpDevelop Project"
ui.Width = 330
ui.Height = 450
' 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
ui.AddLabel "lblNamespace", "Namespace: ", "Provide your objects namespace."
ui.AddTextBox "txtNamespace", "Your.Namespace", "Provide your objects namespace."
' 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:
<%
'------------------------------------------------------------------------------
' SharpDevelopC#.vbgen
' Last Updated: 2 June 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 namespace
Dim buffer
' Grab the namespace
namespace = input.Item("txtNamespace")
Dim databaseName
databaseName = input.Item("cmbDatabase")
Set database = MyMeta.Databases.Item(databaseName)
Set tableNames = input.Item("lstTables")
%>
<Project name="<%=database.Alias%>" standardNamespace="<%=namespace%>" description="" newfilesearch="None" enableviewstate="True" version="1.1" projecttype="C#">
<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%>.cs" subtype="Code" buildaction="Compile" dependson="" data="" /><%
End If
Next
%>
<File name=".\AssemblyInfo.cs" 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 %>
using System;
using System.Reflection;
using 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("C# 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", "cs"
' 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