Exemplo n.º 1
0
        private static String DefaultFactoryType()
        {
            InitializeFactorySection();
            FactoryConfigurationElement factory = null;

            try
            {
                lockFactorySection.EnterReadLock();
                foreach (FactoryConfigurationElement e in factorySection.Values)
                {
                    factory = e;
                    if (factory.IsDefault)
                    {
                        break;
                    }
                }
            }
            finally
            {
                lockFactorySection.ExitReadLock();
            }
            if (factory == null)
            {
                return(null);
            }
            return(factory.FactoryType);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the factory database type according to the factory name.
        /// </summary>
        /// <param name="factoryName">Name of the desire factory.</param>
        /// <returns>Returns the DatabaseType that represents the parameter factoryName.</returns>
        public static DatabaseType GetFactoryDbType(String factoryName)
        {
            InitializeFactorySection();



            bool hasKey = false;
            FactoryConfigurationElement configurationElement = null;

            try
            {
                lockFactorySection.EnterReadLock();
                hasKey = factorySection.TryGetValue(factoryName, out configurationElement);
                hasKey = hasKey && configurationElement != null;
            }
            finally
            {
                lockFactorySection.ExitReadLock();
            }

            if (!hasKey)
            {
                if (InDesignMode && LastFactoryNotFound.Equals(factoryName))
                {
                    LastFactoryNotFound = factoryName;
                }
                return(DatabaseType.Undefined);
            }

            return(configurationElement.DatabaseType);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Gets the factory according to the factory name.
        /// </summary>
        /// <param name="factoryName">Name of the desire factory.</param>
        /// <returns>Returns the DBProviderFactory that represents the parameter factoryName.</returns>
        public static DbProviderFactory GetFactory(String factoryName)
        {
            if (String.IsNullOrEmpty(factoryName))
            {
                return(DbProviderFactories.GetFactory(DefaultFactoryType()));
            }
            InitializeFactorySection();
            FactoryConfigurationElement configurationElement = null;
            bool found = false;

            try
            {
                lockFactorySection.EnterReadLock();
                found = factorySection.TryGetValue(factoryName, out configurationElement);
            }
            finally
            {
                lockFactorySection.ExitReadLock();
            }
            if (!found || configurationElement == null || string.IsNullOrEmpty(configurationElement.FactoryType))
            {
                throw new ArgumentException("The factory " + factoryName + "is not registered on the configuration file; please check it.");
            }
            return(DbProviderFactories.GetFactory(configurationElement.FactoryType));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Gets the default factory type.
        /// </summary>
        /// <returns>The type name of the element.</returns>
        public String DefaultFactoryType()
        {
            FactoryConfigurationElement factory = null;

            foreach (ConfigurationElement e in this)
            {
                factory = e as FactoryConfigurationElement;
                if (factory.IsDefault)
                {
                    break;
                }
            }
            return(factory.FactoryType);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Gets the factory dbtype according to the parameter.
        /// </summary>
        /// <param name="factoryname">The factory name to get the information from.</param>
        /// <returns></returns>
        public DatabaseType FactoryDbType(String factoryname)
        {
            FactoryConfigurationElement factory = null;

            if (String.IsNullOrEmpty(factoryname))
            {
                foreach (ConfigurationElement e in this)
                {
                    factory = e as FactoryConfigurationElement;
                    if (factory.IsDefault)
                    {
                        break;
                    }
                }
            }
            else
            {
                factory = this[factoryname];
            }
            return(factory.DatabaseType);
        }
Exemplo n.º 6
0
 /// <summary>
 /// Adds a new element to the collection.
 /// </summary>
 /// <param name="factory">The factory to be added.</param>
 public void Add(FactoryConfigurationElement factory)
 {
     BaseAdd(factory);
 }