[Adapdev-commits] Adapdev/src/Adapdev.Data/Xml ProviderConfig.cs,1.1,1.2 ProviderConfig.xml,1.3,1.4
Status: Beta
Brought to you by:
intesar66
From: Trevor L. <tre...@us...> - 2005-04-13 04:23:52
|
Update of /cvsroot/adapdev/Adapdev/src/Adapdev.Data/Xml In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7596/src/Adapdev.Data/Xml Modified Files: ProviderConfig.cs ProviderConfig.xml ProviderConfig.xsd ProviderConfig.xsx ProviderInfo.cs Log Message: Index: ProviderConfig.xsd =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev.Data/Xml/ProviderConfig.xsd,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ProviderConfig.xsd 10 Apr 2005 09:59:22 -0000 1.1 --- ProviderConfig.xsd 13 Apr 2005 04:23:42 -0000 1.2 *************** *** 10,13 **** --- 10,23 ---- <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> *************** *** 15,25 **** <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> --- 25,35 ---- <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> *************** *** 30,40 **** </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> --- 40,46 ---- </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> Index: ProviderConfig.cs =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev.Data/Xml/ProviderConfig.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ProviderConfig.cs 10 Apr 2005 09:59:22 -0000 1.1 --- ProviderConfig.cs 13 Apr 2005 04:23:42 -0000 1.2 *************** *** 2,23 **** 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); } --- 2,21 ---- 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 ); } *************** *** 35,206 **** 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; } } --- 33,131 ---- 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()); ! connectionType.PromptFile = GetSettingValue(settingsRow["file"].ToString()); ! } ! if (settingsRow.Table.Columns.Contains("server")) { ! connectionType.SupportsServer = GetSettingState(settingsRow["server"].ToString()); ! connectionType.PromptServer = GetSettingValue(settingsRow["server"].ToString()); ! } ! if (settingsRow.Table.Columns.Contains("name")) { ! connectionType.SupportsName = GetSettingState(settingsRow["name"].ToString()); ! connectionType.PromptName = GetSettingValue(settingsRow["name"].ToString()); ! } ! if (settingsRow.Table.Columns.Contains("userid")) { ! connectionType.SupportsUserID = GetSettingState(settingsRow["userid"].ToString()); ! connectionType.PromptUserID = GetSettingValue(settingsRow["userid"].ToString()); ! } ! if (settingsRow.Table.Columns.Contains("password")) { ! connectionType.SupportsPassword = GetSettingState(settingsRow["password"].ToString()); ! connectionType.PromptPassword = GetSettingValue(settingsRow["password"].ToString()); ! } ! if (settingsRow.Table.Columns.Contains("filter")) { ! connectionType.SupportsFilter = GetSettingState(settingsRow["filter"].ToString()); ! 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()); ! if (providerRow.Table.Columns.Contains("enabled")) connectionProvider.Enabled = GetSettingState(providerRow["enabled"].ToString()); ! 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) { 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 (GetSettingState(setting)) { ! if (setting.ToLower() != "true") return setting.Trim(); } + return string.Empty; } *************** *** 212,216 **** string configFile = String.Empty; string possibleConfig = String.Empty; ! // Look in the current application folder for the file if (configFile == String.Empty) { --- 137,141 ---- string configFile = String.Empty; string possibleConfig = String.Empty; ! // Look in the current application folder for the file if (configFile == String.Empty) { *************** *** 220,224 **** } } ! // If not found there, then override with a hardcoded default // TODO: Allow this to be overriden with the commandline --- 145,149 ---- } } ! // If not found there, then override with a hardcoded default // TODO: Allow this to be overriden with the commandline *************** *** 229,233 **** } } ! 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)); --- 154,158 ---- } } ! 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)); *************** *** 235,239 **** return configFile; } - } ! } --- 160,163 ---- return configFile; } } ! } \ No newline at end of file Index: ProviderInfo.cs =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev.Data/Xml/ProviderInfo.cs,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** ProviderInfo.cs 28 Feb 2005 01:31:49 -0000 1.1.1.1 --- ProviderInfo.cs 13 Apr 2005 04:23:42 -0000 1.2 *************** *** 15,19 **** using System.Runtime.Serialization; - [Serializable()] [System.ComponentModel.DesignerCategoryAttribute("code")] --- 15,18 ---- Index: ProviderConfig.xsx =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev.Data/Xml/ProviderConfig.xsx,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ProviderConfig.xsx 10 Apr 2005 09:59:22 -0000 1.1 --- ProviderConfig.xsx 13 Apr 2005 04:23:42 -0000 1.2 *************** *** 1,11 **** <?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> \ No newline at end of file --- 1,3 ---- <?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 /> \ No newline at end of file Index: ProviderConfig.xml =================================================================== RCS file: /cvsroot/adapdev/Adapdev/src/Adapdev.Data/Xml/ProviderConfig.xml,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ProviderConfig.xml 12 Apr 2005 10:22:57 -0000 1.3 --- ProviderConfig.xml 13 Apr 2005 04:23:42 -0000 1.4 *************** *** 7,18 **** 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"> --- 7,25 ---- 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"> *************** *** 28,32 **** </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"> --- 35,40 ---- </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"> *************** *** 42,46 **** </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"> --- 50,55 ---- </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"> *************** *** 56,60 **** </connection> ! <connection name="Oracle" type="ORACLE" internalProvider="OLEDB (Microsoft)" supportsServer="true" supportsName="true" supportsUserID="true" supportsPassword="true"> <providers> <provider name="Oracle Connect" type="ORACLE" enabled="true"> --- 65,70 ---- </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"> *************** *** 73,77 **** </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"> --- 83,88 ---- </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"> |