From e293e6024ab0d06bb428448abdca1fba3a8bf31f Mon Sep 17 00:00:00 2001 From: gekoukate <1670391937@qq.com> Date: Mon, 19 Jun 2023 11:11:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=92=E9=99=A4=E7=A9=BA=E5=86=85=E5=AE=B9?= =?UTF-8?q?=E5=92=8C=E7=9B=B8=E5=90=8C=E6=95=B0=E6=8D=AE=E9=80=9A=E8=BF=87?= =?UTF-8?q?websocket=E4=B8=8A=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Txgy.FilesWatcher/ViewModels/MainViewModel.cs | 45 ++++++++++--------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/Txgy.FilesWatcher/ViewModels/MainViewModel.cs b/Txgy.FilesWatcher/ViewModels/MainViewModel.cs index c5f96d6..68e4fbd 100644 --- a/Txgy.FilesWatcher/ViewModels/MainViewModel.cs +++ b/Txgy.FilesWatcher/ViewModels/MainViewModel.cs @@ -334,28 +334,33 @@ namespace Txgy.FilesWatcher.ViewModels DateTime lastWriteTime = File.GetLastWriteTime(e.FullPath); watcher.EnableRaisingEvents = false; Debug.WriteLine($"最后修改时间:{lastWriteTime}"); - string lastLine = File.ReadAllLines(e.FullPath).Last(); - System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() => + string lastLine = File.ReadAllLines(e.FullPath).Last().Trim(); + var str= dataList.Where(f => f.Data == lastLine).FirstOrDefault(); + if (!string.IsNullOrWhiteSpace(lastLine) + && str==null) { - DataList.Add(new WatcherFileModel + System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() => { - 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); - })); + 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; }