23 June 2010

eXtremecode ASP.Net Generator Introduction


Overview

eXtremecode or eX ASP.Net Generator is simply a tool which takes a collection of database connections as an input and produce a well-formed Asp.net Application.

eX Generator consists of two applications. One application is eXtremecode Definition Generator (eXDG), for generating database schema which takes collection of database connections as an input and gives databases schema (definition) in the form of an XML file. And second application is eXtremecode Generator (eXG), for generating final code e-g Asp.Net application which takes generated database definitions and predefined templates as an input and gives final result (currenty an Asp.Net application).


eXtremecode Definition Generator (eXDG)

eXDG takes collection of connections which are defined in an XML file. Path of that XML file can be configured from eXDG's applicatin configuratin file.
<configuration>
  <appSettings>
    <add key="ConnectionsPath" value="Connections.config" />
Currently, eXDG supports SQLServer, Oracle and MySQL databases. Example of connections defining XML is shown below.
<connections>
  <connection name="SQLServerConn" connectionString="Persist Security Info=False;User ID=sa;Initial Catalog=DBName;Data Source=ServerName;Password=password" type="SQLServer" isDefault="false" encrypted="false"/>
  <connection name="SQLServer2005Conn" connectionString="Persist Security Info=False;User ID=sa;Initial Catalog=DBName;Data Source=ServerName;Password=password" type="SQLServer05" isDefault="false" encrypted="false"/>
  <connection name="OracleConn" connectionString="Password=password;User ID=userName;Data Source=ServerName;Persist Security Info=True" type="Oracle" isDefault="false" encrypted="false"/>
  <connection name="MySQLConn" connectionString="server=ServerName;User Id=userId;database=dbName;Persist Security Info=True;Password=password;Port=3306" type="MySQL" isDefault="true" encrypted="false"/>
</connections>

Connection Attributes

  • Name: For unique identification of a connection..
  • Connection String: Simply defining connectivity to database. The format of this string depends on type of the connection.
For using MySql Connection, it is required to install MySQL .Net connector first. 
For complete details about MySQL connectivity with .Net application,
please visit MySQL official site.
  • Type: For telling system about type of the database (SQL server,MySQL,Oracle).
  • IsDefault: If we have more then a connection in our application, we can set one connection as a default. If we don't provide the name of the connection while querying to database. System will pass that query to default connection for execution.
  • Encrypted: For telling system about provided connection string, whether it is encrypted or not .

Running eXDG

   Once we define all required connections now we can run eXDG application. At the time of form loading system will read all defined connections and populate a grid with list of  tables and views of respective databases.


Option, Select Related Entities

Normaly, all database tables are not required in an application. If we have large number of tables in our database, it gets difficult to select required entities. So if we check "related entities" check box and then select a table from grid, system will select all related tables of that table for us.

Option, Refresh Entities

If "Refresh Entities" check box is unchecked, when we regenerate definition/schema of entities, system will generate definition for only new selected entities (tables/views) and already generated entities selection will be ignored.
Some time we create new tables in database which have relations with old tables/entities. In that case we want to regenerate old entities so relations of new created tables can also be incorporated with old entity. In order to regenerate old entities, we will keep "Refresh Entities" check box checked.

Generated Definition/Schema Files

Once we click generate button, system will generate two xml files at defined paths.File paths can be configured from application configuration file.
<add key="EntityDefinitionPath" value="eXDefinition.xml" />
<add key="EntityCustomizedPath" value="eXCustomDefinition.xml" /> 

"EnitiyDefinitionPath" is for Xml file which contains whole schema of selected entities. Here is the sample.
<entity name="Promotion" accessorName="SQLServerConn" type="db" table="Promotion" view="Promotion">
    <fields>
      <field name="IsActive" datatype="bit" type="native" key="false" computed="false" unique="false" nullable="false" autoGenerated="false" />
      <field name="Stock" datatype="int" type="native" key="false" computed="false" unique="false" nullable="false" autoGenerated="false" />
      <field name="Title" datatype="text" type="native" key="false" computed="false" unique="false" nullable="true" autoGenerated="false" />
      <field name="LaunchDate" datatype="datetime" type="native" key="false" computed="false" unique="false" nullable="false" autoGenerated="false" />
      <field name="PromotionId" datatype="int" type="native" key="true" computed="true" unique="true" nullable="false" autoGenerated="false" />
      <field name="PromotionType" datatype="int" type="native" key="false" computed="false" unique="false" nullable="false" autoGenerated="false" />
      ........
      ........
 
    </fields>
    <children>
      <entityReference name="CustomerCategoryPromotion">
        <relationalFields referenceField="PromotionId" nativeField="PromotionId" />
      </entityReference>
      <entityReference name="PromotionItem">
        <relationalFields referenceField="PromotionId" nativeField="PromotionId" />
      </entityReference>
      <entityReference name="OrderItem">
        <relationalFields referenceField="PromotionId" nativeField="PromotionId" />
      </entityReference>
    </children>
    <parents>
      <entityReference name="PromotionType">
        <relationalFields referenceField="PromotionTypeId" nativeField="PromotionType" />
      </entityReference>
    </parents>
</entity> 
"EntityCustomizedPath" is for Xml file which contains only name of selected entities with their fields. It is used for entity level customization of generated code. Here is the sample.
<entity name="Promotion">
    <fields>
      <field name="IsActive" />
      <field name="Stock"/>
      <field name="Title" />
      <field name="LaunchDate" />
      <field name="PromotionId"  />
      <field name="PromotionType" />
      ........
      ........
 
    </fields>
</entity> 
I will explain schema attributes and entity level customization in details, in advanced articals.

eXtremecode Generator (eXG)

Once we generate definition and do required customization, now we can generate final code with the help of predefined templates.
Generation of Asp.Net application is actually based on defined templates.
Any kind of  application can be generated by defining required templates.
Currently, I have written templates for ASP.Net C# application only. 
Generating language (the language in which templates are written) is C#.  

Repository.xml

All defined templates will be controlled or managed by "Repository.xml" file. From Repository.xml file, we can configure followings.
  • Name of the project
  • Name of schema and custom entity files
  • Scurity settings
  • Names of template files (Session Files).
  • Defining generated files.
  • Managing custom code of developer.
Repository management is an advanced topic so I will explain it later in more details. Here is an example of  Repository.xml file.
<?xml version="1.0" encoding="utf-8" ?>
<Repository projectName="MYSQLTest" entityDefinitionFile= "EntityDefinitions.xml" entityCustomFile= "EntityCustomized.xml">
 <Security>
  <UserLogin entity="Duplicate-Users" userIdField="UserId" userNameField="UserName" passwordField="Password" defaultRoleIdField="DefaultGroupId" relatedRolesEntity="Duplicate-user_groups" roleIdField="GroupId" />
  <UserRole entity="Duplicate-Groups" roleIdField="GroupId" roleNameField="GroupName" homeModuleIdField="defaultModuleId" relatedModulesEntity="Duplicate-group_modules" moduleIdField="ModuleId"  />
 </Security>
 
 <SessionFiles>
  <!--<File name="report.cs" />
  <File name="share-script.cs" />-->
  <File name="BusinessObject.cs" />
  <File name="IncludedCode.cs" />
  <File name="BODataSet.cs" />
  <File name="BOCommon.cs" />
  <File name="BOList.aspx.cs" />
  <File name="BOList.aspx" />
  <File name="BO.resx" />
  <File name="BOEdit.aspx" />
  <File name="BOEdit.aspx.cs" />
  <File name="Login.aspx.cs" />
  <File name="Login.aspx" />
  <File name="UserProfile.cs" />
  <File name="Default.aspx" />
  <File name="Default.aspx.cs" />
  <File name="sitemap.xml" />
  <File name="Global.asax" />
  <File name="ChangePassword.aspx.cs" />
  <File name="ChangePassword.aspx" />
 </SessionFiles>
 
 <GeneratedFiles>
  <!--Edit Page-->
  <File name="\aspx\{0}BOEdit.aspx.cs" type="table" copyFile="" cond="" 
   mappCustomCode="true" enabled="true" 
   sessionList="BOEditWholeClass" />
   
   <File name="\aspx\{0}BOEdit.aspx" type="table" copyFile="" cond="" 
   mappCustomCode="false"  enabled="true"
   sessionList="ASPXBOEditWholeClass" />
 
  
  
  <!--Business Objects-->
  <File name="\App_Code\BusinessObjects\{0}BO.cs" type="table" copyFile="" cond="" 
   mappCustomCode="false"  enabled="true"
   sessionList="BUZWholeClass" />
 
  <File name="\App_Code\BusinessObjects\{0}BOCol.cs" type="table" copyFile="" cond=""
   mappCustomCode="true"  enabled="true"
   sessionList="BUZColWholeClass" />
  
  
  <!--List Page-->
  <File name="\aspx\{0}BOList.aspx.cs" type="table" copyFile="" cond="" 
   mappCustomCode="true"  enabled="true"
   sessionList="BOListWholeClass" />
   
   <File name="\aspx\{0}BOList.aspx" type="table" copyFile="" cond="" 
   mappCustomCode="true"  enabled="true"
   sessionList="ASPXBOListWholeClass" />
 
   
   <!--Resource-->
   <File name="\App_GlobalResources\BusinessObjects\{0}BO.resx" type="table" copyFile="" cond="" 
   mappCustomCode="true"  enabled="true"
   sessionList="ResourceBOListWholeClass" />
  
  
   
   <!-- Business Base -->
   <File name="\App_Code\DataTables\{0}DataTable.cs" type="table" copyFile="" cond=""
   mappCustomCode="true" enabled="true"
   sessionList="BUZDataTableWholeClass" />
   
   <File name="\App_Code\BODataSet.cs" type="once" copyFile="" cond="" enabled="true"
   mappCustomCode="true" 
   sessionList="BUZDataSetWholeClass" />
   
   <File name="App_Code\BOCommon.cs" type="once" copyFile="" cond="" enabled="true"
   mappCustomCode="true" 
   sessionList="BOCommonWholeClass" /> 
   
   <File name="Login.aspx.cs" type="once" copyFile="" cond="" enabled="true"
   mappCustomCode="true" 
   sessionList="LoginWholeClass" /> 
   
   <File name="Login.aspx" type="once" copyFile="" cond="" enabled="true"
   mappCustomCode="true" 
   sessionList="ASPXLoginWholeClass" /> 
   
   <File name="ChangePassword.aspx.cs" type="once" copyFile="" cond="" enabled="true"
   mappCustomCode="true" 
   sessionList="ChangePasswordWholeClass" /> 
   
   <File name="ChangePassword.aspx" type="once" copyFile="" cond="" enabled="true"
   mappCustomCode="true" 
   sessionList="ASPXChangePasswordWholeClass" />
   
   
   <File name="Default.aspx" type="once" copyFile="" cond="" enabled="true"
   mappCustomCode="true" 
   sessionList="ASPXDefaultWholeClass" /> 
   
   <File name="Default.aspx.cs" type="once" copyFile="" cond="" enabled="true"
   mappCustomCode="true" 
   sessionList="DefaultWholeClass" /> 
   
   <File name="Web.sitemap" type="once" copyFile="" cond="" enabled="true"
   mappCustomCode="true" 
   sessionList="SitemapWholeClass" /> 
   
   <File name="Global.asax" type="once" copyFile="" cond="" enabled="true"
   mappCustomCode="true" 
   sessionList="GlobalASAXWholeClass" />
   
   
   <File name="App_Code/UserProfile.cs" type="once" copyFile="" cond="" enabled="true"
   mappCustomCode="true" 
   sessionList="UserProfileWholeClass" /> 
   
   <File name="unchangedFiles" type="CopyFolder" copyFile="WebSite" cond="" enabled="true"
   mappCustomCode="true" 
   sessionList="UserProfileWholeClass" /> 
   
   
  <!--MappCustomCode= [false,true]  this option can b used when for avoiding custom code conflict but user code
   will be lost. By default its value is true -->
  <!--type = table,once,copy-->
  <!--cond = not using yet-->
 </GeneratedFiles>
</Repository>

Running eXG

First we need to copy generated definition files into the folder of defined templates so we can configure them in "Repository.xml". Once application gets started, select the location of templates and output dirctory where asp.net application wants to be created.


Now click load button for loading templates, last generated entities (definitions generated by eXDG) will be populatd in a grid. Select required entities and click generate button for generating final code.

Option, Overwrite

While generating code, by default system checks whether generated file already created or not. If file already created, system prompts and asks user to overwrite that file or leave it unchanged. If we check "overwrite" check box, system overwrites all selected files without prompting user.

Software Setup

I have uploaded setup of eXtremecode Asp.Net generator here. it contains two sub folder. one contains eXtrtemecode Definition Generator application and otherone contain eXtremecode Generator application with code of predefined templates. I have written steps to generate ASP.Net application in ReadMe.txt file, it will must help you.



Northwind Example

I have generated Asp.Net application for Northwind database. Please download it from here. I have also enclosed the sample configuration of templates for Northwind database with the setup of software in eXG folder so if you will be intrested to generate Northwid Asp.net application your self, you can use that configurations.



Source Code

You can download complete source code of the generator from here. If you modify the product, don't forget to share updated source code at http://extremecodeworld.codeplex.com. For more details about sharing updates of code, please visit here.


Upcoming Articles

That was all the introduction of eXtremecode Asp.net application generator with basic details. I hope this intro will be pretty enough  to generate simple asp.net application. Still there is lot of things which need to be explained,. here is the summary of topics which will be explained in upcoming articles.
  • Generated Definitions/Schema - Explanation of all elements and their attributes.
  • Entity Level Customization -  How to order fields of specific entity in ASPX pages. How to control visibility and nature of web controls.
  • Templates - How to modify templates. what are conventions have to be followed while writing a template.
  • Templates Management and Controlling - How templates will be executed to generate code. Explanation of "Repository.xml" contents, 
  • Security Implementation and Membership Provider - How to manage rights of user in ASP.Net application. explanation of custom Membership provider. Explanation of custom attributes of "Web.sitemap" xml file. Explanation of controling visibility of items in navigation controls (Menu, TreeView and  SiteMapPath) 
  • Embedding of developer's custom code into generated code - how to embed custom code in the way that code will be safe after regenerating of code.
  • Decorators or Application Appearance - How to use decorators. How to define new decorator for designing new layout and appearance of ASP.Net pages.
  • Business Layer - How to query database through Bussiness Objects. Code level details. 
  • Data Access Layer - How to implement new Accessor of database. Code level details.
Priority of posting of advanced articles will be based on your interest.
So please share your interest and provide your feedback that how much you have found  
extremecode Generator helpfull in web development.  
If you are interested to follow up these topics, please subscribe right now.

Awards


Windows 7 Download

Top 4 Download


Digg Google Bookmarks reddit Mixx StumbleUpon Technorati Yahoo! Buzz DesignFloat Delicious BlinkList Furl

5 comments: on "eXtremecode ASP.Net Generator Introduction"

Shakil said...

I would be interested if you do a comparison with ASP.NET Dynamic Data.

Sheikh Abdul Wahid Ahmed said...

Dear Shakil,
Asp.Net Dynamic Data is something different. it generates website at runtime, with the help of predefined asp.net standard (can be modified in asp.net designer) templates. In contrast, eXG generates an Asp.net application first and lets you modify specific pages/forms as your requirements.
In other words, DD generates pages dynamically which have no physical existence so you cannot done specific changes there.

Unlike ASP.Net Dynamic Data, eXG gives you a well formed asp.net application. Further, you can navigate generated CRUD forms, from top menu and even can rearrange them by configuring sitemap XML file.

If you have any query, please feel free to contact me.

STREAMWRITER said...

Hi Sheikh, don't work the configuration of the conections in my download of the eXtreamcode, I would like you to help me with this configuration, I am using ASP.NET(C#), Framework 2.0-3.5, SQL Server 2005, and my connection string is:

Hasan said...

eXcodeGen made my life easier in a project where we had to implement a custom career profile section inside SharePoint by providing custom aspx forms using custom SQL Server DB.

Add/Edit Forms were generated and voilà they started running in minutes. Thanks.

Good Work Dear!

Sheikh Abdul Wahid Ahmed said...

Hi STREAMWRITER,
Please share your problem in details. I will be happy to solve it.

Post a Comment