diff --git a/Txgy.FilesWatcher.sln b/Txgy.FilesWatcher.sln
new file mode 100644
index 0000000..1eae57b
--- /dev/null
+++ b/Txgy.FilesWatcher.sln
@@ -0,0 +1,25 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 17
+VisualStudioVersion = 17.3.32811.315
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Txgy.FilesWatcher", "Txgy.FilesWatcher\Txgy.FilesWatcher.csproj", "{039EE0D8-DA93-4435-AB93-9F24802EC109}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {039EE0D8-DA93-4435-AB93-9F24802EC109}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {039EE0D8-DA93-4435-AB93-9F24802EC109}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {039EE0D8-DA93-4435-AB93-9F24802EC109}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {039EE0D8-DA93-4435-AB93-9F24802EC109}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {8FDCAF0E-AEC9-448E-B672-71BD48DE8F7E}
+ EndGlobalSection
+EndGlobal
diff --git a/Txgy.FilesWatcher/App.xaml b/Txgy.FilesWatcher/App.xaml
new file mode 100644
index 0000000..46d464f
--- /dev/null
+++ b/Txgy.FilesWatcher/App.xaml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/Txgy.FilesWatcher/App.xaml.cs b/Txgy.FilesWatcher/App.xaml.cs
new file mode 100644
index 0000000..2421162
--- /dev/null
+++ b/Txgy.FilesWatcher/App.xaml.cs
@@ -0,0 +1,30 @@
+using Prism.Ioc;
+using Prism.Regions;
+using System.Windows;
+using Txgy.FilesWatcher.Views;
+
+namespace Txgy.FilesWatcher
+{
+ ///
+ /// Interaction logic for App.xaml
+ ///
+ public partial class App
+ {
+ protected override Window CreateShell()
+ {
+ return Container.Resolve();
+ }
+
+ protected override void RegisterTypes(IContainerRegistry containerRegistry)
+ {
+ containerRegistry.RegisterSingleton();
+
+
+
+ var iregion= Container.Resolve();
+ iregion.RegisterViewWithRegion("MainContentRegion", typeof(MainView));
+ }
+
+
+ }
+}
diff --git a/Txgy.FilesWatcher/Txgy.FilesWatcher.csproj b/Txgy.FilesWatcher/Txgy.FilesWatcher.csproj
new file mode 100644
index 0000000..7f589b7
--- /dev/null
+++ b/Txgy.FilesWatcher/Txgy.FilesWatcher.csproj
@@ -0,0 +1,13 @@
+
+
+ WinExe
+ net6.0-windows
+ true
+ True
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Txgy.FilesWatcher/ViewModels/MainViewModel.cs b/Txgy.FilesWatcher/ViewModels/MainViewModel.cs
new file mode 100644
index 0000000..3ec039b
--- /dev/null
+++ b/Txgy.FilesWatcher/ViewModels/MainViewModel.cs
@@ -0,0 +1,216 @@
+using DryIoc;
+using Prism.Commands;
+using Prism.Mvvm;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Controls;
+using System.Windows;
+using System.Collections.ObjectModel;
+using System.Windows.Threading;
+
+namespace Txgy.FilesWatcher.ViewModels
+{
+ internal class MainViewModel:BindableBase
+ {
+ public MainViewModel()
+ {
+
+ WatcherPath = "E:\\mingzf\\txgy\\WatchChanged";
+ InitializeParams();
+ }
+
+ private string watcherPath;
+
+ public string WatcherPath
+ {
+ get { return watcherPath; }
+ set { watcherPath = value; }
+ }
+ private List dataList=new List();
+
+ public List DataList
+
+ {
+ get { return dataList; }
+ set { dataList = value; }
+ }
+
+ private DateTime startTime;
+ public DateTime StartTime { get => startTime; set => SetProperty(ref startTime, value); }
+ private string runTime;
+
+ public string RunTime
+ {
+ get { return runTime; }
+ set { SetProperty(ref runTime, value); }
+ }
+
+ private ObservableCollection intervalTimesSource = new ObservableCollection();
+
+ public ObservableCollection IntervalTimesSource
+ {
+ get { return intervalTimesSource; }
+ set { intervalTimesSource = value; }
+ }
+ private int selectedIndex;
+
+ public int SelectedIndex
+ {
+ get { return selectedIndex; }
+ set { SetProperty(ref selectedIndex, value); }
+ }
+ private int proMonInterval = 10;
+ public int ProMonInterval
+ {
+ get => proMonInterval;
+ set => SetProperty(ref proMonInterval, value);
+ }
+ private bool isIndeterminate = false;
+
+ public bool IsIndeterminate
+ {
+ get { return isIndeterminate; }
+ set { SetProperty(ref isIndeterminate, value); }
+ }
+ public void InitializeParams()
+ {
+ timer1.Interval = TimeSpan.FromSeconds(ProMonInterval);
+ IntervalTimesSource.Add(5);
+ IntervalTimesSource.Add(10);
+ IntervalTimesSource.Add(15);
+ IntervalTimesSource.Add(20);
+ IntervalTimesSource.Add(30);
+ IntervalTimesSource.Add(60);
+ SelectedIndex = 1;
+
+ watcher = new FileSystemWatcher(WatcherPath);
+ //初始化监听
+ 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 += Watcher_Changed;
+ watcher.Created += Watcher_Created;
+ watcher.Deleted += Watcher_Deleted;
+ watcher.Renamed += Watcher_Renamed;
+ watcher.Error += OnError;
+
+ //设置监听文件类型
+ // watcher.Filter = "*.txt";
+ //设置是否监听子目录
+ watcher.IncludeSubdirectories = true;
+ //设置是否启用监听
+ watcher.EnableRaisingEvents = false;
+ watcher.EndInit();
+
+ }
+
+ public DelegateCommand StartCommand => new(Start);
+
+ public DelegateCommand StopCommand => new(Stop);
+
+
+ private void Start()
+ {
+ WatchStartOrSopt(true);
+ }
+
+ private void Stop()
+ {
+ WatchStartOrSopt(false);
+ }
+
+ public DelegateCommand FilePathSaveCommand => new(() =>
+ {
+ System.Windows.Forms.FolderBrowserDialog fbd = new System.Windows.Forms.FolderBrowserDialog();
+ fbd.SelectedPath = WatcherPath;
+ fbd.ShowNewFolderButton = true;
+ if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
+ {
+ // MainModel.DataSavePath = fbd.SelectedPath;
+ //if (MainModel.DataSavePath != _systemConfig.vpnInfo.DataSavePath)
+ //{
+ // updateJson = true;
+ //}
+ }
+ });
+
+ private void OnError(object sender, ErrorEventArgs e)
+ {
+
+ }
+
+ private void Watcher_Changed(object sender, FileSystemEventArgs e)
+ {
+ 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(tmp);
+ }));
+ }
+
+ private void Watcher_Renamed(object sender, RenamedEventArgs e)
+ {
+ 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(tmp);
+ }));
+ }
+
+ private void Watcher_Created(object sender, FileSystemEventArgs e)
+ {
+ 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(tmp);
+ }));
+ }
+
+ private void Watcher_Deleted(object sender, FileSystemEventArgs e)
+ {
+ 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(tmp);
+ }));
+ }
+
+ ///
+ /// 启动或者停止监听
+ ///
+ /// True:启用监听,False:关闭监听
+ private void WatchStartOrSopt(bool IsEnableRaising)
+ {
+ watcher.EnableRaisingEvents = IsEnableRaising;
+ }
+
+ private FileSystemWatcher watcher = new FileSystemWatcher();
+ private DispatcherTimer timer1 = new DispatcherTimer();
+ }
+}
diff --git a/Txgy.FilesWatcher/ViewModels/MainWindowViewModel.cs b/Txgy.FilesWatcher/ViewModels/MainWindowViewModel.cs
new file mode 100644
index 0000000..feabae7
--- /dev/null
+++ b/Txgy.FilesWatcher/ViewModels/MainWindowViewModel.cs
@@ -0,0 +1,19 @@
+using Prism.Mvvm;
+
+namespace Txgy.FilesWatcher.ViewModels
+{
+ public class MainWindowViewModel : BindableBase
+ {
+ private string _title = "Application";
+ public string Title
+ {
+ get { return _title; }
+ set { SetProperty(ref _title, value); }
+ }
+
+ public MainWindowViewModel()
+ {
+
+ }
+ }
+}
diff --git a/Txgy.FilesWatcher/Views/MainView.xaml b/Txgy.FilesWatcher/Views/MainView.xaml
new file mode 100644
index 0000000..2a54a51
--- /dev/null
+++ b/Txgy.FilesWatcher/Views/MainView.xaml
@@ -0,0 +1,100 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Txgy.FilesWatcher/Views/MainView.xaml.cs b/Txgy.FilesWatcher/Views/MainView.xaml.cs
new file mode 100644
index 0000000..97b4c66
--- /dev/null
+++ b/Txgy.FilesWatcher/Views/MainView.xaml.cs
@@ -0,0 +1,28 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Navigation;
+using System.Windows.Shapes;
+
+namespace Txgy.FilesWatcher.Views
+{
+ ///
+ /// MainView.xaml 的交互逻辑
+ ///
+ public partial class MainView : UserControl
+ {
+ public MainView()
+ {
+ InitializeComponent();
+ }
+ }
+}
diff --git a/Txgy.FilesWatcher/Views/MainWindow.xaml b/Txgy.FilesWatcher/Views/MainWindow.xaml
new file mode 100644
index 0000000..3d46c63
--- /dev/null
+++ b/Txgy.FilesWatcher/Views/MainWindow.xaml
@@ -0,0 +1,10 @@
+
+
+
+
+
diff --git a/Txgy.FilesWatcher/Views/MainWindow.xaml.cs b/Txgy.FilesWatcher/Views/MainWindow.xaml.cs
new file mode 100644
index 0000000..9151e45
--- /dev/null
+++ b/Txgy.FilesWatcher/Views/MainWindow.xaml.cs
@@ -0,0 +1,15 @@
+using System.Windows;
+
+namespace Txgy.FilesWatcher.Views
+{
+ ///
+ /// Interaction logic for MainWindow.xaml
+ ///
+ public partial class MainWindow : Window
+ {
+ public MainWindow()
+ {
+ InitializeComponent();
+ }
+ }
+}
diff --git a/Txgy.FilesWatcher/WatchFileHelper.cs b/Txgy.FilesWatcher/WatchFileHelper.cs
new file mode 100644
index 0000000..521df84
--- /dev/null
+++ b/Txgy.FilesWatcher/WatchFileHelper.cs
@@ -0,0 +1,161 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Txgy.FilesWatcher
+{
+ public class WatchFileHelper
+ {
+ int count = 0;
+ FileSystemWatcher watcher = new FileSystemWatcher();
+ int eventCount = 0;
+ string filePath;
+
+ //static List files = new List();
+ public WatchFileHelper(string checkSettingFile)
+ {
+ filePath = checkSettingFile;
+ WatcherStrat(filePath, "*.xml", true, false);
+ }
+
+
+ ///
+ /// 初始化监听
+ ///
+ /// 需要监听的目录
+ /// 需要监听的文件类型(筛选器字符串)
+ /// 是否启用监听
+ /// 是否监听子目录
+ private void WatcherStrat(string StrWarcherPath, string FilterType, bool IsEnableRaising, bool IsInclude)
+ {
+ //初始化监听
+ watcher.BeginInit();
+ //设置监听文件类型
+ watcher.Filter = FilterType;
+ //设置需要监听的更改类型(如:文件或者文件夹的属性,文件或者文件夹的创建时间;NotifyFilters枚举的内容)
+ watcher.NotifyFilter = NotifyFilters.Attributes
+ | NotifyFilters.CreationTime
+ | NotifyFilters.DirectoryName
+ | NotifyFilters.FileName
+ | NotifyFilters.LastAccess
+ | NotifyFilters.LastWrite
+ | NotifyFilters.Security
+ | NotifyFilters.Size;
+ //设置监听的路径
+ watcher.Path = StrWarcherPath;
+ //注册创建文件或目录时的监听事件
+ watcher.Created += new FileSystemEventHandler(watch_created);
+ //注册当指定目录的文件或者目录发生改变的时候的监听事件
+ watcher.Changed += new FileSystemEventHandler(watch_changed);
+ //注册当删除目录的文件或者目录的时候的监听事件
+ watcher.Deleted += new FileSystemEventHandler(watch_deleted);
+ //当指定目录的文件或者目录发生重命名的时候的监听事件
+ watcher.Renamed += new RenamedEventHandler(watch_renamed);
+ //设置是否监听子目录
+ watcher.IncludeSubdirectories = IsInclude;
+ //设置是否启用监听?
+ watcher.EnableRaisingEvents = IsEnableRaising;
+ //结束初始化
+ watcher.EndInit();
+ }
+
+ ///
+ /// 创建文件或者目录时的监听事件
+ ///
+ ///
+ ///
+ private void watch_created(object sender, FileSystemEventArgs e)
+ {
+ //事件内容
+ output("create:" + e.FullPath);
+ }
+
+ ///
+ /// 当指定目录的文件或者目录发生改变的时候的监听事件
+ ///
+ ///
+ ///
+ private void watch_changed(object sender, FileSystemEventArgs e)
+ {
+ //事件内容
+ bool result = false;
+ output("change:" + e.FullPath);
+ if (e.Name.ToLower().Contains("setting.xml"))
+ {
+
+ }
+ }
+ ///
+ /// 当删除目录的文件或者目录的时候的监听事件
+ ///
+ ///
+ ///
+ private void watch_deleted(object sender, FileSystemEventArgs e)
+ {
+ //事件内容
+ output("del:" + e.FullPath);
+ }
+
+ ///
+ /// 当指定目录的文件或者目录发生重命名的时候的事件
+ ///
+ ///
+ ///
+ private void watch_renamed(object sender, RenamedEventArgs e)
+ {
+ //事件内容
+ output("rename:" + e.FullPath);
+ }
+ ///
+ /// 启动或者停止监听
+ ///
+ /// True:启用监听,False:关闭监听
+ private void WatchStartOrSopt(bool IsEnableRaising)
+ {
+ watcher.EnableRaisingEvents = IsEnableRaising;
+ }
+
+
+ private void output(string text)
+ {
+ //FileStream fs = new FileStream("D:\\listen.txt", FileMode.Append);
+ //StreamWriter sw = new StreamWriter(fs, Encoding.Default);
+ //sw.WriteLine(text);
+ //sw.Close();
+ //fs.Close();
+ //files.Add(text);
+ eventCount++;
+ }
+
+ public void button1_Click()
+ {
+ string name = count.ToString() + "_" + eventCount.ToString();
+ FileStream fs = new FileStream("D:\\test\\listen_" + name + ".txt", FileMode.Append);
+ StreamWriter sw = new StreamWriter(fs, Encoding.Default);
+ //foreach (string text in files)
+ //{
+ // sw.WriteLine(text);
+ //}
+ sw.WriteLine("共收到事件:" + eventCount.ToString());
+ //files.Clear();
+ eventCount = 0;
+ sw.Close();
+ fs.Close();
+ count++;
+ // MessageBox.Show("打印完成:" + name, "提示", MessageBoxButtons.OK);
+ }
+
+ public void WatchStop()
+ {
+ WatchStartOrSopt(false);
+ }
+
+ public void WatchStart()
+ {
+ WatchStartOrSopt(true);
+ }
+ }
+}
diff --git a/Txgy.FilesWatcher/WebsocketClient.cs b/Txgy.FilesWatcher/WebsocketClient.cs
new file mode 100644
index 0000000..a96cedc
--- /dev/null
+++ b/Txgy.FilesWatcher/WebsocketClient.cs
@@ -0,0 +1,64 @@
+using SuperSocket.ClientEngine;
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Linq;
+using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
+using WebSocket4Net;
+
+namespace Txgy.FilesWatcher
+{
+ public class WebsocketClient
+ {
+ public WebSocket webSocket4Net = null;
+ public void WebSocketInit()
+ {
+ Console.WriteLine("客户端");
+ webSocket4Net = new WebSocket("ws://localhost:5000/ws");
+ webSocket4Net.Opened += WebSocket4Net_Opened;
+ webSocket4Net.Error += new EventHandler(WebSocket_Error);
+ webSocket4Net.MessageReceived += WebSocket4Net_MessageReceived;
+ webSocket4Net.Open();
+ Console.WriteLine("客户端连接成功!");
+ Thread thread = new Thread(ClientSendMsgToServer);
+ thread.IsBackground = true;
+ thread.Start();
+ // webSocket4Net.Dispose();
+ }
+
+ public void ClientSendMsgToServer()
+ {
+ int i = 88;
+ while (true)
+ {
+ //Console.WriteLine($"客户端发送数据{i++}");
+ Thread.Sleep(TimeSpan.FromSeconds(2));
+ if (webSocket4Net.State == WebSocketState.Open)
+ {
+ webSocket4Net.Send("{\"type\":\"heartbeat\",\"utype\":\"device\",\"uid\":123}");
+ }
+ else if (webSocket4Net.State == WebSocketState.Closed)
+ {
+ Thread.Sleep(TimeSpan.FromSeconds(5));
+ webSocket4Net.Open();
+ }
+ }
+ }
+
+ private void WebSocket4Net_MessageReceived(object sender, MessageReceivedEventArgs e)
+ {
+ Debug.WriteLine($"服务端回复数据:{e.Message}!");
+ }
+
+ private void WebSocket4Net_Opened(object sender, EventArgs e)
+ {
+ // webSocket4Net.Send($"客户端准备发送数据!");
+ }
+ void WebSocket_Error(object sender, ErrorEventArgs e)
+ {
+ Debug.WriteLine("websocket_Error:" + e.Exception.ToString());
+ }
+ }
+}