From 1e05cacd3accaf9e0f01dc9373aac116cfc8e45c Mon Sep 17 00:00:00 2001 From: gekoukate <1670391937@qq.com> Date: Wed, 17 May 2023 18:52:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Images/calendar.png | Bin 0 -> 3934 bytes StartServerWPF.Modules.Main/JsonParser.cs | 17 ++-- .../StartServerWPF.Modules.Main.csproj | 6 ++ .../ViewModels/MainViewModel.cs | 91 ++++++++++-------- .../ViewModels/SetParamDialogViewModel.cs | 37 ++++--- .../Views/MainView.xaml | 10 +- .../Views/SetParamDialog.xaml | 12 ++- .../Views/SetParamDialog.xaml.cs | 36 +++++++ StartServerWPF/Views/MainWindow.xaml | 2 +- 9 files changed, 135 insertions(+), 76 deletions(-) create mode 100644 StartServerWPF.Modules.Main/Images/calendar.png diff --git a/StartServerWPF.Modules.Main/Images/calendar.png b/StartServerWPF.Modules.Main/Images/calendar.png new file mode 100644 index 0000000000000000000000000000000000000000..58733c63860a844f6280f7710d6ef5ac699c9d66 GIT binary patch literal 3934 zcmaKv`#;nD|Ht2Zo5RR4E2m4t7P1cL;1rWNpQ0Rc7IMt7WF|I*4%nqDISx4_%vlZ> zSwhY=`C)t9Zu?=c?fJYv?yv3sWh-Mrekpzc00d1<@U~F) z{rADg13l9mtEo`HB5aK>0o5Zi-vB^Z!W6H6HOlQrzC&NIF*0ek@EPBUBO7KJQC|4k zo_I`exx|=&^aH_kr1|pwza~<8Gx69u4^#O%uU4CsllP5!#8gb$RT0c`$IJTS<_kR? z!*^co9(4NBvd+dA`g(L4<6h*EGdGZO(Kpjh8KvaS$40dNsyG4vOKPbIThg`HTBEDYuQ@m`E`iBg6DkeBVE zRKvTHq<`1_5DgA4pVL48+6Hayj&99GM%l0`>fDP$>)la}@iI8lV=p56eWe!nr6TVW zm{$?V(q9Unf@P8O?;I%WFddr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F<-%GlXy2_zkNiT@j;Gg#7Lt9QPn8ZT6-Io}A z!w)65&beW0Xs5@#2#(Ni&=;iVWgN&d951Y}3S=4N%EVbc2#L5yY)@_o0g#%r2w7$! ty-ueJTJcr-mGNE3F1xCk$w>IVfN2W-_b}!!0`!L&Fg3KoS6}jo|39_C5Yqqv literal 0 HcmV?d00001 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 @@ - + - -