Ok, so the first thing you need is the actual template file that the MyGeneration engine picks up. I've added a basic example below.
You may notice some things, and they're important!
In the file itself are two sections; one for the GUI that is drawn which lets you select which DB elements to use and the other that actually runs the template.
In each section you need to add
references to the DLL's that you will be building your templates in.
You will also need to add the correct
namespaces in.
As we are going to build both the UI and the template engine within the DLL, the contents of the CSGEN file are very minimal.
The body for the template itself does very little work...
- It loads the UI input data
- It creates an instance of the template class
- It overrides the Render method to just call the templates Launch function
And that, as they say, is that.
- Code: Select all
##|TYPE Template
##|UNIQUEID 73823267-1e40-44ba-82e8-150d68f68f9e
##|TITLE My MSSQL Crud Simple $
##|NAMESPACE MyMSSQLCrud.C#
##|SOURCE_TYPE Source
##|OUTPUT_LANGUAGE C#
##|COMMENTS_BEGIN
This template generates simple CRUD stored procs.
##|COMMENTS_END
##|GUI_ENGINE .Net Script
##|GUI_LANGUAGE C#
##|GUI_BEGIN
<%#DEBUG%><%#REFERENCE System.Windows.Forms.dll %>
<%#REFERENCE System.Windows.Forms.dll %>
<%#REFERENCE MyGeneration.MyChanges.dll,Sql Crud Simple.DLL %>
<%#NAMESPACE System, System.Text, System.Collections, Zeus, Zeus.UserInterface, Zeus.DotNetScript, MyGeneration.MyChanges, SQL_Crud_Simple.Interface %>
public class GeneratedGui : DotNetScriptGui
{
protected SqlCrudInterface aInterface;
public GeneratedGui(ZeusGuiContext context) : base(context)
{
if(context.Objects.ContainsKey("DnpUtils"))
{
DnpUtils.ReadInputFromCache(context);
}
aInterface = new SqlCrudInterface(input, MyMeta, DnpUtils, ui);
}
public override void Setup()
{
aInterface.Launch();
}
public void cmbDatabases_onchange(GuiComboBox control)
{
aInterface.cmbDatabases_onchange(control);
}
}
##|GUI_END
##|BODY_MODE Markup
##|BODY_ENGINE .Net Script
##|BODY_LANGUAGE C#
##|BODY_TAG_START <%
##|BODY_TAG_END %>
##|BODY_BEGIN
<%#DEBUG%><%#REFERENCE System.Windows.Forms.dll,MyGeneration.MyChanges.dll,Sql Crud Simple.DLL,System.Drawing.dll,Linq To SQL.dll%><%#NAMESPACE System.Windows.Forms,System.Drawing,System.Collections.Generic,MyGeneration.MyChanges,SQL_Crud_Simple %><%
public class MyBaseTemplate : DotNetScriptTemplate
{
protected MyTemplate aTemplate;
protected SqlCrudScriptSetting ss;
public MyBaseTemplate(ZeusTemplateContext context) : base(context)
{
if (context.Objects.ContainsKey("DnpUtils"))
{
DnpUtils.SaveInputToCache(context);
}
//Set MyMeta options in order to make sure the correct language and data type
//generator are used.
MyMeta.Language = "C#";
MyMeta.DbTarget = "DbType";
ss = new SqlCrudScriptSetting(input, MyMeta.Databases, DnpUtils);
aTemplate =
new MyTemplate(input, MyMeta, DnpUtils, output, ss);
}
public override void Render()
{
aTemplate.Launch();
}
}
##|BODY_END