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 @@ - + + + + + + + + + + + + + + +