public static PaymentGatewayConfiguration GetConfig()
        {
            PaymentGatewayConfiguration config = null;

            if (
                (HttpRuntime.Cache["PaymentGatewayConfiguration"] != null)
                && (HttpRuntime.Cache["PaymentGatewayConfiguration"] is PaymentGatewayConfiguration)
            )
            {
                return (PaymentGatewayConfiguration)HttpRuntime.Cache["PaymentGatewayConfiguration"];
            }
            else
            {

                String configFileName = WebConfigSettings.PaymentGatewayConfigFileName;

                if (!configFileName.StartsWith("~/"))
                {
                    configFileName = "~/" + configFileName;
                }

                String pathToConfigFile = HttpContext.Current.Server.MapPath(configFileName);

                XmlDocument configXml = new XmlDocument();
                configXml.Load(pathToConfigFile);
                config = new PaymentGatewayConfiguration(configXml.DocumentElement);

                AggregateCacheDependency aggregateCacheDependency = new AggregateCacheDependency();
                aggregateCacheDependency.Add(new CacheDependency(pathToConfigFile));

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

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

            }
        }
        public static PaymentGatewayConfiguration GetConfig()
        {
            PaymentGatewayConfiguration config = null;

            if (
                HttpRuntime.Cache["PaymentGatewayConfiguration"] != null &&
                HttpRuntime.Cache["PaymentGatewayConfiguration"] is PaymentGatewayConfiguration
                )
            {
                return((PaymentGatewayConfiguration)HttpRuntime.Cache["PaymentGatewayConfiguration"]);
            }
            else
            {
                string configFileName = WebConfigSettings.PaymentGatewayConfigFileName;

                if (!configFileName.StartsWith("~/"))
                {
                    configFileName = "~/" + configFileName;
                }

                string pathToConfigFile = HttpContext.Current.Server.MapPath(configFileName);

                XmlDocument configXml = new XmlDocument();
                configXml.Load(pathToConfigFile);
                config = new PaymentGatewayConfiguration(configXml.DocumentElement);

                var aggregateCacheDependency = new AggregateCacheDependency();

                aggregateCacheDependency.Add(new CacheDependency(pathToConfigFile));

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

                return((PaymentGatewayConfiguration)HttpRuntime.Cache["PaymentGatewayConfiguration"]);
            }
        }
예제 #3
0
        private static void Initialize()
        {
            PaymentGatewayConfiguration config = PaymentGatewayConfiguration.GetConfig();

            if (
                config.DefaultProvider == null ||
                config.Providers == null ||
                config.Providers.Count < 1
                )
            {
                throw new ProviderException("You must specify a valid default provider.");
            }

            Providers = new PaymentGatewayProviderCollection();

            ProvidersHelper.InstantiateProviders(
                config.Providers,
                Providers,
                typeof(PaymentGatewayProvider)
                );

            Providers.SetReadOnly();
            Provider = Providers[config.DefaultProvider];
        }