diff --git a/StartServerWPF.Modules.Main/Fonts/iconfont.ttf b/StartServerWPF.Modules.Main/Fonts/iconfont.ttf index 682c0fb..4387347 100644 Binary files a/StartServerWPF.Modules.Main/Fonts/iconfont.ttf and b/StartServerWPF.Modules.Main/Fonts/iconfont.ttf differ diff --git a/StartServerWPF.Modules.Main/Images/background.jpg b/StartServerWPF.Modules.Main/Images/background.jpg new file mode 100644 index 0000000..edfc533 Binary files /dev/null and b/StartServerWPF.Modules.Main/Images/background.jpg differ diff --git a/StartServerWPF.Modules.Main/MainModule.cs b/StartServerWPF.Modules.Main/MainModule.cs index 3693808..526d889 100644 --- a/StartServerWPF.Modules.Main/MainModule.cs +++ b/StartServerWPF.Modules.Main/MainModule.cs @@ -17,8 +17,20 @@ namespace StartServerWPF.Modules.Main public void RegisterTypes(IContainerRegistry containerRegistry) { - containerRegistry.RegisterSingleton(); + containerRegistry.RegisterForNavigation(); + containerRegistry.RegisterForNavigation(); + containerRegistry.RegisterForNavigation(); + containerRegistry.RegisterForNavigation(); + containerRegistry.RegisterForNavigation(); + containerRegistry.RegisterForNavigation(); + containerRegistry.RegisterDialog(); + containerRegistry.RegisterDialog(); + + containerRegistry.RegisterSingleton(); + containerRegistry.RegisterSingleton(); + + } } } \ No newline at end of file diff --git a/StartServerWPF.Modules.Main/Models/LoadingEvent.cs b/StartServerWPF.Modules.Main/Models/LoadingEvent.cs new file mode 100644 index 0000000..8570b79 --- /dev/null +++ b/StartServerWPF.Modules.Main/Models/LoadingEvent.cs @@ -0,0 +1,16 @@ +using Prism.Events; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StartServerWPF.Modules.Main.models +{ + public class LoadingPayload + { + public bool IsShow { get; set; } + public string Message { get; set; } + } + public class LoadingEvent : PubSubEvent { } +} diff --git a/StartServerWPF.Modules.Main/Models/ProcessModel.cs b/StartServerWPF.Modules.Main/Models/ProcessModel.cs new file mode 100644 index 0000000..560dc20 --- /dev/null +++ b/StartServerWPF.Modules.Main/Models/ProcessModel.cs @@ -0,0 +1,82 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Newtonsoft.Json; +using Prism.Mvvm; + +namespace StartServerWPF.Modules.Main.Models +{ + public class ProcessModel:BindableBase + { + private string proName; + /// + /// 程序路径 + /// + public string ProName + { + get { return proName; } + set + { + SetProperty(ref proName, value); + } + } + private string proPath; + /// + /// 程序路径 + /// + public string ProPath + { + get { return proPath; } + set { proPath = value; } + } + private string processTile; + /// + /// 启动参数 + /// + public string ProcessTile + { + get { return processTile; } + set { + SetProperty(ref processTile, value); + } + } + + + private string monitorTime; + /// + /// 启动参数 + /// + public string MonitorTime + { + get { return monitorTime; } + set + { + SetProperty(ref monitorTime, value); + } + } + + private string processStatus; + /// + /// 启动参数 + /// + public string ProcessStatus + { + get { return processStatus; } + set + { + SetProperty(ref processStatus, value); + } + } + private int pid; + public int Pid + { + get { return pid; } + set { + + SetProperty(ref pid, value); + } + } + } +} diff --git a/StartServerWPF.Modules.Main/Models/ProcessingInformationModel.cs b/StartServerWPF.Modules.Main/Models/ProcessingInformationModel.cs new file mode 100644 index 0000000..4c0e988 --- /dev/null +++ b/StartServerWPF.Modules.Main/Models/ProcessingInformationModel.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StartServerWPF.Modules.Main.Models +{ + public class ProcessingInformationModel + { + + private string processMes; + /// + /// 启动参数 + /// + public string ProcessMes + { + get { return processMes; } + set + { + processMes = value; + } + } + + + private string monitorTime; + /// + /// 启动参数 + /// + public string MonitorTime + { + get { return monitorTime; } + set + { + monitorTime= value; + } + } + } +} diff --git a/StartServerWPF.Modules.Main/Models/SystemConfig.cs b/StartServerWPF.Modules.Main/Models/SystemConfig.cs index d9b625a..64b5d36 100644 --- a/StartServerWPF.Modules.Main/Models/SystemConfig.cs +++ b/StartServerWPF.Modules.Main/Models/SystemConfig.cs @@ -32,7 +32,7 @@ namespace StartServerWPF.Modules.Main.Models /// /// Monitor(网页显示)程序 /// - public ProcessInfo proMonitor { get; set; } + //public ProcessInfo proMonitor { get; set; } /// /// 波形tools /// diff --git a/StartServerWPF.Modules.Main/Models/WatcherFileModel.cs b/StartServerWPF.Modules.Main/Models/WatcherFileModel.cs new file mode 100644 index 0000000..6c47341 --- /dev/null +++ b/StartServerWPF.Modules.Main/Models/WatcherFileModel.cs @@ -0,0 +1,40 @@ +using Prism.Mvvm; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StartServerWPF.Modules.Main.models +{ + public class WatcherFileModel : BindableBase + { + + private string createTime; + private WatcherChangeTypes changeType; + private string fullPath; + private string name; + private string data; + + public string CreateTime + { + get { return createTime; } + set { SetProperty(ref createTime, value); } + } + public WatcherChangeTypes ChangeType { get => changeType; set => SetProperty(ref changeType, value); } + + public string FullPath { get => fullPath; set => SetProperty(ref fullPath, value); } + + public string Name { get => name; set => SetProperty(ref name, value); } + + public string Data { get => data; set => SetProperty(ref data, value); } + + private bool isSend; + public bool IsSend + { + get { return isSend; } + set { SetProperty(ref isSend, value); } + } + } +} diff --git a/StartServerWPF.Modules.Main/ProcessInfo.cs b/StartServerWPF.Modules.Main/ProcessInfo.cs index 76b2906..def4c30 100644 --- a/StartServerWPF.Modules.Main/ProcessInfo.cs +++ b/StartServerWPF.Modules.Main/ProcessInfo.cs @@ -19,6 +19,17 @@ namespace StartServerWPF.Modules.Main get { return proName; } set { proName = value; } } + private string proTitle; + /// + /// 程序路径 + /// + [JsonProperty] + public string ProTitle + { + get { return proTitle; } + set { proTitle = value; } + } + private string proPath; /// /// 程序路径 diff --git a/StartServerWPF.Modules.Main/StartServerWPF.Modules.Main.csproj b/StartServerWPF.Modules.Main/StartServerWPF.Modules.Main.csproj index e74526c..43a9239 100644 --- a/StartServerWPF.Modules.Main/StartServerWPF.Modules.Main.csproj +++ b/StartServerWPF.Modules.Main/StartServerWPF.Modules.Main.csproj @@ -6,6 +6,7 @@ + @@ -24,7 +25,17 @@ + + + + $(DefaultXamlRuntime) + Designer + + + $(DefaultXamlRuntime) + + \ No newline at end of file diff --git a/StartServerWPF.Modules.Main/ViewModels/FilesWatcherViewModel.cs b/StartServerWPF.Modules.Main/ViewModels/FilesWatcherViewModel.cs new file mode 100644 index 0000000..427f289 --- /dev/null +++ b/StartServerWPF.Modules.Main/ViewModels/FilesWatcherViewModel.cs @@ -0,0 +1,278 @@ +using Prism.Commands; +using Prism.Events; +using Prism.Mvvm; +using StartServerWPF.Modules.Main; +using StartServerWPF.Modules.Main.models; +using System; +using System.Collections.ObjectModel; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Text.Encodings.Web; +using System.Text.Json; +using System.Text.Unicode; +using System.Windows; +using System.Windows.Threading; + +namespace StartServerWPF.Modules.Main.ViewModels +{ + internal class FilesWatcherViewModel : BindableBase + { + public FilesWatcherViewModel(IEventAggregator ea) + { + string filter = "*.txt"; + string str = File.ReadAllText("systemconfig.json"); + WatcherPath = AppDomain.CurrentDomain.BaseDirectory; + InitializeParams(filter); + StartTime = DateTime.Now; + } + private string watcherPath; + + public string WatcherPath + { + get { return watcherPath; } + set { SetProperty(ref watcherPath, value); } + } + + private ObservableCollection dataList = new ObservableCollection(); + + public ObservableCollection DataList + + { + get { return dataList; } + set { SetProperty(ref dataList, value); } + } + + private DateTime startTime; + public DateTime StartTime { get => startTime; set => SetProperty(ref startTime, value); } + + + + private int selectedIndex; + + public int SelectedIndex + { + get { return selectedIndex; } + set { SetProperty(ref selectedIndex, value); } + } + + + + + + + public DelegateCommand StartCommand => new(Start); + + public DelegateCommand StopCommand => new(Stop); + + private void Start() + { + WatchStartOrSopt(true); + StartTime=DateTime.Now; + // _websocketClient.SendMes(JsonSerializer.Serialize(new CSUserSubscribeMessage { type = CSMessage.subscribe })); + } + + private void Stop() + { + WatchStartOrSopt(false); + // _websocketClient.SendMes(JsonSerializer.Serialize(new CSUserSubscribeMessage { type = CSMessage.unsubscribe })); + + } + + public DelegateCommand FilePathSaveCommand => new(() => + { + System.Windows.Forms.FolderBrowserDialog fbd = new System.Windows.Forms.FolderBrowserDialog(); + fbd.SelectedPath = WatcherPath; + fbd.Description = "请选择文件路径"; + fbd.ShowNewFolderButton = true; + if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK) + { + if (fbd.SelectedPath != WatcherPath) + { + WatcherPath = fbd.SelectedPath; + // systemConfig.FilePath = WatcherPath; + var options = new JsonSerializerOptions { + // 整齐打印 + WriteIndented = true, + //重新编码,解决中文乱码问题 + Encoder = JavaScriptEncoder.Create(UnicodeRanges.All) + }; + // string message = JsonSerializer.Serialize(systemConfig, options); + if (File.Exists(settingDataPath)) + { + // File.WriteAllText(settingDataPath, message); + } + } + } + }); + + private string settingDataPath = "systemconfig.json"; + + private void InitializeParams(string fileFilter) + { + + SelectedIndex = 1; + //如果设置的目录不存在设置到根目录 + if (!File.Exists(WatcherPath)) + { + WatcherPath = AppDomain.CurrentDomain.BaseDirectory; + } + watcher = new FileSystemWatcher(); + //初始化监听 + watcher.BeginInit(); + + //设置需要监听的更改类型(如:文件或者文件夹的属性,文件或者文件夹的创建时间;NotifyFilters枚举的内容) + watcher.NotifyFilter = NotifyFilters.Attributes + | NotifyFilters.CreationTime + | NotifyFilters.DirectoryName + | NotifyFilters.FileName + | NotifyFilters.LastAccess + | NotifyFilters.LastWrite + | NotifyFilters.Security + | NotifyFilters.Size; + //设置监听的路径 + watcher.Path = WatcherPath; + watcher.Changed += new FileSystemEventHandler(Watcher_Changed); + // watcher.Created += Watcher_Created; + watcher.Deleted += new FileSystemEventHandler(Watcher_Deleted); + watcher.Renamed += new RenamedEventHandler(Watcher_Renamed); + watcher.Error += OnError; + + //设置监听文件类型 + watcher.Filter = fileFilter; + //设置是否监听子目录 + watcher.IncludeSubdirectories = false; + //设置是否启用监听 + watcher.EnableRaisingEvents = false; + watcher.EndInit(); + + } + + private string DateDiff(DateTime DateTime1, DateTime DateTime2) + { + string dateDiff = null; + TimeSpan ts1 = new TimeSpan(DateTime1.Ticks); + TimeSpan ts2 = new + TimeSpan(DateTime2.Ticks); + TimeSpan ts = ts1.Subtract(ts2).Duration(); + if (ts.Days > 0) + { + dateDiff += ts.Days.ToString() + "天"; + } + if (ts.Hours > 0) + { + dateDiff += ts.Hours.ToString() + "小时"; + } + if (ts.Minutes > 0) + { + dateDiff += ts.Minutes.ToString() + "分钟"; + } + + dateDiff += ts.Seconds.ToString() + "秒"; + return dateDiff; + } + private void OnError(object sender, ErrorEventArgs e) + { + + } + private void Watcher_Changed(object sender, System.IO.FileSystemEventArgs e) + { + // DateTime dt = DateTime.Now; + // string tmp = dt.Hour.ToString() + "时" + dt.Minute.ToString() + "分" + dt.Second.ToString() + "秒" + dt.Millisecond.ToString() + "毫秒,目录发生变化\r\n"; + DateTime lastWriteTime = File.GetLastWriteTime(e.FullPath); + watcher.EnableRaisingEvents = false; + Debug.WriteLine($"最后修改时间:{lastWriteTime}"); + string lastLine = File.ReadAllLines(e.FullPath).Last().Trim(); + var str= dataList.Where(f => f.Data == lastLine).FirstOrDefault(); + if (!string.IsNullOrWhiteSpace(lastLine) + && str==null) + { + System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() => + { + DataList.Add(new WatcherFileModel + { + CreateTime = DateTime.Now.ToString(), + ChangeType = e.ChangeType, + Name = e.Name, + FullPath = e.FullPath, + Data = lastLine, + IsSend = false + }); + + //CSDevicePublish cSDevicePublish = new CSDevicePublish() + //{ + // type = CSMessage.publish, + // message = lastLine, + // serialNumber = DataList.Count, + //}; + //string jsonStr = JsonSerializer.Serialize(cSDevicePublish); + //_websocketClient.SendMes(jsonStr); + })); + } + watcher.EnableRaisingEvents = true; + } + + private void Watcher_Renamed(object sender, RenamedEventArgs e) + { + System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() => { + + DateTime dt = DateTime.Now; + string tmp = dt.Hour.ToString() + "时" + dt.Minute.ToString() + "分" + dt.Second.ToString() + "秒" + dt.Millisecond.ToString() + "毫秒,目录发生变化\r\n"; + tmp += "改变类型 :" + e.ChangeType.ToString() + "\r\n"; ; + tmp += "文件全称:" + e.FullPath + "\r\n"; + //DataList.Add(new WatcherFileModel + //{ + // CreateTime = DateTime.Now.ToString(), + // ChangeType = e.ChangeType, + // Name = e.Name, + // FullPath = e.FullPath, + // Data = tmp + //}); + })); + } + + private void Watcher_Created(object sender, FileSystemEventArgs e) + { + DateTime dt = DateTime.Now; + string tmp = dt.Hour.ToString() + "时" + dt.Minute.ToString() + "分" + dt.Second.ToString() + "秒" + dt.Millisecond.ToString() + "毫秒,目录发生变化\r\n"; + tmp += "改变类型 :" + e.ChangeType.ToString() + "\r\n"; ; + tmp += "文件全称:" + e.FullPath + "\r\n"; + //DataList.Add(new WatcherFileModel + //{ + // CreateTime = DateTime.Now.ToString(), + // ChangeType = e.ChangeType, + // Name = e.Name, + // FullPath = e.FullPath, + // Data = tmp + //}); + } + + private void Watcher_Deleted(object sender, FileSystemEventArgs e) + { + + DateTime dt = DateTime.Now; + string tmp = dt.Hour.ToString() + "时" + dt.Minute.ToString() + "分" + dt.Second.ToString() + "秒" + dt.Millisecond.ToString() + "毫秒,目录发生变化\r\n"; + tmp += "改变类型 :" + e.ChangeType.ToString() + "\r\n"; ; + tmp += "文件全称:" + e.FullPath + "\r\n"; + // DataList.Add(new WatcherFileModel + //{ + // CreateTime= DateTime.Now.ToString(), + // ChangeType=e.ChangeType, + // Name=e.Name, + // FullPath= e.FullPath, + // Data=tmp + //}); + } + + /// + /// 启动或者停止监听 + /// + /// True:启用监听,False:关闭监听 + private void WatchStartOrSopt(bool IsEnableRaising) + { + watcher.EnableRaisingEvents = IsEnableRaising; + } + + private FileSystemWatcher watcher = new FileSystemWatcher(); + } +} diff --git a/StartServerWPF.Modules.Main/ViewModels/LogManagementViewModel.cs b/StartServerWPF.Modules.Main/ViewModels/LogManagementViewModel.cs new file mode 100644 index 0000000..fbc7fa9 --- /dev/null +++ b/StartServerWPF.Modules.Main/ViewModels/LogManagementViewModel.cs @@ -0,0 +1,183 @@ +using HandyControl.Data; +using Microsoft.Win32; +using Prism.Commands; +using Prism.Events; +using Prism.Mvvm; +using Prism.Regions; +using Prism.Services.Dialogs; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Input; + + +namespace StartServerWPF.Modules.Main.ViewModels +{ + + public class LogManagementViewModel : BindableBase + { + IEventAggregator _ea; + private readonly IDialogService _dialogService; + + public LogManagementViewModel( + IRegionManager regionManager, + IEventAggregator ea, IDialogService dialogService) + + { + this._dialogService = dialogService; + InitInfo(); + } + + private string _title = "日志查看"; + public string Title => _title; + + 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; + EndTime = DateTime.Now; + QueryData(); + } + + public void Refresh() + { + QueryData(); + } + + + public void QueryData() + { + + Task.Run(() => + { + //this.ShowLoading(); + //var logsDTO = _systemLogBLL.Query(StartTime, EndTime); + //int index = logsDTO.Count; + //MaxCountPage = (index % countPerPage == 0 ? index / countPerPage : index / countPerPage + 1); + //_totalDataList = logsDTO; + //DataList = _totalDataList.Take(countPerPage).ToList(); + //this.HideLoading(); + }); + } + private void HFWarning() + { + + DialogParameters param = new DialogParameters(); + param.Add("type", 0); + // param.Add("menu", currentMenu); + + 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) + { + try + { + // foreach (var item in _totalDataList) + { + // 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"); + } + } + + private DateTime _StartTime; + + public DateTime StartTime + { + get => _StartTime; + set => SetProperty(ref _StartTime, value); + } + private DateTime _EndTime; + + public DateTime EndTime + { + get => _EndTime; + set => SetProperty(ref _EndTime, value); + } + //private List _DataList; + + //public List DataList + //{ + // get { return _DataList; } + // set { SetProperty(ref _DataList, value); } + //} + ///// + ///// 所有数据 + ///// + //private List _totalDataList; + /// + /// 页码 + /// + private int _pageIndex = 1; + + /// + /// 页码 + /// + public int PageIndex + { + get => _pageIndex; + set => SetProperty(ref _pageIndex, value); + + } + + /// + /// 页码 + /// + private int _MaxCountPage = 15; + + /// + /// 页码 + /// + public int MaxCountPage + { + get => _MaxCountPage; + set => SetProperty(ref _MaxCountPage, value); + } + + private int countPerPage = 15; + /// + /// 页码改变命令 + /// + public DelegateCommand> PageUpdatedCmd => new(PageUpdated); + + /// + /// 页码改变 + /// + private void PageUpdated(FunctionEventArgs info) + { + // DataList = _totalDataList.Skip((info.Info - 1) * countPerPage).Take(countPerPage).ToList(); + } + + } +} diff --git a/StartServerWPF.Modules.Main/ViewModels/LoginViewDialogViewModel.cs b/StartServerWPF.Modules.Main/ViewModels/LoginViewDialogViewModel.cs new file mode 100644 index 0000000..4c4045b --- /dev/null +++ b/StartServerWPF.Modules.Main/ViewModels/LoginViewDialogViewModel.cs @@ -0,0 +1,112 @@ +using Prism.Commands; +using Prism.Mvvm; +using Prism.Services.Dialogs; +using StartServerWPF.Modules.Main.models; +using StartServerWPF.Modules.Main.Models; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Security.Principal; +using System.Text; +using System.Text.Encodings.Web; +using System.Text.Json; +using System.Text.Unicode; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Input; + +namespace StartServerWPF.Modules.Main.ViewModels +{ + public class LoginViewDialogViewModel : BindableBase, IDialogAware + { + public LoginViewDialogViewModel(WebsocketClient websocketClient) + { + this._websocketClient = websocketClient; + } + private string _title = "应用列表"; + public string Title => _title; + private string account = "admin"; + + public string Account + { + get { return account; } + set { SetProperty(ref account, value); } + } + private string password = "123"; + + public string Password + { + get { return password; } + set { SetProperty(ref password, value); } + } + public event Action RequestClose; + + public bool CanCloseDialog() + { + return true; + } + + public void OnDialogClosed() { } + + public void OnDialogOpened(IDialogParameters parameters) + { + // _title = "编辑" + _title; + var _type = parameters.GetValue("type"); + // _title = (_type == 0 ? "新增" : "修改") + _title; + } + + private VpnInfo _mainModel = new VpnInfo(); + public VpnInfo MainModel + { + get => _mainModel; + set { SetProperty(ref _mainModel, value); } + } + private DateTime _moniTime ; + private readonly WebsocketClient _websocketClient; + + public DateTime MoniTime + { + get => _moniTime; + set { SetProperty(ref _moniTime, value); } + } + public DelegateCommand LoginCommand => new(() => { + OnShowLoading(new LoadingPayload { IsShow = true }); + _websocketClient.SiginServer(Account, Password); + }); + public void CloseDialog(DialogResult dialogResult) + { + RequestClose?.Invoke(dialogResult); + } + public ICommand CancelCommand + { + get => new DelegateCommand(() => + { + RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel)); + }); + } + + private string isLoadingVisibile = "Hidden"; + + public string IsLoadingVisibile + { + get { return isLoadingVisibile; } + set { SetProperty(ref isLoadingVisibile, value); } + } + + private string _loadingMessage; + + public string LoadingMessage + { + get { return _loadingMessage; } + set { SetProperty(ref _loadingMessage, value); } + } + + public void OnShowLoading(LoadingPayload msg) + { + this.IsLoadingVisibile = msg.IsShow ? "Visible" : "Hidden"; + this.LoadingMessage = msg.Message; + } + } +} diff --git a/StartServerWPF.Modules.Main/ViewModels/MainViewModel.cs b/StartServerWPF.Modules.Main/ViewModels/MainViewModel.cs index c0e63cb..5b589c3 100644 --- a/StartServerWPF.Modules.Main/ViewModels/MainViewModel.cs +++ b/StartServerWPF.Modules.Main/ViewModels/MainViewModel.cs @@ -1,63 +1,138 @@ -using Prism.Commands; +using Org.BouncyCastle.Crypto.Modes; +using Prism.Commands; using Prism.Mvvm; using Prism.Services.Dialogs; +using StartServerWPF.Modules.Main.models; +using StartServerWPF.Modules.Main.Models; using System; using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.ComponentModel; using System.Diagnostics; using System.IO; using System.Linq; using System.Net; using System.Runtime.InteropServices; using System.Text; +using System.Text.Encodings.Web; +using System.Text.Json; +using System.Text.Unicode; using System.Threading; -using System.Threading.Tasks; -using System.Windows.Controls; using System.Windows; -using System.Collections.ObjectModel; -using StartServerWPF.Modules.Main.Models; -using System.Windows.Media; -using System.Timers; +using System.Windows.Controls; using System.Windows.Threading; -using Org.BouncyCastle.Crypto.Modes.Gcm; -using System.Net.Http.Json; -using System.Text.Json.Serialization; -using System.Text.Json; -using System.Text.Encodings.Web; -using System.Text.Unicode; -using System.Security.Principal; namespace StartServerWPF.Modules.Main.ViewModels { public class MainViewModel : BindableBase { - public MainViewModel(IDialogService dialogService, WebsocketClient websocket) + public MainViewModel(IDialogService dialogService, WebsocketClient websocket, LoginViewDialogViewModel loginViewDialogViewModel) { - Message = "View A from your Prism Module"; + Message = "View A" ; 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(">"); - moniTimeStr = moniTimeStr.Substring(0, moniTimeIndEnd - 1); - MoniStartTime = DateTime.Parse(moniTimeStr); + // int moniTimeInd = sc.proMonitor.ProParams.IndexOf("-btime"); + // string moniTimeStr = sc.proMonitor.ProParams.Substring(moniTimeInd + 7); + // int moniTimeIndEnd = moniTimeStr.IndexOf(">"); + //moniTimeStr = moniTimeStr.Substring(0, moniTimeIndEnd - 1); + // MoniStartTime = DateTime.Parse(moniTimeStr); InitializeParams(); JsonParser.UpdateApmsJson(sc.proApms.ProPath + "apms.json", sc.vpnInfo.DataSavePath); JsonParser.UpdateRecvJson(sc.proRecv.ProPath + "gw.recvftp.json", sc.vpnInfo.DataSavePath); - sc.proMonitor.ProParams = JsonParser.CreateMonitorStartParam(sc.vpnInfo.DataSavePath, MoniStartTime); + // sc.proMonitor.ProParams = JsonParser.CreateMonitorStartParam(sc.vpnInfo.DataSavePath, MoniStartTime); StartTime = DateTime.Now; // labelStartTime.Text = "启动时间:" + StartTime.ToString(); - remDb = new MySqlHelper(sc.remoteDb); Console.WriteLine(System.Environment.CurrentDirectory); Console.WriteLine(sc.remoteDb.ServerAddress + "\t" + sc.remoteDb.ServerPort + "\t" + sc.remoteDb.UserName + "\t" + sc.remoteDb.Password); this._dialogService = dialogService; this._websocket = websocket; + this._loginViewDialogViewModel = loginViewDialogViewModel; _websocket.WebSocketInit(sc.remoteDb.WebsocketUrl); CurrentItemsList = ApmsProcessSliceList; - _websocket.SiginServer(sc.remoteDb.Account,sc.remoteDb.Pwd); + _websocket.WebsocketError = WebSocket_Error; + _websocket.WebSocketMessageReceived = WebSocket4Net_MessageReceived; + + DialogParameters param = new DialogParameters(); + param.Add("type", 1);// 编辑 + _dialogService.ShowDialog( + "LoginViewDialog", + param, + new Action(result => + { + if (result != null && result.Result == ButtonResult.OK) + { + IntilVPN(); + SetControlstatus(); + } + else + { + Environment.Exit(0); + } + })); } + private void WebSocket4Net_MessageReceived(string message) + { + Debug.WriteLine($"服务端回复数据:{message}!"); + using (JsonDocument document = JsonDocument.Parse(message)) + { + JsonElement root = document.RootElement; + if (root.TryGetProperty("type", out JsonElement dataElement)) + { + string type = dataElement.ToString(); + switch (type) + { + case CSMessage.sigin: + var user = JsonSerializer.Deserialize(message, new JsonSerializerOptions + { + // 整齐打印 + WriteIndented = true, + //重新编码,解决中文乱码问题 + Encoder = JavaScriptEncoder.Create(UnicodeRanges.All) + }); + _loginViewDialogViewModel.OnShowLoading(new LoadingPayload { IsShow = false }); + + Application.Current.Dispatcher.Invoke(() => + { + HandyControl.Controls.MessageBox.Show(user.message, "提示"); + if (user.code == 200) + { + _loginViewDialogViewModel.CloseDialog(new DialogResult(ButtonResult.OK)); + } + }); + // this.HideLoading(); + break; + case CSMessage.subscribe: + var sub = JsonSerializer.Deserialize(message, new JsonSerializerOptions + { + // 整齐打印 + WriteIndented = true, + //重新编码,解决中文乱码问题 + Encoder = JavaScriptEncoder.Create(UnicodeRanges.All) + }); + break; + case CSMessage.publish: + var publish = JsonSerializer.Deserialize(message, new JsonSerializerOptions + { + // 整齐打印 + WriteIndented = true, + //重新编码,解决中文乱码问题 + Encoder = JavaScriptEncoder.Create(UnicodeRanges.All) + }); + break; + default: + break; + } + } + } + } + void WebSocket_Error(SuperSocket.ClientEngine.ErrorEventArgs e) + { + //出错后隐藏加载窗口 + Debug.WriteLine("websocket_Error:" + e.Exception.ToString()); + } #region 属性 private string _message; @@ -115,9 +190,9 @@ namespace StartServerWPF.Modules.Main.ViewModels get { return isIndeterminate; } set { SetProperty(ref isIndeterminate, value); } } - private ObservableCollection reciveDataSource=new ObservableCollection(); + private ObservableCollection reciveDataSource=new ObservableCollection(); - public ObservableCollection ReciveDataSource + public ObservableCollection ReciveDataSource { get { return reciveDataSource; } set { reciveDataSource = value; } @@ -143,37 +218,40 @@ namespace StartServerWPF.Modules.Main.ViewModels set => SetProperty(ref proMonInterval, value); } - private ObservableCollection _OutPutItemsSource = new ObservableCollection(); - public ObservableCollection OutPutItemsSource + private ObservableCollection _OutPutItemsSource = new ObservableCollection(); + public ObservableCollection OutPutItemsSource { get => _OutPutItemsSource; set => SetProperty(ref _OutPutItemsSource, value); } - private List _apmsProcessSliceList= new List(); - public List ApmsProcessSliceList + private List _apmsProcessSliceList= new List(); + public List ApmsProcessSliceList { get => _apmsProcessSliceList; set=> SetProperty(ref _apmsProcessSliceList, value); } - private List _apmsEventList = new List(); - public List ApmsEventList + private List _apmsEventList = new List(); + public List ApmsEventList { get => _apmsEventList; set => SetProperty(ref _apmsEventList, value); } - private List _toolsProcessSliceList = new List(); - public List ToolsProcessSliceList + private List _toolsProcessSliceList = new List() { + new ProcessingInformationModel { ProcessMes = "outLine.Data", MonitorTime = DateTime.Now.ToString()}, + new ProcessingInformationModel { ProcessMes = "outLine.Data666", MonitorTime = DateTime.Now.ToString()} + }; + public List ToolsProcessSliceList { get => _toolsProcessSliceList; set => SetProperty(ref _toolsProcessSliceList, value); } - private List _toolsEventList = new List(); - public List ToolsEventList + private List _toolsEventList = new List(); + public List ToolsEventList { get => _toolsEventList; set => SetProperty(ref _toolsEventList, value); @@ -186,25 +264,25 @@ namespace StartServerWPF.Modules.Main.ViewModels return; } list.Add(t1); - if (list.Count > 10) + if (list.Count > 20) { T item = list[0]; list.RemoveAt(0); } } #endregion - private List CurrentItemsList; + private List CurrentItemsList; #region 事件 public DelegateCommand LoadedCommand => new(Loaded); public DelegateCommand UnloadedCommand => new(Unloaded); - public DelegateCommand ConnectVPNCommand => new(ConnectVPN); + public DelegateCommand ConnectVPNCommand => new(ConnectVPN); public DelegateCommand DisConnectVPNCommand => new(DisConnectVPN); public DelegateCommand GetVPNStatusCommand => new(GetVPNStatus); public DelegateCommand SetVPNParaCommand => new(SetVPNPara); public DelegateCommand DisplayLogCommand => new(DisplayLog); - public DelegateCommand OneKeyStartCommand => new(OneKeyStart); - public DelegateCommand OneKeyStopCommand => new(OneKeyStop); + public DelegateCommand StartCommand => new(Start); + // public DelegateCommand OneKeyStopCommand => new(OneKeyStop); public DelegateCommand DisplayRealWavesCommand => new(DisplayRealWaves); public DelegateCommand QueryDataCommand => new(QueryData); public DelegateCommand InsertDataCommand => new(InsertData); @@ -238,9 +316,7 @@ namespace StartServerWPF.Modules.Main.ViewModels }); private void Loaded() - { - IntilVPN(); - SetControlstatus(); + { } public void Unloaded() @@ -254,7 +330,18 @@ namespace StartServerWPF.Modules.Main.ViewModels //WriteSerLog(sc.vpnInfo.SystemLogPath + JsonParser.systemLogFileName, logStr); OneKeyStop(); } - + private void ConnectVPN(object obj) + { + var cBox = obj as CheckBox; + if ((bool)cBox.IsChecked) + { + ConnectVPN(); + } + else + { + DisConnectVPN(); + } + } private void ConnectVPN() { vpn.CreateOrUpdateVPN(sc.vpnInfo.VpnName, sc.vpnInfo.VpnIP); @@ -312,9 +399,22 @@ namespace StartServerWPF.Modules.Main.ViewModels { Process.Start("explorer.exe", sc.vpnInfo.SystemLogPath); } + private void Start( object obj) + { + var cBox = obj as CheckBox; + if((bool)cBox.IsChecked) + { + OneKeyStart(); + } + else + { + OneKeyStop(); + } + } private void OneKeyStart() { + ReciveDataSource.Clear(); foreach (var item in sc.GetType().GetProperties()) { var pro = item.GetValue(sc) as ProcessInfo; @@ -322,10 +422,17 @@ namespace StartServerWPF.Modules.Main.ViewModels { StartTime = DateTime.Now; pro.Pid= StartProcess(pro); - if (sc.proServer.Pid < 32) + ReciveDataSource.Add(new ProcessModel { - ReciveDataSource.Add( pro.ProName+"服务器程序启动失败:" + StartTime.ToString()); - } + ProName = pro.ProName, + ProcessTile = pro.ProTitle, + MonitorTime = DateTime.Now.ToString(), + ProcessStatus = sc.proServer.Pid == 0 ? "正常运行" : "未运行" + }) ; + //if (sc.proServer.Pid < 32) + //{ + // ReciveDataSource.Add( pro.ProName+"服务器程序启动失败:" + StartTime.ToString()); + //} Thread.Sleep(10); } } @@ -338,7 +445,7 @@ namespace StartServerWPF.Modules.Main.ViewModels timer1.Interval = TimeSpan.FromSeconds(ProMonInterval); timer1.Start(); - ReciveDataSource.Clear(); + } private void OneKeyStop() @@ -349,18 +456,14 @@ namespace StartServerWPF.Modules.Main.ViewModels if (pro != null) { int indexPro = KillProcess(pro); - if (indexPro > -1) - { - ReciveDataSource.Add(pro.ProName + "结束成功"); - } - else - { - ReciveDataSource.Add(pro.ProName + "结束失败"); - } + var model= ReciveDataSource.Where(x => x.ProcessTile == pro.ProName).FirstOrDefault(); + if (model == null) continue; + model.MonitorTime= DateTime.Now.ToString(); + model.ProcessStatus = "已停止"; } } - ReciveDataSource.Add("服务停止于:" + DateTime.Now.ToString()); + // ReciveDataSource.Add("服务停止于:" + DateTime.Now.ToString()); timer1.Stop(); IsIndeterminate = false; string logStr = DateTime.Now.ToString("s") + "\t服务器程序关闭"; @@ -450,6 +553,7 @@ namespace StartServerWPF.Modules.Main.ViewModels private DispatcherTimer timer1= new DispatcherTimer(); private readonly IDialogService _dialogService; private readonly WebsocketClient _websocket; + private readonly LoginViewDialogViewModel _loginViewDialogViewModel; public void InitializeParams() { @@ -511,11 +615,11 @@ namespace StartServerWPF.Modules.Main.ViewModels { if (pro.MainModule.ModuleName.Contains(sc.proApms.ProName)) { - AddItems(ApmsProcessSliceList, outLine.Data); + AddItems(ApmsProcessSliceList, new ProcessingInformationModel { ProcessMes= outLine.Data, MonitorTime=DateTime.Now.ToString() }); } else if (pro.MainModule.ModuleName.Contains(sc.proTools.ProName)) { - AddItems(ToolsProcessSliceList, outLine.Data); + AddItems(ToolsProcessSliceList, new ProcessingInformationModel { ProcessMes = outLine.Data, MonitorTime = DateTime.Now.ToString() }); } } } @@ -526,11 +630,11 @@ namespace StartServerWPF.Modules.Main.ViewModels { if (pro.MainModule.ModuleName.Contains(sc.proApms.ProName)) { - AddItems(ApmsEventList, outLine.Data); + AddItems(ApmsEventList, new ProcessingInformationModel { ProcessMes = outLine.Data, MonitorTime = DateTime.Now.ToString() }); } else if (pro.MainModule.ModuleName.Contains(sc.proTools.ProName)) { - AddItems(ToolsEventList, outLine.Data); + AddItems(ToolsEventList, new ProcessingInformationModel { ProcessMes = outLine.Data, MonitorTime = DateTime.Now.ToString() }); } } } @@ -554,7 +658,7 @@ namespace StartServerWPF.Modules.Main.ViewModels private int StartProcess(ProcessInfo proInfo) { bool res= CMDStartProcess(proInfo); - int seInd = res ? 37 : 1; + int seInd = res ? 37 : 0; //int seInd = ShellExecute(IntPtr.Zero, new StringBuilder("open"), new StringBuilder(proInfo.ProName + ".exe") // , new StringBuilder(proInfo.ProParams), new StringBuilder(proInfo.ProPath), proInfo.ShowState); return seInd; @@ -653,26 +757,23 @@ namespace StartServerWPF.Modules.Main.ViewModels private void timer1_Tick(object? sender, EventArgs e) { - ReciveDataSource.Clear(); - ReciveDataSource.Add(DateTime.Now.ToString()); - foreach (var item in sc.GetType().GetProperties()) { var pro = item.GetValue(sc) as ProcessInfo; if (pro != null) { int sfp = FindProcess(pro); + var model = ReciveDataSource.Where(x => x.ProcessTile == pro.ProName).FirstOrDefault(); if (sfp == 0) { - ReciveDataSource.Add(pro.ProName+"服务器程序运行正常"); + model.ProcessStatus = "正常运行"; } else { - ReciveDataSource.Add(pro.ProName + "服务器程序未运行"); + model.ProcessStatus = "重启中"; Thread.Sleep(2); StartProcess(pro); Thread.Sleep(20); - ReciveDataSource.Add(pro.ProName + "服务器程序重启成功"); string logStr = DateTime.Now.ToString("s") + "\t服务器程序" + pro.ProName + "重启"; WriteSerLog(sc.vpnInfo.SystemLogPath + JsonParser.systemLogFileName, logStr); diff --git a/StartServerWPF.Modules.Main/ViewModels/RealTimeWaveformViewModel.cs b/StartServerWPF.Modules.Main/ViewModels/RealTimeWaveformViewModel.cs new file mode 100644 index 0000000..698364c --- /dev/null +++ b/StartServerWPF.Modules.Main/ViewModels/RealTimeWaveformViewModel.cs @@ -0,0 +1,29 @@ +using Prism.Commands; +using Prism.Events; +using Prism.Ioc; +using Prism.Mvvm; +using Prism.Regions; +using Prism.Services.Dialogs; +using System; +using System.Collections.ObjectModel; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Threading; + + + +namespace StartServerWPF.Modules.Main.ViewModels +{ + public class RealTimeWaveformViewModel : BindableBase + { + + IContainerProvider _containerProvider; + + public RealTimeWaveformViewModel( + IRegionManager regionManager, + IContainerProvider containerProvider) + { + _containerProvider = containerProvider; + } + } +} diff --git a/StartServerWPF.Modules.Main/ViewModels/SetParamViewModel.cs b/StartServerWPF.Modules.Main/ViewModels/SetParamViewModel.cs new file mode 100644 index 0000000..519ddab --- /dev/null +++ b/StartServerWPF.Modules.Main/ViewModels/SetParamViewModel.cs @@ -0,0 +1,98 @@ +using Prism.Commands; +using Prism.Mvvm; +using Prism.Services.Dialogs; +using StartServerWPF.Modules.Main.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Input; + +namespace StartServerWPF.Modules.Main.ViewModels +{ + public class SetParamViewModel : BindableBase + { + public SetParamViewModel(MainViewModel mainViewModel) + { + _systemConfig = mainViewModel.sc; + MainModel = _systemConfig.vpnInfo; + MoniTime = mainViewModel.MoniStartTime; + } + private string _title = "应用列表"; + public string Title => _title; + + + + private SystemConfig _systemConfig; + private VpnInfo _mainModel = new VpnInfo(); + public VpnInfo MainModel + { + get => _mainModel; + set { SetProperty(ref _mainModel, value); } + } + private DateTime _moniTime ; + public DateTime MoniTime + { + get => _moniTime; + set { SetProperty(ref _moniTime, value); } + } + + 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(() => + { + System.Windows.Forms.FolderBrowserDialog fbd = new System.Windows.Forms.FolderBrowserDialog(); + fbd.SelectedPath = System.Environment.CurrentDirectory + "\\" + MainModel.SystemLogPath; + fbd.ShowNewFolderButton = true; + if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK) + { + + MainModel.SystemLogPath = fbd.SelectedPath; + } + }); + bool updateJson = false; + + public ICommand ConfirmCommand + { + get => new DelegateCommand(() => + { + // 确认操作 + // 数据校验(关键字段不能为空、年龄做数字区间的校验、做UserName的唯一检查(自定义特性检查) + if (string.IsNullOrEmpty(MainModel.VpnName) || string.IsNullOrEmpty(MainModel.VpnIP)) + { + MessageBox.Show("内容不能为空", "提示", MessageBoxButton.OK); + return; + } + if (MessageBox.Show("确认修改?", "参数设置", MessageBoxButton.OKCancel, + MessageBoxImage.Exclamation) == MessageBoxResult.OK) + { + + + 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/ViewModels/TreeMenuViewModel.cs b/StartServerWPF.Modules.Main/ViewModels/TreeMenuViewModel.cs index 6bdba61..565e669 100644 --- a/StartServerWPF.Modules.Main/ViewModels/TreeMenuViewModel.cs +++ b/StartServerWPF.Modules.Main/ViewModels/TreeMenuViewModel.cs @@ -31,7 +31,9 @@ namespace StartServerWPF.Modules.Main.ViewModels _regionManager = regionManager; this._dialogService = dialogService; //var global = containerProvider.Resolve();// 注册一个单例 - // ea.GetEvent().Subscribe(OnLogin, ThreadOption.UIThread); + // ea.GetEvent().Subscribe(OnLogin, ThreadOption.UIThread); + Menus=new ObservableCollection(); + FillMenus(Menus); } #region 事件 @@ -68,27 +70,26 @@ namespace StartServerWPF.Modules.Main.ViewModels // } //} ///递归 - /// - private void FillMenus(ObservableCollection menus, int parentId) + /// + /// 递归 + /// + /// + private void FillMenus(ObservableCollection menus) { - // var sub = origMenus.Where(m => m.ParentId == parentId).OrderBy(o => o.Index); - - //if (sub.Count() > 0) - //{ - // foreach (var item in sub) - // { - // MenuItemModel mm = new MenuItemModel(_regionManager) - // { - // MenuHeader = item.MenuHeader, - // MenuIcon = item.MenuIcon, - // TargetView = item.TargetView - // }; - // menus.Add(mm); - - // FillMenus(mm.Children = new ObservableCollection(), item.MenuId); - // } - //} + for (int i = 0; i < menuNames.Count; i++) + { + MenuItemModel menuItem = new MenuItemModel(_regionManager) + { + MenuHeader = menuNames[i], + MenuIcon = "\ue63a", + TargetView = viewName[i], + Children = new ObservableCollection(), + IsExpanded = true, + }; + menus.Add(menuItem); + } } - + List menuNames = new List() {"首页","实时波形","波形回放","设置","日志","文件监控" }; + List viewName = new List() { "MainView", "RealTimeWaveformView", "WaveformPlayBackView", "SetParamView", "LogManagementView","FilesWatcherView" }; } } diff --git a/StartServerWPF.Modules.Main/ViewModels/WaveformPlayBackViewModel.cs b/StartServerWPF.Modules.Main/ViewModels/WaveformPlayBackViewModel.cs new file mode 100644 index 0000000..a04a5e5 --- /dev/null +++ b/StartServerWPF.Modules.Main/ViewModels/WaveformPlayBackViewModel.cs @@ -0,0 +1,29 @@ +using Prism.Commands; +using Prism.Events; +using Prism.Ioc; +using Prism.Mvvm; +using Prism.Regions; +using Prism.Services.Dialogs; +using System; +using System.Collections.ObjectModel; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Threading; + + + +namespace StartServerWPF.Modules.Main.ViewModels +{ + public class WaveformPlayBackViewModel : BindableBase + { + + IContainerProvider _containerProvider; + + public WaveformPlayBackViewModel( + IRegionManager regionManager, + IContainerProvider containerProvider) + { + _containerProvider = containerProvider; + } + } +} diff --git a/StartServerWPF.Modules.Main/Views/FilesWatcherView.xaml b/StartServerWPF.Modules.Main/Views/FilesWatcherView.xaml new file mode 100644 index 0000000..ee2000a --- /dev/null +++ b/StartServerWPF.Modules.Main/Views/FilesWatcherView.xaml @@ -0,0 +1,46 @@ + + + + +