Click or drag to resize

Data Connector with XML Provider

This example access data to XML file

SOWIData Connector Provider

Create Class for data access

  1. Create a class based on SOWI Data Connector

    C#
    /// <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>
    {
         // ...
    }
  2. Write the constructor

    Puts connection string and user name for data handling

    C#
    /// <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();
    }

Write methods for data access to XML file

  1. Method SetDB

    ConnectString Property

    Description

    DataSource

    Declaration XML provider. Puts value XML. Detail see SOWIDataProviders

    InitialCatalog

    Puts the XML file name (include path)

    C#
    /// <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;
        }
    }
  2. Method GetList

    Call method DocumentDataItemClassGetList

    C#
    /// <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;
        }
    }
See Also