Sofire suite is a suite developed by individuals starting in August 2009. After several years of continuous optimization and improvement, from the initial v suite to sofire2011 to the current sofire. V1.0, sofire has experienced many project tests and accomplished its mission well. Now, I refactor this set of components,
Try to make it the underlying preferred choice for any platform, framework, and suite . With the spirit of open source, I hope this set of components will continue to grow and mature in the discussion of bloggers.
So what does sofire. V1.0 contain?
: Sofire. V1.0-120604
1. Database Access (sofire. Data)
2. Fast dynamic reflection (sofire. Dynamic)
3. Efficient and brief binary serialization (sofire. serialization. binarysuite)
4. Remote Object Mode (sofire. datacomm. Remote)
5. Secure and Efficient socket (sofire. datacomm. Net)
6. aspect-oriented (sofire. AOP)
7. Because the first port of sofire V1.0 has not been fully transplanted yet.
Previous Article
Next to the previous article, "sofire V1.0 open source -- remoting (1) of winform/SL/webform".
This article describes how to use sofire. Data to perform operations on various databases in the underlying development of the sofire framework. It seems to be a comprehensive encapsulation of ADO. net.
Of course, sofire. the key to which data supports databases is implementation, rather than "not support". Theoretically, all databases are based on ADO. net databases are all supported, while other databases are also partially supported.
Currently, supported databases include MSSQL, Oracle, Oracle, ddtekoracle, oledb, and SQLite. Other databases (such as MySQL) are not currently supported because they are not used in my project. If you want to support other databases, inherit sofire. Data. queryenginebase.
The Framework stipulates that any function has the returned content. In the framework development process, all public functions should have a return description. For example, some functions that process a service may write the following code:
Public datatable gettotalreport (string username, datetime begin, datetime end) {// processing process... return New datatable ();}
Of course, this does not mean that such writing is good or bad. Instead, we recommend that you encapsulate the return values of the function. For example, I can:
Public result <datatable> gettotalreport (string username, datetime begin, datetime end) {try {// processing process... return new datatable () ;}catch (exception ex) {return ex ;}}
With this Convention, You can explicitly tell the function caller that this function returns a value, but this operation function may return an error.
Return description for better processing
If you encounter an operation function with returned content, you can process the returned results in this way.
Public void test () {var r = This. gettotalreport ("A", datetime. now, datetime. now); If (R. issucceed) {datatable table = R. value;} else {exception EX = R. exception ;}}
SimpleCode, Indicating that the return value has the "correctness" of the function operation result, and provides detailed error information. The following is the iresult interface ):
/// <Summary> /// indicates a result (interface ). /// </Summary> Public interface iresult {# region properties /// <summary> // get the error that occurs during execution. /// </Summary> exception {Get;} /// <summary> // obtain a value, indicating whether the execution result is failed. /// </Summary> bool isfailed {Get ;}/// <summary> /// obtain a value indicating whether the execution result is ignored. /// </Summary> bool isignored {Get ;}/// <summary> // obtain a value, indicating whether the execution result is successful. /// </Summary> bool issucceed {Get ;}/// <summary> /// obtain the execution status. /// </Summary> resultstate state {Get ;}# endregion properties # Region Methods /// <summary> /// specify the error message to switch the current result to the failed State. /// </Summary> void tofailded (exception); // <summary> // specify the error message to switch the current result to the failed State. /// </Summary> void tofailded (string exceptionmessage); // <summary> // switch the current result to the ignored status. /// </Summary> void toignored (); // <summary> // switch the current result to a successful state and clear the error message of the result. /// </Summary> void tosuccessed (); // <summary> // indicates a result, which is verified against the current result. If <paramref name = "result"/> is an error result, the current result is converted to an error state. Otherwise, the status of <paramref name = "result"/> is changed. /// </Summary> /// <Param name = "result"> comparison result. </Param> /// <returns> Returns a value indicating whether the result is successful. </Returns> bool checking (result); # endregion Methods} // <summary> // indicates the result (Interface) that contains a returned value ). /// </Summary> /// <typeparam name = "tvalue"> type of the returned value. </Typeparam> Public interface iresult <tvalue>: iresult {# region properties /// <summary> /// set or obtain the return value of the result. If the result is not successful, the default value is returned. /// </Summary> tvalue {Get; Set ;}# endregion properties # Region Methods /// <summary> // switch the current result to a successful state, and clear the error message of the result. /// </Summary> /// <Param name = "value"> the value returned by the result. </Param> void tosuccessed (tvalue value); // <summary> // indicates a result, which is verified against the current result. If <paramref name = "result"/> is an error result, the current result is converted to an error state. Otherwise, the status of <paramref name = "result"/> is changed. /// </Summary> /// <Param name = "result"> comparison result. </Param> /// <Param name = "value"> return value when the status is successful. </Param> /// <returns> Returns a value indicating whether the result is successful. </Returns> bool checking (result, tvalue value); # endregion Methods} // <summary> // indicates the result (Interface) that contains two returned values ). /// </Summary> /// <typeparam name = "tvalue1"> type of the first return value. </Typeparam> // <typeparam name = "tvalue2"> type of the second return value. </Typeparam> Public interface iresult <tvalue1, tvalue2>: iresult {# region properties /// <summary> // sets or obtains the first return value of the result. If the result is not successful, the default value is returned. /// </Summary> tvalue1 value1 {Get; Set ;}/// <summary> // sets or obtains the second return value of the result. If the result is not successful, the default value is returned. /// </Summary> tvalue2 value2 {Get; Set ;}# endregion properties # Region Methods /// <summary> // switch the current result to a successful state, and clear the error message of the result. /// </Summary> /// <Param name = "value1"> the first return value of the result. </Param> /// <Param name = "value2"> the second return value of the result. </Param> void tosuccessed (tvalue1 value1, tvalue2 value2); // <summary> // indicates a result, which is verified against the current result. If <paramref name = "result"/> is an error result, the current result is converted to an error state. Otherwise, the status of <paramref name = "result"/> is changed. /// </Summary> /// <Param name = "result"> comparison result. </Param> /// <Param name = "value1"> the first returned value when the status is successful. </Param> /// <Param name = "value2"> the second return value when the status is successful. </Param> /// <returns> Returns a value indicating whether the result is successful. </Returns> bool checking (result, tvalue1 value1, tvalue2 value2); # endregion Methods}
How is the sofire. Data database connected?
All Database implementations of sofire. Data are derived from sofire. Data. queryenginebase and can be quickly supported by several abstract implementations.
Public void dataconnect () {string connectionstring = ""; oraclequery = new oraclequery (connectionstring ); // Microsoft does not recommend using this method to connect to Oracle ddtekoraclequery oledbquery = new ddtekoraclequery (connectionstring); mssqlquery = new mssqlquery (connectionstring); oledbquery = new oledbquery (connectionstring ); sqlitequery = new sqlitequery (connectionstring); // derived base class Q The ueryenginebase extension can support more databases. }
How is the database queried?
Database Query
Public void execute () {string connectionstring = ""; int uid = 1; ddtekoraclequery oraclequery = new ddtekoraclequery (connectionstring); tableresult R1 = oraclequery. executetable ("select * from users where uid =: uid", "uid", UID); If (r1.issucceed) {datatable table = r1.value ;} sqlquery mssqlquery = new sqlquery (connectionstring); tableresult r2 = mssqlquery. executetable ("select * from users where uid = @ uid", "@ uid", UID); If (r2.issucceed) {datatable table = r2.value ;}}
Of course, the Demo code above only returns a table. For more support, see
Due to this year's working relationship, I have frequent access to Oracle. sofire. Data has gradually developed support for Oracle. For example, it supports multi-line executenoquery and supports cursor parameters.
Private result test1 () {// ">" indicates that this is a stored procedure, or Program Package // pkg_flow_name.up_getflownamebyid returns a cursor parameter. VaR tableresult = query. executetable ("> pkg_flow_name.up_getflownamebyid", new executeparameter ("v_fid", 111, dbtype. varnumeric), query. createcursor ("C"); If (tableresult. issucceed) {console. writeline (tableresult. value. rows. count);} return tableresult;} private result Test2 () {var noqueryresult = query. executenoquery (@ "begin insert into Table1 select * from XXX; insert into Table2 select * from XXX; insert into table3 select * from XXX; insert into table4 select * from XXX; end; "); If (tableresult. issucceed) {console. writeline (tableresult. value. rows. count);} return tableresult ;}
Conclusion
Due to the time relationship (recent job changes), the most important component is the database component of this framework, which is not detailed. Next, you may explain the advanced section of sofire. data. For example, if you support events before and after a query, the query results are automatically converted to objects/sets. However, this kind of code-based things is indeed difficult to read, and it also makes me very confused.
Well, it seems that many people want to think that my blog has a good skin? In fact, this blog is a referenceLi baoheng DarenHe is very grateful for his skin (he is a green version, I am a blue version ).
I am very lazy, but if you encounter any problems or have any suggestions in using this set of components, you can leave a message on the blog and I will reply in time. The source code has been updated. Upload later.