Data Connector with XML Provider |
This example access data to XML file
Create a class based on SOWI Data Connector
/// <summary> /// App Client class based on <see cref="SOWIData.Database.Connector{DataItemClass}"/>) /// </summary> /// <seealso cref="SOWIData.Database.Connector{DataItemClass}"/> /// <seealso cref="Data.Client"/> public class Client : SOWIData.Database.Connector<Data.Client> { // ... }
Write the constructor
Puts connection string and user name for data handling
/// <summary> /// Constructor with parameters: connectin string and user name /// </summary> /// <param name="pConnectionString">XML Connection String properties: DataSource equal XML and InitialCatalog it XML file name</param> /// <param name="pUserName">User name</param> public Client(string pConnectionString, string pUserName) : base(pConnectionString, pUserName) { this.SetDB(); }
Method SetDB
ConnectString Property | Description |
---|---|
DataSource | Declaration XML provider. Puts value XML. Detail see SOWIDataProviders |
InitialCatalog | Puts the XML file name (include path) |
/// <summary> /// Puts XML data connector via property ConnectionString /// </summary> /// <remarks> /// For a XML data connector must the property value DataSource of ConnectionString equal XML (see <see cref="SOWIData.Providers"/>. <para/> /// Then is property value InitialCatalog the XML file name. /// </remarks> /// <seealso cref="SOWIData.Providers"/> /// <seealso cref="SqlConnectionStringBuilder"/> protected override void SetDB() { try { //* analysis of property ConnectionString * SqlConnectionStringBuilder lConnectionString = new SqlConnectionStringBuilder(this.ConnectionString); string lDataSource = lConnectionString.DataSource; if (lDataSource.ToUpper() == SOWIData.Providers.XML.ToString()) { //* puts XML data connector * string lFileName = lConnectionString.InitialCatalog; this.XML = new SOWIData.XML.Document<Data.Client>(lFileName); } } catch (Exception ex) { SIC.Protocol.Write(ref ex); throw ex; } }
Method GetList
Call method DocumentDataItemClassGetList
/// <summary> /// Gives raw data list and is basis for all data processing /// </summary> /// <returns>A data list</returns> protected override List<santesuisseData.Client> GetList() { try { return this.XML.GetList(); } catch (Exception ex) { SIC.Protocol.Write(ref ex); throw ex; } }