Exemplo n.º 1
0
        private static void Initialize()
        {
            providerCollection = new OrderCompletedHandlerProviderCollection();

            try
            {
                OrderCompletedHandlerProviderConfig config = OrderCompletedHandlerProviderConfig.GetConfig();

                if (config != null)
                {
                    if (
                        (config.Providers == null) ||
                        (config.Providers.Count < 1)
                        )
                    {
                        throw new ProviderException("No OrderCompletedHandlerProviders found.");
                    }

                    ProvidersHelper.InstantiateProviders(
                        config.Providers,
                        providerCollection,
                        typeof(OrderCompletedHandlerProvider));
                }
                else
                {
                    // config was null, not a good thing
                    log.Error("OrderCompletedHandlerProviderConfig could not be loaded so empty provider collection was returned");
                }
            }
            catch (NullReferenceException ex)
            {
                log.Error(ex);
            }
            catch (TypeInitializationException ex)
            {
                log.Error(ex);
            }
            catch (ProviderException ex)
            {
                log.Error(ex);
            }

            providerCollection.SetReadOnly();
        }
Exemplo n.º 2
0
        public static OrderCompletedHandlerProviderConfig GetConfig()
        {
            try
            {
                if (
                    (HttpRuntime.Cache["OrderCompletedHandlerProviderConfig"] != null) &&
                    (HttpRuntime.Cache["OrderCompletedHandlerProviderConfig"] is OrderCompletedHandlerProviderConfig)
                    )
                {
                    return((OrderCompletedHandlerProviderConfig)HttpRuntime.Cache["OrderCompletedHandlerProviderConfig"]);
                }

                OrderCompletedHandlerProviderConfig config = new OrderCompletedHandlerProviderConfig();

                String configFolderName = "~/WebStore/OrderCompletedHandlers/";

                string pathToConfigFolder = HttpContext.Current.Server.MapPath(configFolderName);

                if (!Directory.Exists(pathToConfigFolder))
                {
                    return(config);
                }

                DirectoryInfo directoryInfo = new DirectoryInfo(pathToConfigFolder);

                FileInfo[] configFiles = directoryInfo.GetFiles("*.config");

                foreach (FileInfo fileInfo in configFiles)
                {
                    XmlDocument configXml = new XmlDocument();
                    configXml.Load(fileInfo.FullName);
                    config.LoadValuesFromConfigurationXml(configXml.DocumentElement);
                }

                AggregateCacheDependency aggregateCacheDependency = new AggregateCacheDependency();
                string pathToWebConfig = HttpContext.Current.Server.MapPath("~/Web.config");
                aggregateCacheDependency.Add(new CacheDependency(pathToWebConfig));

                System.Web.HttpRuntime.Cache.Insert(
                    "OrderCompletedHandlerProviderConfig",
                    config,
                    aggregateCacheDependency,
                    DateTime.Now.AddYears(1),
                    TimeSpan.Zero,
                    System.Web.Caching.CacheItemPriority.Default,
                    null);

                return((OrderCompletedHandlerProviderConfig)HttpRuntime.Cache["OrderCompletedHandlerProviderConfig"]);
            }
            catch (HttpException ex)
            {
                log.Error(ex);
            }
            catch (System.Xml.XmlException ex)
            {
                log.Error(ex);
            }
            catch (ArgumentException ex)
            {
                log.Error(ex);
            }
            catch (NullReferenceException ex)
            {
                log.Error(ex);
            }

            return(null);
        }
        public static OrderCompletedHandlerProviderConfig GetConfig()
        {
            try
            {
                if (
                    (HttpRuntime.Cache["OrderCompletedHandlerProviderConfig"] != null)
                    && (HttpRuntime.Cache["OrderCompletedHandlerProviderConfig"] is OrderCompletedHandlerProviderConfig)
                )
                {
                    return (OrderCompletedHandlerProviderConfig)HttpRuntime.Cache["OrderCompletedHandlerProviderConfig"];
                }

                OrderCompletedHandlerProviderConfig config = new OrderCompletedHandlerProviderConfig();

                String configFolderName = "~/WebStore/OrderCompletedHandlers/";

                string pathToConfigFolder = HttpContext.Current.Server.MapPath(configFolderName);

                if (!Directory.Exists(pathToConfigFolder)) return config;

                DirectoryInfo directoryInfo = new DirectoryInfo(pathToConfigFolder);

                FileInfo[] configFiles = directoryInfo.GetFiles("*.config");

                foreach (FileInfo fileInfo in configFiles)
                {
                    XmlDocument configXml = new XmlDocument();
                    configXml.Load(fileInfo.FullName);
                    config.LoadValuesFromConfigurationXml(configXml.DocumentElement);

                }

                AggregateCacheDependency aggregateCacheDependency = new AggregateCacheDependency();
                string pathToWebConfig = HttpContext.Current.Server.MapPath("~/Web.config");
                aggregateCacheDependency.Add(new CacheDependency(pathToWebConfig));

                System.Web.HttpRuntime.Cache.Insert(
                    "OrderCompletedHandlerProviderConfig",
                    config,
                    aggregateCacheDependency,
                    DateTime.Now.AddYears(1),
                    TimeSpan.Zero,
                    System.Web.Caching.CacheItemPriority.Default,
                    null);

                return (OrderCompletedHandlerProviderConfig)HttpRuntime.Cache["OrderCompletedHandlerProviderConfig"];

            }
            catch (HttpException ex)
            {
                log.Error(ex);

            }
            catch (System.Xml.XmlException ex)
            {
                log.Error(ex);

            }
            catch (ArgumentException ex)
            {
                log.Error(ex);

            }
            catch (NullReferenceException ex)
            {
                log.Error(ex);

            }

            return null;
        }