SysParam.cs 2.84 KB
Newer Older
潘栩锋's avatar
潘栩锋 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
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;

namespace FLY.Thick.Base.Server
{
    //代替TDInitParam
    public class SysParam : INotifyPropertyChanged, ISaveToXml
    {
        #region 属性,成员变量的代理

19 20 21 22 23
        /// <summary>
        /// 本机obj服务地址
        /// </summary>
        [PropertyChanged.DoNotCheckEquality]
        public IPEndPoint LocalEP { get; set; } = Misc.StringConverter.ToIPEndPoint("127.0.0.1:20006");
潘栩锋's avatar
潘栩锋 committed
24

25 26 27 28 29
        /// <summary>
        /// AD盒地址
        /// </summary>
        [PropertyChanged.DoNotCheckEquality]
        public IPEndPoint FLYAD7EP { get; set; } = Misc.StringConverter.ToIPEndPoint("192.168.250.10:20006");
潘栩锋's avatar
潘栩锋 committed
30

31 32 33 34 35
        /// <summary>
        /// AD盒通讯使用 CRC校验
        /// </summary>
        public bool FLYAD7_HasCRC { get; set; } = false;
        
潘栩锋's avatar
潘栩锋 committed
36 37 38
        /// <summary>
        /// grid 平滑
        /// </summary>
39 40 41 42 43 44
        public int FLYAD7_GridSmooth { get; set; } = 0;

        /// <summary>
        /// 数据库地址,只读,界面没法修改
        /// </summary>
        public string DBPath { get; set; } = @"D:\flydata\thick_history.sqlite3";
潘栩锋's avatar
潘栩锋 committed
45 46 47 48 49 50 51 52 53 54 55 56 57 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
        #endregion

        private string param_path = "sysparam.xml";
        public SysParam()
        {
            this.PropertyChanged += new PropertyChangedEventHandler(SysParam_PropertyChanged);
        }
        public SysParam(string param_path) 
        {
            if (!string.IsNullOrEmpty(param_path))
                this.param_path = param_path;
            Load();
            this.PropertyChanged += new PropertyChangedEventHandler(SysParam_PropertyChanged);
        }
        void SysParam_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (isLoading)
                return;
            if ((e.PropertyName == "FLYAD7EP")||
                (e.PropertyName == "FLYAD7_HasCRC")||
                (e.PropertyName == "FLYAD7_GridSmooth")
            )
            {
                Save();
            }
        }
        bool isLoading = false;
        public bool Load()
        {
            isLoading = true;
            bool ret = Misc.SaveToXmlHepler.Load(param_path, this);
            isLoading = false;
            return ret;
        }

        public void Save()
        {
            Misc.SaveToXmlHepler.Save(param_path, this);

        }
        #region INotifyPropertyChanged 成员

        public event PropertyChangedEventHandler PropertyChanged;
88

潘栩锋's avatar
潘栩锋 committed
89 90 91 92 93 94 95 96
        #endregion

        public string[] GetSavePropertyNames()
        {
            return new string[]{
            "LocalEP",
            "FLYAD7EP",
            "FLYAD7_HasCRC",
97 98
            "FLYAD7_GridSmooth",
            "DBPath"
潘栩锋's avatar
潘栩锋 committed
99 100 101 102
            };
        }
    }
}