1添加websocket通讯;

2增加配置文件设置Url;
3设置的目录不存在设置到根目录;
master
mzhifa 1 year ago
parent cea0140ba3
commit d6721a7ca6

@ -10,4 +10,9 @@
<PackageReference Include="Prism.DryIoc" Version="8.1.97" /> <PackageReference Include="Prism.DryIoc" Version="8.1.97" />
<PackageReference Include="WebSocket4Net" Version="0.15.2" /> <PackageReference Include="WebSocket4Net" Version="0.15.2" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<None Update="systemconfig.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project> </Project>

@ -3,7 +3,6 @@ using Prism.Commands;
using Prism.Mvvm; using Prism.Mvvm;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -11,32 +10,57 @@ using System.Windows.Controls;
using System.Windows; using System.Windows;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Windows.Threading; using System.Windows.Threading;
using Txgy.FilesWatcher.model;
using System.Text.Json.Serialization;
using System.Text.Json;
using System.Net.NetworkInformation;
using System.Threading;
using System.Net.WebSockets;
using System.Diagnostics;
using WebSocket4Net;
using System.IO;
using System.Text.Encodings.Web;
using System.Text.Unicode;
namespace Txgy.FilesWatcher.ViewModels namespace Txgy.FilesWatcher.ViewModels
{ {
internal class MainViewModel:BindableBase internal class MainViewModel:BindableBase
{ {
public MainViewModel() public MainViewModel(WebsocketClient websocketClient )
{ {
string filter = "*.txt";
WatcherPath = "E:\\mingzf\\txgy\\WatchChanged"; string str = File.ReadAllText("systemconfig.json");
InitializeParams(); systemConfig = JsonSerializer.Deserialize<SystemConfig>(str);
WatcherPath = systemConfig.FilePath;
InitializeParams(filter);
StartTime = DateTime.Now;
this._websocketClient = websocketClient;
_websocketClient.WebsocketError = WebSocket_Error;
_websocketClient.WebSocketMessageReceived = WebSocket4Net_MessageReceived;
_websocketClient.WebSocketInit(systemConfig.Url);
}
private void WebSocket4Net_MessageReceived(string message)
{
Debug.WriteLine($"服务端回复数据:{message}");
}
void WebSocket_Error(SuperSocket.ClientEngine.ErrorEventArgs e)
{
Debug.WriteLine("websocket_Error:" + e.Exception.ToString());
} }
private string watcherPath; private string watcherPath;
public string WatcherPath public string WatcherPath
{ {
get { return watcherPath; } get { return watcherPath; }
set { watcherPath = value; } set { SetProperty(ref watcherPath , value); }
} }
private List<string> dataList=new List<string>(); private ObservableCollection<WatcherFileModel> dataList = new ObservableCollection<WatcherFileModel>();
public List<string> DataList public ObservableCollection<WatcherFileModel> DataList
{ {
get { return dataList; } get { return dataList; }
set { dataList = value; } set { SetProperty(ref dataList , value); }
} }
private DateTime startTime; private DateTime startTime;
@ -63,7 +87,7 @@ namespace Txgy.FilesWatcher.ViewModels
get { return selectedIndex; } get { return selectedIndex; }
set { SetProperty(ref selectedIndex, value); } set { SetProperty(ref selectedIndex, value); }
} }
private int proMonInterval = 10; private int proMonInterval = 5;
public int ProMonInterval public int ProMonInterval
{ {
get => proMonInterval; get => proMonInterval;
@ -76,7 +100,8 @@ namespace Txgy.FilesWatcher.ViewModels
get { return isIndeterminate; } get { return isIndeterminate; }
set { SetProperty(ref isIndeterminate, value); } set { SetProperty(ref isIndeterminate, value); }
} }
public void InitializeParams()
public void InitializeParams(string fileFilter)
{ {
timer1.Interval = TimeSpan.FromSeconds(ProMonInterval); timer1.Interval = TimeSpan.FromSeconds(ProMonInterval);
IntervalTimesSource.Add(5); IntervalTimesSource.Add(5);
@ -86,7 +111,11 @@ namespace Txgy.FilesWatcher.ViewModels
IntervalTimesSource.Add(30); IntervalTimesSource.Add(30);
IntervalTimesSource.Add(60); IntervalTimesSource.Add(60);
SelectedIndex = 1; SelectedIndex = 1;
//如果设置的目录不存在设置到根目录
if(!File.Exists(WatcherPath))
{
WatcherPath = AppDomain.CurrentDomain.BaseDirectory;
}
watcher = new FileSystemWatcher(WatcherPath); watcher = new FileSystemWatcher(WatcherPath);
//初始化监听 //初始化监听
watcher.BeginInit(); watcher.BeginInit();
@ -109,11 +138,11 @@ namespace Txgy.FilesWatcher.ViewModels
watcher.Error += OnError; watcher.Error += OnError;
//设置监听文件类型 //设置监听文件类型
// watcher.Filter = "*.txt"; watcher.Filter =fileFilter;
//设置是否监听子目录 //设置是否监听子目录
watcher.IncludeSubdirectories = true; watcher.IncludeSubdirectories = true;
//设置是否启用监听 //设置是否启用监听
watcher.EnableRaisingEvents = false; // watcher.EnableRaisingEvents = false;
watcher.EndInit(); watcher.EndInit();
} }
@ -126,42 +155,98 @@ namespace Txgy.FilesWatcher.ViewModels
private void Start() private void Start()
{ {
WatchStartOrSopt(true); WatchStartOrSopt(true);
StartTime=DateTime.Now;
timer1.Interval = TimeSpan.FromSeconds(ProMonInterval);
timer1.Start();
timer1.Tick += timer1_Tick;
IsIndeterminate = true;
} }
private void Stop() private void Stop()
{ {
WatchStartOrSopt(false); WatchStartOrSopt(false);
timer1.Stop();
IsIndeterminate = false;
} }
public DelegateCommand FilePathSaveCommand => new(() => public DelegateCommand FilePathSaveCommand => new(() =>
{ {
System.Windows.Forms.FolderBrowserDialog fbd = new System.Windows.Forms.FolderBrowserDialog(); System.Windows.Forms.FolderBrowserDialog fbd = new System.Windows.Forms.FolderBrowserDialog();
fbd.SelectedPath = WatcherPath; fbd.SelectedPath = WatcherPath;
fbd.Description = "请选择文件路径";
fbd.ShowNewFolderButton = true; fbd.ShowNewFolderButton = true;
if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK) if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{ {
// MainModel.DataSavePath = fbd.SelectedPath; if (fbd.SelectedPath != WatcherPath)
//if (MainModel.DataSavePath != _systemConfig.vpnInfo.DataSavePath) {
//{ WatcherPath = fbd.SelectedPath;
// updateJson = true; systemConfig.FilePath = WatcherPath;
//} var options = new JsonSerializerOptions {
// 整齐打印
WriteIndented = true,
//重新编码,解决中文乱码问题
Encoder = JavaScriptEncoder.Create(UnicodeRanges.All)
};
string message = JsonSerializer.Serialize(systemConfig, options);
if (File.Exists(settingDataPath))
{
File.WriteAllText(settingDataPath, message);
}
}
} }
}); });
private string settingDataPath = "systemconfig.json";
private void timer1_Tick(object? sender, EventArgs e)
{
RunTime = DateDiff(DateTime.Now, StartTime);
}
private string DateDiff(DateTime DateTime1, DateTime DateTime2)
{
string dateDiff = null;
TimeSpan ts1 = new TimeSpan(DateTime1.Ticks);
TimeSpan ts2 = new
TimeSpan(DateTime2.Ticks);
TimeSpan ts = ts1.Subtract(ts2).Duration();
if (ts.Days > 0)
{
dateDiff += ts.Days.ToString() + "天";
}
if (ts.Hours > 0)
{
dateDiff += ts.Hours.ToString() + "小时";
}
if (ts.Minutes > 0)
{
dateDiff += ts.Minutes.ToString() + "分钟";
}
dateDiff += ts.Seconds.ToString() + "秒";
return dateDiff;
}
private void OnError(object sender, ErrorEventArgs e) private void OnError(object sender, ErrorEventArgs e)
{ {
} }
private void Watcher_Changed(object sender, FileSystemEventArgs e) private void Watcher_Changed(object sender, System.IO.FileSystemEventArgs e)
{ {
Application.Current.Dispatcher.BeginInvoke(new Action(() => { Application.Current.Dispatcher.BeginInvoke(new Action(() => {
DateTime dt = DateTime.Now; DateTime dt = DateTime.Now;
string tmp = dt.Hour.ToString() + "时" + dt.Minute.ToString() + "分" + dt.Second.ToString() + "秒" + dt.Millisecond.ToString() + "毫秒,目录发生变化\r\n"; string tmp = dt.Hour.ToString() + "时" + dt.Minute.ToString() + "分" + dt.Second.ToString() + "秒" + dt.Millisecond.ToString() + "毫秒,目录发生变化\r\n";
tmp += "改变类型 :" + e.ChangeType.ToString() + "\r\n"; ; string lastLine = File.ReadAllLines(e.FullPath).Last();
tmp += "文件全称:" + e.FullPath + "\r\n"; DataList.Add(new WatcherFileModel
DataList.Add(tmp); {
CreateTime = DateTime.Now.ToString(),
ChangeType = e.ChangeType,
Name = e.Name,
FullPath = e.FullPath,
Data = lastLine,
IsSend = false
}) ;
_websocketClient.SendMes(lastLine);
})); }));
} }
@ -173,7 +258,14 @@ namespace Txgy.FilesWatcher.ViewModels
string tmp = dt.Hour.ToString() + "时" + dt.Minute.ToString() + "分" + dt.Second.ToString() + "秒" + dt.Millisecond.ToString() + "毫秒,目录发生变化\r\n"; string tmp = dt.Hour.ToString() + "时" + dt.Minute.ToString() + "分" + dt.Second.ToString() + "秒" + dt.Millisecond.ToString() + "毫秒,目录发生变化\r\n";
tmp += "改变类型 :" + e.ChangeType.ToString() + "\r\n"; ; tmp += "改变类型 :" + e.ChangeType.ToString() + "\r\n"; ;
tmp += "文件全称:" + e.FullPath + "\r\n"; tmp += "文件全称:" + e.FullPath + "\r\n";
DataList.Add(tmp); DataList.Add(new WatcherFileModel
{
CreateTime = DateTime.Now.ToString(),
ChangeType = e.ChangeType,
Name = e.Name,
FullPath = e.FullPath,
Data = tmp
});
})); }));
} }
@ -185,7 +277,14 @@ namespace Txgy.FilesWatcher.ViewModels
string tmp = dt.Hour.ToString() + "时" + dt.Minute.ToString() + "分" + dt.Second.ToString() + "秒" + dt.Millisecond.ToString() + "毫秒,目录发生变化\r\n"; string tmp = dt.Hour.ToString() + "时" + dt.Minute.ToString() + "分" + dt.Second.ToString() + "秒" + dt.Millisecond.ToString() + "毫秒,目录发生变化\r\n";
tmp += "改变类型 :" + e.ChangeType.ToString() + "\r\n"; ; tmp += "改变类型 :" + e.ChangeType.ToString() + "\r\n"; ;
tmp += "文件全称:" + e.FullPath + "\r\n"; tmp += "文件全称:" + e.FullPath + "\r\n";
DataList.Add(tmp); DataList.Add(new WatcherFileModel
{
CreateTime = DateTime.Now.ToString(),
ChangeType = e.ChangeType,
Name = e.Name,
FullPath = e.FullPath,
Data = tmp
});
})); }));
} }
@ -197,7 +296,14 @@ namespace Txgy.FilesWatcher.ViewModels
string tmp = dt.Hour.ToString() + "时" + dt.Minute.ToString() + "分" + dt.Second.ToString() + "秒" + dt.Millisecond.ToString() + "毫秒,目录发生变化\r\n"; string tmp = dt.Hour.ToString() + "时" + dt.Minute.ToString() + "分" + dt.Second.ToString() + "秒" + dt.Millisecond.ToString() + "毫秒,目录发生变化\r\n";
tmp += "改变类型 :" + e.ChangeType.ToString() + "\r\n"; ; tmp += "改变类型 :" + e.ChangeType.ToString() + "\r\n"; ;
tmp += "文件全称:" + e.FullPath + "\r\n"; tmp += "文件全称:" + e.FullPath + "\r\n";
DataList.Add(tmp); DataList.Add(new WatcherFileModel
{
CreateTime= DateTime.Now.ToString(),
ChangeType=e.ChangeType,
Name=e.Name,
FullPath= e.FullPath,
Data=tmp
});
})); }));
} }
@ -212,5 +318,7 @@ namespace Txgy.FilesWatcher.ViewModels
private FileSystemWatcher watcher = new FileSystemWatcher(); private FileSystemWatcher watcher = new FileSystemWatcher();
private DispatcherTimer timer1 = new DispatcherTimer(); private DispatcherTimer timer1 = new DispatcherTimer();
private SystemConfig systemConfig = new SystemConfig();
private readonly WebsocketClient _websocketClient;
} }
} }

@ -5,6 +5,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Txgy.FilesWatcher.Views" xmlns:local="clr-namespace:Txgy.FilesWatcher.Views"
xmlns:i="http://schemas.microsoft.com/xaml/behaviors" xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
xmlns:hc="https://handyorg.github.io/handycontrol"
mc:Ignorable="d" mc:Ignorable="d"
xmlns:prism="http://prismlibrary.com/" xmlns:prism="http://prismlibrary.com/"
prism:ViewModelLocator.AutoWireViewModel="True" prism:ViewModelLocator.AutoWireViewModel="True"
@ -50,7 +51,7 @@
<RowDefinition Height="1*"/> <RowDefinition Height="1*"/>
<RowDefinition Height="1.5*"/> <RowDefinition Height="1.5*"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<TextBlock Text="存储路径:" Grid.Row="0" Grid.Column="0" /> <TextBlock Text="监控文件路径:" Grid.Row="0" Grid.Column="0" />
<DockPanel Grid.Row="1"> <DockPanel Grid.Row="1">
<Button Content="..." Command="{Binding FilePathSaveCommand}" DockPanel.Dock="Right" HorizontalAlignment="Right" Height="28" Width="30"/> <Button Content="..." Command="{Binding FilePathSaveCommand}" DockPanel.Dock="Right" HorizontalAlignment="Right" Height="28" Width="30"/>
<TextBox Text="{Binding WatcherPath}" IsReadOnly="True" DockPanel.Dock="Right" FontSize="10"/> <TextBox Text="{Binding WatcherPath}" IsReadOnly="True" DockPanel.Dock="Right" FontSize="10"/>
@ -65,36 +66,62 @@
<Run Text="运行时间:"/> <Run Text="运行时间:"/>
<Run Text="{Binding RunTime, StringFormat=yyyy-MM-dd HH:mm:ss}"/> <Run Text="{Binding RunTime, StringFormat=yyyy-MM-dd HH:mm:ss}"/>
</TextBlock> </TextBlock>
<DockPanel Grid.Row="4" Grid.ColumnSpan="2" > <!--<DockPanel Grid.Row="4" Grid.ColumnSpan="2" >
<ComboBox DockPanel.Dock="Right" ItemsSource="{Binding IntervalTimesSource}" SelectedIndex="{Binding selectedIndex}" Text="{Binding ProMonInterval}" VerticalAlignment="Center"/> <ComboBox DockPanel.Dock="Right" ItemsSource="{Binding IntervalTimesSource}" SelectedIndex="{Binding selectedIndex}" Text="{Binding ProMonInterval}" VerticalAlignment="Center"/>
<TextBlock Text="监隔间隔(s):" DockPanel.Dock="Right" VerticalAlignment="Center"/> <TextBlock Text="监隔间隔(s):" DockPanel.Dock="Right" VerticalAlignment="Center"/>
</DockPanel> </DockPanel>-->
<ProgressBar Grid.Row="6" Grid.ColumnSpan="3" VerticalAlignment="Bottom" IsIndeterminate="{Binding IsIndeterminate}" Foreground="Green" Value="0"/> <ProgressBar Grid.Row="6" Grid.ColumnSpan="3" VerticalAlignment="Bottom" IsIndeterminate="{Binding IsIndeterminate}" Foreground="Green" Value="0"/>
</Grid> </Grid>
</GroupBox> </GroupBox>
<ListView x:Name="listView" ItemsSource="{Binding DataList}" Grid.Column="1">
<ListBox x:Name="listView" ItemsSource="{Binding DataList}" Margin="5" Grid.Column="1"> <ListView.View>
<ListBox.ItemTemplate> <GridView>
<GridViewColumn Header="时间" DisplayMemberBinding="{Binding CreateTime, StringFormat=yyyy-MM-dd HH:mm:ss}" />
<GridViewColumn Header="内容" Width="300" >
<!--模板化单元格内容-->
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBox Foreground="CornflowerBlue" MinWidth="200" Cursor="Hand" Text="{Binding Data}" IsReadOnly="True" BorderBrush="Transparent" Background="Transparent"></TextBox>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="文件名" Width="80" DisplayMemberBinding="{Binding Name}" />
<GridViewColumn Header="修改类型" Width="80" DisplayMemberBinding="{Binding ChangeType}" />
<GridViewColumn Header="是否发送" >
<!--模板化单元格内容-->
<GridViewColumn.CellTemplate>
<DataTemplate>
<ToggleButton IsEnabled="False" IsChecked="{Binding IsSend}" HorizontalAlignment="Center" Margin="5,4" Style="{StaticResource ToggleButtonSwitch}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
<!--<ListView.ItemTemplate>
<DataTemplate> <DataTemplate>
<Border BorderBrush="#F7F9FA" BorderThickness="0,0,0,1" Background="Transparent"> <Border BorderBrush="#F7F9FA" BorderThickness="0,0,0,1" Background="Transparent">
<Grid Height="30" Background="Transparent" Name="root"> <Grid Height="30" Background="Transparent" Name="root">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="200"/> <ColumnDefinition Width="150"/>
<ColumnDefinition Width="60"/>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="60"/>
<ColumnDefinition Width="60"/> <ColumnDefinition Width="60"/>
<ColumnDefinition /> <ColumnDefinition />
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<TextBlock Text="{Binding CreateTime}" VerticalAlignment="Center" HorizontalAlignment="Center"/> <TextBlock Text="{Binding CreateTime, StringFormat=yyyy-MM-dd HH:mm:ss}" VerticalAlignment="Center" HorizontalAlignment="Center"/>
<TextBlock Text="{Binding UserName}" VerticalAlignment="Center" Grid.Column="1"/> <TextBlock Text="{Binding ChangeType}" VerticalAlignment="Center" Grid.Column="1"/>
<TextBlock Text="{Binding Message}" VerticalAlignment="Center" HorizontalAlignment="Center" Grid.Column="2"/> <TextBlock Text="{Binding Name}" VerticalAlignment="Center" HorizontalAlignment="Center" Grid.Column="2"/>
<TextBlock Text="{Binding Data}" VerticalAlignment="Center" HorizontalAlignment="Center" Grid.Column="3"/>
</Grid> </Grid>
</Border> </Border>
<DataTemplate.Triggers> --><!--<DataTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True"> <Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="root" Property="Background" Value="#F7F9FA"/> <Setter TargetName="root" Property="Background" Value="#F7F9FA"/>
</Trigger> </Trigger>
</DataTemplate.Triggers> </DataTemplate.Triggers>--><!--
</DataTemplate> </DataTemplate>
</ListBox.ItemTemplate> </ListView.ItemTemplate>-->
</ListBox> </ListView>
</Grid> </Grid>
</UserControl> </UserControl>

@ -3,7 +3,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:prism="http://prismlibrary.com/" xmlns:prism="http://prismlibrary.com/"
prism:ViewModelLocator.AutoWireViewModel="True" prism:ViewModelLocator.AutoWireViewModel="True"
Title="{Binding Title}" Height="500" Width="800" > Title="{Binding Title}" Height="500" Width="960" >
<Grid> <Grid>
<ContentControl prism:RegionManager.RegionName="MainContentRegion" /> <ContentControl prism:RegionManager.RegionName="MainContentRegion" />
</Grid> </Grid>

@ -13,35 +13,42 @@ namespace Txgy.FilesWatcher
public class WebsocketClient public class WebsocketClient
{ {
public WebSocket webSocket4Net = null; public WebSocket webSocket4Net = null;
public void WebSocketInit()
public Action<ErrorEventArgs> WebsocketError;
public Action<string> WebSocketMessageReceived;
public void WebSocketInit(string url)
{ {
Console.WriteLine("客户端"); Debug.WriteLine("客户端");
webSocket4Net = new WebSocket("ws://localhost:5000/ws"); webSocket4Net = new WebSocket(url);
webSocket4Net.Opened += WebSocket4Net_Opened; webSocket4Net.Opened += WebSocket4Net_Opened;
webSocket4Net.Error += new EventHandler<ErrorEventArgs>(WebSocket_Error); webSocket4Net.Error += new EventHandler<ErrorEventArgs>(WebSocket_Error);
webSocket4Net.MessageReceived += WebSocket4Net_MessageReceived; webSocket4Net.MessageReceived += WebSocket4Net_MessageReceived;
webSocket4Net.Open(); webSocket4Net.Open();
Console.WriteLine("客户端连接成功!"); Debug.WriteLine("客户端连接成功!");
Thread thread = new Thread(ClientSendMsgToServer); Thread thread = new Thread(SendHeartbeat);
thread.IsBackground = true; thread.IsBackground = true;
thread.Start(); thread.Start();
// webSocket4Net.Dispose();
} }
public void ClientSendMsgToServer() public void SendMes(string message)
{
webSocket4Net.Send(message);
}
private void SendHeartbeat()
{ {
int i = 88; int i = 88;
while (true) while (true)
{ {
//Console.WriteLine($"客户端发送数据{i++}"); //Console.WriteLine($"客户端发送数据{i++}");
Thread.Sleep(TimeSpan.FromSeconds(2)); Thread.Sleep(TimeSpan.FromSeconds(1));
if (webSocket4Net.State == WebSocketState.Open) if (webSocket4Net.State == WebSocketState.Open)
{ {
webSocket4Net.Send("{\"type\":\"heartbeat\",\"utype\":\"device\",\"uid\":123}"); webSocket4Net.Send("{\"type\":\"heartbeat\",\"utype\":\"device\",\"uid\":123}");
} }
else if (webSocket4Net.State == WebSocketState.Closed) else if (webSocket4Net.State == WebSocketState.Closed)
{ {
Thread.Sleep(TimeSpan.FromSeconds(5)); Thread.Sleep(TimeSpan.FromSeconds(10));
webSocket4Net.Open(); webSocket4Net.Open();
} }
} }
@ -49,15 +56,17 @@ namespace Txgy.FilesWatcher
private void WebSocket4Net_MessageReceived(object sender, MessageReceivedEventArgs e) private void WebSocket4Net_MessageReceived(object sender, MessageReceivedEventArgs e)
{ {
WebSocketMessageReceived?.Invoke(e.Message);
Debug.WriteLine($"服务端回复数据:{e.Message}"); Debug.WriteLine($"服务端回复数据:{e.Message}");
} }
private void WebSocket4Net_Opened(object sender, EventArgs e) private void WebSocket4Net_Opened(object sender, EventArgs e)
{ {
// webSocket4Net.Send($"客户端准备发送数据!");
} }
void WebSocket_Error(object sender, ErrorEventArgs e) void WebSocket_Error(object sender, ErrorEventArgs e)
{ {
WebsocketError?.Invoke(e);
Debug.WriteLine("websocket_Error:" + e.Exception.ToString()); Debug.WriteLine("websocket_Error:" + e.Exception.ToString());
} }
} }

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Txgy.FilesWatcher.model
{
public class SystemConfig
{
public string FilePath { get; set; }
public string Url { get; set; }
}
}

@ -0,0 +1,40 @@
using Prism.Mvvm;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Txgy.FilesWatcher.model
{
public class WatcherFileModel : BindableBase
{
private string createTime;
private WatcherChangeTypes changeType;
private string fullPath;
private string name;
private string data;
public string CreateTime
{
get { return createTime; }
set { SetProperty(ref createTime, value); }
}
public WatcherChangeTypes ChangeType { get => changeType; set => SetProperty(ref changeType, value); }
public string FullPath { get => fullPath; set => SetProperty(ref fullPath, value); }
public string Name { get => name; set => SetProperty(ref name, value); }
public string Data { get => data; set => SetProperty(ref data, value); }
private bool isSend;
public bool IsSend
{
get { return isSend; }
set { SetProperty(ref isSend, value); }
}
}
}

@ -0,0 +1,4 @@
{
"Url": "ws://localhost:5000/ws",
"FilePath": "F:\\SourceTest\\Txgy.FilesWatcher"
}
Loading…
Cancel
Save