Project in design mode-permission management system

Source: Internet
Author: User
• This system is a role-controlled permission management system based on the B/S model architecture. The system is developed by me and CAPTCHA. The development tool is. net2003, With the development language C #, can be used for unified permission management of comprehensive websites. Based on the needs of the solution, the following five design modes are used: • Abstract Factory design modes are used to support access to different databases • to generate a single factory, use a single-piece design model • provide users with a unified high-level interface, encapsulate business logic, and use a design model • to achieve different user needs for password encryption, policy mode: The subsystem uses this permission system and does not need to integrate the system. It directly uses the WebService provided by the system for access and uses the proxy mode for loose coupling. Class model diagram database model Diagram

Overall structure of the permission management system
The system is an N-layer model extended based on the classic three-layer mode. The web layer is the user interface layer, which deals with users. The bllfacade layer is the business logic appearance layer, A high-level interface is defined. The web layer only needs to call the simple interface provided by this layer; The bll layer is the business logic layer, and the core business logic code is in this module; the idal layer is the data access object interface layer, which provides consistent data access interfaces for the BLL layer, namely the business logic layer. The oracledal layer is the Oracle Database Access Object layer, which implements all interfaces on the idal layer; the sqlserverdal layer refers to the object Layer for access to the sqlserver database, implementing all interfaces of the idal layer; the model layer refers to the data entity layer; the utility layer refers to the general tool class layer, which is equivalent to a toolkit;

The following component diagram shows the call relationship of each project.

In this system, the data access objects to be created include users, userroles, roles, rolepowers, powers, and categories. In the design, these objects have been abstracted as the corresponding interfaces, and their implementations vary according to the database. ... That is to say, the created object has multiple categories, and each category has different implementations. This is a typical application scenario of the abstract factory model. The abstract factory model can be used to solve the problem. The following figure shows the standard abstract factory pattern class: using system; namespace powermanage
{
/// <Summary>
/// Abstract Factory design mode, which uses the singleton Design Mode
/// </Summary>
Public abstract class dalfactory
{
Private Static dalfactory instance = NULL;
Private Static readonly string dbprovider = system. configuration. configurationsettings. deleettings ["dbprovider"];
// The constructor is a protection function to ensure that there is only one instance in the abstract work.
Protected dalfactory ()
{
}
// Obtain the unique instance of the abstract Project
Public static dalfactory getinstance ()
{
If (instance = NULL)
{
Switch (dbprovider)
{
Case "sqlserverdb ":
Instance = new sqlserverdalfactory ();
Break;
Case "oracledb ":
Instance = new oracledalfactory ();
Break;
Default:
Instance = new sqlserverdalfactory ();
Break;
}
}
Return instance ;}
// Create the categories data layer interface
Public abstract powermanage. idal. icategories createcategories ();
// Create a powers data layer interface
Public abstract powermanage. idal. ipowers createpowers ();
// Create a rolepowers data layer interface
Public abstract powermanage. idal. irolepowers createrolepowers ();
// Create a roles data layer interface
Public abstract powermanage. idal. iroles createroles ();
// Create the userroles data layer interface
Public abstract powermanage. idal. iuserroles createuserroles ();
// Create the users data layer interface
Public abstract powermanage. idal. iusers createusers ();
}
}

Oracle Database Access Object factory public class export ledalfactory: dalfactory {// create categories data layer interface public override powermanage. idal. icategories createcategories () {return New powermanage. oracledal. categories ();}..................} Sqlserver Database Access Object factory public class sqlserverdalfactory: dalfactory {// create categories data layer interface public override powermanage. idal. icategories createcategories () {return New powermanage. sqlserverdal. categories ();}..................}

For example, The bll layer creates the SQL Server database's users object as follows: dalfactory factory = new dalfactory. getinstance ();
Private Static readonly iusers users = factory createusers ();

After the permission management system has deployed the database, once the program is executed, the data access factory must be determined, the Singleton design mode shows you how to create a global object for a unique class instance in your application. That is to say, this object can only be instantiated once, this object also provides a global access point to access it. The Data Access factory can only be instantiated once. The following figure shows the standard single-piece mode: Policy mode // <summary>
/// Encryption Policy Interface
/// </Summary>
Public interface encryptstrategy
{// Encrypt the string
String encrypting (string source, string key );
/// <Summary>
/// Decrypt the key of the string
/// </Summary>
String decrypting (string source, string key );
} Appearance Mode

Proxy mode using system. diagnostics;
Using system. xml. serialization;
Using system;
Using system. Web. Services. Protocols;
Using system. componentmodel;
Using system. Web. Services;
/// <Remarks/>
[System. Diagnostics. debuggerstepthroughattribute ()]
[System. componentmodel. designercategoryattribute ("Code")]
[System. Web. Services. webservicebindingattribute (name = "usersoap", namespace = "http://tempuri.org/")]
Public class webserviceuserproxy: system. Web. Services. Protocols. soaphttpclientprotocol
{

/// <Remarks/>
Public webserviceuserproxy ()
{
This. url = "http: // localhost/web/service/user. asmx ";
}

/// <Remarks/>
[System. web. services. protocols. soapdocumentmethodattrispace ("http://tempuri.org/Login", requestnamespace = "http://tempuri.org/", responsenamespace = "http://tempuri.org/", use = system. web. services. description. soapbindinguse. literal, parameterstyle = system. web. services. protocols. soapparameterstyle. wrapped)]
Public String login (string username, string password, string category)
{
Object [] Results = This. Invoke ("login", new object [] {
Username,
Password,
CATEGORY });
Return (string) (results [0]);
}

/// <Remarks/>
Public System. iasyncresult beginlogin (string username, string password, string category, system. asynccallback callback, object asyncstate)
{
Return this. begininvoke ("login", new object [] {
Username,
Password,
CATEGORY}, callback, asyncstate );
}

/// <Remarks/>
Public String endlogin (system. iasyncresult asyncresult)
{
Object [] Results = This. endinvoke (asyncresult );
Return (string) (results [0]);
}

/// <Remarks/>
[System. web. services. protocols. soapdocumentmethodattrispace ("http://tempuri.org/CheckPower", requestnamespace = "http://tempuri.org/", responsenamespace = "http://tempuri.org/", use = system. web. services. description. soapbindinguse. literal, parameterstyle = system. web. services. protocols. soapparameterstyle. wrapped)]
Public String checkpower (string username, string password, string category, string power)
{
Object [] Results = This. Invoke ("checkpower", new object [] {
Username,
Password,
Category,
Power });
Return (string) (results [0]);
}

/// <Remarks/>
Public System. iasyncresult begincheckpower (string username, string password, string category, string power, system. asynccallback callback, object asyncstate)
{
Return this. begininvoke ("checkpower", new object [] {
Username,
Password,
Category,
Power}, callback, asyncstate );
}

/// <Remarks/>
Public String endcheckpower (system. iasyncresult asyncresult)
{
Object [] Results = This. endinvoke (asyncresult );
Return (string) (results [0]);
}
}

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.