Plug-in web framework

Source: Internet
Author: User

Reprint build high-performance plug-in web framework

Based on the MVC plug-in pattern, a Web framework system supporting database cluster, data real-time synchronization, data publication and subscription is built. Such as:

1, based on plug-in development

The advantage of using plug-in pattern development is that the system framework and business model are effectively separated, and the system update is simple, just update the business plug-in, do not need to move the entire framework, the developers need not care about the entire framework structure.

But plug-in mode debugging is a bit more cumbersome than the efficiency of not using plug-in mode development, because it uses reflection to dynamically load plug-ins.

Login Plugin Example:

Namespace loginplugin{public class Plugin:NetUML.Portal.Framework.AbstractPlugin {public Plugin () {this.            Title = "System login"; This.        Description = "Login Plugin";            } public override string Name {get {return ' Loginplugin ';}            set {}} public override int Startlevel {get {return 2;}        set {}} public override void Start (NetUML.Portal.Framework.IBundleContext context) {} public override void Stop (NetUML.Portal.Framework.IBundleContext context) {} public override Strin        G SymbolicName {set {} get {return ' System.login ';}        } public override list<netuml.portal.framework.menuitem> MenuItems {get {return null;}                } public override NetUML.Portal.Framework.PluginType Plugintype {get { RetUrn NetUML.Portal.Framework.PluginType.Login;            }} public override string Title {get;        Set            } public override string Description {get;        Set }    }}

All plugins must implement NetUML.Portal.Framework.AbstractPlugin this plugin abstract class.

The Start method is executed when the plug-in is loaded, and the Stop method is executed when the plug-in is stopped.

2. Database Engine

Database engine Netuml.dataengine class, using the ibatisnet underlying Access database principle, dynamic creation of idbconnection connection pool, the core code is as follows

  1 namespace Netuml.dataengine 2 {3 public class Dbsession:marshalbyrefobject, Idalsession 4 {5 6  #region Fields 7 Private IDataSource _datasource = null;  8 private bool _istransactionopen = false; 9 private bool _consistent = false; Ten private IDbConnection _connection = null; One private idbtransaction _transaction = null; #endregion public dbsession (IDataSource dataSource) {_datasource = Dataso Urce;  20} public IDataSource DataSource {+ get {return _datasource;         Public System.Data.IDbConnection Connection $ {25 get {return _connection;}  } The public System.Data.IDbTransaction Transaction {get {return _transaction; } The public bool Istransactionstart, {_istran get {returnSactionopen;          } + + private bool Consistent PNS {$ set {_consistent = value;} 39} 40 public void complete (). consistent = true; * OpenConnection () (). OpenConnection (_datasource.connectionstring);  OpenConnection (String connectionString) (_connection = =  NULL) createconnection (connectionString); 55 { _connection. Open (); //if (_logger. isdebugenabled)//{//_logger. Debug (String. Format ("Open Connection \" {0}\ "to \" {1}\ ".", _connection. GetHashCode (). ToString (), _datasource.dbprovider.description));               +/} (Exception ex) 63  {//datamapperexception new Exception (string. Format ("Unable to open connection to \" {0}\ ".", _datasource.dbprovider.description), ex); (_connection). state! = ConnectionState.Open) tion. Open (); //if (_logger. isdebugenabled)//{//_logger. Debug (String. Format ("Open Connection \" {0}\ "to \" {1}\ ".", _connection. GetHashCode (). ToString (), _datasource.dbprovider.description));                     (Exception ex) 79 {80 throw new Exception (string. Format ("Unable to open connection to \" {0}\ ".", _datasource.dbprovider.description), ex);      Bayi} createconnection () 85   {createconnection (_datasource.connectionstring); +//<summary> 89 Create the connection//</summary> public void CreateConnection (string connectionString _connection = _datasource.dbprovider.createconnection (); 94 _connection. ConnectionString = ConnectionString;  CloseConnection () 98 {if (_connection! = null) && (_connection. state = connectionstate.closed)) {101 _connection. Close (); 102//if (_logger. isdebugenabled) 103//{104//_logger. Debug (String. Format ("Close Connection \" {0}\ "to \" {1}\ ".", _connection. GetHashCode (). ToString (), _datasource.dbprovider.description));//}106 _connection. Dispose (); 107}108 _connection = null;109}110 111        public void BeginTransaction (), 113 this. BeginTransaction (_datasource.connectionstring);}115 N/a public void BeginTransaction (string connection String) 117 {118 if (_connection = = NULL | | _connection. state = ConnectionState.Open) 119 {. OpenConnection (connectionString); 121}122 _transaction = _connection. BeginTransaction (); 123//if (_logger. isdebugenabled) 124//{125//_logger. Debug ("Begin Transaction."); 126//}127 _istransactionopen = true;128}129 public void BeginTransaction (bool op enconnection) 131 if (OpenConnection) 133 this. BeginTransaction (); 134}135 else136 {137 if (_connection = null | | _c Onnection.              State = ConnectionState.Open) 138 {139       This. OpenConnection ();}141 _transaction = _connection. BeginTransaction (); 142//if (_logger. isdebugenabled) 143//{144//_logger. Debug ("Begin Transaction.");  145//}146 _istransactionopen = true;147}148}149 public void BeginTransaction (System.Data.IsolationLevel isolationlevel) {151 this. BeginTransaction (_datasource.connectionstring, IsolationLevel);}153 public void BeginTransaction (Strin G connectionString, System.Data.IsolationLevel IsolationLevel) 154 {155 if (_connection = null | | _con Nection. state = ConnectionState.Open) 156 {157 this. OpenConnection (connectionString); 158}159 _transaction = _connection. BeginTransaction (IsolationLevel);//if (_logger.  isdebugenabled) 161//{162//  _logger. Debug ("Begin Transaction."); 163//}164 _istransactionopen = true;165}166 public void BeginTransaction (bool op Enconnection, System.Data.IsolationLevel IsolationLevel) 167 {168 this. BeginTransaction (_datasource.connectionstring, OpenConnection, IsolationLevel); 169}170 public void BeginT             Ransaction (string connectionString, bool OpenConnection, System.Data.IsolationLevel IsolationLevel) 171 {172 if (openconnection) 173 {174 this.                 BeginTransaction (connectionString, IsolationLevel); 175}176 else177 {178 if (_connection = = NULL | | _connection. state = ConnectionState.Open) 179 {//datamapperexception181st Row new Exception ("Sqlmapsession could not invoke StartTransaction (). A Connection must be started. Call OpenConnection () first. "); 182}1_transaction = _connection. BeginTransaction (IsolationLevel); 184//if (_logger. isdebugenabled) 185//{186//_logger. Debug ("Begin Transaction.");  187//}188 _istransactionopen = true;189}190}191 public void CommitTransaction () 192 {193//if (_logger. isdebugenabled) 194//{195//_logger. Debug ("Commit Transaction."); 196//}197 _transaction.commit (); 198 _transaction. Dispose (); 199 _transaction = null;200 _istransactionopen = false;201 202 if (_connecti On. State = connectionstate.closed) 203 {204 this.         CloseConnection (); 205}206}207 208 public void CommitTransaction (bool closeconnection) 209 {closeconnection) 211 {212 This.committransaction (); 213}214 else215 {216//if (_logger. isdebugenabled) 217//{218//_logger. Debug ("Commit Transaction."); 219//}220 _transaction.commit (); 221 _transaction.         Dispose (); 222 _transaction = null;223 _istransactionopen = false;224}225 }226 227 public void RollbackTransaction () 228 {229//if (_logger. isdebugenabled)//{231//_logger. Debug ("RollBack Transaction."); 232//}233 _transaction. Rollback (); 234 _transaction. Dispose (); 235 _transaction = null;236 _istransactionopen = false;237 if (_connection.s Tate! = connectionstate.closed) 238 {239 this. CloseConnection ();}241}242 243 public void RollbackTransaction (bool CloseconnectiON) 244 {245 if (CloseConnection) 246 {247 this. RollbackTransaction (); 248}249 else250 {251//if (_logger. isdebugenabled) 252//{253//_logger. Debug ("RollBack Transaction."); 254//}255 _transaction. Rollback (); _transaction.         Dispose (); 257 _transaction = null;258 _istransactionopen = false;259}260 262 Public IDbCommand CreateCommand (CommandType commandtype) 263 {}261 IDbCommand comma nd = _datasource.dbprovider.createcommand (); 265 command.commandtype = commandtype;266 command.                 Connection = _connection;267 if (_transaction! = null) 268 {269 try270 {271 command. Transaction = _transaction;272}273 CATCh274 {}275}276 if (_connection! = null) 277 {278 Try2 280 command.commandtimeout = _connection.                     connectiontimeout;281}282 catch (NotSupportedException e) 283 {284 if (_logger. isinfoenabled) 285//{286//_logger.         Info (e.message); 287//}288}289}290 return command;291 }292 293 public System.Data.IDbDataParameter createdataparameter () 294 {295 return _DATASOURC         E.dbprovider.createdataparameter (); 296}297 public System.Data.IDbDataAdapter createdataadapter () 298 {299 return _datasource.dbprovider.createdataadapter ();}301 public System.Data.IDbDataA         Dapter createdataadapter (System.Data.IDbCommand command) 302 {303    IDbDataAdapter DataAdapter = null;304 DataAdapter = _datasource.dbprovider.createdataadapter (); 305 Dataadapter.selectcommand = command;306 return dataadapter;307}308 public void Dispose () 309 {310//if (_logger. isdebugenabled) 311//{312//_logger.                 Debug ("Dispose sqlmapsession"); 313//}314 if (_istransactionopen = = false) 315 {316 if (_connection. State = connectionstate.closed) 317 {318 this. CloseConnection (); 319}320}321 else322 {323 if (_cons Istent) 324 {325 this.                 CommitTransaction (); 326 _istransactionopen = false;327}328 else329 {_connection. State = connectionstate.closed) 331 {332                         This.                 RollbackTransaction (); 333 _istransactionopen = false;334}335 }336}337}338}339}

Program structure such as:

3. Database Cluster service

Netuml.dataengine support multi-database connection, host database read and write separation operation, which data tables need to read and write separation can be configured and management, similar to the concept of MVC in the route, we can configure multiple routing table, the routing table content includes the number

According to the table name, the data object keyword and the database information, when the user saves the data, the system looks for the route according to the data table and data object to be saved, then submits to the database according to the configuration information in the route.

Into the development of .....

4. Data synchronization, publishing and subscription services

If the third-party system is connected to the current system, the data in the current system changes, need to immediately notify the incoming system, the change of data submitted to the third-party system, third-party system access to the data for the corresponding processing.

The third-party system only needs to provide a URL address to the current system, and the current system posts the data to the URL address.

Into the development of .....

5, plug-in management

System Framework support upload plug-in package, do not need to the server to update the program, after uploading the plug-in package, the system automatically extract the plug-in package, to dynamically compile loading plug-ins.

The system framework also supports stopping and uninstalling plugins. Such as:

6. Massive documents + Full-Text Search plugin

Document management plug-in supports online browsing and file conversion of documents such as office, converting documents to HTML files, supporting full-text parsing and full-text search capabilities

Into the development of .....

7, the public account of the custom-made plug-in

Into the development of .....

8, to be continued .....

  

Category:. Net

Plug-in web framework

Related Article

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.