示例#1
0
        public object Create(object parent, object configContext, XmlNode node)
        {
            mojoEncryptionConfiguration config = new mojoEncryptionConfiguration();

            config.LoadValuesFromConfigurationXml(node);
            return(config);
        }
        public static mojoEncryptionConfiguration GetConfig()
        {
            //return (mojoEncryptionConfiguration)ConfigurationManager.GetSection("system.web/mojoEncryption");

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

                mojoEncryptionConfiguration config
                    = new mojoEncryptionConfiguration();



                string pathToConfigFile
                    = System.Web.Hosting.HostingEnvironment.MapPath(ConfigHelper.GetStringProperty("mojoCryptoHelperKeyFile", "~/mojoEncryption.config"));

                log.Debug("path to crypto key " + pathToConfigFile);

                if (!File.Exists(pathToConfigFile))
                {
                    log.Error("crypto file not found " + pathToConfigFile);
                    return(config);
                }

                FileInfo fileInfo = new FileInfo(pathToConfigFile);

                XmlDocument configXml = new XmlDocument();
                configXml.Load(fileInfo.FullName);
                config.LoadValuesFromConfigurationXml(configXml.DocumentElement);



                AggregateCacheDependency aggregateCacheDependency
                    = new AggregateCacheDependency();


                aggregateCacheDependency.Add(new CacheDependency(pathToConfigFile));

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

                return((mojoEncryptionConfiguration)HttpRuntime.Cache["mojoEncryptionConfiguration"]);
            }
            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 object Create(object parent, object configContext, XmlNode node)
 {
     mojoEncryptionConfiguration config = new mojoEncryptionConfiguration();
     config.LoadValuesFromConfigurationXml(node);
     return config;
 }
        public static mojoEncryptionConfiguration GetConfig()
        {
            //return (mojoEncryptionConfiguration)ConfigurationManager.GetSection("system.web/mojoEncryption");

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

                mojoEncryptionConfiguration config
                    = new mojoEncryptionConfiguration();

                string pathToConfigFile
                    = System.Web.Hosting.HostingEnvironment.MapPath(ConfigHelper.GetStringProperty("mojoCryptoHelperKeyFile", "~/mojoEncryption.config"));

                log.Debug("path to crypto key " + pathToConfigFile);

                if (!File.Exists(pathToConfigFile))
                {
                    log.Error("crypto file not found " + pathToConfigFile);
                    return config;
                }

                FileInfo fileInfo = new FileInfo(pathToConfigFile);

                XmlDocument configXml = new XmlDocument();
                configXml.Load(fileInfo.FullName);
                config.LoadValuesFromConfigurationXml(configXml.DocumentElement);

                AggregateCacheDependency aggregateCacheDependency
                    = new AggregateCacheDependency();

                aggregateCacheDependency.Add(new CacheDependency(pathToConfigFile));

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

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

            }
            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;
        }