Пример #1
0
        private static void LoadProviders()
        {
            // Avoid claiming lock if providers are already loaded
            if (_provider == null)
            {
                lock (_lock)
                {
                    // Do this again to make sure _provider is still null
                    if (_provider == null)
                    {
                        // Get a reference to the <TaxServiceSection> section
                        TaxServiceSection section = (TaxServiceSection)
                                                    WebConfigurationManager.GetSection
                                                        ("TaxService");

                        // Only want one provider here
                        _provider = (TaxProvider)ProvidersHelper.InstantiateProvider
                                        (section.Providers[0], typeof(TaxProvider));


                        if (_provider == null)
                        {
                            throw new ProviderException
                                      ("Unable to load default TaxProvider");
                        }
                    }
                }
            }
        }
Пример #2
0
 public static void InstantiateProviders(ProviderSettingsCollection providerSettings, ProviderCollection providers, Type type)
 {
     foreach (ProviderSettings settings in providerSettings)
     {
         providers.Add(ProvidersHelper.InstantiateProvider(settings, type));
     }
 }
Пример #3
0
        /// <summary>
        /// Helper method of instantiating a specific provider
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="sectionName"></param>
        /// <param name="providerName"></param>
        /// <returns></returns>
        public static T InstantiateProvider <T>(string sectionName, string providerName) where T : ProviderBase
        {
            T provider;

            var configSection = (ProviderConfigurationSection)ConfigurationManager.GetSection(sectionName);

            if (configSection != null)
            {
                var providerSettings = configSection.Providers[providerName];
                if (providerSettings == null)
                {
                    throw new ProviderException($"Unable to find '{sectionName}' provider");
                }

                provider = ProvidersHelper.InstantiateProvider(providerSettings, typeof(T)) as T;
                if (provider == null)
                {
                    throw new ProviderException($"Provider configuration section '{sectionName}' missing.");
                }
            }
            else
            {
                throw new ProviderException($"Provider configuration section '{sectionName}' missing.");
            }

            return(provider);
        }
Пример #4
0
        internal CacheStoreProvider GetObjectCache(bool createIfDoesNotExist)
        {
            if (_objectCache == null && createIfDoesNotExist)
            {
                lock (this) {
                    if (_objectCache == null)
                    {
                        NameValueCollection cacheProviderSettings = HostingEnvironment.CacheStoreProviderSettings;

                        if (cacheProviderSettings != null)
                        {
                            string providerName = (string)cacheProviderSettings["name"]; // Grab this now, as InstantiateProvider will remove it from settings
                            cacheProviderSettings["isPublic"] = "true";
                            _objectCache = (CacheStoreProvider)ProvidersHelper.InstantiateProvider(cacheProviderSettings, typeof(CacheStoreProvider));
                            _objectCache.Initialize(providerName, cacheProviderSettings);
                        }
                        else
                        {
                            if (_internalCache is AspNetCache)
                            {
                                _objectCache = new AspNetCache((AspNetCache)_internalCache, isPublic: true);
                            }
                            else
                            {
                                _objectCache = new AspNetCache(isPublic: true);
                            }
                            _objectCache.Initialize(null, new NameValueCollection());
                        }
                    }
                }
            }

            return(_objectCache);
        }
Пример #5
0
        private static void LoadProvider()
        {
            // if we do not have initiated the provider
            if (_provider == null)
            {
                lock (_lock)
                {
                    // Do this again to make sure _provider is still null
                    if (_provider == null)
                    {
                        // Get a reference to the <requestService> section
                        ChatServiceSection section = (ChatServiceSection)WebConfigurationManager.GetSection("LCSK/chatService");

                        // Load the default provider
                        if (section.Providers.Count > 0 && !string.IsNullOrEmpty(section.DefaultProvider) && section.Providers[section.DefaultProvider] != null)
                        {
                            _provider = (ChatProvider)ProvidersHelper.InstantiateProvider(section.Providers[section.DefaultProvider], typeof(ChatProvider));
                        }

                        if (_provider == null)
                        {
                            throw new ProviderException("Unable to load the ChatProvider");
                        }
                    }
                }
            }
        }
Пример #6
0
        private static void LoadProvider()
        {
            // Avoid claiming lock if providers are already loaded
            if (_provider == null)
            {
                lock (_lock)
                {
                    // Do this again to make sure _provider is still null
                    if (_provider == null)
                    {
                        // Get a reference to the <PaymentService> section
                        PaymentServiceSection section = (PaymentServiceSection)
                                                        WebConfigurationManager.GetSection
                                                            ("PaymentService");

                        // Load registered providers and point _provider
                        // to the default provider

                        //since this is a CC provider, we only want one
                        //so no collections for providers.
                        //however feel free to change this as needed.
                        _provider = (PaymentProvider)ProvidersHelper.InstantiateProvider(section.Providers[0], typeof(PaymentProvider));

                        if (_provider == null)
                        {
                            throw new ProviderException
                                      ("Unable to load default PaymentProvider");
                        }
                    }
                }
            }
        }
Пример #7
0
   public SendProviderBase GetSendProviderBase(string MapName)
   {
     try 
     {
       ProviderSettings settings = sendConfig.Providers[MapName];
       return (SendProviderBase)ProvidersHelper.InstantiateProvider(settings, typeof(SendProviderBase));
     }
     //appropriate catch block and whatever else
 }}
Пример #8
0
        private static SearchProvider InitializeConfiguredProvider()
        {
            SearchProviderElement searchProviders = SearchConfiguration.Instance.SearchProviders;
            SearchProvider        searchProvider  = (SearchProvider)ProvidersHelper.InstantiateProvider(searchProviders.Providers[searchProviders.DefaultProvider], typeof(SearchProvider));

            if (searchProvider != null)
            {
                return(searchProvider);
            }
            throw new ProviderException("Unable to load default SearchProvider");
        }
Пример #9
0
        internal static List <SearchProviderBase> InitFromConfig()
        {
            List <SearchProviderBase> searchProviders = new List <SearchProviderBase>();
            SearchSection             sectionSection  = SearchSection.GetConfigurationSection();

            foreach (ProviderSettings ps in sectionSection.Providers)
            {
                SearchProviderBase _provider = ProvidersHelper.InstantiateProvider(ps, Type.GetType(ps.Type)) as SearchProviderBase;
                searchProviders.Add(_provider);
            }
            return(searchProviders);
        }
Пример #10
0
        private static SearchProvider InitializeConfiguredProvider()
        {
            SearchProviderElement searchProviders = SearchConfiguration.Instance.SearchProviders;

            if (searchProviders.Providers == null)
            {
                throw new ProviderException("Failed to initialize search provider section");
            }
            SearchProvider expr_43 = (SearchProvider)ProvidersHelper.InstantiateProvider(searchProviders.Providers[searchProviders.DefaultProvider], typeof(SearchProvider));

            if (expr_43 == null)
            {
                throw new ProviderException("Unable to load default SearchProvider");
            }
            return(expr_43);
        }
Пример #11
0
        static void Main(string[] args)
        {
            ServiceJobSection          jobSection    = (ServiceJobSection)ConfigurationManager.GetSection("ServiceJobSection");
            ServiceJobInfoCollection   JobCollection = jobSection.JobCollection;
            ProviderSettingsCollection jobProviders  = (ProviderSettingsCollection)jobSection.JobProviders;

            for (int i = 0; i < JobCollection.Count; i++)
            {
                ProviderSettings   providerSetting = jobProviders[JobCollection[i].Provider];
                ServiceJobProvider provider        = (ServiceJobProvider)ProvidersHelper.InstantiateProvider(providerSetting, typeof(ServiceJobProvider));

                if (!JobProviders.Contains(JobCollection[i].JobName))
                {
                    provider.JobInfo = JobCollection[i];
                    JobProviders.Add(JobCollection[i].JobName, provider);
                }
            }
            JobDetect();
        }
Пример #12
0
        private static void SetProvider(string appConfigPath)
        {
            if (!File.Exists(appConfigPath))
            {
                throw new Exception("There's no config file present at " + appConfigPath);
            }
            ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();

            Console.WriteLine("Building configuration from " + Path.Combine(Directory.GetCurrentDirectory(), appConfigPath));
            fileMap.ExeConfigFilename = appConfigPath;
            Configuration subConfig = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);

            try
            {
                DbmlBuilderSection section = (DbmlBuilderSection)subConfig.GetSection("DbmlBuilderService");

                if (section != null)
                {
                    Db.ConfigSection = section;
                    string connectionStringName = section.Providers[0].Parameters["connectionStringName"];
                    if (connectionStringName == null)
                    {
                        throw new ConfigurationErrorsException("The Parameter 'connectionStringName' was not specified");
                    }
                    ConnectionStringSettings connSettings = subConfig.ConnectionStrings.ConnectionStrings[connectionStringName];
                    if (connSettings == null)
                    {
                        throw new ConfigurationErrorsException(string.Format(
                                                                   "ConnectionStrings section missing connection string with the name '{0}'", connectionStringName));
                    }

                    Db.Service = (SqlDataProvider)ProvidersHelper.InstantiateProvider(
                        section.Providers[0], typeof(SqlDataProvider));
                    Db.Service.DefaultConnectionStringName = connectionStringName;
                    Db.Service.DefaultConnectionString     = connSettings.ConnectionString;
                }
            }
            catch (ConfigurationErrorsException x)
            {
                //let the user know the config was problematic...
                Console.WriteLine("There is an error with your config file. '{0}'", x.Message);
            }
        }
Пример #13
0
        /// <summary>
        /// Instantiate the default provider for the providers collection
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="sectionName"></param>
        /// <returns></returns>
        public static T InstantiateDefaultProvider <T>(string sectionName) where T : ProviderBase
        {
            T provider;

            try
            {
                var configSection = (ProviderConfigurationSection)ConfigurationManager.GetSection(sectionName);
                if (configSection != null)
                {
                    var providerSettings = configSection.Providers[configSection.DefaultProvider];
                    if (providerSettings == null)
                    {
                        throw new ProviderException($"Unable to find default '{sectionName}' provider");
                    }

                    provider = ProvidersHelper.InstantiateProvider(providerSettings, typeof(T)) as T;
                    if (provider == null)
                    {
                        throw new ProviderException($"Unable to load default'{sectionName}' provider");
                    }
                }
                else
                {
                    throw new ProviderException($"Provider configuration section '{sectionName}' missing.");
                }
            }
            catch (ProviderException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new ProviderException($"Unable to load default '{sectionName}' provider. Error: {ex.Message}");
            }

            return(provider);
        }
Пример #14
0
        protected override void OnStart(string[] args)
        {
            ServiceJobSection          jobSection    = (ServiceJobSection)ConfigurationManager.GetSection("ServiceJobSection");
            ServiceJobInfoCollection   JobCollection = jobSection.JobCollection;
            ProviderSettingsCollection jobProviders  = (ProviderSettingsCollection)jobSection.JobProviders;

            for (int i = 0; i < JobCollection.Count; i++)
            {
                ProviderSettings   providerSetting = jobProviders[JobCollection[i].Provider];
                ServiceJobProvider provider        = (ServiceJobProvider)ProvidersHelper.InstantiateProvider(providerSetting, typeof(ServiceJobProvider));

                if (!JobProviders.Contains(JobCollection[i].JobName))
                {
                    provider.JobInfo = JobCollection[i];
                    JobProviders.Add(JobCollection[i].JobName, provider);
                }
            }

            Thread threadJobDetect = new Thread(new ThreadStart(this.JobDetect));

            threadJobDetect.Start();

            Log.WriteLog(Resources.ServiceStarted, "Log\\ServiceInfo.txt", true);
        }
Пример #15
0
        public PaymentProvider GetProviderInstance(string name)
        {
            return(_providers.GetOrAdd(name, s =>
            {
                var settings = Providers[name];

                var type = Type.GetType(settings.Type);
                if (type == null)
                {
                    return null;
                }

                try
                {
                    return (PaymentProvider)ProvidersHelper.InstantiateProvider(settings, type);
                }
                catch (Exception e)
                {
                    ECommerceLog.WriteLog("Error instantiating provider", e);

                    return null;
                }
            }));
        }
 private static ProviderBase InstantiateProvider(ProviderSettings settings)
 {
     return(ProvidersHelper.InstantiateProvider(settings, typeof(CaptchaProvider)));
 }
Пример #17
0
        public void Init(HttpApplication app)
        {
            config = (SessionStateSection)WebConfigurationManager.GetSection("system.web/sessionState");

            ProviderSettings settings;

            switch (config.Mode)
            {
            case SessionStateMode.Custom:
                settings = config.Providers [config.CustomProvider];
                if (settings == null)
                {
                    throw new HttpException(String.Format("Cannot find '{0}' provider.", config.CustomProvider));
                }
                break;

            case SessionStateMode.Off:
                return;

            case SessionStateMode.InProc:
                settings = new ProviderSettings(null, typeof(SessionInProcHandler).AssemblyQualifiedName);
                break;

            case SessionStateMode.SQLServer:
                settings = new ProviderSettings(null, typeof(SessionSQLServerHandler).AssemblyQualifiedName);
                break;

            case SessionStateMode.StateServer:
                settings = new ProviderSettings(null, typeof(SessionStateServerHandler).AssemblyQualifiedName);
                break;

            default:
                throw new NotImplementedException(String.Format("The mode '{0}' is not implemented.", config.Mode));
            }

            handler = (SessionStateStoreProviderBase)ProvidersHelper.InstantiateProvider(settings, typeof(SessionStateStoreProviderBase));

            if (String.IsNullOrEmpty(config.SessionIDManagerType))
            {
                idManager = new SessionIDManager();
            }
            else
            {
                Type idManagerType = HttpApplication.LoadType(config.SessionIDManagerType, true);
                idManager = (ISessionIDManager)Activator.CreateInstance(idManagerType);
            }

            try {
                idManager.Initialize();
            } catch (Exception ex) {
                throw new HttpException("Failed to initialize session ID manager.", ex);
            }

            supportsExpiration = handler.SetItemExpireCallback(OnSessionExpired);
            HttpRuntimeSection runtime = HttpRuntime.Section;

            executionTimeout = runtime.ExecutionTimeout;
            //executionTimeoutMS = executionTimeout.Milliseconds;

            this.app = app;

            app.BeginRequest        += new EventHandler(OnBeginRequest);
            app.AcquireRequestState += new EventHandler(OnAcquireRequestState);
            app.ReleaseRequestState += new EventHandler(OnReleaseRequestState);
            app.EndRequest          += new EventHandler(OnEndRequest);
        }
 private SessionStateStoreProviderAsyncBase SecureInstantiateAsyncProvider(ProviderSettings settings)
 {
     return
         ((SessionStateStoreProviderAsyncBase)
          ProvidersHelper.InstantiateProvider(settings, typeof(SessionStateStoreProviderAsyncBase)));
 }