From ad7e868748c7a9c359edb01c7a2fc5d77697d145 Mon Sep 17 00:00:00 2001 From: Dynesshely Date: Fri, 24 Mar 2023 12:41:06 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=BE=20Feat(DevicePage,=20WebManager):?= =?UTF-8?q?=20=E7=8E=B0=E5=9C=A8=E5=8F=AF=E4=BB=A5=E5=9C=A8=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E7=AE=A1=E7=90=86=E7=95=8C=E9=9D=A2=E7=9B=B4=E6=8E=A5?= =?UTF-8?q?=E5=81=9C=E6=AD=A2=E8=AE=BE=E5=A4=87=E6=9C=8D=E5=8A=A1=E5=99=A8?= =?UTF-8?q?=E6=88=96=E8=80=85=E9=87=8D=E5=90=AF=E8=AE=BE=E5=A4=87=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E5=99=A8.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Managers/WebManager.cs | 23 +++++++++++++--- ViewModels/Pages/DevicePageViewModel.cs | 36 ++++++++++++++++++++++--- Views/Pages/DevicePage.axaml | 18 +++++++++++++ 3 files changed, 71 insertions(+), 6 deletions(-) diff --git a/Managers/WebManager.cs b/Managers/WebManager.cs index 530f01f8..2583ccc2 100644 --- a/Managers/WebManager.cs +++ b/Managers/WebManager.cs @@ -3,6 +3,7 @@ using System; using System.Collections.ObjectModel; using System.Threading; +using System.Threading.Tasks; namespace KitX_Dashboard.Managers; @@ -21,6 +22,8 @@ public WebManager() /// /// 开始执行网络相关服务 /// + /// 是否启动插件服务器 + /// 是否启动设备服务器 /// 网络管理器本身 public WebManager Start(bool startPluginsServer = true, bool startDevicesServer = true) { @@ -61,6 +64,8 @@ public WebManager Start(bool startPluginsServer = true, bool startDevicesServer /// /// 停止执行网络相关服务 /// + /// 是否停止插件服务器 + /// 是否停止设备服务器 /// 网络管理器本身 public WebManager Stop(bool stopPluginsServer = true, bool stopDevicesServer = true) { @@ -82,11 +87,23 @@ public WebManager Stop(bool stopPluginsServer = true, bool stopDevicesServer = t /// /// 重启网络相关服务 /// + /// 是否重启插件服务器 + /// 是否重启设备服务器 + /// 重新启动前要执行的操作 /// 网络管理器本身 - public WebManager Restart() + public WebManager Restart(bool restartPluginsServer = true, bool restartDevicesServer = true, + Action? actionBeforeStarting = null) { - Stop(); - Start(); + Stop(stopPluginsServer: restartPluginsServer, stopDevicesServer: restartDevicesServer); + + Task.Run(async () => + { + await Task.Delay(Program.Config.Web.UDPSendFrequency + 100); + + actionBeforeStarting?.Invoke(); + + Start(startPluginsServer: restartPluginsServer, startDevicesServer: restartDevicesServer); + }); return this; } diff --git a/ViewModels/Pages/DevicePageViewModel.cs b/ViewModels/Pages/DevicePageViewModel.cs index 6775a6a2..2b8ba55b 100644 --- a/ViewModels/Pages/DevicePageViewModel.cs +++ b/ViewModels/Pages/DevicePageViewModel.cs @@ -1,6 +1,8 @@ -using KitX_Dashboard.Views.Pages.Controls; +using KitX_Dashboard.Commands; +using KitX_Dashboard.Views.Pages.Controls; using System.Collections.ObjectModel; using System.ComponentModel; +using System.Threading.Tasks; namespace KitX_Dashboard.ViewModels.Pages; @@ -13,6 +15,9 @@ public DevicePageViewModel() NoDevice_TipHeight = DeviceCards.Count == 0 ? 300 : 0; DevicesCount = DeviceCards.Count.ToString(); }; + + RestartDevicesServerCommand = new(RestartDevicvesServer); + StopDevicesServerCommand = new(StopDevicvesServer); } internal string? SearchingText { get; set; } @@ -25,7 +30,8 @@ internal string DevicesCount set { devicesCount = value; - PropertyChanged?.Invoke(this, new(nameof(DevicesCount))); + PropertyChanged?.Invoke(this, + new(nameof(DevicesCount))); } } @@ -37,10 +43,34 @@ internal double NoDevice_TipHeight set { noDevice_TipHeight = value; - PropertyChanged?.Invoke(this, new(nameof(NoDevice_TipHeight))); + PropertyChanged?.Invoke(this, + new(nameof(NoDevice_TipHeight))); } } + internal DelegateCommand? RestartDevicesServerCommand { get; set; } + + internal DelegateCommand? StopDevicesServerCommand { get; set; } + + internal static void RestartDevicvesServer(object _) + { + Program.WebManager?.Restart( + restartPluginsServer: false, + actionBeforeStarting: () => DeviceCards.Clear() + ); + } + + internal static void StopDevicvesServer(object _) + { + Program.WebManager?.Stop(stopPluginsServer: false); + + Task.Run(async () => + { + await Task.Delay(Program.Config.Web.UDPSendFrequency + 200); + DeviceCards.Clear(); + }); + } + internal static ObservableCollection DeviceCards => Program.DeviceCards; public new event PropertyChangedEventHandler? PropertyChanged; diff --git a/Views/Pages/DevicePage.axaml b/Views/Pages/DevicePage.axaml index 543c067e..6d52a5bc 100644 --- a/Views/Pages/DevicePage.axaml +++ b/Views/Pages/DevicePage.axaml @@ -35,6 +35,24 @@ Classes="Font" Text="{DynamicResource Text_Device_Tip_Detected}"/> + + + + + + +