[Adapdev-commits] Adapdev/src/Adapdev.Data/Xml ProviderConfig.cs,1.6,1.7 ProviderConfig.xml,1.8,1.9
Status: Beta
Brought to you by:
intesar66
From: Sean M. <int...@us...> - 2005-11-16 07:02:02
|
Update of /cvsroot/adapdev/Adapdev/src/Adapdev.Data/Xml In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv909/src/Adapdev.Data/Xml Added Files: ProviderConfig.cs ProviderConfig.xml ProviderConfig.xsd ProviderConfig.xsx ProviderInfo.cs ProviderInfo.xml ProviderInfo.xsd ProviderInfo.xsx Log Message: --- NEW FILE: ProviderConfig.cs --- using System; using System.Reflection; using System.Xml; using System.Data; using System.IO; using System.Text.RegularExpressions; namespace Adapdev.Data { /// <summary> /// DBConnectionManager manages the loading of the ADAPDEV.XML file into the DBConnection* classes /// </summary> [System.ComponentModel.DesignerCategoryAttribute("code")] public class ProviderConfig : DataSet { private DbConnectionTypes _connectionTypes = null; public ProviderConfig() : this( FindConfigFile() ) { } public ProviderConfig( string config ) { _connectionTypes = LoadConfig ( config ); } // Provides Get Access the the COnnection Types Instance public DbConnectionTypes ConnectionTypes { get { return _connectionTypes; } } /// <summary> /// Loads a config file into a XMLDocument and populates a DBConnectionTypes collection of the /// database connection details found in the config file. /// </summary> /// <param name="config">The name (and path) of a config file containing <connection> elements</param> /// <returns>A Collection of Connection Types</returns> private DbConnectionTypes LoadConfig ( string config ) { try { this.ReadXml(config); DbConnectionTypes connectionTypes = new DbConnectionTypes(); DataRow connectionsRow = this.Tables["connections"].Rows[0]; // Read the available connections from the connections collection // -------------------------------------------------------------- foreach (DataRow connectionRow in connectionsRow.GetChildRows("connections_connection")) { DbConnectionType connectionType = new DbConnectionType(); connectionType.Name = connectionRow["name"].ToString(); connectionType.DbTypeName = connectionRow["type"].ToString(); connectionType.InternalProviderName = connectionRow["internalProvider"].ToString(); // Read the Settings for this connection type // -------------------------------------------------------------- foreach (DataRow settingsRow in connectionRow.GetChildRows("connection_settings")) { if (settingsRow.Table.Columns.Contains("file")) { connectionType.SupportsFile = GetSettingState(settingsRow["file"].ToString(),false); connectionType.PromptFile = GetSettingValue(settingsRow["file"].ToString()); } if (settingsRow.Table.Columns.Contains("server")) { connectionType.SupportsServer = GetSettingState(settingsRow["server"].ToString(),true); connectionType.PromptServer = GetSettingValue(settingsRow["server"].ToString()); } if (settingsRow.Table.Columns.Contains("name")) { connectionType.SupportsName = GetSettingState(settingsRow["name"].ToString(),true); connectionType.PromptName = GetSettingValue(settingsRow["name"].ToString()); } if (settingsRow.Table.Columns.Contains("userid")) { connectionType.SupportsUserID = GetSettingState(settingsRow["userid"].ToString(),true); connectionType.PromptUserID = GetSettingValue(settingsRow["userid"].ToString()); } if (settingsRow.Table.Columns.Contains("password")) { connectionType.SupportsPassword = GetSettingState(settingsRow["password"].ToString(),true); connectionType.PromptPassword = GetSettingValue(settingsRow["password"].ToString()); } if (settingsRow.Table.Columns.Contains("filter")) { connectionType.SupportsFilter = GetSettingState(settingsRow["filter"].ToString(),false); connectionType.PromptFilter = GetSettingValue(settingsRow["filter"].ToString()); } } // Read each of the Providers Details // -------------------------------------------------------------- foreach (DataRow providersRow in connectionRow.GetChildRows("connection_providers")) { foreach (DataRow providerRow in providersRow.GetChildRows("providers_provider")) { DbConnectionProvider connectionProvider = new DbConnectionProvider(); connectionProvider.Name = providerRow["name"].ToString(); connectionProvider.ProviderTypeName = providerRow["type"].ToString(); connectionProvider.Parent = connectionType; connectionProvider.Template = Regex.Replace(providerRow["provider_Text"].ToString(), @"[\r\t\n]", ""); if (providerRow.Table.Columns.Contains("allowEmptyParameters")) connectionProvider.AllowEmptyParameters = GetSettingState(providerRow["allowEmptyParameters"].ToString(), true); if (providerRow.Table.Columns.Contains("enabled")) connectionProvider.Enabled = GetSettingState(providerRow["enabled"].ToString(),true); if (providerRow.Table.Columns.Contains("fileMask")) connectionProvider.FileMask = providerRow["fileMask"].ToString(); connectionType.Providers.Add(connectionProvider); } } connectionTypes.Add(connectionType); } return connectionTypes; } catch (Exception ex) { throw new ApplicationException(String.Format("Could not reference the ProviderConfig.xml configuration file: {0}\n{1}", config, ex.Message)); } } /// <summary> /// Returns the State if defined for a property. If it is false, return false /// otherwise return true. /// </summary> /// <param name="setting"></param> /// <returns></returns> private bool GetSettingState(string setting, bool defaultFlag) { if (setting == null) return defaultFlag; if (setting.Equals(string.Empty)) return defaultFlag; try { return Convert.ToBoolean(setting); } catch { return true; } } /// <summary> /// Return the setting for a property. If the property was "false" return a empty string /// or if the property was "true" return a empty string, otherwise return the contents. /// </summary> /// <param name="setting"></param> /// <returns></returns> private string GetSettingValue(string setting) { if (setting == null) return string.Empty; if (setting.Equals(string.Empty)) return string.Empty; try { bool flag = Convert.ToBoolean(setting); return string.Empty; } catch { return setting.Trim(); } } /// <summary> /// Determine the location and allow overriding of the ConfigFile /// </summary> /// <returns></returns> public static string FindConfigFile () { string configFile = String.Empty; string possibleConfig = String.Empty; // Look in the current application folder for the file if (configFile == String.Empty) { possibleConfig = AppDomain.CurrentDomain.BaseDirectory + @"ProviderConfig.XML"; if (System.IO.File.Exists(possibleConfig)) { configFile = possibleConfig; } } // If not found there, then override with a hardcoded default // TODO: Allow this to be overriden with the commandline if (configFile == String.Empty) { possibleConfig = @"..\..\..\..\..\Adapdev\src\Adapdev.Data\Xml\ProviderConfig.xml"; if (System.IO.File.Exists(possibleConfig)) { configFile = possibleConfig; } } if (configFile == String.Empty) { throw new ApplicationException(String.Format("Could not find the ProviderConfig.xml configuration file.\n It should exist in {0}", AppDomain.CurrentDomain.BaseDirectory)); } return configFile; } } } --- NEW FILE: ProviderInfo.xsd --- <?xml version="1.0"?> <xs:schema id="ProvidersInfo" targetNamespace="http://tempuri.org/ProviderInfo.xsd" xmlns:mstns="http://tempuri.org/ProviderInfo.xsd" xmlns="http://tempuri.org/ProviderInfo.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" attributeFormDefault="qualified" elementFormDefault="qualified"> <xs:element name="ProvidersInfo" msdata:IsDataSet="true" msdata:EnforceConstraints="False"> <xs:complexType> <xs:choice maxOccurs="unbounded"> <xs:element name="ProviderInfo"> <xs:complexType> <xs:sequence> <xs:element name="Type" minOccurs="0" maxOccurs="unbounded"> <xs:complexType> <xs:sequence> <xs:element name="Id" type="xs:string" minOccurs="0" /> <xs:element name="Name" type="xs:string" minOccurs="0" /> <xs:element name="Object" type="xs:string" minOccurs="0" /> <xs:element name="Prefix" type="xs:string" minOccurs="0" /> <xs:element name="Postfix" type="xs:string" minOccurs="0" /> <xs:element name="Default" type="xs:string" minOccurs="0" /> <xs:element name="TestDefault" type="xs:string" minOccurs="0" /> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> <xs:attribute name="Name" form="unqualified" type="xs:string" /> </xs:complexType> </xs:element> </xs:choice> </xs:complexType> </xs:element> </xs:schema> --- NEW FILE: ProviderConfig.xml --- <?xml version="1.0" encoding="utf-8"?> <adapdev xmlns="http://tempuri.org/ProviderConfig.xsd"> <connections> <!-- You MUST specify a OLEDB connecion type as a minimum for a provider and specifiy it in the internalProvider attribute. Defining a connection string, use the following field replacement tokens: {0} Server Name or file location {1} Data Source or Initial Catalog Name {2} User Name or UserID to connect as {3} Password Available Settings are: <server file="true">Prompt</server> <name>Prompt<name> <userid>Prompt</userid> <password>Prompt</password> Note: When specifying a Driver={name} you must specify using {{ eg: Driver={{SQL Server}} --> <connection name="SQL Server" type="SQLSERVER" internalProvider="OLEDB"> <settings file="false" server="true" name="true" userid="true" password="true"/> <providers> <provider name="Sql Connect" type="SQLSERVER" allowEmptyParameters="true"> Data Source={0}; Initial Catalog={1}; User ID={2}; Password={3}; Trusted_Connection=false; </provider> <provider name="OLEDB" type="OLEDB"> Provider=sqloledb;Data Source={0}; Initial Catalog={1}; User ID={2}; Password={3}; </provider> <provider name="ODBC" type="ODBC" enabled="false"> Driver={{SQL Server}};Server={0}; Database={1}; Uid={2}; Pwd={3}; </provider> </providers> </connection> <connection name="SQL Server - Trusted" type="SQLSERVER" internalProvider="OLEDB"> <settings file="false" server="true" name="true" userid="false" password="false"/> <providers> <provider name="Sql Connect" type="SQLSERVER"> Data Source={0}; Initial Catalog={1}; Integrated Security=SSPI; </provider> <provider name="OLEDB" type="OLEDB"> Provider=sqloledb;Data Source={0}; Initial Catalog={1}; Integrated Security=SSPI </provider> <provider name="ODBC" type="ODBC" enabled="false"> Driver={{SQL Server}};Server={0}; Database={1}; Trusted_Connection=yes; </provider> </providers> </connection> <connection name="Microsoft Access" type="ACCESS" internalProvider="OLEDB"> <settings file="true" server="false" name="false" userid="true" password="true"/> <providers> <provider name="ODBC" type="ODBC" enabled="false"> Driver={{Microsoft Access Driver (*.mdb)}}; Dbq={0}; Uid={2}; Pwd={3}; </provider> <provider name="OLEDB" type="OLEDB" fileMask="Access Database (*.mdb)|*.mdb"> Provider=Microsoft.Jet.OLEDB.4.0; Data Source={0}; User ID={2}; Password={3}; </provider> <provider name="OLEDB (DNS)" type="OLEDB" fileMask="File Data Sources (*.dsn)|*.dsn"> DSN={0};Uid={2};Pwd={3}; </provider> </providers> </connection> <connection name="Oracle" type="ORACLE" internalProvider="OLEDB (Microsoft)"> <settings file="false" server="true" name="false" userid="true" password="true" filter="Schema"/> <providers> <provider name="Oracle Connect" type="ORACLE" enabled="true"> Data Source={0}; User ID={2}; Password={3}; Integrated Security=no; </provider> <provider name="OLEDB (Microsoft)" type="OLEDB" enabled="true"> Provider=msdaora; Data Source={0}; Database={1}; User ID={2}; Password={3}; </provider> <provider name="OLEDB (Oracle)" type="OLEDB" enabled="false"> Provider=OraOLEDB; Data Source={0}; User ID={2}; Password={3}; </provider> <provider name="ODBC" type="ODBC" enabled="false"> Driver={{Microsoft ODBC for Oracle}}; Server={0}; Uid={2}; Pwd={3} </provider> </providers> </connection> <connection name="Oracle - Trusted" type="ORACLE" internalProvider="OLEDB (Oracle)"> <settings file="false" server="true" name="Schema" userid="true" password="true"/> <providers> <provider name="Oracle Connect" type="ORACLE" enabled="false"> Data Source={0}; Integrated Security=yes; </provider> <provider name="OLEDB (Oracle)" type="OLEDB" enabled="false"> Provider=OraOLEDB; Data Source={0}; OSAuthent=1; </provider> </providers> </connection> <connection name="MySql" type="MYSQL" internalProvider="MySql Native"> <settings file="false" server="true" name="true" userid="true" password="true"/> <providers> <provider name="MySql Native" type="MYSQL" enabled="true"> Data Source={0};Database={1};User ID={2};Password={3}; </provider> <provider name="ODBC" type="ODBC" enabled="false"> DRIVER={{MySQL ODBC 3.51 Driver}};SERVER={0};DATABASE={1};USER={2};PASSWORD={3}; </provider> </providers> </connection> </connections> </adapdev> --- NEW FILE: ProviderConfig.xsx --- <?xml version="1.0" encoding="utf-8"?> <!--This file is auto-generated by the XML Schema Designer. It holds layout information for components on the designer surface.--> <XSDDesignerLayout /> --- NEW FILE: ProviderConfig.xsd --- <?xml version="1.0"?> <xs:schema id="adapdev" targetNamespace="http://tempuri.org/ProviderConfig.xsd" xmlns:mstns="http://tempuri.org/ProviderConfig.xsd" xmlns="http://tempuri.org/ProviderConfig.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" attributeFormDefault="qualified" elementFormDefault="qualified"> <xs:element name="adapdev" msdata:IsDataSet="true" msdata:Locale="en-NZ" msdata:EnforceConstraints="False"> <xs:complexType> <xs:choice maxOccurs="unbounded"> <xs:element name="connections"> <xs:complexType> <xs:sequence> <xs:element name="connection" minOccurs="0" maxOccurs="unbounded"> <xs:complexType> <xs:sequence> <xs:element name="settings" minOccurs="0" maxOccurs="unbounded"> <xs:complexType> <xs:attribute name="file" form="unqualified" type="xs:string" /> <xs:attribute name="server" form="unqualified" type="xs:string" /> <xs:attribute name="name" form="unqualified" type="xs:string" /> <xs:attribute name="userid" form="unqualified" type="xs:string" /> <xs:attribute name="password" form="unqualified" type="xs:string" /> <xs:attribute name="filter" form="unqualified" type="xs:string" /> </xs:complexType> </xs:element> <xs:element name="providers" minOccurs="0" maxOccurs="unbounded"> <xs:complexType> <xs:sequence> <xs:element name="provider" nillable="true" minOccurs="0" maxOccurs="unbounded"> <xs:complexType> <xs:simpleContent msdata:ColumnName="provider_Text" msdata:Ordinal="3"> <xs:extension base="xs:string"> <xs:attribute name="name" form="unqualified" type="xs:string" /> <xs:attribute name="type" form="unqualified" type="xs:string" /> <xs:attribute name="allowEmptyParameters" form="unqualified" type="xs:string" /> <xs:attribute name="enabled" form="unqualified" type="xs:string" /> <xs:attribute name="fileMask" form="unqualified" type="xs:string" /> </xs:extension> </xs:simpleContent> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> <xs:attribute name="name" form="unqualified" type="xs:string" /> <xs:attribute name="type" form="unqualified" type="xs:string" /> <xs:attribute name="internalProvider" form="unqualified" type="xs:string" /> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xs:choice> </xs:complexType> </xs:element> </xs:schema> --- NEW FILE: ProviderInfo.cs --- (This appears to be a binary file; contents omitted.) --- NEW FILE: ProviderInfo.xml --- <?xml version="1.0" encoding="utf-8" ?> <ProvidersInfo xmlns="http://tempuri.org/ProviderInfo.xsd"> <ProviderInfo Name="oledb"> <Type> <Id>20</Id> <Name>BigInt</Name> <Object>Int64</Object> <Prefix></Prefix> <Postfix></Postfix> <Default>0</Default> <TestDefault>2</TestDefault> </Type> <Type> <Id>128</Id> <Name>Binary</Name> <Object>Byte[]</Object> <Prefix></Prefix> <Postfix></Postfix> <Default>null</Default> [...1486 lines suppressed...] <Type> <Id>252</Id> <Name>longtext</Name> <Object>Byte[]</Object> <Prefix>'</Prefix> <Postfix>'</Postfix> <Default></Default> <TestDefault></TestDefault> </Type>--> <Type> <Id>254</Id> <Name>uint</Name> <Object>Int32</Object> <Prefix></Prefix> <Postfix></Postfix> <Default>0</Default> <TestDefault>1</TestDefault> </Type> </ProviderInfo> </ProvidersInfo> --- NEW FILE: ProviderInfo.xsx --- <?xml version="1.0" encoding="utf-8"?> <!--This file is auto-generated by the XML Schema Designer. It holds layout information for components on the designer surface.--> <XSDDesignerLayout /> |