From e5f395f71680bae37ace63281f805bc6767a0fc4 Mon Sep 17 00:00:00 2001 From: mzhifa Date: Sun, 23 Jul 2023 20:33:53 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E7=95=8C=E9=9D=A2=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Fonts/iconfont.ttf | Bin .../Images/Union.png | Bin .../Images/background.jpg | Bin .../Images/calendar.png | Bin StartServerWPF.Assets/LogHelper.cs | 34 ++++ .../Properties/AssemblyInfo.cs | 55 ++++++ .../Properties/Resources.Designer.cs | 62 +++++++ .../Properties/Resources.resx | 117 +++++++++++++ .../Properties/Settings.Designer.cs | 30 ++++ .../Properties/Settings.settings | 7 + .../StartServerWPF.Assets.csproj | 87 ++++++++++ .../Styles/BaseResources.xaml | 2 +- StartServerWPF.Modules.Main/JsonParser.cs | 1 - .../Models/LogMessageModel.cs | 11 +- .../Models/UserMessage.cs | 1 + .../StartServerWPF.Modules.Main.csproj | 25 +-- .../ViewModels/LogManagementViewModel.cs | 98 +++++------ .../ViewModels/MainViewModel.cs | 161 ++++++++---------- .../Views/LogManagementView.xaml | 23 ++- .../Views/LoginViewDialog.xaml | 2 +- .../Views/MainView.xaml | 2 +- .../Views/RealTimeWaveformView.xaml | 6 +- .../Views/TreeMenuView.xaml | 2 +- .../Views/WaveformPlayBackView.xaml | 6 +- .../StartServerWPF.Modules.MseedChart.csproj | 6 + .../ViewModels/ChartPlotViewModel.cs | 38 +++-- StartServerWPF.sln | 6 + StartServerWPF/StartServerWPF.csproj | 4 + .../ViewModels/MainWindowViewModel.cs | 18 +- StartServerWPF/Views/MainWindow.xaml | 4 +- StartServerWPF/mseed2ascii.exe | Bin 0 -> 327168 bytes 31 files changed, 620 insertions(+), 188 deletions(-) rename {StartServerWPF.Modules.Main => StartServerWPF.Assets}/Fonts/iconfont.ttf (100%) rename {StartServerWPF.Modules.Main => StartServerWPF.Assets}/Images/Union.png (100%) rename {StartServerWPF.Modules.Main => StartServerWPF.Assets}/Images/background.jpg (100%) rename {StartServerWPF.Modules.Main => StartServerWPF.Assets}/Images/calendar.png (100%) create mode 100644 StartServerWPF.Assets/LogHelper.cs create mode 100644 StartServerWPF.Assets/Properties/AssemblyInfo.cs create mode 100644 StartServerWPF.Assets/Properties/Resources.Designer.cs create mode 100644 StartServerWPF.Assets/Properties/Resources.resx create mode 100644 StartServerWPF.Assets/Properties/Settings.Designer.cs create mode 100644 StartServerWPF.Assets/Properties/Settings.settings create mode 100644 StartServerWPF.Assets/StartServerWPF.Assets.csproj rename {StartServerWPF.Modules.Main => StartServerWPF.Assets}/Styles/BaseResources.xaml (74%) create mode 100644 StartServerWPF/mseed2ascii.exe diff --git a/StartServerWPF.Modules.Main/Fonts/iconfont.ttf b/StartServerWPF.Assets/Fonts/iconfont.ttf similarity index 100% rename from StartServerWPF.Modules.Main/Fonts/iconfont.ttf rename to StartServerWPF.Assets/Fonts/iconfont.ttf diff --git a/StartServerWPF.Modules.Main/Images/Union.png b/StartServerWPF.Assets/Images/Union.png similarity index 100% rename from StartServerWPF.Modules.Main/Images/Union.png rename to StartServerWPF.Assets/Images/Union.png diff --git a/StartServerWPF.Modules.Main/Images/background.jpg b/StartServerWPF.Assets/Images/background.jpg similarity index 100% rename from StartServerWPF.Modules.Main/Images/background.jpg rename to StartServerWPF.Assets/Images/background.jpg diff --git a/StartServerWPF.Modules.Main/Images/calendar.png b/StartServerWPF.Assets/Images/calendar.png similarity index 100% rename from StartServerWPF.Modules.Main/Images/calendar.png rename to StartServerWPF.Assets/Images/calendar.png diff --git a/StartServerWPF.Assets/LogHelper.cs b/StartServerWPF.Assets/LogHelper.cs new file mode 100644 index 0000000..4c38f3b --- /dev/null +++ b/StartServerWPF.Assets/LogHelper.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StartServerWPF.Assets +{ + public class LogHelper + { + + public static void WriteSerLog(string fn, string logstr) + { + // try + { + fn = fn + "SerLog_" + DateTime.Now.ToString("yyyyMMdd") + ".txt"; + if (!File.Exists(fn)) + { + Directory.CreateDirectory(Path.GetDirectoryName(fn)); + } + using (StreamWriter sw = new StreamWriter(fn, true, Encoding.Default)) + { + sw.WriteLine(logstr); + sw.Close(); + } + } + //catch (Exception ex) + //{ + + //} + } + } +} diff --git a/StartServerWPF.Assets/Properties/AssemblyInfo.cs b/StartServerWPF.Assets/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..a93d6ae --- /dev/null +++ b/StartServerWPF.Assets/Properties/AssemblyInfo.cs @@ -0,0 +1,55 @@ +using System.Reflection; +using System.Resources; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Windows; + +// 有关程序集的一般信息由以下 +// 控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("StartServerWPF.Assets")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("StartServerWPF.Assets")] +[assembly: AssemblyCopyright("Copyright © 2023")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 会使此程序集中的类型 +//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 +//请将此类型的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +//若要开始生成可本地化的应用程序,请设置 +//.csproj 文件中的 CultureYouAreCodingWith +//例如,如果您在源文件中使用的是美国英语, +//使用的是美国英语,请将 设置为 en-US。 然后取消 +//对以下 NeutralResourceLanguage 特性的注释。 更新 +//以下行中的“en-US”以匹配项目文件中的 UICulture 设置。 + +//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] + + +[assembly:ThemeInfo( + ResourceDictionaryLocation.None, //主题特定资源词典所处位置 + //(未在页面中找到资源时使用, + //或应用程序资源字典中找到时使用) + ResourceDictionaryLocation.SourceAssembly //常规资源词典所处位置 + //(未在页面中找到资源时使用, + //、应用程序或任何主题专用资源字典中找到时使用) +)] + + +// 程序集的版本信息由下列四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值 +//通过使用 "*",如下所示: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/StartServerWPF.Assets/Properties/Resources.Designer.cs b/StartServerWPF.Assets/Properties/Resources.Designer.cs new file mode 100644 index 0000000..e41d58d --- /dev/null +++ b/StartServerWPF.Assets/Properties/Resources.Designer.cs @@ -0,0 +1,62 @@ +//------------------------------------------------------------------------------ +// +// 此代码由工具生成。 +// 运行时版本: 4.0.30319.42000 +// +// 对此文件的更改可能导致不正确的行为,如果 +// 重新生成代码,则所做更改将丢失。 +// +//------------------------------------------------------------------------------ + +namespace StartServerWPF.Assets.Properties { + + + /// + /// 强类型资源类,用于查找本地化字符串等。 + /// + // 此类是由 StronglyTypedResourceBuilder + // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 + // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen + // (以 /str 作为命令选项),或重新生成 VS 项目。 + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// 返回此类使用的缓存 ResourceManager 实例。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if ((resourceMan == null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("StartServerWPF.Assets.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// 重写当前线程的 CurrentUICulture 属性,对 + /// 使用此强类型资源类的所有资源查找执行重写。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + } +} diff --git a/StartServerWPF.Assets/Properties/Resources.resx b/StartServerWPF.Assets/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/StartServerWPF.Assets/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/StartServerWPF.Assets/Properties/Settings.Designer.cs b/StartServerWPF.Assets/Properties/Settings.Designer.cs new file mode 100644 index 0000000..c682eed --- /dev/null +++ b/StartServerWPF.Assets/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace StartServerWPF.Assets.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/StartServerWPF.Assets/Properties/Settings.settings b/StartServerWPF.Assets/Properties/Settings.settings new file mode 100644 index 0000000..033d7a5 --- /dev/null +++ b/StartServerWPF.Assets/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/StartServerWPF.Assets/StartServerWPF.Assets.csproj b/StartServerWPF.Assets/StartServerWPF.Assets.csproj new file mode 100644 index 0000000..4e0cc9a --- /dev/null +++ b/StartServerWPF.Assets/StartServerWPF.Assets.csproj @@ -0,0 +1,87 @@ + + + + + Debug + AnyCPU + {EA0D3C2D-5BEB-420C-9222-2E6E5F40BF5C} + library + StartServerWPF.Assets + StartServerWPF.Assets + v4.6.1 + 512 + {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 4 + true + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + 4.0 + + + + + + + + + Code + + + True + True + Resources.resx + + + True + Settings.settings + True + + + ResXFileCodeGenerator + Resources.Designer.cs + + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + + + MSBuild:Compile + Designer + + + + + + + + + \ No newline at end of file diff --git a/StartServerWPF.Modules.Main/Styles/BaseResources.xaml b/StartServerWPF.Assets/Styles/BaseResources.xaml similarity index 74% rename from StartServerWPF.Modules.Main/Styles/BaseResources.xaml rename to StartServerWPF.Assets/Styles/BaseResources.xaml index 761e695..46fde0d 100644 --- a/StartServerWPF.Modules.Main/Styles/BaseResources.xaml +++ b/StartServerWPF.Assets/Styles/BaseResources.xaml @@ -1,4 +1,4 @@  - pack://application:,,,/StartServerWPF.Modules.Main;component/Fonts/#iconfont + pack://application:,,,/StartServerWPF.Assets;component/Fonts/#iconfont \ No newline at end of file diff --git a/StartServerWPF.Modules.Main/JsonParser.cs b/StartServerWPF.Modules.Main/JsonParser.cs index 01c43cd..c5b9e65 100644 --- a/StartServerWPF.Modules.Main/JsonParser.cs +++ b/StartServerWPF.Modules.Main/JsonParser.cs @@ -15,7 +15,6 @@ namespace StartServerWPF.Modules.Main // 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) diff --git a/StartServerWPF.Modules.Main/Models/LogMessageModel.cs b/StartServerWPF.Modules.Main/Models/LogMessageModel.cs index 9ee4643..88c70eb 100644 --- a/StartServerWPF.Modules.Main/Models/LogMessageModel.cs +++ b/StartServerWPF.Modules.Main/Models/LogMessageModel.cs @@ -9,10 +9,19 @@ namespace StartServerWPF.Modules.Main.Models { public class LogMessageModel { - public int LogType { get; set; } + public string LogType { get; set; } public string AppName { get; set; } public string State { get; set; } public DateTime OriginTime { get; set; } public string Message { get; set; } + public string Oprate { get; set; } + + + + public override string ToString() + { + string str = $"{OriginTime.ToString("s")} {LogType} {AppName} {State} "; + return str; + } } } diff --git a/StartServerWPF.Modules.Main/Models/UserMessage.cs b/StartServerWPF.Modules.Main/Models/UserMessage.cs index 40b127c..61b25c0 100644 --- a/StartServerWPF.Modules.Main/Models/UserMessage.cs +++ b/StartServerWPF.Modules.Main/Models/UserMessage.cs @@ -28,6 +28,7 @@ namespace StartServerWPF.Modules.Main.Models public string message { get; set; } public int uid { get; set; } public int code { get; set; } + public string account { get; set; } } public class CSUserSubscribeMessage diff --git a/StartServerWPF.Modules.Main/StartServerWPF.Modules.Main.csproj b/StartServerWPF.Modules.Main/StartServerWPF.Modules.Main.csproj index 43a9239..3fa0cc5 100644 --- a/StartServerWPF.Modules.Main/StartServerWPF.Modules.Main.csproj +++ b/StartServerWPF.Modules.Main/StartServerWPF.Modules.Main.csproj @@ -5,10 +5,18 @@ True - - - - + + + + + + + + + + + + @@ -18,17 +26,14 @@ + + + ..\StartServerWPF\DotRas.dll - - - - - - $(DefaultXamlRuntime) diff --git a/StartServerWPF.Modules.Main/ViewModels/LogManagementViewModel.cs b/StartServerWPF.Modules.Main/ViewModels/LogManagementViewModel.cs index c3750a6..a6173fa 100644 --- a/StartServerWPF.Modules.Main/ViewModels/LogManagementViewModel.cs +++ b/StartServerWPF.Modules.Main/ViewModels/LogManagementViewModel.cs @@ -21,23 +21,27 @@ namespace StartServerWPF.Modules.Main.ViewModels { IEventAggregator _ea; private readonly IDialogService _dialogService; + private readonly MainViewModel _mainViewModel; public LogManagementViewModel( - IEventAggregator ea, IDialogService dialogService) - + IEventAggregator ea, IDialogService dialogService, MainViewModel mainViewModel) + { this._dialogService = dialogService; - InitInfo(); + this._mainViewModel = mainViewModel; } private string _title = "日志查看"; public string Title => _title; + public ICommand LoadedCommand => new DelegateCommand(()=> + { + InitInfo(); + }); public ICommand UploadCommand { get; set; } public DelegateCommand QueryDataCommand => new(QueryData); public DelegateCommand ResetQueryDataCommand => new(InitInfo); - public DelegateCommand HFWarningCommand => new(HFWarning); private void InitInfo() { StartTime = DateTime.Today; @@ -53,67 +57,53 @@ namespace StartServerWPF.Modules.Main.ViewModels public void QueryData() { + SelectIndexLogType = "全部"; DataList = new List(); - string fileName = ""; - // File.Exists(""); + string fileName = _mainViewModel.sc.vpnInfo.SystemLogPath+ "SerLog_" + EndTime.ToString("yyyyMMdd") + ".txt"; + if (!File.Exists(fileName)) + return; Task.Run(() => { - // var lines= File.ReadAllLines(fileName); - for (int i = 0; i < 10; i++) + _queryDataList = new List(); + var lines= File.ReadAllLines(fileName); + foreach (var item in lines) { - DataList.Add(new LogMessageModel() + var str= item.Trim().Split(" "); + + _queryDataList.Add(new LogMessageModel() { - AppName = "app"+i, - LogType = 1, - Message = "start", - OriginTime = DateTime.Now.AddMinutes(i), - State = "启动中" + OriginTime = Convert.ToDateTime(str[0]), + LogType = str[1], + AppName = str[2], + State = str[3] }); } + _totalDataList = _queryDataList; + int index = _queryDataList.Count; + MaxCountPage = (index % countPerPage == 0 ? index / countPerPage : index / countPerPage + 1); + DataList = _totalDataList.Take(countPerPage).ToList(); }); } - private void HFWarning() - { - DialogParameters param = new DialogParameters(); - param.Add("type", 0); - ShowEditDialog(param); - } - private void ShowEditDialog(DialogParameters param) - { - _dialogService.ShowDialog( - "HFLogDialog", - param, - new Action(result => - { - if (result != null && result.Result == ButtonResult.OK) - { - System.Windows.MessageBox.Show("数据已保存", "提示"); - Refresh(); - } - })); - } - public void WriteTxt(FileStream fs) + + + private string _SelectIndexLogType; + + public string SelectIndexLogType { - try + get => _SelectIndexLogType; + set { - // foreach (var item in _totalDataList) + if (_queryDataList != null) { - // string mesg = item.CreateTime + "\t" + item.UserName + "\t" + item.UserId + "\t" + item.Message; - //获得字节数组 - // mesg = mesg + "\n"; - // byte[] data = System.Text.Encoding.Default.GetBytes(mesg); - //开始写入 - // fs.Write(data, 0, data.Length); - } - //清空缓冲区、关闭流 - fs.Flush(); - fs.Close(); - } - catch - { - Console.WriteLine("WriteError"); + _totalDataList = _queryDataList.Where(l => l.LogType == value).ToList(); + int index = _totalDataList.Count; + MaxCountPage = (index % countPerPage == 0 ? index / countPerPage : index / countPerPage + 1); + DataList = _totalDataList.Take(countPerPage).ToList(); + } + SetProperty(ref _SelectIndexLogType, value); } + } private DateTime _StartTime; @@ -140,7 +130,9 @@ namespace StartServerWPF.Modules.Main.ViewModels ///// ///// 所有数据 ///// - //private List _totalDataList; + private List _totalDataList; + + private List _queryDataList; /// /// 页码 /// @@ -181,7 +173,7 @@ namespace StartServerWPF.Modules.Main.ViewModels /// private void PageUpdated(FunctionEventArgs info) { - // DataList = _totalDataList.Skip((info.Info - 1) * countPerPage).Take(countPerPage).ToList(); + DataList = _totalDataList.Skip((info.Info - 1) * countPerPage).Take(countPerPage).ToList(); } } diff --git a/StartServerWPF.Modules.Main/ViewModels/MainViewModel.cs b/StartServerWPF.Modules.Main/ViewModels/MainViewModel.cs index d9f1f44..2ff11ab 100644 --- a/StartServerWPF.Modules.Main/ViewModels/MainViewModel.cs +++ b/StartServerWPF.Modules.Main/ViewModels/MainViewModel.cs @@ -1,7 +1,9 @@ -using Org.BouncyCastle.Crypto.Modes; +using K4os.Compression.LZ4.Engine; +using Org.BouncyCastle.Crypto.Modes; using Prism.Commands; using Prism.Mvvm; using Prism.Services.Dialogs; +using StartServerWPF.Assets; using StartServerWPF.Modules.Main.models; using StartServerWPF.Modules.Main.Models; using System; @@ -97,6 +99,14 @@ namespace StartServerWPF.Modules.Main.ViewModels { _websocket.SendMes(JsonSerializer.Serialize(new CSUserSubscribeMessage { type = CSMessage.subscribe })); _loginViewDialogViewModel.CloseDialog(new DialogResult(ButtonResult.OK)); + var log = new LogMessageModel + { + LogType = "系统", + AppName = "系统", + State = user.account+ "登录", + OriginTime = DateTime.Now, + }; + LogHelper.WriteSerLog(sc.vpnInfo.SystemLogPath, log.ToString()); } }); break; @@ -298,8 +308,14 @@ namespace StartServerWPF.Modules.Main.ViewModels vpn.CreateOrUpdateVPN(sc.vpnInfo.VpnName, sc.vpnInfo.VpnIP); 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 + JsonParser.systemLogFileName, logStr); + var log = new LogMessageModel + { + LogType="网络", + AppName="VPN", + State="连接", + OriginTime = DateTime.Now, + }; + LogHelper.WriteSerLog(sc.vpnInfo.SystemLogPath , log.ToString()); SetControlstatus(); } @@ -311,8 +327,14 @@ namespace StartServerWPF.Modules.Main.ViewModels Thread.Sleep(500); SetControlstatus(); Thread.Sleep(100); - string logStr = DateTime.Now.ToString("s") + "\tVPN手动断开"; - WriteSerLog(sc.vpnInfo.SystemLogPath + JsonParser.systemLogFileName, logStr); + var log = new LogMessageModel + { + LogType = "网络", + AppName = "VPN", + State = "断开", + OriginTime = DateTime.Now, + }; + LogHelper.WriteSerLog(sc.vpnInfo.SystemLogPath , log.ToString()); } } @@ -384,8 +406,14 @@ namespace StartServerWPF.Modules.Main.ViewModels } } RunTime = DateDiff(DateTime.Now, StartTime); - string logStr = StartTime.ToString("s") + "\t服务器程序启动"; - WriteSerLog(sc.vpnInfo.SystemLogPath + JsonParser.systemLogFileName, logStr); + var log = new LogMessageModel + { + LogType = "系统", + AppName = "系统", + State = "启动服务程序", + OriginTime = DateTime.Now, + }; + LogHelper.WriteSerLog(sc.vpnInfo.SystemLogPath , log.ToString()); IsIndeterminate =true; timer1.Interval = TimeSpan.FromSeconds(ProMonInterval); timer1.Start(); @@ -407,8 +435,14 @@ namespace StartServerWPF.Modules.Main.ViewModels } timer1.Stop(); IsIndeterminate = false; - string logStr = DateTime.Now.ToString("s") + "\t服务器程序关闭"; - WriteSerLog(sc.vpnInfo.SystemLogPath + JsonParser.systemLogFileName, logStr); + var log = new LogMessageModel + { + LogType = "系统", + AppName = "系统", + State = "启动服务关闭", + OriginTime = DateTime.Now, + }; + LogHelper.WriteSerLog(sc.vpnInfo.SystemLogPath , log.ToString()); StartTime = new DateTime(); } @@ -477,10 +511,14 @@ namespace StartServerWPF.Modules.Main.ViewModels IntervalTimesSource.Add(30); IntervalTimesSource.Add(60); SelectedIndex = 1; - JsonParser.systemLogFileName = "SerLog_" + DateTime.Now.ToString("yyyyMMdd") + ".txt"; - string logStr = DateTime.Now.ToString("s") + "\t程序启动"; - WriteSerLog(sc.vpnInfo.SystemLogPath + JsonParser.systemLogFileName, logStr); - //CheckIp(); + var log = new LogMessageModel + { + LogType = "系统", + AppName = "系统", + State = "程序启动", + OriginTime = DateTime.Now, + }; + LogHelper.WriteSerLog(sc.vpnInfo.SystemLogPath , log.ToString()); } #region 方法 private bool CMDStartProcess(ProcessInfo proInfo) @@ -687,13 +725,19 @@ namespace StartServerWPF.Modules.Main.ViewModels Thread.Sleep(2); StartProcess(pro); Thread.Sleep(20); - string logStr = DateTime.Now.ToString("s") + "\t服务器程序" + pro.ProName + "重启"; - WriteSerLog(sc.vpnInfo.SystemLogPath + JsonParser.systemLogFileName, logStr); + var log = new LogMessageModel + { + LogType = "应用", + AppName = pro.ProName, + State = "重启", + OriginTime = DateTime.Now, + }; + LogHelper.WriteSerLog(sc.vpnInfo.SystemLogPath , log.ToString()); string jsonStr= JsonSerializer.Serialize(new CSDeviceWebhook { type= CSMessage.webhook, - message=logStr, + message = log.ToString(), }, new JsonSerializerOptions { // 整齐打印 @@ -705,81 +749,25 @@ namespace StartServerWPF.Modules.Main.ViewModels } } } - #region 注释 - //int sfp = FindProcess(sc.proServer); - //if (sfp == 0) - //{ - // ReciveDataSource.Add("服务器程序运行正常"); - //} - //else - //{ - // ReciveDataSource.Add("服务器程序未运行"); - // Thread.Sleep(2); - // StartProcess(sc.proServer); - // Thread.Sleep(20); - // ReciveDataSource.Add("服务器程序重启成功"); - // string logStr = DateTime.Now.ToString("s") + "\t服务器程序" + sc.proServer.ProName + "重启"; - // WriteSerLog(sc.vpnInfo.SystemLogPath + JsonParser.systemLogFileName, logStr); - //} - //sfp = FindProcess(sc.proRecv); - //if (sfp == 0) - //{ - // ReciveDataSource.Add("接收数据程序运行正常"); - //} - //else - //{ - // ReciveDataSource.Add("接收数据程序未运行"); - // Thread.Sleep(2); - // StartProcess(sc.proRecv); - // Thread.Sleep(20); - // ReciveDataSource.Add("接收数据程序重启成功"); - // string logStr = DateTime.Now.ToString("s") + "\t接收数据程序" + sc.proRecv.ProName + "重启"; - // WriteSerLog(sc.vpnInfo.SystemLogPath + JsonParser.systemLogFileName, logStr); - //} - //sfp = FindProcess(sc.proApms); - //if (sfp == 0) - //{ - // ReciveDataSource.Add("自动识别程序运行正常"); - //} - //else - //{ - // ReciveDataSource.Add("自动识别程序未运行"); - // Thread.Sleep(2); - // StartProcess(sc.proApms); - // Thread.Sleep(20); - // ReciveDataSource.Add("自动识别程序重启成功"); - // string logStr = DateTime.Now.ToString("s") + "\t自动识别程序" + sc.proApms.ProName + "重启"; - // WriteSerLog(sc.vpnInfo.SystemLogPath + JsonParser.systemLogFileName, logStr); - //} - //sfp = FindProcess(sc.proMonitor); - //if (sfp == 0) - //{ - // ReciveDataSource.Add("网页服务程序运行正常"); - //} - //else - //{ - // ReciveDataSource.Add("网页服务程序未运行"); - // Thread.Sleep(2); - // StartProcess(sc.proMonitor); - // Thread.Sleep(20); - // ReciveDataSource.Add("网页服务程序重启成功"); - // string logStr = DateTime.Now.ToString("s") + "\t网页服务程序" + sc.proMonitor.ProName + "重启"; - // WriteSerLog(sc.vpnInfo.SystemLogPath + JsonParser.systemLogFileName, logStr); - //} - #endregion RunTime = DateDiff(DateTime.Now, StartTime); vpnStatus = vpn.CheckVpnStatus(sc.vpnInfo.VpnName); if (!vpnStatus) { 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 + JsonParser.systemLogFileName, logStr); + var log = new LogMessageModel + { + LogType = "应用", + AppName = "VPN", + State = "重连", + OriginTime = DateTime.Now, + }; + LogHelper.WriteSerLog(sc.vpnInfo.SystemLogPath , log.ToString()); string jsonStr = JsonSerializer.Serialize(new CSDeviceWebhook { type = CSMessage.webhook, - message = logStr, + message = log.ToString(), }, new JsonSerializerOptions { @@ -807,7 +795,6 @@ namespace StartServerWPF.Modules.Main.ViewModels } } } - //return AddressIP; } public void SetControlstatus() @@ -829,16 +816,6 @@ namespace StartServerWPF.Modules.Main.ViewModels } } - public void WriteSerLog(string fn, string logstr) - { - if(!File.Exists(fn)) - { - Directory.CreateDirectory(Path.GetDirectoryName(fn)); - } - StreamWriter sw = new StreamWriter(fn, true, Encoding.Default); - sw.WriteLine(logstr); - sw.Close(); - } #endregion } diff --git a/StartServerWPF.Modules.Main/Views/LogManagementView.xaml b/StartServerWPF.Modules.Main/Views/LogManagementView.xaml index 5cf8c09..b9167db 100644 --- a/StartServerWPF.Modules.Main/Views/LogManagementView.xaml +++ b/StartServerWPF.Modules.Main/Views/LogManagementView.xaml @@ -3,6 +3,7 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:i="http://schemas.microsoft.com/xaml/behaviors" xmlns:prism="http://prismlibrary.com/" prism:ViewModelLocator.AutoWireViewModel="True" xmlns:hc="https://handyorg.github.io/handycontrol" @@ -22,6 +23,14 @@ + + + + + + + + @@ -35,15 +44,15 @@ - + - - - + +