[Adapdev-commits] Adapdev/src/Adapdev.Data/Xml ProviderConfig.cs,NONE,1.1 ProviderConfig.xml,NONE,1.
Status: Beta
Brought to you by:
intesar66
From: Trevor L. <tre...@us...> - 2005-04-10 09:59:40
|
Update of /cvsroot/adapdev/Adapdev/src/Adapdev.Data/Xml In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22225/src/Adapdev.Data/Xml Modified Files: ProviderInfo.xml Added Files: ProviderConfig.cs ProviderConfig.xml ProviderConfig.xsd ProviderConfig.xsx Log Message: 1. Modifications to support the ProviderConfig file for Database/Provider dynamic customisation 2. Added support classes for Oracle 3. Enhanced UI to support dynamic ProviderConfig --- 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="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="1"> <xs:extension base="xs:string"> <xs:attribute name="name" type="xs:string" use="required"/> <xs:attribute name="type" form="unqualified" type="xs:string" use="required"/> <xs:attribute name="allowEmptyParameters" form="unqualified" type="xs:Boolean" use="optional"/> <xs:attribute name="enabled" type="xs:Boolean" use="optional"/> <xs:attribute name="fileMask" type="xs:Boolean" use="optional"/> </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" use="required"/> <xs:attribute name="type" form="unqualified" type="xs:string" use="required"/> <xs:attribute name="internalProvider" type="xs:string" use="required"/> <xs:attribute name="supportsServer" form="unqualified" type="xs:Boolean" /> <xs:attribute name="supportsName" form="unqualified" type="xs:Boolean" /> <xs:attribute name="supportsUserID" form="unqualified" type="xs:Boolean" /> <xs:attribute name="supportsPassword" form="unqualified" type="xs:Boolean" /> </xs:complexType> </xs:element> </xs:sequence> </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 Note: When specifying a Driver={name} you must specify using {{ eg: Driver={{SQL Server}} --> <connection name="SQL Server" type="SQLSERVER" internalProvider="OLEDB" supportsServer="true" supportsName="true" supportsUserID="true" supportsPassword="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" supportsServer="true" supportsName="true" supportsUserID="false" supportsPassword="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" supportsServer="false" supportsName="false" supportsUserID="true" supportsPassword="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)" supportsServer="true" supportsName="false" supportsUserID="true" supportsPassword="true"> <providers> <provider name="Oracle Connect" type="ORACLE" enabled="false"> Data Source={0}; User ID={2}; Password={3}; Integrated Security=no; </provider> <provider name="OLEDB (Microsoft)" type="OLEDB" enabled="false"> Provider=msdaora; Data Source={0}; 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)" supportsServer="true" supportsName="false" supportsUserID="false" supportsPassword="false"> <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> </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 layoutVersion="2" viewPortLeft="0" viewPortTop="0" zoom="100"> <connections_XmlElement left="317" top="254" width="5292" height="2963" selected="0" zOrder="1" index="0" expanded="1"> <connection_XmlElement left="317" top="3725" width="5292" height="2963" selected="0" zOrder="2" index="0" expanded="1"> <providers_XmlElement left="317" top="7196" width="5292" height="2963" selected="0" zOrder="5" index="0" expanded="1"> <provider_XmlElement left="317" top="10667" width="5292" height="2963" selected="0" zOrder="8" index="0" expanded="1" /> </providers_XmlElement> </connection_XmlElement> </connections_XmlElement> </XSDDesignerLayout> --- NEW FILE: ProviderConfig.cs --- using System; using System.Reflection; using System.Xml; 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> public class ProviderConfig { private DbConnectionTypes _connectionTypes = null; public ProviderConfig() { _connectionTypes = LoadConfig (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 ) { DbConnectionTypes _connectionTypes = null; // Load the config file into a XML Document instance try { XmlTextReader reader = new XmlTextReader(config); XmlDocument document = new XmlDocument(); try { document.Load(reader); } catch (Exception ex) { throw new ApplicationException(String.Format("Could not load the ProviderConfig.xml configuration file: {0}\n{1}", config, ex.Message)); } XmlNodeReader nodeReader = new XmlNodeReader(document); _connectionTypes = LoadNodes (nodeReader); } catch (Exception ex) { throw new ApplicationException(String.Format("Could not reference the ProviderConfig.xml configuration file: {0}\n{1}", config, ex.Message)); } return _connectionTypes; } /// <summary> /// Load the Connection Type infromation from the XML Stream /// </summary> /// <param name="reader">A Node Reader Node</param> /// <returns>A Collection of Connection Types</returns> private DbConnectionTypes LoadNodes (XmlNodeReader reader) { DbConnectionTypes _connectionTypes = new DbConnectionTypes(); try { reader.MoveToContent(); while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: if (reader.Name == "connection") { DbConnectionType _connectionType = new DbConnectionType(); if (reader.MoveToFirstAttribute()) { do { switch (reader.Name.ToLower()) { case "name": _connectionType.Name = reader.Value; break; case "type": _connectionType.DbTypeName = reader.Value; break; case "internalprovider": _connectionType.InternalProviderName = reader.Value; break; case "supportsserver": _connectionType.SupportsServer = Convert.ToBoolean(reader.Value); break; case "supportsname": _connectionType.SupportsName = Convert.ToBoolean(reader.Value); break; case "supportsuserid": _connectionType.SupportsUserID = Convert.ToBoolean(reader.Value); break; case "supportspassword": _connectionType.SupportsPassword = Convert.ToBoolean(reader.Value); break; default: break; } } while (reader.MoveToNextAttribute()); } // Read the child <provider> elements for this connection reader.Read(); LoadProviders(_connectionType, _connectionType.Providers, reader.ReadOuterXml()); // Ensure that the connection object has a name. If none was provider, // set the connection name to the database name. if (_connectionType.Name.Equals("")) { _connectionType.Name = _connectionType.DbTypeName; } // Ensure the connection name is unique in the collection int index = 0; while (_connectionTypes.Contains(_connectionType.Name) && index < 100) { _connectionType.Name = _connectionType.Name + Convert.ToString(index++); } if (index > 99) throw new ApplicationException("Internal error occured building a unique Connection Name."); _connectionTypes.Add(_connectionType); } break; } } } catch (Exception ex) { throw new ApplicationException(String.Format("Invalid ProviderConfig.xml (Providers) Configuration File (statement: {0})\n{1}",reader.ToString(),ex.Message)); } return _connectionTypes; } /// <summary> /// Load a "providers" section from the Config File /// </summary> /// <param name="providers"></param> /// <param name="providersXML"></param> private void LoadProviders(DbConnectionType connection, DbConnectionProviders providers, string providersXML) { XmlTextReader reader = new XmlTextReader(new StringReader(providersXML)); DbConnectionProvider _connectionProvider = null; try { while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: if (reader.Name == "provider") { _connectionProvider = new DbConnectionProvider(); if (reader.MoveToFirstAttribute()) { do { switch (reader.Name.ToLower()) { case "name": _connectionProvider.Name = reader.Value; break; case "type": _connectionProvider.ProviderTypeName = reader.Value; break; case "filemask": _connectionProvider.FileMask = reader.Value; break; case "allowEmptyParameters": _connectionProvider.AllowEmptyParameters = Convert.ToBoolean(reader.Value); break; case "enabled": _connectionProvider.Enabled = Convert.ToBoolean(reader.Value); break; default: break; } } while (reader.MoveToNextAttribute()); // Store the Parent so this instance can reference the parent _connectionProvider.Parent = connection; // Ensure that the provider object has a name. If none was provider, // set the provider name to the database name. if (_connectionProvider.Name.Equals("")) { _connectionProvider.Name = _connectionProvider.DbTypeName; } // Ensure the Provider name is unique in the collection int index = 0; while (providers.Contains(_connectionProvider.Name) && index < 100) { _connectionProvider.Name = _connectionProvider.Name + Convert.ToString(index++); } if (index > 99) throw new ApplicationException("Internal error occured building a unique Provider Name."); } } break; case XmlNodeType.Text: if (_connectionProvider != null) { string connectionTemplate = Regex.Replace(reader.Value, @"[\r\t\n]", ""); _connectionProvider.Template = connectionTemplate.Trim(); } break; case XmlNodeType.EndElement: if (_connectionProvider != null) { providers.Add(_connectionProvider); } _connectionProvider = null; break; } } } catch (Exception ex) { throw new ApplicationException(String.Format("Invalid ProviderConfig.xml (Provider) Configuration File (statement: {0})\n{1}",reader.ToString(),ex.Message)); } finally { _connectionProvider = null; } } /// <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; } } } Index: ProviderInfo.xml =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev.Data/Xml/ProviderInfo.xml,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** ProviderInfo.xml 28 Feb 2005 01:31:50 -0000 1.1.1.1 --- ProviderInfo.xml 10 Apr 2005 09:59:22 -0000 1.2 *************** *** 614,617 **** --- 614,887 ---- </ProviderInfo> <ProviderInfo Name="oracle"> + <Type> + <Id>1</Id> + <Name>CHAR</Name> + <Object>String</Object> + <Prefix>'</Prefix> + <Postfix>'</Postfix> + <Default>""</Default> + <TestDefault>"test"</TestDefault> + </Type> + <Type> + <Id>2</Id> + <Name>NCHAR</Name> + <Object>String</Object> + <Prefix>'</Prefix> + <Postfix>'</Postfix> + <Default>""</Default> + <TestDefault>"test"</TestDefault> + </Type> + <Type> + <Id>3</Id> + <Name>VARCHAR2</Name> + <Object>String</Object> + <Prefix>'</Prefix> + <Postfix>'</Postfix> + <Default>""</Default> + <TestDefault>"test"</TestDefault> + </Type> + <Type> + <Id>4</Id> + <Name>NVARCHAR2</Name> + <Object>String</Object> + <Prefix>'</Prefix> + <Postfix>'</Postfix> + <Default>""</Default> + <TestDefault>"test"</TestDefault> + </Type> + <Type> + <Id>5</Id> + <Name>VARCHAR</Name> + <Object>String</Object> + <Prefix>'</Prefix> + <Postfix>'</Postfix> + <Default>""</Default> + <TestDefault>"test"</TestDefault> + </Type> + <Type> + <Id>6</Id> + <Name>NVARCHAR</Name> + <Object>String</Object> + <Prefix>'</Prefix> + <Postfix>'</Postfix> + <Default>""</Default> + <TestDefault>"test"</TestDefault> + </Type> + <Type> + <Id>7</Id> + <Name>LONG</Name> + <Object>Int32</Object> + <Prefix></Prefix> + <Postfix></Postfix> + <Default></Default> + <TestDefault></TestDefault> + </Type> + <Type> + <Id>8</Id> + <Name>NUMBER</Name> + <Object>Decimal</Object> + <Prefix></Prefix> + <Postfix></Postfix> + <Default>0</Default> + <TestDefault>0.00</TestDefault> + </Type> + <Type> + <Id>9</Id> + <Name>DATE</Name> + <Object>DateTime</Object> + <Prefix>'</Prefix> + <Postfix>'</Postfix> + <Default>DateTime.Now</Default> + <TestDefault>DateTime.Now</TestDefault> + </Type> + <Type> + <Id>10</Id> + <Name>TIMESTAMP</Name> + <Object>DateTime</Object> + <Prefix>'</Prefix> + <Postfix>'</Postfix> + <Default>DateTime.Now</Default> + <TestDefault>DateTime.Now</TestDefault> + </Type> + <Type> + <Id>11</Id> + <Name>TIMESTAMP WITH LOCAL TIME ZONE</Name> + <Object>DateTime</Object> + <Prefix>'</Prefix> + <Postfix>'</Postfix> + <Default>DateTime.Now</Default> + <TestDefault>DateTime.Now</TestDefault> + </Type> + <Type> + <Id>12</Id> + <Name>TIMESTAMP WITH TIME ZONE</Name> + <Object>DateTime</Object> + <Prefix>'</Prefix> + <Postfix>'</Postfix> + <Default>DateTime.Now</Default> + <TestDefault>DateTime.Now</TestDefault> + </Type> + <Type> + <Id>13</Id> + <Name>INTERVAL DAY TO SECOND</Name> + <Object>TimeSpan</Object> + <Prefix>'</Prefix> + <Postfix>'</Postfix> + <Default>TimeSpan.Zero</Default> + <TestDefault>TimeSpan.Zero</TestDefault> + </Type> + <Type> + <Id>14</Id> + <Name>INTERVAL YEAR TO MONTH</Name> + <Object>TimeSpan</Object> + <Prefix>'</Prefix> + <Postfix>'</Postfix> + <Default>TimeSpan.Zero</Default> + <TestDefault>TimeSpan.Zero</TestDefault> + </Type> + <Type> + <Id>15</Id> + <Name>RAW</Name> + <Object>Byte[]</Object> + <Prefix></Prefix> + <Postfix></Postfix> + <Default>null</Default> + <TestDefault>null</TestDefault> + </Type> + <Type> + <Id>16</Id> + <Name>LONGRAW</Name> + <Object>Byte[]</Object> + <Prefix></Prefix> + <Postfix></Postfix> + <Default>null</Default> + <TestDefault>null</TestDefault> + </Type> + <Type> + <Id>17</Id> + <Name>BFILE</Name> + <Object>OracleBFile</Object> + <Prefix></Prefix> + <Postfix></Postfix> + <Default>null</Default> + <TestDefault>null</TestDefault> + </Type> + <Type> + <Id>18</Id> + <Name>BLOB</Name> + <Object>OracleLob</Object> + <Prefix></Prefix> + <Postfix></Postfix> + <Default>null</Default> + <TestDefault>null</TestDefault> + </Type> + <Type> + <Id>19</Id> + <Name>BYTE</Name> + <Object>Byte</Object> + <Prefix></Prefix> + <Postfix></Postfix> + <Default>0</Default> + <TestDefault>0</TestDefault> + </Type> + <Type> + <Id>20</Id> + <Name>CLOB</Name> + <Object>OracleLob</Object> + <Prefix></Prefix> + <Postfix></Postfix> + <Default>null</Default> + <TestDefault>null</TestDefault> + </Type> + <Type> + <Id>21</Id> + <Name>DOUBLE</Name> + <Object>Double</Object> + <Prefix></Prefix> + <Postfix></Postfix> + <Default>0</Default> + <TestDefault>0</TestDefault> + </Type> + <Type> + <Id>22</Id> + <Name>FLOAT</Name> + <Object>Single</Object> + <Prefix></Prefix> + <Postfix></Postfix> + <Default>0</Default> + <TestDefault>0</TestDefault> + </Type> + <Type> + <Id>23</Id> + <Name>INT16</Name> + <Object>Int16</Object> + <Prefix></Prefix> + <Postfix></Postfix> + <Default>0</Default> + <TestDefault>0</TestDefault> + </Type> + <Type> + <Id>24</Id> + <Name>INT32</Name> + <Object>Int32</Object> + <Prefix></Prefix> + <Postfix></Postfix> + <Default>0</Default> + <TestDefault>0</TestDefault> + </Type> + <Type> + <Id>25</Id> + <Name>LONGVARCHAR</Name> + <Object>String</Object> + <Prefix>'</Prefix> + <Postfix>'</Postfix> + <Default>""</Default> + <TestDefault>"test"</TestDefault> + </Type> + <Type> + <Id>26</Id> + <Name>NCLOB</Name> + <Object>OracleLob</Object> + <Prefix></Prefix> + <Postfix></Postfix> + <Default>null</Default> + <TestDefault>null</TestDefault> + </Type> + <Type> + <Id>27</Id> + <Name>ROWID</Name> + <Object>String</Object> + <Prefix>'</Prefix> + <Postfix>'</Postfix> + <Default>""</Default> + <TestDefault>"rowid"</TestDefault> + </Type> + <Type> + <Id>28</Id> + <Name>SBYTE</Name> + <Object>SByte</Object> + <Prefix></Prefix> + <Postfix></Postfix> + <Default>0</Default> + <TestDefault>0</TestDefault> + </Type> + <Type> + <Id>29</Id> + <Name>UINT16</Name> + <Object>UInt16</Object> + <Prefix></Prefix> + <Postfix></Postfix> + <Default>0</Default> + <TestDefault>0</TestDefault> + </Type> + <Type> + <Id>30</Id> + <Name>UINT32</Name> + <Object>UInt32</Object> + <Prefix></Prefix> + <Postfix></Postfix> + <Default>0</Default> + <TestDefault>0</TestDefault> + </Type> </ProviderInfo> <ProviderInfo Name="dbtype_oledb"> |