diff --git a/StartServerWPF.Modules.Main/Images/calendar.png b/StartServerWPF.Modules.Main/Images/calendar.png
new file mode 100644
index 0000000..58733c6
Binary files /dev/null and b/StartServerWPF.Modules.Main/Images/calendar.png differ
diff --git a/StartServerWPF.Modules.Main/JsonParser.cs b/StartServerWPF.Modules.Main/JsonParser.cs
index 58fda2a..24081cc 100644
--- a/StartServerWPF.Modules.Main/JsonParser.cs
+++ b/StartServerWPF.Modules.Main/JsonParser.cs
@@ -10,8 +10,14 @@ using StartServerWPF.Modules.Main.Model;
namespace StartServerWPF.Modules.Main
{
- public static class JsonParser
+ public class JsonParser
{
+ // public static string zyProPath = @"\serverprogram";
+
+ public static string systemConfigPath = "SystemConfig.json";
+ public static string systemLogFileName;
+ public static string serverVision = "20230517";
+
public static SystemConfig ReadSystemJsonFile(string jsonFile)
{
//try
@@ -93,15 +99,6 @@ namespace StartServerWPF.Modules.Main
{
string str = JsonConvert.SerializeObject(sc, Formatting.Indented);
File.WriteAllText(jsonFile, str);
- //using (StreamWriter sw = new StreamWriter(jsonFile))
- //{
- // JsonSerializer js = new JsonSerializer();
- // JsonWriter jw = new JsonTextWriter(sw);
-
- // js.Serialize(jw, sc);
- // jw.Close();
- // sw.Close();
- //}
}
public static void UpdateApmsJson(string apmsJsonPath, string savePath)
diff --git a/StartServerWPF.Modules.Main/StartServerWPF.Modules.Main.csproj b/StartServerWPF.Modules.Main/StartServerWPF.Modules.Main.csproj
index 70b599b..25de221 100644
--- a/StartServerWPF.Modules.Main/StartServerWPF.Modules.Main.csproj
+++ b/StartServerWPF.Modules.Main/StartServerWPF.Modules.Main.csproj
@@ -4,6 +4,9 @@
true
True
+
+
+
@@ -15,4 +18,7 @@
..\StartServerWPF\DotRas.dll
+
+
+
\ No newline at end of file
diff --git a/StartServerWPF.Modules.Main/ViewModels/MainViewModel.cs b/StartServerWPF.Modules.Main/ViewModels/MainViewModel.cs
index e21c894..89b1160 100644
--- a/StartServerWPF.Modules.Main/ViewModels/MainViewModel.cs
+++ b/StartServerWPF.Modules.Main/ViewModels/MainViewModel.cs
@@ -23,8 +23,8 @@ namespace StartServerWPF.Modules.Main.ViewModels
public MainViewModel(IDialogService dialogService)
{
Message = "View A from your Prism Module";
- Console.WriteLine(System.Environment.CurrentDirectory + "\\" + systemConfigPath);
- sc = JsonParser.ReadSystemJsonFile(systemConfigPath);
+ Console.WriteLine(System.Environment.CurrentDirectory + "\\" + JsonParser.systemConfigPath);
+ sc = JsonParser.ReadSystemJsonFile(JsonParser.systemConfigPath);
int moniTimeInd = sc.proMonitor.ProParams.IndexOf("-btime");
string moniTimeStr = sc.proMonitor.ProParams.Substring(moniTimeInd + 7);
int moniTimeIndEnd = moniTimeStr.IndexOf(">");
@@ -54,30 +54,47 @@ namespace StartServerWPF.Modules.Main.ViewModels
}
private DateTime startTime;
private DateTime moniStartTime;
- public DateTime StartTime { get => startTime; set => startTime = value; }
- public DateTime MoniStartTime { get => moniStartTime; set => moniStartTime = value; }
+ public DateTime StartTime { get => startTime; set => SetProperty(ref startTime, value); }
+ public DateTime MoniStartTime { get => moniStartTime; set => SetProperty(ref moniStartTime, value); }
private string runTime;
public string RunTime
{
get { return runTime; }
- set { runTime = value; }
+ set { SetProperty(ref runTime, value); }
}
private string vPNStatus;
public string VPNStatus
{
get { return vPNStatus; }
- set { vPNStatus = value; }
+ set { SetProperty(ref vPNStatus, value);
+ }
}
private string vpnIP;
public string VpnIP
{
get { return vpnIP; }
- set { vpnIP = value; }
+ set { SetProperty(ref vpnIP, value); }
+ }
+ private string vPNStatusForeColor;
+
+ public string VPNStatusForeColor
+ {
+ get { return vPNStatusForeColor; }
+ set { SetProperty(ref vPNStatusForeColor, value); }
}
+ private bool vPNIsConnect;
+
+ public bool VPNIsConnect
+ {
+ get { return vPNIsConnect; }
+ set { SetProperty(ref vPNIsConnect, value); }
+ }
+
+
private ObservableCollection reciveDataSource=new ObservableCollection();
@@ -99,7 +116,7 @@ namespace StartServerWPF.Modules.Main.ViewModels
public int SelectedIndex
{
get { return selectedIndex; }
- set { selectedIndex = value; }
+ set { SetProperty(ref selectedIndex, value); }
}
private bool isEnabledStart;
@@ -107,12 +124,12 @@ namespace StartServerWPF.Modules.Main.ViewModels
public bool IsEnabledStart
{
get { return isEnabledStart; }
- set { isEnabledStart = value; }
+ set { SetProperty(ref isEnabledStart, value); }
}
private int proMonInterval = 10;
public int ProMonInterval { get => proMonInterval;
- set => proMonInterval = value;
+ set => SetProperty(ref proMonInterval, value);
}
#endregion
@@ -144,7 +161,7 @@ namespace StartServerWPF.Modules.Main.ViewModels
KillProcess(sc.proApms);
KillProcess(sc.proMonitor);
string logStr = DateTime.Now.ToString("s") + "\t程序关闭";
- WriteSerLog(sc.vpnInfo.SystemLogPath + systemLogFileName, logStr);
+ WriteSerLog(sc.vpnInfo.SystemLogPath + JsonParser.systemLogFileName, logStr);
//switch (kserindex)
//{
// case -1:
@@ -179,7 +196,7 @@ namespace StartServerWPF.Modules.Main.ViewModels
vpn.ConnectVPN(sc.vpnInfo.VpnName, sc.vpnInfo.VpnUserName, sc.vpnInfo.VpnPsw);
Thread.Sleep(1000);
string logStr = DateTime.Now.ToString("s") + "\tVPN手动连接";
- WriteSerLog(sc.vpnInfo.SystemLogPath + systemLogFileName, logStr);
+ WriteSerLog(sc.vpnInfo.SystemLogPath + JsonParser.systemLogFileName, logStr);
SetControlstatus();
}
@@ -192,7 +209,7 @@ namespace StartServerWPF.Modules.Main.ViewModels
SetControlstatus();
Thread.Sleep(100);
string logStr = DateTime.Now.ToString("s") + "\tVPN手动断开";
- WriteSerLog(sc.vpnInfo.SystemLogPath + systemLogFileName, logStr);
+ WriteSerLog(sc.vpnInfo.SystemLogPath + JsonParser.systemLogFileName, logStr);
}
}
@@ -268,7 +285,7 @@ namespace StartServerWPF.Modules.Main.ViewModels
// labelStartTime.Text = "启动时间:" + StartTime.ToString();
RunTime = "运行时间:" + DateDiff(DateTime.Now, StartTime);
string logStr = StartTime.ToString("s") + "\t服务器程序启动";
- WriteSerLog(sc.vpnInfo.SystemLogPath + systemLogFileName, logStr);
+ WriteSerLog(sc.vpnInfo.SystemLogPath + JsonParser.systemLogFileName, logStr);
// progressBar1.Style = ProgressBarStyle.Marquee;
IsEnabledStart = false;
@@ -320,7 +337,7 @@ namespace StartServerWPF.Modules.Main.ViewModels
timer1.Stop();
// progressBar1.Style = ProgressBarStyle.Continuous;
string logStr = DateTime.Now.ToString("s") + "\t服务器程序关闭";
- WriteSerLog(sc.vpnInfo.SystemLogPath + systemLogFileName, logStr);
+ WriteSerLog(sc.vpnInfo.SystemLogPath + JsonParser.systemLogFileName, logStr);
// labelStartTime.Text = "启动时间:";
StartTime = new DateTime();
@@ -427,14 +444,6 @@ namespace StartServerWPF.Modules.Main.ViewModels
[DllImport("shell32.dll")]
public static extern int ShellExecute(IntPtr hwnd, StringBuilder lpszOp, StringBuilder lpszFile, StringBuilder lpszParams, StringBuilder lpszDir, int FsShowCmd);
- public string proPath;
- public string zyProPath = @"\serverprogram";
-
- public string systemConfigPath = "SystemConfig.json";
- public string systemLogFileName;
-
- public int showState = 0;
- public string serverVision = "20210629";
public VPNHelper vpn;
@@ -449,7 +458,7 @@ namespace StartServerWPF.Modules.Main.ViewModels
public void InitializeParams()
{
timer1.Interval = ProMonInterval * 1000;
- this.Message = "服务器版本:" + serverVision;
+ this.Message = "服务器版本:" + JsonParser.serverVision;
IntervalTimesSource.Add(5);
IntervalTimesSource.Add(10);
IntervalTimesSource.Add(15);
@@ -457,9 +466,9 @@ namespace StartServerWPF.Modules.Main.ViewModels
IntervalTimesSource.Add(30);
IntervalTimesSource.Add(60);
SelectedIndex = 1;
- systemLogFileName = "SerLog_" + DateTime.Now.ToString("yyyyMMdd") + ".txt";
+ JsonParser.systemLogFileName = "SerLog_" + DateTime.Now.ToString("yyyyMMdd") + ".txt";
string logStr = DateTime.Now.ToString("s") + "\t程序启动";
- WriteSerLog(sc.vpnInfo.SystemLogPath + systemLogFileName, logStr);
+ WriteSerLog(sc.vpnInfo.SystemLogPath + JsonParser.systemLogFileName, logStr);
//CheckIp();
}
#region 方法
@@ -582,7 +591,7 @@ namespace StartServerWPF.Modules.Main.ViewModels
Thread.Sleep(20);
ReciveDataSource.Add("服务器程序重启成功");
string logStr = DateTime.Now.ToString("s") + "\t服务器程序" + sc.proServer.ProName + "重启";
- WriteSerLog(sc.vpnInfo.SystemLogPath + systemLogFileName, logStr);
+ WriteSerLog(sc.vpnInfo.SystemLogPath + JsonParser.systemLogFileName, logStr);
}
sfp = FindProcess(sc.proRecv);
if (sfp == 0)
@@ -597,7 +606,7 @@ namespace StartServerWPF.Modules.Main.ViewModels
Thread.Sleep(20);
ReciveDataSource.Add("接收数据程序重启成功");
string logStr = DateTime.Now.ToString("s") + "\t接收数据程序" + sc.proRecv.ProName + "重启";
- WriteSerLog(sc.vpnInfo.SystemLogPath + systemLogFileName, logStr);
+ WriteSerLog(sc.vpnInfo.SystemLogPath + JsonParser.systemLogFileName, logStr);
}
sfp = FindProcess(sc.proApms);
if (sfp == 0)
@@ -612,7 +621,7 @@ namespace StartServerWPF.Modules.Main.ViewModels
Thread.Sleep(20);
ReciveDataSource.Add("自动识别程序重启成功");
string logStr = DateTime.Now.ToString("s") + "\t自动识别程序" + sc.proApms.ProName + "重启";
- WriteSerLog(sc.vpnInfo.SystemLogPath + systemLogFileName, logStr);
+ WriteSerLog(sc.vpnInfo.SystemLogPath + JsonParser.systemLogFileName, logStr);
}
sfp = FindProcess(sc.proMonitor);
if (sfp == 0)
@@ -627,7 +636,7 @@ namespace StartServerWPF.Modules.Main.ViewModels
Thread.Sleep(20);
ReciveDataSource.Add("网页服务程序重启成功");
string logStr = DateTime.Now.ToString("s") + "\t网页服务程序" + sc.proMonitor.ProName + "重启";
- WriteSerLog(sc.vpnInfo.SystemLogPath + systemLogFileName, logStr);
+ WriteSerLog(sc.vpnInfo.SystemLogPath + JsonParser.systemLogFileName, logStr);
}
RunTime = "运行时间:" + DateDiff(DateTime.Now, StartTime);
vpnStatus = vpn.CheckVpnStatus(sc.vpnInfo.VpnName);
@@ -636,7 +645,7 @@ namespace StartServerWPF.Modules.Main.ViewModels
vpn.ConnectVPN(sc.vpnInfo.VpnName, sc.vpnInfo.VpnUserName, sc.vpnInfo.VpnPsw);
Thread.Sleep(1000);
string logStr = DateTime.Now.ToString("s") + "\tVPN断开,重连";
- WriteSerLog(sc.vpnInfo.SystemLogPath + systemLogFileName, logStr);
+ WriteSerLog(sc.vpnInfo.SystemLogPath + JsonParser.systemLogFileName, logStr);
}
}
public void GetLocalIp()
@@ -664,20 +673,24 @@ namespace StartServerWPF.Modules.Main.ViewModels
if (vpnStatus)
{
//gbServerControl.Enabled = true;
- // buttonConnectVPN.Enabled = false;
+ // buttonConnectVPN.Enabled = false;
- // buttonDisconnectVPN.Enabled = true;
- // labelVPNstatus.ForeColor = Color.Blue;
+ // buttonDisconnectVPN.Enabled = true;
+ // labelVPNstatus.ForeColor = Color.Blue;
+ VPNIsConnect = true;
+ VPNStatusForeColor = "#FF0000FF";
VPNStatus = "VPN已连接";
- VpnIP = "本机IP:" + vpn.GetLocalIp();
+ VpnIP = vpn.GetLocalIp();
}
else
{
- // gbServerControl.Enabled = false;
- // buttonConnectVPN.Enabled = true;
+ // gbServerControl.Enabled = false;
+ // buttonConnectVPN.Enabled = true;
- // buttonDisconnectVPN.Enabled = false;
- // labelVPNstatus.ForeColor = Color.Red;
+ // buttonDisconnectVPN.Enabled = false;
+ // labelVPNstatus.ForeColor = Color.Red;
+ VPNIsConnect = false;
+ VPNStatusForeColor = "#FFFF0000";
VPNStatus = "VPN未连接";
}
}
diff --git a/StartServerWPF.Modules.Main/ViewModels/SetParamDialogViewModel.cs b/StartServerWPF.Modules.Main/ViewModels/SetParamDialogViewModel.cs
index 6c54b69..e796609 100644
--- a/StartServerWPF.Modules.Main/ViewModels/SetParamDialogViewModel.cs
+++ b/StartServerWPF.Modules.Main/ViewModels/SetParamDialogViewModel.cs
@@ -33,11 +33,13 @@ namespace StartServerWPF.Modules.Main.ViewModels
{
// _title = "编辑" + _title;
var _type = parameters.GetValue("type");
- // _title = (_type == 0 ? "新增" : "修改") + _title;
- MainModel = parameters.GetValue("model");
+ // _title = (_type == 0 ? "新增" : "修改") + _title;
+ _systemConfig = parameters.GetValue("model");
+ MainModel= _systemConfig.vpnInfo;
MoniTime= parameters.GetValue("moniTime");
}
+ private SystemConfig _systemConfig;
private VpnInfo _mainModel = new VpnInfo();
public VpnInfo MainModel
{
@@ -53,12 +55,17 @@ namespace StartServerWPF.Modules.Main.ViewModels
public DelegateCommand FilePathSaveCommand=> new(()=>
{
+ updateJson = false;
System.Windows.Forms.FolderBrowserDialog fbd = new System.Windows.Forms.FolderBrowserDialog();
fbd.SelectedPath = MainModel.DataSavePath;
fbd.ShowNewFolderButton = true;
if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
MainModel.DataSavePath = fbd.SelectedPath;
+ if (MainModel.DataSavePath != _systemConfig.vpnInfo.DataSavePath)
+ {
+ updateJson = true;
+ }
}
});
public DelegateCommand LogPathSaveCommand=> new(() =>
@@ -75,6 +82,7 @@ namespace StartServerWPF.Modules.Main.ViewModels
MainModel.SystemLogPath = fbd.SelectedPath;
}
});
+ bool updateJson = false;
public ICommand ConfirmCommand
{
get => new DelegateCommand(() =>
@@ -83,29 +91,20 @@ namespace StartServerWPF.Modules.Main.ViewModels
// 数据校验(关键字段不能为空、年龄做数字区间的校验、做UserName的唯一检查(自定义特性检查)
if (string.IsNullOrEmpty(MainModel.VpnName) || string.IsNullOrEmpty(MainModel.VpnIP))
{
- MessageBox.Show("内容不能为空", "提示", System.Windows.MessageBoxButton.OK);
+ MessageBox.Show("内容不能为空", "提示", MessageBoxButton.OK);
return;
}
if (MessageBox.Show("确认修改?", "参数设置", MessageBoxButton.OKCancel,
MessageBoxImage.Exclamation) == MessageBoxResult.OK)
{
- //if (updateSysConfig)
- //{
- // JsonParser.WriteSystemConfigFile(fm.systemConfigPath, fsc);
- //}
- //if (updateJson)
- //{
- // JsonParser.UpdateRecvJson(fm.sc.proRecv.ProPath + fm.sc.proRecv.JsonPath, fm.sc.DataSavePath);
- // JsonParser.UpdateApmsJson(fm.sc.proApms.ProPath + fm.sc.proApms.JsonPath, fm.sc.DataSavePath);
- //}
- //var device = _deviceInfoModel.deviceInfoModelList.Where(device => device.Index == MainModel.Index).FirstOrDefault();
- //if (device != null)
- //{
- // _deviceInfoModel.deviceInfoModelList.Remove(device);
- // _deviceInfoModel.deviceInfoModelList.Add(MainModel);
- // _deviceInfoModel.Save();
- //}
+
+ JsonParser.WriteSystemConfigFile(JsonParser.systemConfigPath, _systemConfig);
+ if (updateJson)
+ {
+ JsonParser.UpdateRecvJson(_systemConfig.proRecv.ProPath + _systemConfig.proRecv.JsonPath, _systemConfig.vpnInfo.DataSavePath);
+ JsonParser.UpdateApmsJson(_systemConfig.proApms.ProPath + _systemConfig.proApms.JsonPath, _systemConfig.vpnInfo.DataSavePath);
+ }
RequestClose?.Invoke(new DialogResult(ButtonResult.OK));
}
});
diff --git a/StartServerWPF.Modules.Main/Views/MainView.xaml b/StartServerWPF.Modules.Main/Views/MainView.xaml
index 02775b3..4bf0968 100644
--- a/StartServerWPF.Modules.Main/Views/MainView.xaml
+++ b/StartServerWPF.Modules.Main/Views/MainView.xaml
@@ -39,15 +39,15 @@
-
+
-
-
-
+
+
+
-
+
diff --git a/StartServerWPF.Modules.Main/Views/SetParamDialog.xaml b/StartServerWPF.Modules.Main/Views/SetParamDialog.xaml
index 282dc40..2f29535 100644
--- a/StartServerWPF.Modules.Main/Views/SetParamDialog.xaml
+++ b/StartServerWPF.Modules.Main/Views/SetParamDialog.xaml
@@ -67,8 +67,16 @@
-
-
+
+
+
+
+
+
+
+
+
+