Integrating mojoPortal and .netTiers

Introduction

NOTE: Comments with Colored Background Provided by Rick Hubka

Over many years of programming, I have used various methods to streamline creating web applications. The efforts were geared towards one goal: produce applications in a repeatable and efficient manner. Often, clients wanted to integrate a public facing website with internal web applications. The main purpose was to allow clients to be self-sufficient in maintaining the content of the website but not interfere with the applications.

 

Those thoughts led to researching various open source content management systems and code generation tools. I had written a couple of code generation tools over the years using different architectures and techniques. The obvious benefit was that the code on one project was architected and had been tested on other projects. However, I wanted a solution that would provide more CMS features and integrate robust application architecture.

 

We came across mojoPortal and CodeSmith with the netTiers framework. They are front-runners for addressing these concepts. The only problem is that they do not integrate out-of-the-box. After a few brainstorming sessions, it seemed not only possible, but absolutely essential that we find a solution to integrate these two awesome products.

 

Over the next few days, I will post the results of our integration efforts. This will be aimed at describing the overall process and not meant as a de-facto standard. There will be various implementation strategies that we choose for the sake of “making it work." If you discover better ways to make it work, please share in a constructive manner.

 

With that being said, let’s begin our journey…

Prepare for Integration (Part 1)

 

We will start with a simple example that uses one table in a SQL Database. ACMETools is the name of the database. Acme.Tools is the namespace used when the netTiers code was generated using CodeSmith. I will use the Organization table from the database in the example.

 

NOTE: If you want to debug along with the mojoPortal code, include the netTiers projects associated with the dlls in the mojoPortal solution file.

 

1.Create a database called ACMETools.

2.Create a user named ACMEToolsUser with the password ACMETools.

3.Provide the ACMEToolsUser with dbo permissions to the ACMETools database.

4.Create the Organization table in the ACMETools database.

 

CREATE TABLE [dbo].[Organization](

[OrganizationID] [int] IDENTITY(1,1) NOT NULL,

[Name] [varchar](50) NOT NULL,

[AddressLine1] [varchar](50) NULL,

[AddressLine2] [varchar](50) NULL,

[City] [varchar](50) NULL,

[State] [varchar](2) NULL,

[Zip] [varchar](10) NULL,

CONSTRAINT [PK_Organization] PRIMARY KEY CLUSTERED

(

[OrganizationID] ASC

)WITH (PAD_INDEX= OFF, STATISTICS_NORECOMPUTE= OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS= ON, ALLOW_PAGE_LOCKS= ON) ON [PRIMARY]

) ON [PRIMARY]

 

5.Use CodeSmith to generate the netTiers code.

Recommended initial settings to change before generating code:

     ChooseSourceDatabase=ACMETools

     OutputDirectory= <Select Your Output Location>

      RootNameSpace=Acme.Tools

      SourceTables= <Select the Organization table>

      DotNetVersion= v4

      ExecuteSql=true (to generate stored procedures for your selected table)

      IncludeDatabaseFeatures=SQLServer2005

      BusinessLogicLayerNameSpace=BLL

      DataAccessNameSpace=DAL 

6.Build the netTiers solution.

7.Copy the following dlls from the netTiers Website bin folder to the mojoPortal web bin folder.

Acme.Tools.BLL.dll

Acme.Tools.DAL.dll

Acme.Tools.DAL.SqlClient.dll

Acme.Tools.Web.dll

Microsoft.Practices.EnterpriseLibrary.Common.dll

Microsoft.Practices.EnterpriseLibrary.Data.dll 

 

8.Include the contents of the following sections from the netTiers web.config file to the mojoPortal web.config file.

a.configSections – You will need to add the section tag.

 

<configSections>

<sectionname="ACME.Tools.DAL"type="ACME.Tools.DAL.Bases.KeySysServiceSection, ACME.Tools.DAL"allowDefinition="MachineToApplication"restartOnExternalChanges="true" />

</configSections>

b.connectionStrings - You will need to add the connectionStrings section.

<connectionStrings>

<addname="ACME.Tools.DAL.ConnectionString"connectionString="Data Source=localhost;Initial Catalog=ACMETools;User ID=ACMEToolsUser;Password=ACMETools" />

</connectionStrings>

c.SqlProvider section – You will need to add this section.

<ACME.Tools.DALdefaultProvider="SqlNetTiersProvider">

<providers>

<addname="SqlNetTiersProvider"type="ACME.Tools.DAL.SqlClient.SqlKeySysProvider, ACME.Tools.DAL.SqlClient" connectionStringName="ACME.Tools.DAL.ConnectionString"

providerInvariantName="System.Data.SqlClient"

entityFactoryType="ACME.Tools.BLL.EntityFactory"

useEntityFactory="true" enableEntityTracking="false" enableMethodAuthorization="false"

useStoredProcedure="false" defaultCommandTimeout="30"

/>

</providers>

</ACME.Tools.DAL>

d.Add the following tag prefixes to the controls section.

<controls>

<addtagPrefix="asp"namespace="System.Web.UI"assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>

<addtagPrefix="data"namespace="ACME.Tools.Web.Data"assembly="ACME.Tools.Web"/>

<addtagPrefix="data"namespace="ACME.Tools.Web.UI"assembly="ACME.Tools.Web"/>

</controls>

e.Add the EntityTransactionModule tag to the httpModules section.

<httpModules>

<addname="EntityTransactionModule"type="ACME.Tools.Web.Data.EntityTransactionModule, ACME.Tools.Web"/>

</httpModules>

 

5.Open the netTiers generated Visual Studio solution file to modify the code.

a.Create a folder named mojoPortal under the Admin folder.

b.Create two folders under the mojoPortal folder named PageControls and UserControls.

c.Copy the contents of the netTiers generated UserControls folder to the mojoPortal\UserControls folder. This will make it easier to copy the files to the mojoPortal later.

d.CodeSmith / netTiers genrates two pages for each table selected in your code generation. In this example, it created Organization.aspx and OrganizationEdit.aspx for the Organization table.

e.Copy the netTiers generated Organization.aspx and the OrganizationEdit.aspx files to the mojoPortal\PageControls folder. Do not copy the associated code-behind (*.cs) files.

f.Rename the mojoPortal\PageControls\Organization.aspx file to OrganizationListPage.ascx.

g.Rename the mojoPortal\PageControls\OrganizationEdit.aspx file to OrganizationEditPage.ascx.

 

 

 

Please e-mail with comments.

Wednesday, December 29, 2010 11:19:00 AM Categories: CodeSmith mojoPortal netTiers
Jarick Rager