Friday, September 12, 2008

Index

1. Anthem.Net

Anthem.Net is a solution for MS.Net application using Ajax. Different from MS Ajax 1.0, which uses update panel callback and refresh unit, Anthem.Net wraps all MS.Net web controls so that they make call backs rather than post backs as designed by default, and it refreshes the content of each single control with the result of it's render method.


Among its features, I mostly like the following features:
PreCallBackFunction - a javascript function or method called before callback function is called.
PostCallBackFunction - a javascript function or method called after callback function is called.
Anthem_InvokePageMethod(methodName:string) - a javascript function calls a .Net backend method.
Makes it very flexible and easy for html page to use javascript communicate with backend ASP.Net code .

e.g.
<script type="javascript">
Anthem_InvokePageMethod("BindData");
</script>

is to refresh/rerender DataGrid control on the page by a callback to the BindData backend method.

[Anthem.Method]
public void BindData()
{
dataGrid.DataSource = ...
dataGrid.Bind();

}



2. Generic way of showing user-friendly exceptions - ErrorHandler - the solution is with a user control.

3. Maintain Access proviliges for the Web application
To setup privileges for a web application, you need to clarify users, functions and their relations.

Role is a group of users who are similar in such a way that they share same privileges. Role just helps to simplify the process of granting accessibility to users.

Surely, you also can group functions to achieve the same objective. In a web application, functions are actually pages.


4. Lightweight update Cache and Session
Generally, aspx pages have a heavy viewstate. this makes callback "heavy-weight". because viewstate is going along with callbacks.
In the case of just changing state, updating cache or session for example, viewstate is not useful for the job, you can make a "light-weight" call by calling to a designated page, which has nothing on the page but the code of logic hooked to the Page_Load event.

The following is a demonstration of this idea:




5.Implement Business layer and unified way of communication between presentation and business logic layers

5.1 Define DataSets
5.2 Parameter class
5.3 Initialization of the header
5.4 Load and transfer dataset
(a DTO includes header , passing-in parameters and return dataset three parts)

6. The base page - Template.cs
A base page is a class that extracts the commonalities of a set of pages, if not all, that inherit from it. It is a abstraction effort to page development. Abstraction is a very important tool that simplifies coding, eliminates duplication and improve code maintainability.

It is one of the most important of OO modeling technics.

In following example, base page includes the logic of accessing user information and authentication logic, because all pages need to check if a user has the privileges to access it.





7. Unified way of handling page-level exceptions

8. Handle application level exceptions and authentication with global.asax

9. Implementing DAL

DAL code is depending on datasource. connection string, sqlParameter SqlCommand and so forth. these types comes from ADO.Net are datasource specific.

The task of our application DAL is to decouple data access logic from business logic. this makes the upper layer datasource independant.

what's in and what's out?
The request to DAL could be very flexible. There is no way to enumerate all of them without business layer clearly defined.

By knowing this, you understand the way to implement DAL is a iterative, evolving process. No sing big bang for it.

Another point that has to be made is that the output of DAL is a set of data objects to be used by business layer. So the types of these data objects is the protocol between BL and DAL, both have reference to tjem. These data types are refered as model Layer, because it includes all business entities. It defines the boundary or scope or the application.



10. Using Action diagram to demonstrate presentation logic and business logic
In an event-driven paradigm, to develop a page is coding for event handlers. For a Asp.Net page , there are two types of handlers:

(1) Page_Load event. It happens the first time of a page is requested.
(2) Postback and Callback events

The first case, you need to implement events in the page level, usually page_load, page_init etc...
usually, the page_load handler.

*some code, you don't want to execute if the request is a postback or callback, it is just easy, because Page object already wrapped the status value.

If(IsPostBack)
{
...
}

The second case, a web control usually has a postback or call back event which hooks up with its handlers.
the following diagram shows Page_Load event process.

figure 1: Page_Load event process

figure 2: Presentation logic of Rejection button



11. Application Prototyping

First visual impression is always important for one to decide or refuse. When starting a project, the stake holder wish to have a look at what the application is going to be. Prototyping is a commonly used approach to do this. Prototyping is also very useful in communication between business people and technical folks. BA and Technical lead work closely to get protyping done. it shows in the BRD - Business Requirement Document.


It includes:
(1) The drawing of a page in terms of html controls or other extended controls with javascript
(2) The data to populate above controls if it is not used for collecting input from user
(3) The behavior: represent the relationship between those controls for example, when select a different item from a list, a text box refresh with different content.
(4) For search criteria, you also need define matching logic

figure 3-6 shows sample documents.


12. Dynamic Javascript

13. Implement submodal popup

14. Authentication Logic



------------------------------------------------------------
Attachments:

1. Code snippets

Global.cs ... global.asax, application level setting, exception, authentication etc.
Page_Error ... in base page, generic way to handle page level exeption
LightweightCallback ... call back with AJAX to update backend Cache, Session and other state info
DTOClass ... Generic object to transfer between presentation and business logic layers, handle exception messages
Athem.Button ... Anthem wrapper for ASP button
Anthem.GridView ... Anthem wrapper for ASP GridView
Anthem Interface ... interface used in Anthem
Anthem.js ... Anthem javascript library
Table schema for security
Use Relationship in DataSet
Submodal.js
submodal.css
securityLogic.cs
dynamicJavascript.cs


2. Figures

Figure 1: Page_Load event process
Figure 2: Presentation Logic for Settlement Rejection Button
Figure 3: Settlemement Verify Summary Page Prototype
Figure 4: Fields Defination of a Page Prototype
Figure 5: Data Column Definition for a Page Prototype
Figure 6: Search Maching Criteria Definition for a Page Prototype
Figure 7: Table Schema for Security
Figure 8: AssemblyOfDTOs - the assembly of DTOs

No comments: