修改测试

master
mzhifa 2 years ago
parent d6721a7ca6
commit 345b4d970b

@ -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<WatcherFileModel> dataList = new ObservableCollection<WatcherFileModel>();
public ObservableCollection<WatcherFileModel> 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);
}));
}

@ -24,6 +24,7 @@
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="100"/>
<RowDefinition Height="30"/>
<RowDefinition Height="50"/>
<RowDefinition Height="30"/>
@ -32,21 +33,37 @@
<RowDefinition Height="30*"/>
<RowDefinition Height="30"/>
</Grid.RowDefinitions>
<RadioButton GroupName="start" Content="启动" Grid.Column="0" VerticalAlignment="Center">
<Grid Grid.Row="0" Grid.ColumnSpan="2">
<Grid.RowDefinitions>
<RowDefinition Height="30"/>
<RowDefinition Height="30"/>
<RowDefinition Height="10*"/>
</Grid.RowDefinitions>
<DockPanel Grid.Row="0" >
<TextBlock Text="用户名:" VerticalAlignment="Center"/>
<TextBox Text="{Binding Account}" DockPanel.Dock="Right"/>
</DockPanel>
<DockPanel Grid.Row="1" >
<TextBlock Text="密 码:" VerticalAlignment="Center"/>
<hc:PasswordBox UnsafePassword="{Binding Password,UpdateSourceTrigger=PropertyChanged}" IsSafeEnabled="False" ShowClearButton="True" ShowEyeButton="True" DockPanel.Dock="Right"/>
</DockPanel>
<Button Grid.Row="2" Content="登录" Command="{Binding LoginCommand}"/>
</Grid>
<RadioButton GroupName="start" Content="启动" Grid.Row="1" Grid.Column="0" VerticalAlignment="Center">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Checked">
<i:InvokeCommandAction Command="{Binding StartCommand}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</RadioButton>
<RadioButton GroupName="start" Content="关闭" IsChecked="True" Grid.Column="1" VerticalAlignment="Center">
<RadioButton GroupName="start" Content="关闭" IsChecked="True" Grid.Row="1" Grid.Column="1" VerticalAlignment="Center">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Checked">
<i:InvokeCommandAction Command="{Binding StopCommand}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</RadioButton>
<Grid Grid.Row="1" Grid.ColumnSpan="2">
<Grid Grid.Row="2" Grid.ColumnSpan="2">
<Grid.RowDefinitions>
<RowDefinition Height="1*"/>
<RowDefinition Height="1.5*"/>
@ -58,11 +75,11 @@
</DockPanel>
</Grid>
<TextBlock Grid.Row="2" VerticalAlignment="Center" Grid.ColumnSpan="3">
<TextBlock Grid.Row="3" VerticalAlignment="Center" Grid.ColumnSpan="3">
<Run Text="启动时间:"/>
<Run Text="{Binding StartTime,StringFormat=yyyy-MM-dd HH:mm:ss}"/>
</TextBlock>
<TextBlock Grid.Row="3" Grid.ColumnSpan="2" VerticalAlignment="Center">
<TextBlock Grid.Row="4" Grid.ColumnSpan="2" VerticalAlignment="Center">
<Run Text="运行时间:"/>
<Run Text="{Binding RunTime, StringFormat=yyyy-MM-dd HH:mm:ss}"/>
</TextBlock>
@ -70,7 +87,7 @@
<ComboBox DockPanel.Dock="Right" ItemsSource="{Binding IntervalTimesSource}" SelectedIndex="{Binding selectedIndex}" Text="{Binding ProMonInterval}" VerticalAlignment="Center"/>
<TextBlock Text="监隔间隔(s):" DockPanel.Dock="Right" VerticalAlignment="Center"/>
</DockPanel>-->
<ProgressBar Grid.Row="6" Grid.ColumnSpan="3" VerticalAlignment="Bottom" IsIndeterminate="{Binding IsIndeterminate}" Foreground="Green" Value="0"/>
<ProgressBar Grid.Row="7" Grid.ColumnSpan="3" VerticalAlignment="Bottom" IsIndeterminate="{Binding IsIndeterminate}" Foreground="Green" Value="0"/>
</Grid>
</GroupBox>
<ListView x:Name="listView" ItemsSource="{Binding DataList}" Grid.Column="1">

@ -4,8 +4,10 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using Txgy.FilesWatcher.model;
using WebSocket4Net;
namespace Txgy.FilesWatcher
@ -24,11 +26,18 @@ namespace Txgy.FilesWatcher
webSocket4Net.Error += new EventHandler<ErrorEventArgs>(WebSocket_Error);
webSocket4Net.MessageReceived += WebSocket4Net_MessageReceived;
webSocket4Net.Open();
Debug.WriteLine("客户端连接成功!");
Thread thread = new Thread(SendHeartbeat);
thread.IsBackground = true;
thread.Start();
}
public void SiginServer(string account,string password)
{
string jsonstr= JsonSerializer.Serialize(new CSUserSigin { type = CSMessage.sigin, utpye = "device", account=account,password=password});
SendMes(jsonstr);
}
public void SendMes(string message)
{
@ -37,7 +46,6 @@ namespace Txgy.FilesWatcher
private void SendHeartbeat()
{
int i = 88;
while (true)
{
//Console.WriteLine($"客户端发送数据{i++}");

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Txgy.FilesWatcher.model
{
class CSMessage
{
public const string heartbeat = "heartbeat";
public const string sigin = "sigin";
public const string offer = "offer";
public const string subscribe = "subscribe";
public const string unsubscribe = "unsubscribe";
public const string publish = "publish";
public const string close = "close";
public const string kickoff = "kickoff";
}
}

@ -0,0 +1,57 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Txgy.FilesWatcher.model
{
public class CSUserSigin
{
public string type { get; set; }
public string utpye { get; set; }
/// <summary>
/// 用户id
/// </summary>
public int uid { get; set; }
/// <summary>
/// 用户的key
/// </summary>
public string key { get; set; }
public string account { get; set; }
public string password { get; set; }
}
public class SCUserSigin
{
public string type { get; set; }
public string message { get; set; }
public int uid { get; set; }
public string code { get; set; }
}
public class CSUserSubscribeMessage
{
public string type { get; set; }
public string message { get; set; }
public int uid { get; set; }
}
public class SCUserSubscribeMessage
{
public string type { get; set; }
public string code { get; set; }
public int uid { get; set; }
}
public class CSDevicePublish
{
public string type { get; set; }
public string message { get; set; }
public int uid { get; set; }
}
public class SCDevicePublish
{
public string type { get; set; }
public string code { get; set; }
public string message { get; set; }
}
}

@ -1,4 +1,4 @@
{
"Url": "ws://localhost:5000/ws",
"Url": "ws://43.138.12.228:80/ws",
"FilePath": "F:\\SourceTest\\Txgy.FilesWatcher"
}

@ -0,0 +1,25 @@
C2S
{"type":"sigin","utype":"device","uid":123}
{"type":"sigin","code":"OK","uid":123}
C2S
{"type":"sigin","utype":"user","uid":123}
{"type":"sigin","code":"OK","uid":123}
C2S
{"type":"subscribe","message":"mes","uid":123}
{"type":"subscribe","code":"OK","uid":123}
C2S
{"type":"unsubscribe","message":"mes","uid":123}
{"type":"unsubscribe","code":"OK","uid":123}
S2C
{"type":"publish","message":"DAFSDFSADfsaSFASdf","code":"OK"}
S2C
{"type":"sigin","code":"OK","uid":"123"}
C2S
{"type":"heartbeat","utype":"device","uid":123}
C2S
{"type":"close","utype":"device","uid":123}
Loading…
Cancel
Save