大幅度重构代码,还需要完善测试【A large number of changes, need coding】

This commit is contained in:
dathlin
2017-05-04 11:43:50 +08:00
parent 119eafd6b2
commit f8c17d882e
34 changed files with 3611 additions and 911 deletions

View File

@@ -0,0 +1,61 @@
using HslCommunication.BasicFramework;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace CommonLibrary
{
/// <summary>
/// 系统更新日志类窗体
/// </summary>
public partial class FormUpdateLog : Form
{
/// <summary>
/// 实例化一个更新窗口的对象,用来呈现更新日志
/// </summary>
/// <param name="versions">包含了更新细节的一个对象,更新日志,更新内容</param>
public FormUpdateLog(IEnumerable<VersionInfo> versions)
{
InitializeComponent();
Versions = versions;
}
private IEnumerable<VersionInfo> Versions = null;
private void FormUpdateLog_Load(object sender, EventArgs e)
{
richTextBox1.SelectionIndent = 3;
richTextBox1.SelectionHangingIndent = 16;
richTextBox1.SelectionRightIndent = 3;
listBox1.DataSource = Versions;
listBox1.SelectedIndexChanged += ListBox1_SelectedIndexChanged;
ListBox1_SelectedIndexChanged(null, new EventArgs());
}
private void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (listBox1.SelectedItem != null)
{
VersionInfo info = listBox1.SelectedItem as VersionInfo;
if (info != null)
{
richTextBox1.Clear();
richTextBox1.AppendText("版本:" + info.VersionNum + Environment.NewLine);
richTextBox1.AppendText("日期:" + info.ReleaseDate.ToShortDateString() + Environment.NewLine);
richTextBox1.AppendText(Environment.NewLine);
richTextBox1.AppendText("内容:" + Environment.NewLine +
info.UpdateDetails.ToString() + Environment.NewLine);
richTextBox1.SelectionStart = 0;
}
}
}
}
}

View File

@@ -0,0 +1,119 @@
namespace CommonLibrary
{
partial class FormUpdateLog
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.label2 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.listBox1 = new System.Windows.Forms.ListBox();
this.richTextBox1 = new System.Windows.Forms.RichTextBox();
this.SuspendLayout();
//
// label2
//
this.label2.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.label2.AutoSize = true;
this.label2.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label2.ForeColor = System.Drawing.Color.Black;
this.label2.Location = new System.Drawing.Point(144, 9);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(90, 21);
this.label2.TabIndex = 9;
this.label2.Text = "更新日志:";
//
// label1
//
this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.label1.AutoSize = true;
this.label1.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label1.ForeColor = System.Drawing.Color.Black;
this.label1.Location = new System.Drawing.Point(12, 9);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(74, 21);
this.label1.TabIndex = 8;
this.label1.Text = "版本号:";
//
// listBox1
//
this.listBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)));
this.listBox1.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.listBox1.FormattingEnabled = true;
this.listBox1.ItemHeight = 21;
this.listBox1.Location = new System.Drawing.Point(15, 39);
this.listBox1.Name = "listBox1";
this.listBox1.Size = new System.Drawing.Size(123, 403);
this.listBox1.TabIndex = 10;
//
// richTextBox1
//
this.richTextBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.richTextBox1.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.richTextBox1.Location = new System.Drawing.Point(148, 38);
this.richTextBox1.Name = "richTextBox1";
this.richTextBox1.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.Vertical;
this.richTextBox1.Size = new System.Drawing.Size(489, 394);
this.richTextBox1.TabIndex = 11;
this.richTextBox1.Text = "";
//
// FormUpdateLog
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(651, 448);
this.Controls.Add(this.richTextBox1);
this.Controls.Add(this.listBox1);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.Name = "FormUpdateLog";
this.ShowIcon = false;
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "更新日志";
this.Load += new System.EventHandler(this.FormUpdateLog_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.ListBox listBox1;
private System.Windows.Forms.RichTextBox richTextBox1;
}
}

View File

@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@@ -0,0 +1,59 @@
using HslCommunication.BasicFramework;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace CommonLibrary
{
/// <summary>
/// 控制版本号的窗口类
/// </summary>
public partial class FormVersionControl : Form
{
/// <summary>
///
/// </summary>
/// <param name="settings"></param>
public FormVersionControl(ServerSettings settings)
{
InitializeComponent();
Settings = settings;
}
private ServerSettings Settings = null;
private void FormVersionControl_Shown(object sender, EventArgs e)
{
textBox1.Text = Settings.SystemVersion.ToString();
textBox2.Focus();
}
private void userButton1_Click(object sender, EventArgs e)
{
try
{
Settings.SystemVersion = new SystemVersion(textBox2.Text);
}
catch(Exception ex)
{
MessageBox.Show("版本号格式错误应为1.0.0" + Environment.NewLine +
"错误描述:" + ex.Message);
}
try
{
Settings.SaveToFile();
MessageBox.Show("保存成功");
}
catch(Exception ex)
{
MessageBox.Show("数据保存失败" + Environment.NewLine +
"错误描述:" + ex.Message);
}
}
}
}

View File

@@ -0,0 +1,122 @@
using HslCommunication.Controls;
namespace CommonLibrary
{
partial class FormVersionControl
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.userButton1 = new UserButton();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(24, 31);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(68, 17);
this.label1.TabIndex = 0;
this.label1.Text = "当前版本:";
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(101, 28);
this.textBox1.Name = "textBox1";
this.textBox1.ReadOnly = true;
this.textBox1.Size = new System.Drawing.Size(261, 23);
this.textBox1.TabIndex = 1;
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(101, 68);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(261, 23);
this.textBox2.TabIndex = 3;
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(24, 71);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(68, 17);
this.label2.TabIndex = 2;
this.label2.Text = "更新版本:";
//
// userButton1
//
this.userButton1.BackColor = System.Drawing.Color.Transparent;
this.userButton1.CustomerInformation = "";
this.userButton1.EnableColor = System.Drawing.Color.FromArgb(((int)(((byte)(190)))), ((int)(((byte)(190)))), ((int)(((byte)(190)))));
this.userButton1.Font = new System.Drawing.Font("微软雅黑", 9F);
this.userButton1.Location = new System.Drawing.Point(145, 110);
this.userButton1.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.userButton1.Name = "userButton1";
this.userButton1.Size = new System.Drawing.Size(110, 30);
this.userButton1.TabIndex = 4;
this.userButton1.UIText = "保存";
this.userButton1.Click += new System.EventHandler(this.userButton1_Click);
//
// FormVersionControl
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(397, 158);
this.Controls.Add(this.userButton1);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.label2);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.label1);
this.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.MaximizeBox = false;
this.MaximumSize = new System.Drawing.Size(413, 197);
this.MinimizeBox = false;
this.MinimumSize = new System.Drawing.Size(413, 197);
this.Name = "FormVersionControl";
this.ShowIcon = false;
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "系统版本更新";
this.Shown += new System.EventHandler(this.FormVersionControl_Shown);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.Label label2;
private UserButton userButton1;
}
}

View File

@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@@ -0,0 +1,138 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Linq;
using System.IO;
using HslCommunication.BasicFramework;
//2017-02-10
namespace CommonLibrary
{
/// <summary>
/// 服务器的常用参数保存,包含了版本号,公告,是否允许登录,不能登录说明
/// </summary>
public class ServerSettings : SoftFileSaveBase
{
/// <summary>
/// 系统的版本号,可以用来验证版本更新的依据
/// 初始化1.0.0
/// </summary>
public SystemVersion SystemVersion { get; set; } = new SystemVersion("1.0.0");
/// <summary>
/// 系统的公告信息,默认为测试公告
/// </summary>
public string Announcement { get; set; } = "测试公告";
/// <summary>
/// 是否允许账户登录
/// 超级管理员账户除外
/// </summary>
public bool Can_Account_Login { get; set; } = true;
/// <summary>
/// 不允许登录系统的原因
/// </summary>
public string Account_Forbidden_Reason { get; set; } = "系统处于维护中,请稍后登录。";
/// <summary>
/// 获取需要存储的数据
/// </summary>
/// <returns></returns>
public override string ToSaveString()
{
JObject json = new JObject
{
{ nameof(SystemVersion), new JValue(SystemVersion.ToString()) },
{ nameof(Announcement), new JValue(Announcement) },
{ nameof(Can_Account_Login), new JValue(Can_Account_Login) },
{ nameof(Account_Forbidden_Reason), new JValue(Account_Forbidden_Reason) }
};
return json.ToString();
}
/// <summary>
/// 从字符串数据加载配置
/// </summary>
/// <param name="content"></param>
public override void LoadByString(string content)
{
JObject json = JObject.Parse(content);
SystemVersion = new SystemVersion(json.Property(nameof(SystemVersion)).Value.Value<string>());
Announcement = json.Property(nameof(Announcement)).Value.Value<string>();
Can_Account_Login = SoftBasic.GetValueFromJsonObject(json, nameof(Can_Account_Login), Can_Account_Login);
Account_Forbidden_Reason = SoftBasic.GetValueFromJsonObject(json, nameof(Account_Forbidden_Reason), Account_Forbidden_Reason);
}
}
/// <summary>
/// 用户客户端存储本地JSON数据的类包含了所有需要存储的信息
/// </summary>
public class JsonSettings : SoftFileSaveBase
{
/// <summary>
/// 实例化一个设置的对象
/// </summary>
public JsonSettings()
{
SystemInfo = SoftAuthorize.GetInfo();
}
/// <summary>
/// 指示系统是否是更新后第一次运行
/// </summary>
public bool IsNewVersionRunning { get; set; } = true;
/// <summary>
/// 上次系统登录的用户名
/// </summary>
public string LoginName { get; set; } = "";
/// <summary>
/// 上次系统登录的密码
/// </summary>
public string Password { get; set; } = "";
/// <summary>
/// 当前计算机的机器码,用来判定参数是否是正确的
/// </summary>
public string SystemInfo { get; private set; }
public override string ToSaveString()
{
JObject json = new JObject();
json.Add(nameof(LoginName), new JValue(LoginName));
json.Add(nameof(Password), new JValue(Password));
json.Add(nameof(IsNewVersionRunning), new JValue(IsNewVersionRunning));
json.Add(nameof(SystemInfo), new JValue(SystemInfo));
return json.ToString();
}
public override void LoadByString(string content)
{
JObject json = JObject.Parse(content);
string systemInfo = SoftBasic.GetValueFromJsonObject(json, nameof(SystemInfo), "");
if (systemInfo == SystemInfo)
{
//文件匹配正确
LoginName = SoftBasic.GetValueFromJsonObject(json, nameof(LoginName), LoginName);
IsNewVersionRunning = SoftBasic.GetValueFromJsonObject(json, nameof(IsNewVersionRunning), IsNewVersionRunning);
Password = SoftBasic.GetValueFromJsonObject(json, nameof(Password), Password);
}
}
/// <summary>
/// 使用指定的解密实现数据解密
/// </summary>
public override void LoadByFile()
{
LoadByFile(m => SoftSecurity.MD5Decrypt(m, CommonLibrary.Security));
}
public override void SaveToFile()
{
SaveToFile(m => SoftSecurity.MD5Encrypt(m, CommonLibrary.Security));
}
}
}