The growing pain of my first template

Anything that doesn't fall into the defect or enhancement categories

The growing pain of my first template

Postby Q Johnson on Tue Mar 28, 2006 4:48 pm

New and confused.

I can't find any examples of VB.NET UI scripts, so I'm using a VBScript one that seems to be working fine (thanks to whoever built the one I carved up <g>)

But I want to use a VB.NET Source template. It doesn't seem as if this should be a problem from what I can see. I _CAN_ mix and match these source languages, right?

OK... assuming I get a 'yes' to that, here's my first problem:
The UI runs fine, I click OK and am greeted by this:
------------------------------------------------------------------------
Exception Type:NullReferenceException
Source:DotNetScriptingEngine
Method: Void EngineExecuteCode(Zeus.IZeusCodeSegment, Zeus.IZeusContext)
Line 0 Column 0
Message:Object reference not set to an instance of an object.
-------------------------------------------------------------------------

If it was just on SOME actual line of code, I'd have a prayer of understanding what I've done to offend. But I just don't have a clue. This looked just fine in VS2003 (although, of course, I can't RUN it there).

FYI, the Output window has an amazingly brief amount of text considering how far it seems to have run. It only shows about seven lines of output and they are, of course, those which require no MyMeta content.

Here's the first 15 or so lines of code in case that helps.
------- Begin Code ---------------
Public Class GeneratedTemplate
Inherits DotNetScriptTemplate

Public Sub New(ByVal context As ZeusContext)
MyBase.New(context)
End Sub

'---------------------------------------------------
' Render() is where you want to write your logic
'---------------------------------------------------
Public Overrides Sub Render()
'
Dim oDB As IDatabase = MyMeta.Databases(Input.Item(\"cmbDatabase\"))
Dim oTable As ITable = oDB.Tables(Input.Item(\"lstTables\"))
'
' Now begin calling section writers
' Be consistent here; pass ITable to all of them, not a string

' Call Write ClassLevelInfo
Call ClassLevelInfo(oTable)

' Call Write MemVar Declarations
Call MemVarDeclarations(oTable)
----------------- End Code -----------------------------

the ClassLevelInfo routine looks like:
----------------- Begin Code -----------------------------
Private Sub ClassLevelInfo(ByVal poTable As ITable)

Dim strClassName As String = poTable.Alias
With output
.autoTabLn(\"<Serializable()> _\")
.autoTabLn(\"Public Class \" & strClassName & \"Base\")
.incTab()
.autoTabLn(\"Inherits BusinessBase\")
.autoTabLn(\"\")
End With
'
' [Note: the \"End Class\" is written by caller]
'
End Sub
----------------- End Code -----------------------------


There is NO '<%' at the top of the file. That seems correct to me for a VB.Net Template. My template properties include:
Type: Template
Mode: Pure
Template Scripting Engine: .Net Script
Template Language: VB.Net
Gui Scripting Engine: Microsoft Script
Gui Language: VBScript
Output Language: VB.Net

Thanks in advance,

Q Johnson[code][/code]
Q Johnson
Lurker
 
Posts: 8
Joined: Tue Mar 28, 2006 4:04 pm
Location: Austin. Texas

Postby mike.griffin on Tue Mar 28, 2006 5:05 pm

Look in the Tutorials section, there are VB.NET templates there. If you're stuck send your template to support@mygenerationsoftware.com and will get it running for you.
User avatar
mike.griffin
Site Admin
 
Posts: 3290
Joined: Sat Apr 03, 2004 6:10 am
Location: Indianapolis, IN

The growing pain of my first template

Postby Q Johnson on Tue Mar 28, 2006 5:29 pm

Thanks very much for the offer. I've already dispatched the mail to you.

Your quote is quite good; here's a favorite of mine:

\"A foolish consistency is the hobgoblin of little minds.\"
Ralph Waldo Emerson - \"Self-Reliance\"

Q
Q Johnson
Lurker
 
Posts: 8
Joined: Tue Mar 28, 2006 4:04 pm
Location: Austin. Texas

Include files

Postby Q Johnson on Sat Apr 08, 2006 4:00 pm

The Tips and Tricks topic says I can use:

<%#FILE filename.cs %>

syntax in a vb.net template. But I get a scripting error exception when I try to use this that complains \"Character is not valid\".

I've used scripting VERY little and am probably doing something stupid. I just tried to put the following line at the top of the template:

<%#FILE MyGenSupport.vb %>

FYI - I'm looking for a way to put templates in separate files with their own routines for generating sections of code. Then a new template could simply call for the code from a number of files (namespaces) in order to generate a particular section of code. So it would only take, say, ten lines of code or so to generate seven whole SECTIONS of code in a new template. For example:

---- in Render() -----
Dim oERO as new EditableRootObjectTemplate(context)
Dim oECC as new EditableChildCollectionTemplate(context)
Dim oTable As ITable = oDB.Tables(Input.Item(\"lstTables\")(0))

Call oERO.ClassLevelInfo(oTable)
Call oERO.MemvarDeclarations(oTable)
Call oECC.PropsMethods(oTable)
Call oECC.ValidationRules(oTable)
Call oECC.Constructors(oTable)
Call oECC.FactorySharedMethods(oTable)
Call oECC.DataAccess(oTable)

This would make my template creation in VS2K3 much easier.
Thanks in advance.

Q Johnson
Q Johnson
Lurker
 
Posts: 8
Joined: Tue Mar 28, 2006 4:04 pm
Location: Austin. Texas

Postby mike.griffin on Thu Apr 13, 2006 12:50 am

Here's an example:

Code: Select all
<%
Public Class GeneratedTemplate
         Inherits DotNetScriptTemplate

   Public Sub New(context As ZeusContext)
      MyBase.New(context)
   End Sub

   '---------------------------------------------------
   ' Render() is where you want to write your logic   
   '---------------------------------------------------
   Public Overrides Sub Render

      output.writeLn (\"Hello world.\")
      
      Render1()
      
   End Sub
   
   %><%#FILE c:\\\\file.vb %><%

End Class
%>

The seperate file:
Code: Select all
Public Sub Render1
    output.writeLn (\"It worked.\")
End Sub

The output
Hello world.
It worked.
User avatar
mike.griffin
Site Admin
 
Posts: 3290
Joined: Sat Apr 03, 2004 6:10 am
Location: Indianapolis, IN

The growing pain of my first template

Postby Q Johnson on Thu Apr 13, 2006 1:10 am

The code is C#, but I'll assume that doesn't matter.

However, I notice that the C# file BEGINS WITH one of those \"scripty\" characters.

My VB template is Pure mode. Am I going to be able to include this line in it:

%><%#FILE c:\\\\file.vb %><%

???

Would switching to MarkUp mode make it possible? Are there any consequences of such a switch that I should know about? What is that Mode stuff about anyway?

TIA,

Q
Q Johnson
Lurker
 
Posts: 8
Joined: Tue Mar 28, 2006 4:04 pm
Location: Austin. Texas

Postby RoryBecker on Fri Aug 03, 2007 12:23 pm

I have a similar issue to Mr Johnson

\"Character is not valid.\"

The file that I wish to include (and I might add *is* being included) contains scripty symbols.

My includable file is:
Code: Select all
Public Sub Render1
    Call X()
End Sub
<%If SomeFunction(Columns) Then
%>
    Public Sub X()
        ' Do Thing1
    End Sub
<% Else %>
    Public Sub X()
        ' Do Thing2
    End Sub
<%End If
%>
Function SomeFunction() As Boolean
   Return True
End Function


This is a really simple example. I have a lot of this.

I am including it with the FILE tag thus
Code: Select all
<%#FILE C:\\\\Integration\\\\Generation\\\\GeneralDataAccess.vb %>


and yet the \"Character is not valid.\" error persists highlighting the line
Code: Select all
<%If SomeFunction(Columns) Then


What can I do to get the desired result?
Rory Becker

Find my Blog at http://rorybecker.blogspot.com/
Find my DXCore Plugins at http://www.rorybecker.co.uk/
RoryBecker
Lurker
 
Posts: 6
Joined: Thu May 18, 2006 9:39 pm

Postby justin.greenwood on Fri Aug 03, 2007 1:51 pm

First, take a look at the \"Template Source\" tab. It basically shows the final version of the code before it is compiled. You will probably see the problem there. If you would like, you could send me a zip with your files and I will give you a solution.
User avatar
justin.greenwood
Site Admin
 
Posts: 441
Joined: Sat Apr 03, 2004 6:10 am
Location: Indianapolis, IN

Postby RoryBecker on Fri Aug 03, 2007 2:29 pm

Ok..

Something about the phrase
\"Template Source\" tab
triggered something in my head.

Now that I look at the aforementioned tab, I see that there are <% and %> all over it. It looks like the included file was included after the processing of such symbols and therefore the system is trying to compile the generated template output together with my raw include file.

I was hoping that my include file would be copied wholesale prior to any processing.

This would seem not to be the case.

I have been reading around and it seems that I need to look to subtemplates as a way to do this.

FWIW.... my current \"Working Code\" is like this
Code: Select all
Public Class GeneratedTemplate
   Inherits DotNetScriptTemplate

   Public Sub New( context As ZeusContext )
      MyBase.New(context)
   End Sub

   Public Overrides Sub Render
      MyMeta.Language = \"VB.NET\"
      MyMeta.DbTarget  = \"SqlClient\"
      'call Render1
      'call Render2
   End Sub
   Private Sub Render1()
      Dim GeneralDB as New GeneralDB(MyMeta, MyMeta.Databases(\"Database1\"), Output)
      GeneralDB.ExportPath = \"C:\\Integration\\Database1\\GeneratedCode\\DataAccess\"
      GeneralDB.SomeProperty = \"SomeValueA\"
      GeneralDB.SomeProperty2 = \"SomeValueB\"
      Call GeneralDB.GenerateTable(Database.Tables(\"MyTable1\"))
      Call GeneralDB.GenerateView(Database.Views(\"SomeView1\"))
      Call GeneralDB.GenerateView(Database.Views(\"SomeView2\"))
   End Sub
   Private Sub Render2()
      Dim GeneralDB as New GeneralDB(MyMeta, MyMeta.Databases(\"Database2\"), Output)
      GeneralDB.ExportPath = \"C:\\Integration\\Database2\\GeneratedCode\\DataAccess\"
      GeneralDB.SomeProperty = \"SomeValueC\"
      GeneralDB.SomeProperty2 = \"SomeValueD\"
      Call GeneralDB.GenerateAllTableClasses()
      Call GeneralDB.GenerateAllViewClasses()
   End Sub
   
End Class
Public Class GeneralDB
   Public SomeProperty as String
   Public SomeProperty2 as String
   Public ExportPath As String
   Private mDatabase As IDatabase
   Private mMyMeta as MyMeta.dbRoot
   Private mOutput as IZeusOutput
   
   Public Sub New(MyMeta as MyMeta.dbroot, Database as IDatabase, OutPut as IZeusOutput)
      mMyMeta = MyMeta
      mOutput = Output
      mDatabase = Database
   End Sub
   
   Public Sub GenerateAllTableFiles()
      For Each Table as ITable in mDatabase.Tables
         Call GenerateTable(Table)
      Next
   End sub
   
   Public Sub GenerateAllViewFiles()
      For Each Table as ITable in mDatabase.Tables
         Call GenerateTable(Table)
      Next
   End sub
   
   Public sub GenerateTable(Table as ITable)%>   
   ' Table '<%= Table.Name %>' stuff here.
   Public Readonly Property GetTable<%= Table.Name %>Name() as String
      Get
         Return \"<%= Table.Name %>\"
      End Get
   End Property
   <%   
   End Sub    
   
   Public Sub GenerateView(View as IView)%>
   ' View '<%= View.Name %>' stuff here.
   Public Readonly Property GetTable<%= View.Name %>Name() as String
      Get
         Return \"<%= View.Name %>\"
      End Get
   End Property
   <%   
   End Sub
End Class

Now note my Render procedure. there are 2 commented out lines designed to call 2 different sets of code for 2 different databases.

what I would like do is to remove the \"GeneralDB\" class from this template into some other file (Perhaps \"TemplateCommon.vb\").

Then I could duplicate the remaining code and Call render1 from one template and call render2 from the other.

2 templates used for different databases triggered at different times but which share some common code.

The trouble is that the common code contains <% and %>.


I have been looking as I say at the SubTemplate stuff but it seems that I couldn't call a specific method on a subtemplate.

Please note that changing <% and %> to output.Writeline statements would be a very long job and from my point of view would make the commoncode very hard to maintain.

Hopefully I have now outlined the problem properly.

Any ideas.... questions... feel free to ask away.

Thanks in advance.
Rory Becker

Find my Blog at http://rorybecker.blogspot.com/
Find my DXCore Plugins at http://www.rorybecker.co.uk/
RoryBecker
Lurker
 
Posts: 6
Joined: Thu May 18, 2006 9:39 pm

Postby RoryBecker on Fri Aug 03, 2007 2:32 pm

Appologies... I think I hit a maximum message length with that last post.

Here is the rather small conclusion to said post...
-------------------------------------------------------------
The trouble is that the common code contains <% and %>.


I have been looking as I say at the SubTemplate stuff but it seems that I couldn't call a specific method on a subtemplate.

Please note that changing <% and %> to output.Writeline statements would be a very long job and from my point of view would make the commoncode very hard to maintain.

Hopefully I have now outlined the problem properly.

Any ideas.... questions... feel free to ask away.

Thanks in advance.
Rory Becker

Find my Blog at http://rorybecker.blogspot.com/
Find my DXCore Plugins at http://www.rorybecker.co.uk/
RoryBecker
Lurker
 
Posts: 6
Joined: Thu May 18, 2006 9:39 pm

Postby RoryBecker on Mon Aug 06, 2007 8:14 pm

No News here?
Rory Becker

Find my Blog at http://rorybecker.blogspot.com/
Find my DXCore Plugins at http://www.rorybecker.co.uk/
RoryBecker
Lurker
 
Posts: 6
Joined: Thu May 18, 2006 9:39 pm

Postby justin.greenwood on Thu Aug 09, 2007 6:00 pm

well, there are ways to do what you need to do. Subtemplates are good, but you need to pass something in the context to tell the subtemplate what to do - in your case, which method to call. the context object holds the input hash; and it gets passed into any subtemplates. So basically, set context.input[\"methodToCall\"] = \"runx\"; or something like that - I don't have the exact syntax at the moment. In the subtemplate, you can check for than value and act accordingly. The template include feature (parsing the <% %>) is not included in the DotNetScript template engine yet. It could easily be added though in a future build. Put a feature request on the sourceforge page and we'll get to it.
User avatar
justin.greenwood
Site Admin
 
Posts: 441
Joined: Sat Apr 03, 2004 6:10 am
Location: Indianapolis, IN


Return to General Questions or Comments

Who is online

Users browsing this forum: No registered users and 0 guests

cron