Skip to content

Commit

Permalink
💾 Feat(DevicePage, WebManager): 现在可以在设备管理界面直接停止设备服务器或者重启设备服务器.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dynesshely committed Mar 24, 2023
1 parent 738c00b commit ad7e868
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 6 deletions.
23 changes: 20 additions & 3 deletions Managers/WebManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System;
using System.Collections.ObjectModel;
using System.Threading;
using System.Threading.Tasks;

namespace KitX_Dashboard.Managers;

Expand All @@ -21,6 +22,8 @@ public WebManager()
/// <summary>
/// 开始执行网络相关服务
/// </summary>
/// <param name="startPluginsServer">是否启动插件服务器</param>
/// <param name="startDevicesServer">是否启动设备服务器</param>
/// <returns>网络管理器本身</returns>
public WebManager Start(bool startPluginsServer = true, bool startDevicesServer = true)
{
Expand Down Expand Up @@ -61,6 +64,8 @@ public WebManager Start(bool startPluginsServer = true, bool startDevicesServer
/// <summary>
/// 停止执行网络相关服务
/// </summary>
/// <param name="stopPluginsServer">是否停止插件服务器</param>
/// <param name="stopDevicesServer">是否停止设备服务器</param>
/// <returns>网络管理器本身</returns>
public WebManager Stop(bool stopPluginsServer = true, bool stopDevicesServer = true)
{
Expand All @@ -82,11 +87,23 @@ public WebManager Stop(bool stopPluginsServer = true, bool stopDevicesServer = t
/// <summary>
/// 重启网络相关服务
/// </summary>
/// <param name="restartPluginsServer">是否重启插件服务器</param>
/// <param name="restartDevicesServer">是否重启设备服务器</param>
/// <param name="actionBeforeStarting">重新启动前要执行的操作</param>
/// <returns>网络管理器本身</returns>
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;
}

Expand Down
36 changes: 33 additions & 3 deletions ViewModels/Pages/DevicePageViewModel.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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; }
Expand All @@ -25,7 +30,8 @@ internal string DevicesCount
set
{
devicesCount = value;
PropertyChanged?.Invoke(this, new(nameof(DevicesCount)));
PropertyChanged?.Invoke(this,
new(nameof(DevicesCount)));
}
}

Expand All @@ -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<DeviceCard> DeviceCards => Program.DeviceCards;

public new event PropertyChangedEventHandler? PropertyChanged;
Expand Down
18 changes: 18 additions & 0 deletions Views/Pages/DevicePage.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,24 @@
Classes="Font"
Text="{DynamicResource Text_Device_Tip_Detected}"/>
</StackPanel>

<StackPanel Margin="0,0,20,0"
HorizontalAlignment="Right"
VerticalAlignment="Center"
Orientation="Horizontal">

<Button Command="{Binding RestartDevicesServerCommand}">
<icon:MaterialIcon Width="20"
Height="20"
Kind="Refresh"/>
</Button>
<Button Margin="10,0" Command="{Binding StopDevicesServerCommand}">
<icon:MaterialIcon Width="20"
Height="20"
Kind="Stop"/>
</Button>

</StackPanel>
</Grid>
<DockPanel Margin="10">
<Border Height="{Binding NoDevice_TipHeight}" DockPanel.Dock="Top">
Expand Down

0 comments on commit ad7e868

Please sign in to comment.