⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 siteconfig.cs

📁 动易SiteFactory&#8482 网上商店系统1.0源代码
💻 CS
字号:
namespace PowerEasy.Components
{
    using System;
    using System.Collections.ObjectModel;
    using System.IO;
    using System.Security;
    using System.Web;
    using System.Web.Caching;
    using System.Xml.Serialization;

    public sealed class SiteConfig
    {
        private string filePath;

        public SiteConfig()
        {
            if (this.filePath == null)
            {
                HttpContext current = HttpContext.Current;
                if (current != null)
                {
                    this.filePath = current.Server.MapPath("~/Config/Site.config");
                }
                else
                {
                    this.filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Config/Site.config");
                }
            }
        }

        public SiteConfig(string path)
        {
            this.filePath = path;
        }

        public static SiteConfigInfo ConfigInfo()
        {
            SiteConfigInfo info = SiteCache.Get("CK_System_SiteConfigInfo") as SiteConfigInfo;
            if (info == null)
            {
                info = ConfigReadFromFile();
                SiteCache.Insert("CK_System_SiteConfigInfo", info, new CacheDependency(new SiteConfig().FilePath));
            }
            if (info == null)
            {
                info = new SiteConfigInfo();
            }
            return info;
        }

        public static SiteConfigInfo ConfigReadFromFile()
        {
            using (Stream stream = new FileStream(new SiteConfig().FilePath, FileMode.Open, FileAccess.Read))
            {
                XmlSerializer serializer = new XmlSerializer(typeof(SiteConfigInfo));
                return (SiteConfigInfo) serializer.Deserialize(stream);
            }
        }

        public void Update(SiteConfigInfo config)
        {
            try
            {
                XmlSerializer serializer = new XmlSerializer(typeof(SiteConfigInfo));
                using (Stream stream = new FileStream(this.filePath, FileMode.Create, FileAccess.Write, FileShare.None))
                {
                    XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces();
                    namespaces.Add("", "");
                    serializer.Serialize(stream, config, namespaces);
                }
            }
            catch (SecurityException exception)
            {
                throw new SecurityException(exception.Message, exception.DenySetInstance, exception.PermitOnlySetInstance, exception.Method, exception.Demanded, exception.FirstPermissionThatFailed);
            }
        }

        public string FilePath
        {
            get
            {
                return this.filePath;
            }
            set
            {
                this.filePath = value;
            }
        }

        public static Collection<FrontTemplate> FrontTemplateList
        {
            get
            {
                return ConfigInfo().FrontTemplateList;
            }
        }

        public static PowerEasy.Components.IPLockConfig IPLockConfig
        {
            get
            {
                return ConfigInfo().IPLockConfig;
            }
        }

        public static PowerEasy.Components.MailConfig MailConfig
        {
            get
            {
                return ConfigInfo().MailConfig;
            }
        }

        public static PowerEasy.Components.ShopConfig ShopConfig
        {
            get
            {
                return ConfigInfo().ShopConfig;
            }
        }

        public static PowerEasy.Components.SiteInfo SiteInfo
        {
            get
            {
                return ConfigInfo().SiteInfo;
            }
        }

        public static PowerEasy.Components.SiteOption SiteOption
        {
            get
            {
                return ConfigInfo().SiteOption;
            }
        }

        public static PowerEasy.Components.SmsConfig SmsConfig
        {
            get
            {
                return ConfigInfo().SmsConfig;
            }
        }

        public static PowerEasy.Components.ThumbsConfig ThumbsConfig
        {
            get
            {
                return ConfigInfo().ThumbsConfig;
            }
        }

        public static PowerEasy.Components.UserConfig UserConfig
        {
            get
            {
                return ConfigInfo().UserConfig;
            }
        }

        public static PowerEasy.Components.WaterMarkConfig WaterMarkConfig
        {
            get
            {
                return ConfigInfo().WaterMarkConfig;
            }
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -