排除空内容和相同数据通过websocket上传

master
gekoukate 1 year ago
parent b65f5476c6
commit e293e6024a

@ -334,28 +334,33 @@ namespace Txgy.FilesWatcher.ViewModels
DateTime lastWriteTime = File.GetLastWriteTime(e.FullPath); DateTime lastWriteTime = File.GetLastWriteTime(e.FullPath);
watcher.EnableRaisingEvents = false; watcher.EnableRaisingEvents = false;
Debug.WriteLine($"最后修改时间:{lastWriteTime}"); Debug.WriteLine($"最后修改时间:{lastWriteTime}");
string lastLine = File.ReadAllLines(e.FullPath).Last(); string lastLine = File.ReadAllLines(e.FullPath).Last().Trim();
System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() => 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(), DataList.Add(new WatcherFileModel
ChangeType = e.ChangeType, {
Name = e.Name, CreateTime = DateTime.Now.ToString(),
FullPath = e.FullPath, ChangeType = e.ChangeType,
Data = lastLine, Name = e.Name,
IsSend = false FullPath = e.FullPath,
}); Data = lastLine,
IsSend = false
CSDevicePublish cSDevicePublish = new CSDevicePublish() });
{
type = CSMessage.publish, CSDevicePublish cSDevicePublish = new CSDevicePublish()
message = lastLine, {
serialNumber = DataList.Count, type = CSMessage.publish,
}; message = lastLine,
string jsonStr = JsonSerializer.Serialize(cSDevicePublish); serialNumber = DataList.Count,
_websocketClient.SendMes(jsonStr); };
})); string jsonStr = JsonSerializer.Serialize(cSDevicePublish);
_websocketClient.SendMes(jsonStr);
}));
}
watcher.EnableRaisingEvents = true; watcher.EnableRaisingEvents = true;
} }

Loading…
Cancel
Save