Commit 718601f2 authored by 潘栩锋's avatar 潘栩锋 🚴

地址 与 密码 添加默认值功能。 放在 default 文件夹

parent ee279be4
...@@ -39,7 +39,10 @@ namespace FObjBase ...@@ -39,7 +39,10 @@ namespace FObjBase
/// </summary> /// </summary>
[JsonProperty] [JsonProperty]
public List<ConnAddr> ConnAddrs { get; } = new List<ConnAddr>(); public List<ConnAddr> ConnAddrs { get; } = new List<ConnAddr>();
/// <summary>
/// 默认地址
/// </summary>
List<ConnDefaultAddr> DefaultAddrs { get; } = new List<ConnDefaultAddr>();
/// <summary> /// <summary>
/// 连接到 另一个Obj系统 /// 连接到 另一个Obj系统
...@@ -53,10 +56,15 @@ namespace FObjBase ...@@ -53,10 +56,15 @@ namespace FObjBase
var connaddr = ConnAddrs.Find(c => c.ConnName == connName); var connaddr = ConnAddrs.Find(c => c.ConnName == connName);
if (connaddr == null) if (connaddr == null)
{ {
string addr = "0.0.0.1:12345";//没有默认值,创建连接到不存在的地址,避免出错
//没有,那就创建一个 //没有,那就创建一个
//创建连接到不存在的地址,避免出错 //查找默认值
connaddr = new ConnAddr() { ConnName = connName, Addr = "0.0.0.1:12345" }; var defaultAddr = DefaultAddrs.Find(c => c.ConnName == connName);
if (defaultAddr != null)
addr = defaultAddr.Addr;
connaddr = new ConnAddr() { ConnName = connName, Addr = addr };
ConnAddrs.Add(connaddr); ConnAddrs.Add(connaddr);
} }
foreach (var id in fObjClient.GetIDs()) foreach (var id in fObjClient.GetIDs())
...@@ -113,12 +121,27 @@ namespace FObjBase ...@@ -113,12 +121,27 @@ namespace FObjBase
string filename = "serviceManager.json"; string filename = "serviceManager.json";
string file_default_path = "default/serviceManager.default.json";
void LoadDefault() {
if (!File.Exists(file_default_path))
return;
try
{
string json = File.ReadAllText(file_default_path);
var p = JsonConvert.DeserializeObject<List<ConnDefaultAddr>>(json);
DefaultAddrs.AddRange(p);
}
catch(Exception e)
{
}
}
/// <summary> /// <summary>
/// 加载配置 /// 加载配置
/// </summary> /// </summary>
public void Load() void Load()
{ {
LoadDefault();
if (File.Exists(filename)) if (File.Exists(filename))
{ {
try try
...@@ -190,4 +213,16 @@ namespace FObjBase ...@@ -190,4 +213,16 @@ namespace FObjBase
/// </summary> /// </summary>
public List<UInt32> ClientIds = new List<UInt32>(); public List<UInt32> ClientIds = new List<UInt32>();
} }
public class ConnDefaultAddr {
/// <summary>
/// 连接器名称
/// </summary>
public string ConnName;
/// <summary>
/// 设备地址
/// </summary>
public string Addr;
}
} }
...@@ -18,14 +18,19 @@ namespace FLY.Thick.Base.UI ...@@ -18,14 +18,19 @@ namespace FLY.Thick.Base.UI
public class PasswordAuthorize:INotifyPropertyChanged public class PasswordAuthorize:INotifyPropertyChanged
{ {
const string JSONDIST_KEY = "password"; const string JSONDIST_KEY = "password";
/// <summary>
/// 服务器
/// </summary>
IJsonDistService jsonDist; IJsonDistService jsonDist;
/// <summary> /// <summary>
/// 数据库 /// 数据库
/// </summary> /// </summary>
[PropertyChanged.DoNotCheckEquality] [PropertyChanged.DoNotCheckEquality]
public PasswordJsonDb Db { get; private set; } = new PasswordJsonDb(); public PasswordJsonDb Db { get; private set; } = new PasswordJsonDb();
PasswordJsonDb DbDefault;
/// <summary> /// <summary>
/// 修改时间 /// 修改时间,这个是服务器保存数据的时间。一切以服务器为准
/// </summary> /// </summary>
public DateTime Time { get; set; } public DateTime Time { get; set; }
...@@ -74,20 +79,31 @@ namespace FLY.Thick.Base.UI ...@@ -74,20 +79,31 @@ namespace FLY.Thick.Base.UI
} }
} }
/// <summary>
/// 设置默认数据 void check_db()
/// </summary>
void default_db()
{ {
Time = DateTime.MinValue; if (DbDefault == null)
Db = new PasswordJsonDb() return;
{ if (DbDefault.UiLvs.Count == 0)
Pws = new List<PasswordCell>{ return;
new PasswordCell(){Level = 10, Password = "flymeasure"},
new PasswordCell(){Level = 1, Password = "1"} if (Db == null)
}, Db = new PasswordJsonDb();
UiLvs = new List<UiLvCell>()
}; // 界面权限
foreach (var uiLv in DbDefault.UiLvs) {
if (!Db.UiLvs.Any(u => u.UiName == uiLv.UiName)) {
Db.UiLvs.Add(new UiLvCell() { UiName = uiLv.UiName, Level = uiLv.Level, Description = uiLv.Description });
}
}
//密码
if (Db.Pws.Count() == 0) {
foreach (var pw in DbDefault.Pws)
{
Db.Pws.Add(new PasswordCell() { Password = pw.Password, Level=pw.Level });
}
}
} }
/// <summary> /// <summary>
/// 从服务器获取数据 /// 从服务器获取数据
...@@ -100,8 +116,7 @@ namespace FLY.Thick.Base.UI ...@@ -100,8 +116,7 @@ namespace FLY.Thick.Base.UI
if (retData == null) if (retData == null)
{ {
//没有数据 //没有数据
//放入默认值 //什么都不做
push_db(Db);
} }
else else
{ {
...@@ -109,15 +124,18 @@ namespace FLY.Thick.Base.UI ...@@ -109,15 +124,18 @@ namespace FLY.Thick.Base.UI
var p = (distCell.Value).ToObject<PasswordJsonDb>(); var p = (distCell.Value).ToObject<PasswordJsonDb>();
if (p == null || p.Pws==null || p.Pws.Count()==0)//异常 if (p == null || p.Pws==null || p.Pws.Count()==0)//异常
{ {
push_db(Db); //什么都不做
} }
else else
{ {
//只要时间与服务器的不一样,全部覆盖!!
if (Time != distCell.Time) if (Time != distCell.Time)
{ {
Time = distCell.Time;
Db = p; Db = p;
check_db();
Save(); Save();
Time = distCell.Time;
} }
} }
} }
...@@ -169,10 +187,9 @@ namespace FLY.Thick.Base.UI ...@@ -169,10 +187,9 @@ namespace FLY.Thick.Base.UI
public int GetLv(string uiName) public int GetLv(string uiName)
{ {
Base.Common.UiLvCell uiLvCell; Base.Common.UiLvCell uiLvCell;
uiLvCell = Db.UiLvs.Find(c => c.UiName == uiName);
if (Db.UiLvs == null) if (uiLvCell == null)
{ {
Db.UiLvs = new List<Base.Common.UiLvCell>();
uiLvCell = new Base.Common.UiLvCell() uiLvCell = new Base.Common.UiLvCell()
{ {
UiName = uiName UiName = uiName
...@@ -180,31 +197,19 @@ namespace FLY.Thick.Base.UI ...@@ -180,31 +197,19 @@ namespace FLY.Thick.Base.UI
//没有,添加 //没有,添加
Db.UiLvs.Add(uiLvCell); Db.UiLvs.Add(uiLvCell);
}
else
{
uiLvCell = Db.UiLvs.Find(c => c.UiName == uiName);
if (uiLvCell == null)
{
uiLvCell = new Base.Common.UiLvCell()
{
UiName = uiName
};
//没有,添加
Db.UiLvs.Add(uiLvCell);
}
} }
return uiLvCell.Level; return uiLvCell.Level;
} }
string file_path = "password.json"; string file_path = "password.json";
string file_default_path = "default/password.default.json";
public event PropertyChangedEventHandler PropertyChanged; public event PropertyChangedEventHandler PropertyChanged;
public void Apply(PasswordJsonDb db) public void Apply(PasswordJsonDb db)
{ {
//设置jsonDist,不需要设置到本地。
//jsonDist内的参数被修改后,会推送数据出来。到时再获取。
push_db(db); push_db(db);
} }
void Save() void Save()
...@@ -214,7 +219,7 @@ namespace FLY.Thick.Base.UI ...@@ -214,7 +219,7 @@ namespace FLY.Thick.Base.UI
Db = Db, Db = Db,
Time = Time Time = Time
}; };
string json = Newtonsoft.Json.JsonConvert.SerializeObject(p); string json = Newtonsoft.Json.JsonConvert.SerializeObject(p, Newtonsoft.Json.Formatting.Indented);
try try
{ {
File.WriteAllText(file_path, json); File.WriteAllText(file_path, json);
...@@ -224,29 +229,41 @@ namespace FLY.Thick.Base.UI ...@@ -224,29 +229,41 @@ namespace FLY.Thick.Base.UI
} }
} }
void LoadDefault() {
if (!File.Exists(file_default_path))
return;
string json = File.ReadAllText(file_default_path);
try
{
var p = Newtonsoft.Json.JsonConvert.DeserializeObject<PasswordJsonDb>(json);
DbDefault = p;
}
catch
{
}
}
void Load() void Load()
{ {
LoadDefault();
if (!File.Exists(file_path)) if (!File.Exists(file_path))
{
default_db();
return; return;
}
string json = File.ReadAllText("password.json"); string json = File.ReadAllText(file_path);
try try
{ {
var p = Newtonsoft.Json.JsonConvert.DeserializeObject<PasswordJsonDb2>(json); var p = Newtonsoft.Json.JsonConvert.DeserializeObject<PasswordJsonDb2>(json);
Db = p.Db; Db = p.Db;
Time = p.Time; Time = p.Time;
check_db();
} }
catch { catch {
} }
if (Db == null || Db.Pws == null || Db.Pws.Count()==0) //异常
{
default_db();
}
} }
} }
...@@ -272,24 +289,27 @@ namespace FLY.Thick.Base.UI ...@@ -272,24 +289,27 @@ namespace FLY.Thick.Base.UI
public class PasswordJsonDb2 public class PasswordJsonDb2
{ {
/// <summary>
/// 与服务器同步参数
/// </summary>
public PasswordJsonDb Db; public PasswordJsonDb Db;
/// <summary> /// <summary>
/// 修改时间 /// 修改时间
/// </summary> /// </summary>
public DateTime Time; public DateTime Time;
} }
public class PasswordJsonDb public class PasswordJsonDb
{ {
/// <summary> /// <summary>
/// 界面授权列表 /// 界面授权列表
/// </summary> /// </summary>
public List<UiLvCell> UiLvs; public List<UiLvCell> UiLvs { get; } = new List<UiLvCell>();
/// <summary> /// <summary>
/// 密码列表 /// 密码列表
/// </summary> /// </summary>
public List<PasswordCell> Pws; public List<PasswordCell> Pws { get; } = new List<PasswordCell>();
} }
} }
...@@ -119,10 +119,8 @@ namespace FLY.Thick.Base.UI ...@@ -119,10 +119,8 @@ namespace FLY.Thick.Base.UI
return; return;
} }
} }
for (int i=0;i<UiLvs.Count();i++) foreach(var c in UiLvs)
{ {
var c = UiLvs[i];
if (c.Level < 0 || c.Level > 10) if (c.Level < 0 || c.Level > 10)
{ {
FLY.ControlLibrary.Window_WarningTip.Show( FLY.ControlLibrary.Window_WarningTip.Show(
...@@ -131,11 +129,12 @@ namespace FLY.Thick.Base.UI ...@@ -131,11 +129,12 @@ namespace FLY.Thick.Base.UI
return; return;
} }
} }
this.passwordAuthorize.Apply(new PasswordJsonDb()
{ var p = new PasswordJsonDb();
Pws = Pws.ToList(), p.Pws.AddRange(Pws);
UiLvs = UiLvs.ToList() p.UiLvs.AddRange(UiLvs);
});
this.passwordAuthorize.Apply(p);
FLY.ControlLibrary.Window_Tip.ShowShortTime( FLY.ControlLibrary.Window_Tip.ShowShortTime(
"修改成功", "修改成功",
......
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