Use isline framework to Develop ASP. net programs 3-use dataprovider to access data (below)

Source: Internet
Author: User

The previous section introduced the operations on SQL Server and Oracle databases in dataprovider. This section describes the file system support.

Dataprovider not only supports SQL Server and Oracle operations, but also supports file operations. Currently, files in Built-in 3 Support objects such as XML, text, and config, which are located in the xmlprovider, textprovider, and suitconfigprovider class libraries. You can call them by yourself. Most file operations use static operations.

1. operations on the config file

Here we also introduce the getitem, getsection, appenditem, and removeelement methods in the suitconfigprovider class library. item and node content in config, and add or remove nodes. For example, the following item information is displayed:

<Add key = "nameabc" value = "test"/>

Use the suitconfigprovider. getitem ("nameabc") statement to obtain the content of this item immediately. The methods in the suitconfigprovider class are implemented as static and can be called directly.

2. Operations on text files:

Many projects require operations on text files, which may involve file creation, content appending, and deletion. These operations are encapsulated in the isline class library, users can conveniently call methods to implement these functions. The isline class library automatically performs error judgment, resource optimization, and other operations. The method is described as follows:

● Static string getcontent (string fileinfo): This method has two reloads to obtain the file content.

● Static bool createfile (string fileinfo): This method creates a file. The parameter is the file path and file name.

● Static bool appendfile (string STR, string fileinfo): This method has two reloads to append the file content.

The above methods are very common and have been optimized. For example, when the user calls the appendfile method, the isline class library will automatically determine whether the operated file exists, if the object does not exist, a file is created first, and content is appended. This avoids errors caused by the absence of the file.

3. xml file operations:

You can write XML files.ProgramThis is the most commonly used file. It is favored by a concise structured system. The isline class library encapsulates the daily operations on such files. The following is a list of methods.

● Static list

● Static bool createfile (string singlenode, string fileinfo): This method creates a file, and the input file is the file path and root node name.

● Static bool appendfile (string singlenode, string element, list

In addition, some support information can be used in Web. config to configure dataprovider. These configurations determine the location of the database factory used for reflection and multi-database connection information.

The supported information (select Configuration) is as follows:

Key name: isline. provider. dataprovider. cfgdllname

Role: Location of the reflected database factory DLL

Key name: isline. Security. configuration. tokenkey

Role: The seed used for encryption (string)

Key name: isline. Data. configuration. dbconnectstring

Role: database connection information

Key name: isline. Data. configuration. textproviderfileinfo

Role: default file location

Key name: isline. Data. configuration. sqlserverconnectstring

Role: sqldatabase connection information

Key name: isline. Data. configuration. oracleconnectstring

Role: Oracle database connection information

Cache support for isline. Data. containerdefiner namespaces:

Here we will mention the cache support information for classes in the namespace, which is located in the isline. Data. containerdefiner namespace.

This class implements four interfaces: isqlcontainer, ioraclecontainer, ifilecontainer, and idisposable, including common ADO. NET data objects, such as dataset and reader, can be directly assigned to the corresponding objects in the containerdefine class by using the data objects obtained by oracleprovider or sqleprovider. containerdefine caches the objects.

Note that when containerdefine is declared, the constructor has two parameters. The first parameter is to enable httpruntime caching, and the second parameter is the cache name. After the DataSet object in CD is assigned a value, will be automatically cached. The next time you call CD. the DataSet object is automatically read from the cache and does not require oracleprovider (). the executedataset () method is used to retrieve data again. Currently, cache is supported.. Net runtime cache and context cache. Of course, the cache policy is disabled by default. The cache is enabled only when the constructor receives the preceding parameters.

For more information about cache, seeArticle"Isline. httpcontent. httpcontentprovider namespace series ".

Dataprovider has not introduced many other things, so I will not introduce them one by one here. For more information about the dataprovider database method, it will not take up valuable pages because of its long length, if you are interested, you can access the author's blog to obtain relevant information.

In addition, you can use this namespace to process data transactions, but you must follow a series of interface contracts to provide them with database factories, deploy the database file of the factory as follows, so that before ilfw runs, the private method dbproviderformating () is used to reflect the factory provided by the user. The specifications provided by users are as follows:

● DLL deployment path: islineframework \ isline. provider. dataprovider. cfgdllname, where isline. provider. dataprovider. dldllname is the DLL name configured in Web. config.

● Namespace of the factory: isline. provider. dataprovider

● Factory class name: dbfactory

● Method type dbproviderfactory

● Method Name: getdbprovider ()

Dataprovider also has a class "dbprovider". This provider does not specify whether it is sqlserver, Oracle, or other databases. You need to comply with the interface contract mentioned above in advance to implement configution. DLL, and placed in the agreed location (this location is in the web. config), the program will automatically reflect and use the method. In the future, when you change the database, you only need to replace the DLL and do not need to modify the main program.

"Dbprovider" also encapsulates Microsoft's dbproviderfactory. As you may know, I will not introduce it much. The call method name and method are the same as those described above.

So far, the data access layer has been fully described. Next, we will begin to explain how to perform log operations.

This article has been published simultaneously in the software report and cannot be reproduced by any personal media.

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.