using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace FLY.FilmCasting.AutoDie.Server
{
    public class SysParam
    {
        /// <summary>
        /// OBJ服务端口
        /// </summary>
        public int OBJ_Port { get; set; } = 20007;

        /// <summary>
        /// 测厚仪服务器地址
        /// </summary>
        public string ThickAddr { get; set; } = "127.0.0.1:20006";

        /// <summary>
        /// 数据库保持时间 默认6个月
        /// </summary>
        public int DbKeepMonth { get; set; } = 6;

        public SysParam()
        {
            if (!Load())
                Save();
        }
        string file_path = "system.json";
        public void Save()
        {
            try
            {
                string json = JsonConvert.SerializeObject(this, Formatting.Indented);
                File.WriteAllText(file_path, json);
            }
            catch
            {
                //异常，没有json 编码失败

            }
        }
        public bool Load()
        {
            if (File.Exists(file_path))
            {
                try
                {
                    string json = File.ReadAllText(file_path);
                    JsonConvert.PopulateObject(json, this);
                    return true;
                }
                catch
                {
                    //异常，没有json 解码失败

                }
                return false;
            }
            return false;

        }
    }
}
