Esempio n. 1
0
        private static GeographicProvider GetCurrentObject()
        {
            // Get the names of providers
            var config = ProviderConfiguration.GetProviderConfiguration(ProviderType);

            // Read specific configuration information for this provider
            var providerSettings = (ProviderSettings)config.Providers[config.DefaultProvider];

            // In the cache?
            var cacheKey = "Appleseed::Web::GeographicProvider::" + config.DefaultProvider;

            if (CurrentCache[cacheKey] == null)
            {
                // The assembly should be in \bin or GAC, so we simply need

                // to get an instance of the type
                try
                {
                    CurrentCache.Insert(
                        cacheKey, ProviderHelper.InstantiateProvider(providerSettings, typeof(GeographicProvider)));
                }
                catch (Exception e)
                {
                    throw new Exception("Unable to load provider", e);
                }
            }

            return((GeographicProvider)CurrentCache[cacheKey]);
        }
        /// <summary>
        /// Instances this instance.
        /// </summary>
        /// <returns></returns>
        public static UrlBuilderProvider Instance()
        {
            // Use the cache because the reflection used later is expensive
            Cache  cache = HttpRuntime.Cache;
            string cacheKey;
            // Get the names of providers
            ProviderConfiguration config = ProviderConfiguration.GetProviderConfiguration(providerType);
            // Read specific configuration information for this provider
            //ProviderSettings providerSettings = (ProviderSettings) config.Providers[config.DefaultProvider];
            AppleseedProviderSettings providerSettings = (AppleseedProviderSettings)config.Providers[config.DefaultProvider];

            // In the cache?
            cacheKey = "Appleseed::Web::UrlBuilder::" + config.DefaultProvider;

            if (cache[cacheKey] == null)
            {
                // The assembly should be in \bin or GAC, so we simply need

                // to get an instance of the type
                try
                {
                    cache.Insert(cacheKey,
                                 ProviderHelper.InstantiateProvider(providerSettings, typeof(UrlBuilderProvider)));
                }

                catch (Exception e)
                {
                    throw new Exception("Unable to load provider", e);
                }
            }
            return((UrlBuilderProvider)cache[cacheKey]);
        }
        /// <summary>
        /// Instances this instance.
        /// </summary>
        /// <returns></returns>
        public static LogProvider Instance()
        {
            // Use the cache because the reflection used later is expensive
            Cache  cache = HttpRuntime.Cache;
            string cacheKey;

            // Get the names of providers
            ProviderConfiguration config;

            config = ProviderConfiguration.GetProviderConfiguration(providerType);

            //If config not found (missing web.config)
            if (config == null)
            {
                //Try to provide a default anyway
                XmlDocument defaultNode = new XmlDocument();
                defaultNode.LoadXml(
                    "<log defaultProvider=\"Log4NetLog\"><providers><clear /><add name=\"Log4NetLog\" type=\"Rainbow.Framework.Logging.Log4NetLogProvider, Rainbow.Provider.Implementation\" /></providers></log>");

                // Get the names of providers
                config = new ProviderConfiguration();
                config.LoadValuesFromConfigurationXml(defaultNode.DocumentElement);
            }

            // Read specific configuration information for this provider
            ProviderSettings providerSettings = (ProviderSettings)config.Providers[config.DefaultProvider];

            // In the cache?
            cacheKey = "Rainbow::Configuration::Log::" + config.DefaultProvider;
            if (cache[cacheKey] == null)
            {
                // The assembly should be in \bin or GAC, so we simply need
                // to get an instance of the type
                try
                {
                    cache.Insert(cacheKey, ProviderHelper.InstantiateProvider(providerSettings, typeof(LogProvider)));
                }
                catch (Exception e)
                {
                    throw new Exception("Unable to load provider", e);
                }
            }

            return((LogProvider)cache[cacheKey]);
        }