temp
This commit is contained in:
parent
0a437ecec2
commit
9528b1f636
|
@ -2,6 +2,7 @@
|
|||
{
|
||||
internal class Config
|
||||
{
|
||||
public int mode = 0;
|
||||
public string sn = "";
|
||||
public string disk0 = "";
|
||||
public string disk1 = "";
|
||||
|
|
|
@ -6,25 +6,32 @@
|
|||
xmlns:local="clr-namespace:Topuino_Client_Windows"
|
||||
mc:Ignorable="d"
|
||||
Closing="Window_Closing"
|
||||
Title="Topuino 客户端" Height="150" Width="400">
|
||||
Title="Topuino 客户端" Height="180" Width="400">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
<StackPanel Grid.Row="0" Orientation="Horizontal" HorizontalAlignment="Left" Margin="5">
|
||||
<StackPanel Grid.Row="0" Orientation="Horizontal" Margin="5">
|
||||
<Label Content="运行模式:" VerticalAlignment="Center" />
|
||||
<RadioButton x:Name="RadioButton_UsbMode" VerticalAlignment="Center" Margin="5,0" IsChecked="True">USB 模式</RadioButton>
|
||||
<RadioButton x:Name="RadioButton_OnlineMode" VerticalAlignment="Center" Margin="5,0">在线模式</RadioButton>
|
||||
<RadioButton x:Name="RadioButton_LocalMode" VerticalAlignment="Center" Margin="5,0">本地模式</RadioButton>
|
||||
</StackPanel>
|
||||
<StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Left" Margin="5">
|
||||
<TextBlock Text="设备 SN:" VerticalAlignment="Center"/>
|
||||
<TextBox x:Name="TextBox_DeviceSn" Width="80" VerticalAlignment="Center" />
|
||||
</StackPanel>
|
||||
<StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Left" Margin="5">
|
||||
<StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Left" Margin="5">
|
||||
<TextBlock Text="0 号磁盘:" VerticalAlignment="Center"/>
|
||||
<ComboBox x:Name="ComboBox_Disk0" Height="20" Width="60" VerticalAlignment="Center"/>
|
||||
<Separator Width="10" Background="Transparent" />
|
||||
<TextBlock Text="1 号磁盘:" VerticalAlignment="Center"/>
|
||||
<ComboBox x:Name="ComboBox_Disk1" Height="20" Width="60" VerticalAlignment="Center"/>
|
||||
</StackPanel>
|
||||
<StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Right" Margin="5">
|
||||
<StackPanel Grid.Row="3" Orientation="Horizontal" HorizontalAlignment="Right" Margin="5">
|
||||
<Button Content="保存" Click="Button_Save_Click" Height="20" Width="40" />
|
||||
<Separator Width="10" Background="Transparent" />
|
||||
<Button Content="隐藏" Click="Button_Hide_Click" Height="20" Width="40" />
|
||||
|
|
|
@ -56,38 +56,72 @@ namespace Topuino_Client_Windows
|
|||
|
||||
private NotifyIcon trayIon = new NotifyIcon();
|
||||
|
||||
private int mode = 0;
|
||||
private string sn = "";
|
||||
private List<DriveInfo> allDrives;
|
||||
private DriveInfo? drive0 = null;
|
||||
private DriveInfo? drive1 = null;
|
||||
|
||||
private Config? initConfig = null;
|
||||
|
||||
private Thread? refreshThread = null;
|
||||
|
||||
private ManualResetEvent requestStop = new ManualResetEvent(false);
|
||||
private ManualResetEvent stopDone = new ManualResetEvent(false);
|
||||
|
||||
private PublicComm onlineClient = new PublicComm();
|
||||
private UsbComm usbClient = new UsbComm();
|
||||
|
||||
private void LoadConfig()
|
||||
{
|
||||
try
|
||||
{
|
||||
initConfig = JsonConvert.DeserializeObject<Config>(File.ReadAllText("Config.json"));
|
||||
Config? initConfig = JsonConvert.DeserializeObject<Config>(File.ReadAllText("Config.json"));
|
||||
if (initConfig == null)
|
||||
{
|
||||
throw new Exception();
|
||||
}
|
||||
|
||||
switch (initConfig.mode)
|
||||
{
|
||||
case 0:
|
||||
RadioButton_UsbMode.IsChecked = true;
|
||||
mode = 0;
|
||||
break;
|
||||
case 1:
|
||||
RadioButton_OnlineMode.IsChecked = true;
|
||||
mode = 1;
|
||||
break;
|
||||
case 2:
|
||||
RadioButton_LocalMode.IsChecked = true;
|
||||
mode = 2;
|
||||
break;
|
||||
default:
|
||||
RadioButton_UsbMode.IsChecked = true;
|
||||
mode = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
// check if drivers missing
|
||||
bool disk0Found = false;
|
||||
bool disk1Fount = false;
|
||||
foreach (DriveInfo drive in allDrives)
|
||||
{
|
||||
if (drive.Name != initConfig.disk0 && drive.Name != initConfig.disk1)
|
||||
if (drive.Name == initConfig.disk0)
|
||||
{
|
||||
initConfig.disk0 = drive.Name;
|
||||
initConfig.disk1 = drive.Name;
|
||||
break;
|
||||
disk0Found = true;
|
||||
}
|
||||
if (drive.Name == initConfig.disk1)
|
||||
{
|
||||
disk1Fount = true;
|
||||
}
|
||||
}
|
||||
if (!disk0Found)
|
||||
{
|
||||
initConfig.disk0 = allDrives[0].Name;
|
||||
}
|
||||
if (!disk1Fount)
|
||||
{
|
||||
initConfig.disk1 = allDrives[0].Name;
|
||||
}
|
||||
|
||||
for (int i = 0; i < allDrives.Count; i++)
|
||||
{
|
||||
|
@ -149,25 +183,62 @@ namespace Topuino_Client_Windows
|
|||
}
|
||||
|
||||
#pragma warning disable CS8602 // Dereference of a possibly null reference.
|
||||
Dictionary<string, string> statusInfo = new Dictionary<string, string>();
|
||||
statusInfo.Add("SN", sn);
|
||||
statusInfo.Add("CPU_PERCENT", ((int)cpuCounter.NextValue()).ToString());
|
||||
statusInfo.Add("MEM_PERCENT", ((int)ramPercentUsed).ToString());
|
||||
statusInfo.Add("DISK_PERCENT", ((int)((double)(drive0.TotalSize - drive0.AvailableFreeSpace) / drive0.TotalSize * 100)).ToString());
|
||||
statusInfo.Add("DISK1_PERCENT", ((int)((double)(drive1.TotalSize - drive1.AvailableFreeSpace) / drive1.TotalSize * 100)).ToString());
|
||||
statusInfo.Add("DISK_READ_RATE", ((int)diskReadCounter.NextValue()).ToString());
|
||||
statusInfo.Add("DISK_WRITE_RATE", ((int)diskWriteCounter.NextValue()).ToString());
|
||||
statusInfo.Add("NET_SENT_RATE", ((int)(netBytesSentAfter - netBytesSentBefore)).ToString());
|
||||
statusInfo.Add("NET_RECV_RATE", ((int)(netBytesSentAfter - netBytesSentBefore)).ToString());
|
||||
MonitorData data = new MonitorData
|
||||
{
|
||||
sn = sn,
|
||||
cpuPercent = (byte)cpuCounter.NextValue(),
|
||||
memPercent = (byte)ramPercentUsed,
|
||||
disk0Percent = (byte)((double)(drive0.TotalSize - drive0.AvailableFreeSpace) / drive0.TotalSize * 100),
|
||||
disk1Percent = (byte)((double)(drive1.TotalSize - drive1.AvailableFreeSpace) / drive1.TotalSize * 100),
|
||||
diskReadRate = (uint)diskReadCounter.NextValue(),
|
||||
diskWriteRate = (uint)diskWriteCounter.NextValue(),
|
||||
netSentRate = (uint)(netBytesSentAfter - netBytesSentBefore),
|
||||
netRecvRate = (uint)(netBytesReceiveAfter - netBytesReceiveBefore),
|
||||
};
|
||||
#pragma warning restore CS8602 // Dereference of a possibly null reference.
|
||||
|
||||
PublicComm connection = new PublicComm();
|
||||
connection.Post(statusInfo);
|
||||
}
|
||||
|
||||
stopDone.Set();
|
||||
}
|
||||
|
||||
private struct MonitorData
|
||||
{
|
||||
public string sn;
|
||||
public byte cpuPercent;
|
||||
public byte memPercent;
|
||||
public byte disk0Percent;
|
||||
public byte disk1Percent;
|
||||
public uint diskReadRate;
|
||||
public uint diskWriteRate;
|
||||
public uint netSentRate;
|
||||
public uint netRecvRate;
|
||||
}
|
||||
|
||||
private void UsbRun(MonitorData data)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void OnlineRun(MonitorData data)
|
||||
{
|
||||
Dictionary<string, string> statusInfo = new Dictionary<string, string>();
|
||||
statusInfo.Add("SN", data.sn);
|
||||
statusInfo.Add("CPU_PERCENT", data.cpuPercent.ToString());
|
||||
statusInfo.Add("MEM_PERCENT", data.memPercent.ToString());
|
||||
statusInfo.Add("DISK_PERCENT", data.disk0Percent.ToString());
|
||||
statusInfo.Add("DISK1_PERCENT", data.disk1Percent.ToString());
|
||||
statusInfo.Add("DISK_READ_RATE", data.diskReadRate.ToString());
|
||||
statusInfo.Add("DISK_WRITE_RATE", data.diskWriteRate.ToString());
|
||||
statusInfo.Add("NET_SENT_RATE", data.netSentRate.ToString());
|
||||
statusInfo.Add("NET_RECV_RATE", data.netRecvRate.ToString());
|
||||
}
|
||||
|
||||
private void OfflineRun(MonitorData data)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void ShowErrorBox(string msg)
|
||||
{
|
||||
System.Windows.MessageBox.Show(
|
||||
|
@ -202,6 +273,7 @@ namespace Topuino_Client_Windows
|
|||
if (!drive0.IsReady || !drive1.IsReady)
|
||||
{
|
||||
ShowErrorBox("磁盘未就绪");
|
||||
Mouse.OverrideCursor = null;
|
||||
return;
|
||||
}
|
||||
#pragma warning restore CS8602 // Dereference of a possibly null reference.
|
||||
|
@ -215,6 +287,29 @@ namespace Topuino_Client_Windows
|
|||
private async void SaveConfig()
|
||||
{
|
||||
Config newConfig = new Config();
|
||||
newConfig.mode = 0;
|
||||
|
||||
if (RadioButton_UsbMode.IsChecked != null)
|
||||
{
|
||||
if ((bool)RadioButton_UsbMode.IsChecked)
|
||||
{
|
||||
newConfig.mode = 0;
|
||||
}
|
||||
}
|
||||
if (RadioButton_OnlineMode.IsChecked != null)
|
||||
{
|
||||
if ((bool)RadioButton_OnlineMode.IsChecked)
|
||||
{
|
||||
newConfig.mode = 1;
|
||||
}
|
||||
}
|
||||
if (RadioButton_LocalMode.IsChecked != null)
|
||||
{
|
||||
if ((bool)RadioButton_LocalMode.IsChecked)
|
||||
{
|
||||
newConfig.mode = 2;
|
||||
}
|
||||
}
|
||||
newConfig.sn = sn;
|
||||
#pragma warning disable CS8602 // Dereference of a possibly null reference.
|
||||
newConfig.disk0 = drive0.Name;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
{
|
||||
"mode": 0,
|
||||
"sn": "V0000T0000",
|
||||
"disk0": "C:\\",
|
||||
"disk1": "C:\\"
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Topuino_Client_Windows
|
||||
{
|
||||
internal class UsbComm
|
||||
{
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue