SysParam.cs 2.76 KB
Newer Older
潘栩锋's avatar
潘栩锋 committed
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
using FLY.Weight.UI.Client.UIModule;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Net;
using System.Text;

namespace FLY.Weight.UI.Client
{
    public class SysParam : Misc.ISaveToXml, INotifyPropertyChanged
    {
        static SysParam current;
        public static SysParam Current
        {
            get
            {
                if (current == null)
                {
                    current = new SysParam();
                }
                return current;
            }
        }

        #region 属性,成员变量的代理
        public IPEndPoint ServerEP { get; set; }

        /// <summary>
        /// 主界面显示厚度
        /// </summary>
        public bool HasThickness { get; set; } = true;

        /// <summary>
        /// 由于不支持int[] 所以要使用string,以后再转换
        /// </summary>
38 39
        public string BinCnts_json { get; set; } = JsonConvert.SerializeObject(new int[] {4,4,4});// "[4,4,4]";

潘栩锋's avatar
潘栩锋 committed
40 41 42 43 44 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 88 89 90 91 92 93 94

        /// <summary>
        /// 数组
        /// </summary>
        public int[] BinCnts {
            get{
                return JsonConvert.DeserializeObject<int[]>(BinCnts_json);
            }
            set {
                string json = JsonConvert.SerializeObject(value);
                BinCnts_json = json;
            }
        }
        public FlowGraphParams GraphParams { get; } = new FlowGraphParams();


        public string Path = "weightparam.xml";
        #endregion

        static SysParam()
        {
            Misc.SaveToXmlHepler.Regist(typeof(FlowGraphParams));
        }
        public SysParam()
        {
            ServerEP = Misc.StringConverter.ToIPEndPoint("127.0.0.1:20005");
            if (!Load())
                Save();

            this.PropertyChanged += SysParam_PropertyChanged;
        }

        private void SysParam_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (e.PropertyName == "BinCnts")
            {
                Save();
            }
        }

        public bool Load()
        {
            return Misc.SaveToXmlHepler.Load(Path, this);
        }
        public void Save()
        {
            Misc.SaveToXmlHepler.Save(Path, this);
        }

        public string[] GetSavePropertyNames()
        {
            return new string[]{
                "ServerEP",
                "BinCnts_json",
                "HasThickness",
95
                "GraphParams"
潘栩锋's avatar
潘栩锋 committed
96 97 98 99 100 101 102 103 104
            };
        }
        protected void NotifyProperty(string propertyname)
        {
            if (PropertyChanged != null)
                PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyname));
        }
        public event PropertyChangedEventHandler PropertyChanged;
    }
105

潘栩锋's avatar
潘栩锋 committed
106
}