SysParam.cs 2.24 KB
Newer Older
潘栩锋's avatar
潘栩锋 committed
1 2 3 4 5 6 7 8 9 10
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Misc;
using System.Net;
using System.IO;
using System.ComponentModel;
using System.Xml.Serialization;
using FLY.Thick.Base.Common;
11
using Newtonsoft.Json;
潘栩锋's avatar
潘栩锋 committed
12 13 14 15

namespace FLY.Thick.Base.Server
{
    //代替TDInitParam
16
    public class SysParam : INotifyPropertyChanged
潘栩锋's avatar
潘栩锋 committed
17 18 19
    {
        #region 属性,成员变量的代理

20 21 22
        /// <summary>
        /// 本机obj服务地址
        /// </summary>
23
        public string Addr { get; set; } = "0.0.0.0:20006";
潘栩锋's avatar
潘栩锋 committed
24

25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
        /// <summary>
        /// AD盒硬件版本, 默认为 A版:flyad7, B版:ad2021
        /// </summary>
        public string FlyAdHardwareVersion { get; set; } = "A";

        /// <summary>
        /// 数据库保存的月数
        /// </summary>
        public int DbKeepMonth { get; set; } = 12;

        /// <summary>
        /// 数据库路径
        /// </summary>
        public string DbDirPath { get; set; } = @"D:\flydata";

潘栩锋's avatar
潘栩锋 committed
40 41
        #endregion

42
        private string param_path = "sysparam.json";
潘栩锋's avatar
潘栩锋 committed
43 44
        public SysParam()
        {
45

潘栩锋's avatar
潘栩锋 committed
46 47 48 49 50
        }
        public SysParam(string param_path) 
        {
            if (!string.IsNullOrEmpty(param_path))
                this.param_path = param_path;
51 52 53
            if (!Load()) {
                Save();
            }
潘栩锋's avatar
潘栩锋 committed
54
        }
55 56


57
        public bool Load()
潘栩锋's avatar
潘栩锋 committed
58
        {
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
            try
            {
                if (File.Exists(param_path))
                {
                    string json = File.ReadAllText(param_path);
                    JsonConvert.PopulateObject(json, this);
                    return true;
                }
            }
            catch
            {
                //异常,没有json 解码失败
            }

            return false;
        }
        public bool Save()
        {
            try
            {
                File.WriteAllText(param_path, JsonConvert.SerializeObject(this, Formatting.Indented));
                return true;
            }
            catch
            {
                //异常,没有json 编码失败

            }
            return false;

潘栩锋's avatar
潘栩锋 committed
89 90 91 92 93 94
        }


        #region INotifyPropertyChanged 成员

        public event PropertyChangedEventHandler PropertyChanged;
95

潘栩锋's avatar
潘栩锋 committed
96 97
        #endregion

98

潘栩锋's avatar
潘栩锋 committed
99 100
    }
}