Automatic code based on .NET

zhaozj2021-02-16  43

Automatic code based on .NET

Abstract: When developing ASP.NET database software, in order to achieve rapid development and mitigation workload, we propose some of the .NET-based automatic code machine solutions, some universalization modules for ASP.NET database software Implementation code automatically generated. This paper introduces the system model and related technologies of the automatic code machine, and make a detailed description of the automatic acquisition technology, template and label replacement techniques and XML storage files. The software implements the expected function and has certain flexibility and expansibility, and has achieved satisfactory results.

Keywords: .net, automatic code machine, template label, XML storage

1. background

Microsoft integrates many technologies, launched .Net this cross-language, cross-platform technical specification, .NET's most core part is a general language runtime (CLR) in the bottom of .NET Framework, it is a unified operation of more than 20 languages. Environment, providing memory management, exception processing, security, version control, component communication and other system services for these languages. In particular, ASP.NET, due to its strong features, superior performance and convenient deployment, etc., is the first choice for more and more software developers.

Although Microsoft Visual Studio .NET provides a good ASP.NET development environment, it is more in the development of the ASP.NET database software, such as display, add, modify, delete, etc., basically Repeatedly prepared, and it is easy to make mistakes. In order to achieve rapid development and mitigator's workload, we propose the development of .NET-based automatic code machine solutions, the partial generalization module of the ASP.NET database software implements the code automatic generation, and has certain flexibility and Denomability has achieved satisfactory results.

This article gives the model and system structure of auto code machine development, and discusses relevant algorithms and technologies.

2. System model

database

Automatic code machine

XML file storage

template

file

Replacement tag

finally

project

ASP.NET and C # code

Figure 1 System Model

3. Procedures process and related technologies

Automated code machine is an application developed by C #, stores user operation information with XML files, which is easy to modify and reuse projects. Since most of our software projects use SQL Server database, we have special support for the SQL Server database. Automatic code automatically obtains related information according to the database specified by the user, such as fields, types, primary keys, descriptions, etc., users can modify this information, select and delete fields that need to be displayed or processed, or control the final page. The display order and processing effect of each field, the automatic code machine is replaced with the template file, automatically generates the necessary code for database operations, including display, add, modify, delete, etc., and follow the ASP.NET representation The specification that is separated from the business layer, generates the corresponding .aspx file and .cs file. For automatically generated file users can be used directly in the project, or they can be developed on the original basis.

3.1 Automatic acquisition of database information

Here we give some key code for SQL Server database operations.

1. List all the databases on the current server:

Select name from master..xysdatabases Order by name

2. List all user data tables in the current database:

Select Name from (current database) .. sysobjects where type = 'u' and name not like '% Properties' Order by Name3. List all the fields of a piece of data:

String.format ("Select {0} .. syscolumns. * From {0} .. syscolumns, {0} .. sysobjects where {0} .. sysObjects.name = '{1}' and {0} .. syscolumns. .id = {0} .. sysObjects.id Order by colorder, current database, current data table)

4. List the primary key of a piece of data sheet:

String.Format ("Select * from {0} .. {1}", current database, current data sheet)

5. List the details of a data table field:

String.format ("Select * from {0} .information_schema.columns as col, {0} .. sysobjects as obj, {0}. sysproperties as pro where table_name = '{1}' and col.table_name = Obj. Name and pro.id = obj.id and pro.Smallid = colu.ordinal_position and color = = '{2}', current database, current data table, current data table field)

The above code can automatically obtain related information of the database, data sheet, and fields, for example, the description information of the field can be automatically acquired, directly for generating the table headerText column of the page, and the user can manually modify various information on the automatic code.

3.2 Processing for different needs of fields

Different fields have different needs when implementing the database, the different fields will have different needs, such as: some requires an empty way to input, some to automatically generate a water number, some to use the tick (not worth), some to use SQL Statements from other data sheets to generate drop-down lists, and so on. If you can only implement a general space to be input, additional processing has to be handled when you encounter different needs. To this end, we will extract several data field requirements with the highest frequency, as a set of functional modules, users only need to select the desired function and provide the information, the code will automatically generate all code.

The following requirements are described below:

1. Space-to-input: This is the most common way, you need to determine the type of field to prevent user error input. When there is a top and lower limit request, the relevant judgment code can be automatically generated.

2. Automatically generate flow: This is a common way of primary key, and users do not need to input, and the system is automatically generated.

3. Tomb (is not worth): This is a Boolean or 0, 1 numeric commonly used processing method, and the final generated code will receive the user's input with CheckBox.

4. Drop the SQL list: Use the SQL statement from another data table to generate a drop-down list. This is also a very common demand in the actual project. If the programmer is still expensive from the head-write code, it involves the generation, selection, modification of the drop-down list, and the use of the automatic code only needs to enter the necessary SQL. The statement is, for example, to implement the drop-down list to display the student name, select the corresponding secondary number to the database, simply fill in the SQL statement: select name, ID from students, the rest of the task is handed over to the auto code machine. 5. SQL generating value: Similar to the previous situation, it is the result of a specific value that meets the conditions, such as the average score of the student: SELECT AVG (Score) from Students_Score, and can be divided into allowing end user modifications and not allowing modification Two cases.

6. Default: that is, the system's automatic default value can also be divided into allowing end user modifications and not allowing modifications.

The above is the most common demand, using these features to greatly reduce programmers' workload and achieve rapid development goals.

In addition, in order to realize the scalability of the system, we specifically designed the Custom Dec. list module to realize the dynamic load of user-defined projects. For example, a field is classified, divided into Mandarin songs, Cantonese songs, Taiwanese songs, etc., users can customize the following files:

Mandarin song

Cantonese song

Taiwanese song

Automatic code function accepts and identifies user-defined files and completes various related processing. This module greatly increases the scalability of the system, providing effective supplements for the need for software design, and provides an interface for future extensions.

3.3 Template file and label replacement technology

After obtaining the necessary information from a few steps, use the label replacement technology to replace the tags in the template file to generate available code.

Since the .NET code has a certain framework, such as information display is divided into an ASPX page representation layer and the CS code business layer, the traffic layer interacts with the database. Since the frame has a certain versatility, the general code of the frame is extracted into a template file, and the portion therein uses the tag to mark it, and the corresponding specific information is replaced with the corresponding specific information in the template when generating the code, and finally generates complete Code. The workflow for template files and labels is shown in Figure 2.

Template file

Main_mode.cs

..........

String $ 3 $;

..........

label

Label replacement

..........

Song_ID Replace $ 3 $

........

Final code

Main_song.cs

..........

String Song_ID;

............ .....

Replacement information corresponding to label

Figure 2 Label replacement workflow

In the illustration, it is only a brief description of the replacement process. When the actual design, it mainly includes three aspects:

1. Template file extraction. First we analyze the code of the ASP.NET program, lay a typical actual application, and extract the general code framework.

2. label design. The label is very critical and there are many kinds. We have designed 23 labels, mainly divided into three categories: normal labels, such as defined variables, etc., complex labels, such as logical judgment; composite labels, complex tags, For example, a loop processing module. 3. Label replacement. The main job of the automatic code is to utilize the information obtained from the user and the database, and generate the actual information to replace the corresponding label after prerequisites. The label is replaced into the display module and modification module. Each module is divided into page layers and business layers. When replacing the layers, it is localized, first simply after composite, guarantee the correctness of the replacement.

Advantages of template and label replacement:

1. Level is clear. The hierarchy of the final code originates from the template code, the clear template hierarchy guarantees the hierarchical principle of the final code.

2. Understandable. The template file is a separate file, and the user can read the template file for easy understanding.

3. Modified. This is also the biggest advantage of template files. The user can modify the template on the basis of understanding the template and will be reflected immediately in the generated project code. If the template file is cured in the auto code machine, the user cannot modify the template, although it will be simple but will lose flexibility when writing an automatic code machine, so we have selected the processing method of the plug-in template file.

4. Alternative. In addition to local modifications, templates can be replaced. Multi-set templates can be provided by the user.

5. Versatility. The template is extracted on a variety of actual demand, with large versatility, no need to modify, to adapt to most items, and modify the final code based on the final code.

6. Consistency. Since all generated code is generated by the template, the code has strict consistency on the style of the page layer and the business layer, similar to the factory production. The modification of the pattern can be completed by modifying the template.

3.4 XML Storage File

A complete code generating cannot be formed once, and it may be modified by multiple modifications, and this code may be multiplexed. To this end, the automatic code provides saving and reading. The first time you generate a set of code, you can save this time, you can read the last item next time, and modify it on the original basis.

Storage media can generally select databases, XML files, or normal files, we have selected XML files in this project, as this project uses XML files as the following benefits:

1. XML storage information can be handled in an automatic code. .NET provides good support for XML, and the program can communicate directly with the XML file through the DataSet object.

2. The XML file is used as a local database. It has been accepted from the convenience of the database operation, but also saves the use of SQL Server or other databases, the free movement of the software is implemented.

3. You can make full use of the powerful features of XML, implement data direct conversion and automatic processing, such as automatic conversion to web pages to establish indexes and links for all projects.

The following is some of our primary XML Schema:

For detailed explanations and instances of XML storage files, it is no longer described here. Interested readers can refer to our actual software.

4. Program application and effect

At present, this software has been developed successfully, and the expected purpose of rapid development and mitigator's workload is achieved by testing and has been used in multiple actual projects.

Some items used:

1. Laiyang Steel Plant Blast Furnace Control System Basic Data Record Module. It mainly includes a variety of raw materials and analytical test report modules.

2. Data Enter Module in Information Construction of Ji Steel First Refining Factory. This project continues to develop on the basis of the previous project, and includes the basic data module of the production of materials.

3. VOD system data management module. Automatically generate the computer's background data management function code machine, saving the management module that originally planned independently developed.

4. E-commerce development platform basic information management module.

5. Rapid development of knowledge management prototype systems. Due to the use of an automated code machine, you don't have to write code to quickly generate prototype systems, which provides help for further research and discussion of the project.

It is not difficult to see that the automatic code can be used in basic data processing, which satisfies most demands, easy to operate, and has certain flexibility and scalability. We are currently preparing to further develop automatic code machines on the original basis, provide more template and functional modules, and increase its versatility, so that more developers can use this software.

转载请注明原文地址:https://www.9cbs.com/read-24966.html

New Post(0)