Commit eaf0704a authored by 潘栩锋's avatar 潘栩锋 🚴

优化 SysParam 改为 保存 json文件

parent da297f04
......@@ -8,23 +8,23 @@ using System.IO;
using System.ComponentModel;
using System.Xml.Serialization;
using FLY.Thick.Base.Common;
using Newtonsoft.Json;
namespace FLY.Thick.Base.Server
{
//代替TDInitParam
public class SysParam : INotifyPropertyChanged, ISaveToXml
public class SysParam : INotifyPropertyChanged
{
#region 属性,成员变量的代理
/// <summary>
/// 本机obj服务地址
/// </summary>
[PropertyChanged.DoNotCheckEquality]
public IPEndPoint LocalEP { get; set; } = Misc.StringConverter.ToIPEndPoint("127.0.0.1:20006");
public string Addr { get; set; } = "0.0.0.0:20006";
#endregion
private string param_path = "sysparam.xml";
private string param_path = "sysparam.json";
public SysParam()
{
......@@ -33,14 +33,44 @@ namespace FLY.Thick.Base.Server
{
if (!string.IsNullOrEmpty(param_path))
this.param_path = param_path;
Load();
if (!Load()) {
Save();
}
}
public bool Load()
bool Load()
{
try
{
if (File.Exists(param_path))
{
string json = File.ReadAllText(param_path);
JsonConvert.PopulateObject(json, this);
return true;
}
}
catch
{
bool ret = Misc.SaveToXmlHepler.Load(param_path, this);
return ret;
//异常,没有json 解码失败
}
return false;
}
public bool Save()
{
try
{
File.WriteAllText(param_path, JsonConvert.SerializeObject(this, Formatting.Indented));
return true;
}
catch
{
//异常,没有json 编码失败
}
return false;
}
......@@ -50,11 +80,6 @@ namespace FLY.Thick.Base.Server
#endregion
public string[] GetSavePropertyNames()
{
return new string[]{
"LocalEP"
};
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment