Exemplo n.º 1
0
        ///<summary>
        /// Configuration based provider loading, will load the providers on first call.
        ///</summary>
        private static void LoadProviders()
        {
            // Avoid claiming lock if providers are already loaded
            if (_provider == null)
            {
                lock (SyncRoot)
                {
                    // Do this again to make sure _provider is still null
                    if (_provider == null)
                    {
                        // Load registered providers and point _provider to the default provider
                        _providers = new Shmzh.Components.SystemComponent.ProviderCollection();
                        var thisSection = Section();
                        ProvidersHelper.InstantiateProviders(thisSection.Providers, _providers, typeof(Shmzh.Components.SystemComponent.Provider));
                        _provider = _providers[thisSection.DefaultProvider] as DataProvider;

                        if (_provider == null)
                        {
                            throw new ProviderException("Unable to load default NetTiersProvider");
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
            /// <summary>
            /// Instantiates the configured providers based on the supplied connection string.
            /// </summary>
            private void LoadProviders()
            {
                DataRepository.LoadProviders();

                // Avoid claiming lock if providers are already loaded
                if (_providers == null)
                {
                    lock (SyncRoot)
                    {
                        // Do this again to make sure _provider is still null
                        if (_providers == null)
                        {
                            var thisSection = Section();
                            // apply connection information to each provider
                            for (int i = 0; i < thisSection.Providers.Count; i++)
                            {
                                thisSection.Providers[i].Parameters["connectionStringName"] = _connectionStringName;
                                // remove previous connection string, if any
                                thisSection.Providers[i].Parameters.Remove("connectionString");

                                if (!String.IsNullOrEmpty(_connectionString))
                                {
                                    thisSection.Providers[i].Parameters["connectionString"] = _connectionString;
                                }
                            }

                            // Load registered providers and point _provider to the default provider
                            _providers = new Shmzh.Components.SystemComponent.ProviderCollection();

                            ProvidersHelper.InstantiateProviders(thisSection.Providers, _providers, typeof(Shmzh.Components.SystemComponent.Provider));
                            _provider = _providers[thisSection.DefaultProvider];
                        }
                    }
                }
            }
Exemplo n.º 3
0
        /// <summary>
        /// Enables the DataRepository to programatically create and 
        /// pass in a <c>NetTiersProvider</c> during runtime.
        /// </summary>
        /// <param name="provider">An instatiated NetTiersProvider.</param>
        /// <param name="setAsDefault">ability to set any valid provider as the default provider for the DataRepository.</param>
        public static void LoadProvider(Shmzh.Components.SystemComponent.Provider provider, bool setAsDefault)
        {
            if (provider == null)
                throw new ArgumentNullException("provider");

            if (_providers == null)
            {
                lock (SyncRoot)
                {
                    if (_providers == null)
                        _providers = new Shmzh.Components.SystemComponent.ProviderCollection();
                }
            }

            if (_providers[provider.Name] == null)
            {
                lock (_providers.SyncRoot)
                {
                    _providers.Add(provider);
                }
            }

            if (_provider == null || setAsDefault)
            {
                lock (SyncRoot)
                {
                    if (_provider == null || setAsDefault)
                        _provider = provider as DataProvider;
                }
            }
        }