private static void Initialize()
        {
            providerCollection = new GCheckoutNotificationHandlerProviderCollection();

            try
            {
                GCheckoutNotificationConfiguration config
                    = GCheckoutNotificationConfiguration.GetConfig();

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

                    ProvidersHelper.InstantiateProviders(
                        config.Providers,
                        providerCollection,
                        typeof(GCheckoutNotificationHandlerProvider));
                }
                else
                {
                    // config was null, not a good thing
                    log.Error("GCheckoutNotificationConfiguration 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();

            //}
            //catch (Exception ex)
            //{
            //    log.Error(ex);
            //    initializationException = ex;
            //    isInitialized = false;
            //    //throw ex;
            //    return;
            //}

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

                GCheckoutNotificationConfiguration config
                    = new GCheckoutNotificationConfiguration();

                String configFolderName = "~/Setup/ProviderConfig/gcheckoutnotificationhandlers/";

                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(
                    "GCheckoutNotificationConfiguration",
                    config,
                    aggregateCacheDependency,
                    DateTime.Now.AddYears(1),
                    TimeSpan.Zero,
                    System.Web.Caching.CacheItemPriority.Default,
                    null);

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

            }
            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;
        }
예제 #3
0
        public static GCheckoutNotificationConfiguration GetConfig()
        {
            try
            {
                if (
                    (HttpRuntime.Cache["GCheckoutNotificationConfiguration"] != null) &&
                    (HttpRuntime.Cache["GCheckoutNotificationConfiguration"] is GCheckoutNotificationConfiguration)
                    )
                {
                    return((GCheckoutNotificationConfiguration)HttpRuntime.Cache["GCheckoutNotificationConfiguration"]);
                }

                GCheckoutNotificationConfiguration config
                    = new GCheckoutNotificationConfiguration();

                String configFolderName = "~/Setup/ProviderConfig/gcheckoutnotificationhandlers/";

                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(
                    "GCheckoutNotificationConfiguration",
                    config,
                    aggregateCacheDependency,
                    DateTime.Now.AddYears(1),
                    TimeSpan.Zero,
                    System.Web.Caching.CacheItemPriority.Default,
                    null);

                return((GCheckoutNotificationConfiguration)HttpRuntime.Cache["GCheckoutNotificationConfiguration"]);
            }
            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);
        }