- Download setup, include source code (external site)
Release historyFull Set of nhib1_templates, click here. Now you can Add/Remove custom columns, relations, controls. Now smartcode offerCodesmith template compatibility. Allow Code Generation for views IntroductionSmart code is a new open source project onKontacWeb site. This is the part one of two articles of smart code generator. What is smart code? Smart code is an open source and template-driven Code Generator tool (released under both BSD license and lesser GPL library license). With the next features:
- Smart code operates by reading a database schema, allowing the user to set certain extended properties for tables and columns, and applying templates to each table in order to generate code.
- Smart code main building blocks are tables, views, columns, and top level project definition.
- In smart code, a template is a program that generates text (which is generally code in a programming language), and may be written in C # Or VB. net (or theoretically in any. NET language that supports the creation of dynamic-link libraries, or DLLs ).
- A template library (or library, for short) is a logical grouping of templates. A Template takes as input a model and an table or view to generate the code
- Allow you to build fully-functional prototypes of web-based applications that interact with database systems.
- Fast, because your libraries templates are compiled code and does not need parser script expressions
- Use Visual Studio to access to smartcode object model and debug your templates!
- Easy to extend, allow you create your custom drivers for access to other databases, and add custom properties to customize the Code Generation
BackgroundDespite great advances in software development tools and methodologies, software construction is still very much a detailed and difficult task. this has motivated the Development of Automatic Programming Techniques and programming patterns, in order to eliminate or systematize the development of common and repetitive solution ubuntures. The smart code-generation tool makes possible the automatic generation of programs and components that interact with database systems. it works by reading a database schema, allowing the user to set certain extended properties for tables and columns, and applying templates to each table in order to generate code. the templates are themselves programs that access the smart code object model to produce tailored programs and components. although smartcode comes with a set of core templates, users may edit these or create their own to suit their particle project needs. moreover, templates may be written in C # Or VB. net (or theoretically in any. NET language that supports the creation of dynamic-link libraries ). this is a very powerful paradigm. The benefits of code reuseThe greatest productivity gains in software construction come from reusing components that have already been developed and validated. moreover, in certain circumstances reusing software may also increase job satisfaction. for example, how many times have us as programmers been asked to develop functionality (including a user interface) for creating, updating, and deleting records from a database Ta Ble? If there was a way to automate this process, programmers cocould eliminate some of the most tedious and repetitive work in a typical database project. and they cocould be able to focus more on ensuring that systems meet their requirements. Reusing Software also has organizational benefits. in a typical software development shop, Every programmer has her own way of coding database-Table maintenance tasks. this makes the software harder to maintain, because one programmer may not necessarily be familiar with the techniques of another. if there was a standard, automatic way of producing certain kinds of code, and programmers were trained on the process and on the generated code, anyone cocould maintain the parts of systems developed in this way. also, a newly-hired programmer cocould quickly come to speed on how to maintain this code for all the existing systems that were based on the standard, automatic way of producing it. Another organizational benefit, if properly supported, is encouraging the discovery and automation of code patterns and solution ubuntures. Methods of code reuseAlthough extends methods exist for reusing code, such
- Using existing routines and classes, without any modifications.
- Modifying existing routines and classes to accommodate new requirements.
- Hand-editing existing code to accommodate a new environment (e.g., data-access code in which one edits table and column names to update a different table), and
- Buying off-the-shelf software; e.g., ActiveX controls.
It is still the case that automatically generating the code from a high-level specification is the most flexible and reliable strategy. The smart code EnvironmentThe smart code environment consists of menus and window panes. This section explains them. Top menuThe smart code top menu offers the following options:
- File
New: connect to a database and create a new project. Open: locate and open an smart Code project file. Save: Save the current project. Save as: Save the current project under a new file name. Exit: Quit smartcode.
- Project
Refresh project: refresh the loaded project with the info from database.
- Generation
Load Library...: load an existing library from global assembly cache. View libraries: display a list of the loaded libraries. Generate: Bring up the window that displays the current template assignments, allows changing or making new template assignments, and starts the code-generation process.
- Help
Help: contact to me ....:) About...: displays version and brief license information.
The explorer paneThe tables, views, relations and columns objects are located on the left-hand-side of the screen and displays a list of all the these objects in the project, in the form of a tree view. The object property paneThe project Pane appears on the right-hand-side of the screen when the project (the root node) is selected on the each objects: The Project allow the user to view and change objects properties. Smartcode ProjectsA project is a group of tables, views, relations, property settings, template libraries, and template assignments, and is tied to a database. this section explains how to open, create, and save projects, and also how to understand and set project properties. Opening existing projectsSmart Code project files have an ". SCP" extension, they can be opened via the file top-menuOpen Creating new projectsA project may be created by accessing the file top-menu,NewOption or by clicking onNewIn the main toolbar. This starts the project-creation dialog: The steps to create a new project are
- Naming the project.
- Select the database and location string, and click on OK.
- On the next Windows choosing database objects.
Template LibrariesA template is a program that generates text (which is generally code in a programming language), and may be written in C # VB. net (or theoretically in any. NET language that can create a dynamic-link library, or DLL ). A template library (or library, for short) is a logical grouping of templates. A template takes as input a project and an entity to generate the code. each template defines a naming convention for the name of the file in which to store the code it generates; this naming convention is typically based on the entity's name. for example, customer_sample3.txt Templates, sample codeEach template look like this (in VB. NET ): Collapse Imports System Imports SmartCode.Template Public Class Sample3 Inherits TemplateBase Public Sub New() MyBase.Name = "Sample3" MyBase.CreateOutputFile = True MyBase.Description = "This template demonstrates using static and dynamic contents." MyBase.OutputFolder = "Samples\Sample3" MyBase.IsProjectTemplate = False End Sub Public Overloads Overrides Function OutputFileName() As String Return Table.Code + "_Sample3.txt" End Function Public Overloads Overrides Sub ProduceCode() WriteLine("This is some static content.") WriteLine("Table: " + Table.Name) For Each column As SmartCode.Model.Column In Table.AllColumns WriteLine("Column: {0}", column.Name) Next WriteLine("This is more static content.") WriteLine() End Sub End Class Add/Remove template Libraries Template libraries may be removed from the view libraies sub menu from the generation top menu, or by clicking on the icon in the main toolbar. in both cases, a library dialog allows for add libraries or selecting the desired template library assembly, and remove this. Generating codeThe process of generating code consists of assigning templates to tables, views and selecting the target folder in which to place the generated files. The process is begun by selectingGenerateFrom the generation option in the top menu, or by clicking on the icon in the main toolbar. Once the tables and columns properties have been set appropriately, templates are assigned to each of the tables views or project in order to generate code. Assignments are achieved by selecting the entity (or entities, by keeping the ctrl key pressed) on the left-hand-side, selecting the template (or templates, by keeping the Shift key pressed) on the right-hand-side, and then pressing the right-arrow button in the middle. the left-arrow button is used to remove individually-Selected assignments. Code Generation and its resultsWhen the generate button is pressed, a dialog is displayed in which the user is asked to choose the folder in which to place the generated files: Pressing the OK button begins the actual code generation. smartcode displays PROGRESS IN THE NEXT form: Note: When generating files, existing files are automatically overwritten without asking. Refresh ProjectsIf there are changes in the underlying table or view of an entity, one may wish to refresh its properties. this may be accomplished by clicking the refresh project item from refresh menu this action allow you add/update Tables and columns from database. For Delete object, simply select the object and click on remove option from toolbar in Explorer pane. Project level templatesIn the last sections we have learn to generate code runing templates assigned to entities, but else in the practics usually we have to generate code for all objects contained in the domain e.g. the list of all tables in the database; With smartcode we have the option to assign a template to project level, to run only one time, each time that we run the code generation, we can found this template in the second tab called "project templates", in the main "setting code generation" Dialog Creating user interfacesSmartcode offer the possibility to generate code for user interfaces, You Can setting the control type for each column as shown the next image: Build templates to create code for UI is simple, by example the next code teach how: foreach (Column column in table.AllColumns()) { if (column.Control is SmartCode.Model.Profile.TextBox) { WriteLine(@"<asp:TextBox runat=""server"" ID=""ui{0}""/>", column.Code); } else if (column.Control is SmartCode.Model.Profile.CheckBox) { WriteLine(@"<asp:CheckBox runat=""server"" ID=""ui{0}""/>", column.Code); } else ............ } The core template LibrariesThe smart code package comes withBetaCore sets of template libraries for generating code in C #, that use stored procedures to access and modify data.
- Stored Procedures libraries: these templates generate SQL Server 2000 scripts for creating stored procedures that insert, delete, update, and search for records in tables.
- Common data libraries (typeddataset): This template generate code for XSD to render to typeddataset objects used to transport data between the tiers
- Data tier libraries: these templates generate code for supporting the data access classes
- Business tier libraries: these templates generate code for supporting the access to data tier
About Danilo Mendez
|
Danilo is the creator of Smart Rules, a business rules engine. he is an industry consultant working primarily with companies interested in implementing dynamic rules programming concepts to add flexibility to their ubuntures on web, Ce, and desktop platforms. he operates his own website, kontac, where you will find more information. To contact Danilo, email him at danilo.mendez@gmail.com. Click here to view Danilo Mendez's online profile. |
|