Underlying development technology of. Net after years of work

Source: Internet
Author: User

I have been working for five years. Because it is not a Computer Science Department, the first job is to create web pages and maintain ASP scripts.ProgramSometimes I want to make pictures. In short, there is no excuse to say that I won't do a task. I want to make up for it and then finish it. Later, I got the opportunity to participate in programming and development. In addition, at that time, I wanted to use C #. Net for development. I didn't want to participate in Delphi development. Instead, I had to go through layer-by-layer forwarding, But I was handed over to Delphi for development. After working hard, I used. Net for development. A negative idea will say that the job is complicated, complicated, and positive. The job assigned to you by the boss is a competent employee. It's time for graduates to look for a job. If they cannot find a job for development at the moment, don't worry. First, follow the company's arrangement to do a software test or a job in document management, when there is a chance for a vacant developer, you can introduce yourself to the programmer field. Opportunities are reserved for prepared persons, aren't they?

Always used. net is an ERP/mis-type software. If you are not proficient in your studies, you can complete your tasks. In your spare time, you can also create integrated toolkit. Next, let's share what I think. NET technology.

1. Communication Technology (remoting, WCF, asmx)

The common three-tier architecture, database, data access layer, and interface layer. Communication technology defines the call conventions and methods between layer-3 components. In this way, some abstraction is used as an example. Now we want to create an invoicing project. The basic functions are warehouse receiving, warehouse picking, and warehouse transferring. The query function should be able to query warehouse entry and exit journals,
Inventory balance. For a warehouse import business whose material is flex0901, it is completed in the form of ORM.CodeAs follows:
Inventorymovmententity receept = new inventorymovmententity ("ref1108080001", "receipt ");
Inventorymovmentdetailentity detail = receept. inventorymovmentdetails. addnew ();
Detail. itemno = "flex0901 ";
Detail. movedate = datetime. now;
Inventorymovementdal. instance. Save (receept );

Here are a few issues that are well handled, such
1) This is an improvement in data reading and writing of ORM, from piecing together SQL reading and writing to building entities. If you use Dal + SQL script, the pseudo code is as follows:
String MySQL = "insert icmovl (refno, direction) values ('ref1108080001 ', 'receip ')";
Inventorymovementdal. instance. executenonquery (MySQL );
MySQL = "insert icmovd (itemno, movedate) values ('flex0901 ', '2017/8 ')";
Inventorymovementdal. instance. executenonquery (MySQL );
Here, we omit the period of the patchwork parameter value and place the value directly in the SQL statement.
In the latter way, when a new field is added and the system is extended, the cost of modification and maintenance is significantly higher than that of the former.

2) The single-piece mode, inventorymovementdal. instance, is used to perform unified data read/write operations, instead
Inventorymovementdal inventorydal = new inventorymovementdal ();
Inventorydal. Save (receept );

This single-piece mode leads to the necessity of communication technology. When many users operate the Data Warehouse import function at the same time, it means that there are many inventorymovementdal data write operations at the same time, which may cause problems.
1) it is difficult to control the reference numbers of warehouse receiving orders for the first and second documents. To ensure that there are no duplicates, we need to go to the database to check whether the warehouse receiving ticket with the reference number already exists, that is, the beginning of the Save method of inventorymovementdal,
To include such a piece of code, it is represented by Dal + SQL script.
String MySQL = "select count (1) From icmoh_where refno = 'ref1108080001 '";
Bool existing = inventorymovementdal. instance. executescalar (MySQL)> 0;
As you can imagine, when the number of concurrent users is 100, every warehousing service requires a data check in advance to go back and forth to the database, so the program performance is definitely not good.
2) For inventory reports, multiple concurrent inventorymovementdal results in inconsistent data before and after. The inventory balance report can now read the materials flex0901 and 100 PCs. If you do not manually refresh the data when a warehouse order is placed into flex0901 of PC, at this time, the report still shows that the inventory balance of material flex0901 is 100, rather than 300. this is sometimes an unacceptable result.
You can create a timer to regularly refresh the inventory balance. The problem here is that inventorymovementdal has only one instance, so you cannot tell yourself that there is a new inventory and read the data again. A concurrency mechanism is required to notify the inventorymovementdal instance that new data is added to the inventory balance and the report needs to be refreshed.

3) Some data items are global and are unique to the entire system and need special processing.
For example, if the number of concurrent users allowed by the ERP system is exceeded and 10 Users are allowed to connect to the system, they cannot be processed;
A user of the ERP system improved the default currency of the current system from HK $ to US $. Other users should be aware of this change. At this time, it is unlikely that the user currently operating the business will exit and re-enter the system;
When a network failure occurs, the ERP system must be able to know the network failure and suspend ongoing operations. This can be understood as an effective improvement. When the system cannot connect to the SQL server, to prevent users who are currently inputting data, otherwise, the system cannot store the data, A message indicating a network-related or instance-specific error occurred while establishing a connection to SQL Server is displayed. the server was not found or was not accessible. verify that the Instance name is correct and that SQL server is configured to allow remote connections users will complain that your software is not ready, although this is not your fault.
For example, the current user is editing customer information. In the event of a network fault, the interface is disable. With the help of concurrency in communication technology, it can be achieved.

I have not advertised remoting or WCF in the whole article. I would like to explain the benefits of remoting and WCF. When your program encounters these problems, can you consider communication technology to improve performance and customer experience.

 

2 reflection, dynamic compilation

Reflection is a technique used to dynamically obtain the metadata of an assembly. net programmers have an answer to the question. You can choose to remember it. Just like in the course of cell structure in high school biology, cells are composed of cell membranes, cells, and cells. Based on the program experience, never ask why is not a good habit. Even Microsoft APIs may be crazy if they violate the call conventions.

See the following code.
Assembly = assembly. getexecutingassembly ();

Object entryform = activator. createinstance (formbasetype) as form;

Entryform. mdiparent = this;
Entryform. Show ();
Entryform. Activate ();
The meaning of the Code is relatively simple. Create the formbasetype type from the current Assembly and call its method. From the method name, we can see that this is a child form created by MDI and the Code of the Child form is displayed.
This small code is also the basic idea of the plug-in framework. Please refer to the examples in the management console tool management software general development framework (Open Source Code) to understand its usefulness.
There are too many examples of application reflection in ERP/MIS systems. The data access interface inventorymovementdal is used to find and call its implementation class by means of reflection. The form also has its child form to obtain attributes and pass values by reflection. The entire ERP system framework, it is also built by reflection.

See the figure below. The three modules of ERP are paradox. ERP. systemadministration, paradox. ERP. engineering, paradox. ERP. inventory is paradox. framework. kernal reflection call, if you write another paradox. ERP. the sales module of sales can be called by the framework without any changes.

The example of dynamic compilation is applied to a wage system. See the figure.

There are several ways to parse the formular formula for wages. Here we use a dynamic compilation method. Think of every wage item as a class attribute, and put the content of formular into a method, calculate the job as an expression, apply the reflection, and return the values of each attribute.
Public class formularcalculation
{
Public static object build (string [] items, string formular)
{
String namespace = "";
String classname = "formularcalculation ";
String methodname = "run ";
Csharpcodeprovider compiler = new csharpcodeprovider ();
Compilerparameters paras = new compilerparameters ();
Paras. generateexecutable = false;
Paras. generateinmemory = true;

Stringbuilder classsrc = new stringbuilder ();
Classsrc. append ("using system;" + environment. newline );
Classsrc. append ("namespace" + namespace + "{" + environment. newline );
Classsrc. append ("public class" + classname + "{" + environment. newline );
Foreach (string item in items)
{
Classsrc. append ("Public decimal" + item + ";" + environment. newline );
}
Classsrc. append ("Public void run () {basic salary = 5000;" + environment. newline );
String [] format = RegEx. Split (formular, environment. newline );
Foreach (string prop in format)
{
Classsrc. append (prop + ";" + environment. newline );
}
Classsrc. append ("}" + environment. newline );
Classsrc. append ("}" + environment. newline );
Classsrc. append ("}" + environment. newline );
String source = classsrc. tostring ();

Compilerresults result = compiler. compileassemblyfromsource (paras, source );
Compilererrorcollection error = result. errors;
Assembly = result. compiledassembly;
Object EVAL = assembly. createinstance (namespace + "." + classname );
Methodinfo method = eval. GetType (). getmethod (methodname );
Object reobj = method. Invoke (Eval, null );
Return eval;
}
}
The call method is as follows:
String [] items = {"total payable", "basic salary", "bonus", "Welfare fee", "total fee deduction", "Social Security", "Tax ", "Real-Time total", "taxable income "};
String formular = @ "total amount = basic salary + bonus + Welfare fee-total fee deduction;
Total fee deduction = Social Security + Tax + taxable income;
Total real-time payment = total amount to be issued-total fee deduction ;";
Object OBJ = formularcalculation. Build (items, formular );
Type type = obj. GetType ();
Foreach (propertyinfo fi in type. getproperties (bindingflags. nonpublic | bindingflags. Public
| Bindingflags. instance | bindingflags. declaredonly ))
{
String value = Fi. Name; // obtain the calculated values of each attribute.
}
Dynamic compilation is also applied to software encryption, and the encryption program is generated in the memory. Source code , Dynamically compile and run, and check whether it complies with the license authorization.

3 ORM (Nhibernate, llbl Gen) object relationship ing

Although we can find many reasons to reject the Orm, such as poor performance, poor interface, and no Nhibernate designer, yes, this is all the reason. However, once I have been familiar with Orm, I find that this tool is no longer necessary for system creation. Compared with ERP/MIS systems, most of the time it is struggling with SQL read/write. Orm brings you several benefits that cannot be ignored.
1) to add or delete database fields, there is almost no need to change the interface and program. I agree with this. Even a very stable system cannot avoid customization. You also need to add some fields. If you use SQL to piece together, you need to change almost all relevant content, in addition, the benefits of the compiler syntax check cannot be obtained. during compilation, the orm can detect some Type Mismatch problems.
2) The real separation between the interface and logic changes the computing logic without modifying the interface, that is, implementing the MVC and MVP modes. In fact, we can skip these two modes, we are only Using ORM to read and write databases.
3) code is more elegant, debugging is easier, and maintenance is convenient.

After the LINQ technology, Microsoft has made great efforts to develop the Entity Framework, which is not recommended for use in projects. The advantage of MS is that it finds a technology useful, or develops a very effective tool, and eventually it will do well, such as Visual Studio and office, but it takes time, it must constantly learn, observe, and improve things, especially those such as APIs. If it is updated too quickly, it will pose a great risk to the project, A stable API is most needed in a project. Ms intends to give up something, which will gradually reduce resources and the number of followers. After a long time, it will fade out the developers' sight.
After years of development, nhib.pdf is stable, easy to use, and has a huge JavaCommunity(Hibernate) support, there is no answer to the problem.

4. workflow Workflow

At present, Microsoft has released two versions of workflow. Net 3.5 and. Net 4.0, which should be regarded as two products, not a simple version upgrade.

Common requirements in the ERP/MIS field are:
1) procurement order approval (if conditions are met) requirements:

If the amount is greater than or equal to 500 and the buyer is a, you must approve the request by May.

When the amount is greater than or equal to 500 and the buyer is B, Jack must approve the request.

If the amount is less than 500, you can post the post directly without approval.
2) When the project changes ECN, notify the production department to reschedule the plan and notify the warehouse to arrange the delivery of materials.
For such types of requirements, each enterprise has different requirements. To achieve the purpose of customization, you do not want to write code separately for different customers, and workflow is not required. You can customize code for different customers without using a workflow.
Ms workflows are also made into middleware, and you need to override as much as possible

Please refer to "Information Infrastructure workflow development" to learn more about workflows.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.