/// <summary> /// Get instance of APDalProvider from settigns. /// </summary> /// <param name="name">The name.</param> /// <param name="type">The type.</param> /// <param name="connectionString">The connection string.</param> /// <param name="providerName">The provider name.</param> /// <returns>The instance of APDalProvider.</returns> public static APDalProvider InstantiateProvider(string name, string type, string connectionString, string providerName) { Type settingsType = null; if (settingsType == null) { settingsType = APTypeHelper.LoadType(type); } if (settingsType == null) { throw new ProviderException(String.Format("Can not load type '{0}'.", type)); } APDalProvider provider = Activator.CreateInstance(settingsType) as APDalProvider; if (provider == null) { throw new ProviderException(String.Format("Can not create instance of type '{0}'.", type)); } NameValueCollection config = new NameValueCollection() { { "connectionString", connectionString }, { "providerName", providerName } }; provider.Initialize(name, config); return(provider); }
/// <summary> /// Create a new APDatabase object with DAL provider. /// </summary> /// <param name="provider">DAL providers.</param> public APDatabase(APDalProvider provider) { if (provider == null) { throw new ArgumentNullException("provider"); } _provider = provider; }
/// <summary> /// Create a new APDatabase object with DAL provider name. /// </summary> /// <param name="providerName">DAL provider name.</param> public APDatabase(string providerName) { if (providerName == null) { throw new ArgumentNullException("providerName"); } if (providerName == String.Empty) { throw new ArgumentException("providerName"); } _provider = Providers[providerName]; }
/// <summary> /// Load config file. /// Defaults, you can use 'null' parameter, Web project maybe find web.config, winform project maybe find /// app.config. /// </summary> /// <param name="configurationManager">The configurationManager.</param> public static void LoadConfig(System.Configuration.Configuration configurationManager) { if (configurationManager == null) { //cfgSection = (APQuerySection)WebConfigurationManager.GetSection("APQuery"); cfgSection = (APQuerySection)ConfigurationManager.GetSection("APQuery"); } else { cfgSection = (APQuerySection)configurationManager.GetSection("APQuery"); } if (cfgSection == null) { throw new ConfigurationErrorsException(APResource.GetString(APResource.APConfig_NotFindSection, "APQuery")); } providersCollection = new APDalProviderCollection(); ProvidersHelper.InstantiateProviders(cfgSection.Providers, providersCollection, typeof(APDalProvider)); defaultProvider = Providers[cfgSection.DefaultProvider]; if (defaultProvider == null) { throw new ConfigurationErrorsException(APResource.GetString(APResource.APProvider_NotFound, cfgSection.DefaultProvider)); } }
/// <summary> /// Create a new APDatabase object. /// </summary> public APDatabase() { _provider = defaultProvider; }
/// <summary> /// Load config file. /// Defaults, you can use 'null' parameter, Web project maybe find web.config, winform project maybe find /// app.config. /// </summary> /// <param name="configurationManager">The configurationManager.</param> public static void LoadConfig(System.Configuration.Configuration configurationManager) { if (configurationManager == null) { //cfgSection = (APQuerySection)WebConfigurationManager.GetSection("APQuery"); cfgSection = (APQuerySection)ConfigurationManager.GetSection("APQuery"); } else { cfgSection = (APQuerySection)configurationManager.GetSection("APQuery"); } if (cfgSection == null) throw new ConfigurationErrorsException(APResource.GetString(APResource.APConfig_NotFindSection, "APQuery")); providersCollection = new APDalProviderCollection(); ProvidersHelper.InstantiateProviders(cfgSection.Providers, providersCollection, typeof(APDalProvider)); defaultProvider = Providers[cfgSection.DefaultProvider]; if (defaultProvider == null) throw new ConfigurationErrorsException(APResource.GetString(APResource.APProvider_NotFound, cfgSection.DefaultProvider)); }
/// <summary> /// Create a new APDatabase object with DAL provider. /// </summary> /// <param name="provider">DAL providers.</param> public APDatabase(APDalProvider provider) { if (provider == null) throw new ArgumentNullException("provider"); _provider = provider; }
/// <summary> /// Create a new APDatabase object with DAL provider name. /// </summary> /// <param name="providerName">DAL provider name.</param> public APDatabase(string providerName) { if (providerName == null) throw new ArgumentNullException("providerName"); if (providerName == String.Empty) throw new ArgumentException("providerName"); _provider = Providers[providerName]; }
/// <summary> /// Create a new APDatabase object. /// </summary> public APDatabase() { _provider = defaultProvider; }
/// <summary> /// Copy some dal providers to array. /// </summary> /// <param name="array">The array to copy to.</param> /// <param name="index">The first item in the collection to copy.</param> public void CopyTo(APDalProvider[] array, int index) { base.CopyTo(array, index); }