From 345b4d970bbd018c60bf344403606314dfe68b02 Mon Sep 17 00:00:00 2001 From: mzhifa Date: Thu, 8 Jun 2023 23:53:00 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Txgy.FilesWatcher/ViewModels/MainViewModel.cs | 50 +++++++++++++--- Txgy.FilesWatcher/Views/MainView.xaml | 29 ++++++++-- Txgy.FilesWatcher/WebsocketClient.cs | 10 +++- Txgy.FilesWatcher/model/CSMessage.cs | 18 ++++++ Txgy.FilesWatcher/model/UserMessage.cs | 57 +++++++++++++++++++ Txgy.FilesWatcher/systemconfig.json | 2 +- protocol | 25 ++++++++ 7 files changed, 174 insertions(+), 17 deletions(-) create mode 100644 Txgy.FilesWatcher/model/CSMessage.cs create mode 100644 Txgy.FilesWatcher/model/UserMessage.cs create mode 100644 protocol diff --git a/Txgy.FilesWatcher/ViewModels/MainViewModel.cs b/Txgy.FilesWatcher/ViewModels/MainViewModel.cs index 4c60486..8ec7f65 100644 --- a/Txgy.FilesWatcher/ViewModels/MainViewModel.cs +++ b/Txgy.FilesWatcher/ViewModels/MainViewModel.cs @@ -24,9 +24,9 @@ using System.Text.Unicode; namespace Txgy.FilesWatcher.ViewModels { - internal class MainViewModel:BindableBase + internal class MainViewModel : BindableBase { - public MainViewModel(WebsocketClient websocketClient ) + public MainViewModel(WebsocketClient websocketClient) { string filter = "*.txt"; string str = File.ReadAllText("systemconfig.json"); @@ -42,6 +42,10 @@ namespace Txgy.FilesWatcher.ViewModels private void WebSocket4Net_MessageReceived(string message) { Debug.WriteLine($"服务端回复数据:{message}!"); + if(message == "sigin") + { + MessageBox.Show("登录成功"); + } } void WebSocket_Error(SuperSocket.ClientEngine.ErrorEventArgs e) { @@ -52,15 +56,16 @@ namespace Txgy.FilesWatcher.ViewModels public string WatcherPath { get { return watcherPath; } - set { SetProperty(ref watcherPath , value); } + set { SetProperty(ref watcherPath, value); } } + private ObservableCollection dataList = new ObservableCollection(); public ObservableCollection DataList { get { return dataList; } - set { SetProperty(ref dataList , value); } + set { SetProperty(ref dataList, value); } } private DateTime startTime; @@ -100,7 +105,20 @@ namespace Txgy.FilesWatcher.ViewModels get { return isIndeterminate; } set { SetProperty(ref isIndeterminate, value); } } - + private string account; + + public string Account + { + get { return account; } + set { SetProperty(ref account, value); } + } + private string password; + + public string Password + { + get { return password; } + set { SetProperty(ref password, value); } + } public void InitializeParams(string fileFilter) { timer1.Interval = TimeSpan.FromSeconds(ProMonInterval); @@ -112,7 +130,7 @@ namespace Txgy.FilesWatcher.ViewModels IntervalTimesSource.Add(60); SelectedIndex = 1; //如果设置的目录不存在设置到根目录 - if(!File.Exists(WatcherPath)) + if (!File.Exists(WatcherPath)) { WatcherPath = AppDomain.CurrentDomain.BaseDirectory; } @@ -138,15 +156,22 @@ namespace Txgy.FilesWatcher.ViewModels watcher.Error += OnError; //设置监听文件类型 - watcher.Filter =fileFilter; + watcher.Filter = fileFilter; //设置是否监听子目录 watcher.IncludeSubdirectories = true; //设置是否启用监听 - // watcher.EnableRaisingEvents = false; + // watcher.EnableRaisingEvents = false; watcher.EndInit(); } + public DelegateCommand LoginCommand => new(() => { + + _websocketClient.SiginServer(Account, Password); + + }); + + public DelegateCommand StartCommand => new(Start); public DelegateCommand StopCommand => new(Stop); @@ -246,7 +271,14 @@ namespace Txgy.FilesWatcher.ViewModels Data = lastLine, IsSend = false }) ; - _websocketClient.SendMes(lastLine); + + CSDevicePublish cSDevicePublish = new CSDevicePublish() + { + type = CSMessage.publish, + message = lastLine, + }; + string jsonStr = JsonSerializer.Serialize(cSDevicePublish); + _websocketClient.SendMes(jsonStr); })); } diff --git a/Txgy.FilesWatcher/Views/MainView.xaml b/Txgy.FilesWatcher/Views/MainView.xaml index c935d69..2f6a962 100644 --- a/Txgy.FilesWatcher/Views/MainView.xaml +++ b/Txgy.FilesWatcher/Views/MainView.xaml @@ -24,6 +24,7 @@ + @@ -32,21 +33,37 @@ - + + + + + + + + + + + + + + +