lixiaojun
2024-08-15 11bfb11f3f352315fe64104509adda13d9f870d0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
 
namespace Eventech.DynPicture.Model
{
    /// <summary>
    /// xml配置信息类
    /// </summary>
    public class XmlConfigInfo
    {
        //默认xml配置文件名称
        private const string _xmlConfigFileName = "DynamicPictureDefaultConfig.xml";
 
        //获取xml配置文件全路径名称
        private static string GetXmlConfigFileName()
        {
            return System.IO.Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, _xmlConfigFileName);
        }
 
        /// <summary>
        /// 配置信息
        /// </summary>
        public static ConfigInfo ConfigInfo
        {
            get
            {
                if (_configInfo == null)
                {
                    var fileFullName = GetXmlConfigFileName();
                    if (!System.IO.File.Exists(fileFullName))
                    {
                        _configInfo = new ConfigInfo();
                        var xele = _configInfo.ToXElement();
                        xele.Save(fileFullName);
                    }
                    else
                    {
                        var xele = XElement.Load(fileFullName);
                        _configInfo = ConfigInfo.GetConfigInfo(xele);
                    }
                }
                return _configInfo;
            }
        }
        private static ConfigInfo _configInfo;
 
        /// <summary>
        /// 设置配置
        /// </summary>
        /// <param name="xmlInfo"></param>
        public static void SetConfig(ConfigInfo xmlInfo)
        {
            _configInfo = xmlInfo;
            var fileFullName = GetXmlConfigFileName();
            var xele = xmlInfo.ToXElement();
            xele.Save(fileFullName);
        }
 
    }
}