示例#1
0
        static DbManager()
        {
            AddDataProvider(new Sql2008DataProvider());
            AddDataProvider(new SqlDataProvider());
            AddDataProvider(new AccessDataProvider());
            AddDataProvider(new OleDbDataProvider());
            AddDataProvider(new OdbcDataProvider());

            BLToolkitSection section = BLToolkitSection.Instance;

            if (section != null)
            {
                _defaultConfiguration = section.DefaultConfiguration;

                foreach (DataProviderElement provider in section.DataProviders)
                {
                    Type             dataProviderType = Type.GetType(provider.TypeName, true);
                    DataProviderBase providerInstance = (DataProviderBase)Activator.CreateInstance(dataProviderType);

                    if (!string.IsNullOrEmpty(provider.Name))
                    {
                        providerInstance.UniqueName = provider.Name;
                    }

                    providerInstance.Configure(provider.Attributes);

                    AddDataProvider(providerInstance);

                    if (!provider.Default)
                    {
                        continue;
                    }

                    if (_defaultDataProviderName != null)
                    {
                        throw new ConfigurationErrorsException(string.Format(
                                                                   Resources.DbManager_MoreThenOneDefaultProvider, _defaultDataProviderName, providerInstance.UniqueName),
                                                               provider.ElementInformation.Source, provider.ElementInformation.LineNumber);
                    }

                    _defaultDataProviderName = providerInstance.UniqueName;
                }
            }

            string dataProviders = ConfigurationManager.AppSettings.Get("BLToolkit.DataProviders");

            if (dataProviders != null)
            {
                Debug.WriteLineIf(TraceSwitch.TraceWarning, "Using appSettings\\BLToolkit.DataProviders is obsolete. Consider using bltoolkit configuration section instead.", TraceSwitch.DisplayName);
                foreach (string dataProviderTypeName in dataProviders.Split(';'))
                {
                    AddDataProvider(Type.GetType(dataProviderTypeName, true));
                }
            }

            if (string.IsNullOrEmpty(_defaultConfiguration))
            {
                _defaultConfiguration = ConfigurationManager.AppSettings.Get("BLToolkit.DefaultConfiguration");
            }

            if (string.IsNullOrEmpty(_defaultDataProviderName))
            {
                _defaultDataProviderName = SqlDataProviderBase.NameString;
            }
        }