CodeSmith VB Templates for CSLA 3.6

CodeSmith VB Templates for CSLA 3.6

Old forum URL: forums.lhotka.net/forums/t/6592.aspx


nj609eagle posted on Wednesday, March 11, 2009

I spent some time converting the existing C# templates from CSLAContrib to VB.

The biggest change in these templates is that we are not using LINQ to SQL for our data access nor are we using a DataAccess Layer object.

We place a files called DBConnections on our web servers, but not within the wwwroot folder.  this usually resides on a separate drive than the web site.  We place two entries in our web.config files that  help locate the proper db sonnection strings.  We add a key called  ConnectionString_Config_File which will contain the physical path of the file that contains the connection strings.  The second key is EnvironmentMode .  This allows us to have Development, QA and production sections within our DBConnections file.

Within our own Application Framework classes we have a utility function called GetConnectionString. You will see refrences to this in the dataAccess Templates attached. That function is here:

Public Shared Function GetConnectionString(ByVal databaseName As String) As String

Dim configFile As String
Dim configXmlDocument As New XmlDocument
Dim databaseNode As XmlNode
Dim databaseQuery As New StringBuilder
Dim xPath As String = String.Empty
Dim connectionString As String
Dim configMode As String
Dim mode As EnvironmentMode

configMode = ConfigurationManager.AppSettings("EnvironmentMode")
mode =
CType(configMode, EnvironmentMode) 'An Enum for Pro, QA, Dev

' read config to determine if connection string is encrypted
configFile = ConfigurationManager.AppSettings("ConnectionString_Config_File")
If File.Exists(configFile) Then
         
configXmlDocument.Load(configFile)

         xPath = String.Format("/root/connectionstring[translate(@mode,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')='{0}']/database[translate(@name,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')='{1}']", mode.ToString.ToLower, databaseName.ToLower)

databaseNode = configXmlDocument.SelectSingleNode(xPath)
If databaseNode Is Nothing Then
      
Throw New Exception(String.Format("The connection string could not be found in {0}. Database key = {1}", configFile, databaseName))
Else
      
connectionString = databaseNode.Attributes("value").Value
      
If connectionString = "" Then
            
Throw New Exception("The connection string cannot blank.")
      
End If
End If
Else
            
Throw New FileNotFoundException("The database connection string configuration file could not be found at " & configFile & ".")

End If
Return connectionString
End Function

 

Other changes to the templates include adding the Select, Insert, update, and Delete stored procedures the object will use.  We have several DB's with existing stored procedures so it was key for us to reuse them.  Additionaly these are used to help build the parameter statements for the appropiate command objects.  You'll see then in a include file called InitializeInsertUpdateParams.

I removed all of the Indent() calls.  This was becoming very confusing during the conversion and since CodeSmith takes your physical indents to and uses them, this I found was cleaner.

I also removed the ability to base the object from an XML file.  This was done so that we had a clean template and allowed us to have a little less confusion in the TemplateBase.vb file.

Since most of the TemplateBase file was done using a code converter tool, there are still some elements in C# because they were contained with a string.Format function and enclosed in quotes.  I'm sure some may find these templaetes usefull, others may find them lacking key points for their development.  But I think it's a strong start and easily updated for those that are more comfortable with vb than c#

reagan123 replied on Wednesday, March 11, 2009

Thanks!
I'm going to check these out today.

I appreciate the work on converting these templates.

reagan123 replied on Wednesday, March 11, 2009

Hmm.. I'm fairly new to CodeSmith, but I can't get any of the templates to open without compile errors.  I tried opening  EditableRoot.cst, EditableChild.cst, ReadOnlyChild.cst and they all fail.

I'm currently using CodeSmith 2.6.

Any Ideas?

---------------- Compile started -----------------

(54,0): error BC32035: Attribute specifier is not a complete statement. Use a line continuation to apply the attribute to the following statement.
(57,0): error BC30035: Syntax error.
(58,0): error BC30689: Statement cannot appear outside of a method body.
(59,0): error BC30630: 'End Get' must be preceded by a matching 'Get'.
(60,0): error BC30035: Syntax error.
(61,0): error BC30689: Statement cannot appear outside of a method body.
(62,0): error BC30188: Declaration expected.
(63,0): error BC30087: 'End If' must be preceded by a matching 'If'.
(64,0): error BC30188: Declaration expected.
(65,0): error BC30632: 'End Set' must be preceded by a matching 'Set'.
(66,0): error BC30431: 'End Property' must be preceded by a matching 'Property'.
(70,0): error BC32035: Attribute specifier is not a complete statement. Use a line continuation to apply the attribute to the following statement.
(73,0): error BC30035: Syntax error.
(74,0): error BC30689: Statement cannot appear outside of a method body.
(75,0): error BC30630: 'End Get' must be preceded by a matching 'Get'.
(76,0): error BC30035: Syntax error.
(77,0): error BC30689: Statement cannot appear outside of a method body.
(78,0): error BC30188: Declaration expected.
(79,0): error BC30087: 'End If' must be preceded by a matching 'If'.
(80,0): error BC30188: Declaration expected.
(81,0): error BC30632: 'End Set' must be preceded by a matching 'Set'.
(82,0): error BC30431: 'End Property' must be preceded by a matching 'Property'.
(86,0): error BC32035: Attribute specifier is not a complete statement. Use a line continuation to apply the attribute to the following statement.
(89,0): error BC30035: Syntax error.
(90,0): error BC30689: Statement cannot appear outside of a method body.
(91,0): error BC30630: 'End Get' must be preceded by a matching 'Get'.
(92,0): error BC30035: Syntax error.
(93,0): error BC30689: Statement cannot appear outside of a method body.
(94,0): error BC30188: Declaration expected.
(95,0): error BC30087: 'End If' must be preceded by a matching 'If'.
(96,0): error BC30188: Declaration expected.
(97,0): error BC30632: 'End Set' must be preceded by a matching 'Set'.
(98,0): error BC30431: 'End Property' must be preceded by a matching 'Property'.
(106,0): error BC32035: Attribute specifier is not a complete statement. Use a line continuation to apply the attribute to the following statement.
(108,0): error BC30035: Syntax error.
(109,0): error BC30689: Statement cannot appear outside of a method body.
(110,0): error BC30630: 'End Get' must be preceded by a matching 'Get'.
(111,0): error BC30035: Syntax error.
(112,0): error BC30188: Declaration expected.
(113,0): error BC30632: 'End Set' must be preceded by a matching 'Set'.
(114,0): error BC30431: 'End Property' must be preceded by a matching 'Property'.
(117,0): error BC32035: Attribute specifier is not a complete statement. Use a line continuation to apply the attribute to the following statement.
(119,0): error BC30035: Syntax error.
(120,0): error BC30689: Statement cannot appear outside of a method body.
(121,0): error BC30630: 'End Get' must be preceded by a matching 'Get'.
(122,0): error BC30035: Syntax error.
(123,0): error BC30188: Declaration expected.
(124,0): error BC30632: 'End Set' must be preceded by a matching 'Set'.
(125,0): error BC30431: 'End Property' must be preceded by a matching 'Property'.
(130,0): error BC32035: Attribute specifier is not a complete statement. Use a line continuation to apply the attribute to the following statement.
(132,0): error BC30035: Syntax error.
(133,0): error BC30689: Statement cannot appear outside of a method body.
(134,0): error BC30630: 'End Get' must be preceded by a matching 'Get'.
(135,0): error BC30035: Syntax error.
(136,0): error BC30188: Declaration expected.
(137,0): error BC30632: 'End Set' must be preceded by a matching 'Set'.
(138,0): error BC30431: 'End Property' must be preceded by a matching 'Property'.
(150,0): error BC32035: Attribute specifier is not a complete statement. Use a line continuation to apply the attribute to the following statement.
(152,0): error BC30035: Syntax error.
(153,0): error BC30689: Statement cannot appear outside of a method body.
(154,0): error BC30630: 'End Get' must be preceded by a matching 'Get'.
(155,0): error BC30035: Syntax error.
(156,0): error BC30188: Declaration expected.
(157,0): error BC30632: 'End Set' must be preceded by a matching 'Set'.
(158,0): error BC30431: 'End Property' must be preceded by a matching 'Property'.
(161,0): error BC32035: Attribute specifier is not a complete statement. Use a line continuation to apply the attribute to the following statement.
(163,0): error BC30035: Syntax error.
(164,0): error BC30689: Statement cannot appear outside of a method body.
(165,0): error BC30630: 'End Get' must be preceded by a matching 'Get'.
(166,0): error BC30035: Syntax error.
(167,0): error BC30188: Declaration expected.
(168,0): error BC30632: 'End Set' must be preceded by a matching 'Set'.
(169,0): error BC30431: 'End Property' must be preceded by a matching 'Property'.
(172,0): error BC32035: Attribute specifier is not a complete statement. Use a line continuation to apply the attribute to the following statement.
(174,0): error BC30035: Syntax error.
(175,0): error BC30689: Statement cannot appear outside of a method body.
(176,0): error BC30630: 'End Get' must be preceded by a matching 'Get'.
(177,0): error BC30035: Syntax error.
(178,0): error BC30188: Declaration expected.
(179,0): error BC30632: 'End Set' must be preceded by a matching 'Set'.
(180,0): error BC30431: 'End Property' must be preceded by a matching 'Property'.
(183,0): error BC32035: Attribute specifier is not a complete statement. Use a line continuation to apply the attribute to the following statement.
(185,0): error BC30035: Syntax error.
(186,0): error BC30689: Statement cannot appear outside of a method body.
(187,0): error BC30630: 'End Get' must be preceded by a matching 'Get'.
(188,0): error BC30035: Syntax error.
(189,0): error BC30188: Declaration expected.
(190,0): error BC30632: 'End Set' must be preceded by a matching 'Set'.
(191,0): error BC30431: 'End Property' must be preceded by a matching 'Property'.
(200,0): error BC32035: Attribute specifier is not a complete statement. Use a line continuation to apply the attribute to the following statement.
(202,0): error BC30035: Syntax error.
(203,0): error BC30689: Statement cannot appear outside of a method body.
(204,0): error BC30630: 'End Get' must be preceded by a matching 'Get'.
(205,0): error BC30035: Syntax error.
(206,0): error BC30188: Declaration expected.
(207,0): error BC30632: 'End Set' must be preceded by a matching 'Set'.
(208,0): error BC30431: 'End Property' must be preceded by a matching 'Property'.
(211,0): error BC32035: Attribute specifier is not a complete statement. Use a line continuation to apply the attribute to the following statement.
(213,0): error BC30035: Syntax error.
(214,0): error BC30689: Statement cannot appear outside of a method body.
(215,0): error BC30630: 'End Get' must be preceded by a matching 'Get'.
(0,0): error BC30041: Maximum number of errors has been exceeded.

Build complete -- 102 errors, 0 warnings

---------------------- Done ----------------------

Build failed

nj609eagle replied on Wednesday, March 11, 2009

An additional modification I made was to change teh attributes on the properties within the TemplateBase.vb file.  I'm using CodeSmith 4 so there attribute tages were depreciated.  It was bothering me to see these warnings when other errors were causing the compile to fail.

Change the attributes on the properties back to the 2.6 format:

<CodeTemplateProperty(CodeTemplatePropertyOption.Required), Category("3. Options"), Description("What type of Transaction should this Business Object use?")> _

 

reagan123 replied on Wednesday, March 11, 2009

Thanks... I'll give it a shot.  I appreciate the response.

Copyright (c) Marimer LLC