mirror of
https://github.com/tribufu/ServerManagers
synced 2026-05-06 15:17:34 +00:00
Server Monitor Changes
- added Start, Stop, Restart, Update and Backup buttons and functionality.
This commit is contained in:
parent
9cf57736a4
commit
3f4cc944b7
10 changed files with 1445 additions and 23 deletions
|
|
@ -366,6 +366,7 @@
|
|||
<Resource Include="Art\StatusWarning.ico" />
|
||||
<Resource Include="Art\Collapse.ico" />
|
||||
<Resource Include="Art\Expand.ico" />
|
||||
<Resource Include="Art\Restart.ico" />
|
||||
<Content Include="GameData\Genesis2.gamedata">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
|
|
|
|||
BIN
src/ARKServerManager/Art/Restart.ico
Normal file
BIN
src/ARKServerManager/Art/Restart.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 100 KiB |
|
|
@ -440,6 +440,7 @@
|
|||
<!--#region Server Monitor Window -->
|
||||
<sys:String x:Key="ServerMonitor_Title">Server Monitor</sys:String>
|
||||
|
||||
<sys:String x:Key="ServerMonitor_SelectedColumnLabel">Selected</sys:String>
|
||||
<sys:String x:Key="ServerMonitor_TotalCountLabel">Total Servers:</sys:String>
|
||||
<sys:String x:Key="ServerMonitor_ServerColumnLabel">Server</sys:String>
|
||||
<sys:String x:Key="ServerMonitor_MapColumnLabel">Map</sys:String>
|
||||
|
|
@ -449,6 +450,13 @@
|
|||
<sys:String x:Key="ServerMonitor_StatusColumnLabel">Status</sys:String>
|
||||
|
||||
<sys:String x:Key="ServerMonitor_CreateShortcutButtonTooltip">Create a desktop shortcut to open this form directly.</sys:String>
|
||||
<sys:String x:Key="ServerMonitor_StartServersButtonTooltip">Start the selected servers.</sys:String>
|
||||
<sys:String x:Key="ServerMonitor_StopServersButtonTooltip">Stop the selected servers.</sys:String>
|
||||
<sys:String x:Key="ServerMonitor_RestartServersButtonTooltip">Restart the selected servers.</sys:String>
|
||||
<sys:String x:Key="ServerMonitor_UpdateServersButtonTooltip">Update the selected servers.</sys:String>
|
||||
<sys:String x:Key="ServerMonitor_BackupServersButtonTooltip">Backup the selected servers.</sys:String>
|
||||
<sys:String x:Key="ServerMonitor_SelectAllServersButtonTooltip">Select all servers.</sys:String>
|
||||
<sys:String x:Key="ServerMonitor_UnselectAllServersButtonTooltip">Unselect all servers.</sys:String>
|
||||
<sys:String x:Key="ServerMonitor_PlayerListButtonTooltip">Open the Player List window.</sys:String>
|
||||
<sys:String x:Key="ServerMonitor_RCONButtonTooltip">Open the RCON window.</sys:String>
|
||||
<sys:String x:Key="ServerMonitor_StartServerTooltip">Start the server.</sys:String>
|
||||
|
|
@ -459,7 +467,21 @@
|
|||
<sys:String x:Key="ServerMonitor_UpgradeServer_FailedTitle">Server Update Error</sys:String>
|
||||
<sys:String x:Key="ServerMonitor_UpgradeServer_FailedLabel">Another server is being upgraded, wait until the upgrade has finished and try again.</sys:String>
|
||||
<sys:String x:Key="ServerMonitor_CloseWindow_ConfirmTitle">Confirm Window Close</sys:String>
|
||||
<sys:String x:Key="ServerMonitor_CloseWindow_ConfirmLabel">You are currently perform a server update, closing the window with disconnect you from steamcmd. Do you want to continue closing the window?</sys:String>
|
||||
<sys:String x:Key="ServerMonitor_CloseWindow_ConfirmLabel">You are currently performing a server update, closing the window will disconnect you from steamcmd. Do you want to continue closing the window?</sys:String>
|
||||
<sys:String x:Key="ServerMonitor_StartServers_ConfirmTitle">Confirm Start Servers</sys:String>
|
||||
<sys:String x:Key="ServerMonitor_StartServers_ConfirmLabel">You are about to start the selected servers. Do you want to continue?</sys:String>
|
||||
<sys:String x:Key="ServerMonitor_StopServers_ConfirmTitle">Confirm Stop Servers</sys:String>
|
||||
<sys:String x:Key="ServerMonitor_StopServers_ConfirmLabel">You are about to stop the selected servers. Do you want to continue?</sys:String>
|
||||
<sys:String x:Key="ServerMonitor_RestartServers_ConfirmTitle">Confirm Restart Servers</sys:String>
|
||||
<sys:String x:Key="ServerMonitor_RestartServers_ConfirmLabel">You are about to restart the selected servers. Do you want to continue?</sys:String>
|
||||
<sys:String x:Key="ServerMonitor_UpdateServers_ConfirmTitle">Confirm Update Servers</sys:String>
|
||||
<sys:String x:Key="ServerMonitor_UpdateServers_ConfirmLabel">You are about to update the selected servers. Do you want to continue?</sys:String>
|
||||
<sys:String x:Key="ServerMonitor_BackupServers_ConfirmTitle">Confirm Backup Servers</sys:String>
|
||||
<sys:String x:Key="ServerMonitor_BackupServers_ConfirmLabel">You are about to backup the selected servers. Do you want to continue?</sys:String>
|
||||
<sys:String x:Key="ServerMonitor_NoServersSelected_ErrorTitle">Selected Servers Error</sys:String>
|
||||
<sys:String x:Key="ServerMonitor_NoServersSelected_ErrorLabel">You have not selected any servers. Selected one or more servers in the list and try again.</sys:String>
|
||||
<sys:String x:Key="ServerMonitor_RunningProcesses_ConfirmTitle">Close Server Monitor Error</sys:String>
|
||||
<sys:String x:Key="ServerMonitor_RunningProcesses_ConfirmLabel">The server monitor window cannot be closed at this time. One or more of the servers is currently starting, shutting down or restarting.</sys:String>
|
||||
<!--#endregion-->
|
||||
|
||||
<!--#region Shutdown Window -->
|
||||
|
|
|
|||
|
|
@ -4,6 +4,9 @@
|
|||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:tb="http://www.hardcodet.net/taskbar"
|
||||
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
|
||||
xmlns:sm="clr-namespace:ServerManagerTool"
|
||||
xmlns:smw="clr-namespace:ServerManagerTool.Windows"
|
||||
xmlns:clib="clr-namespace:ServerManagerTool.Common.Lib;assembly=ServerManager.Common"
|
||||
xmlns:com="clr-namespace:ServerManagerTool.Common;assembly=ServerManager.Common"
|
||||
xmlns:enum="clr-namespace:ServerManagerTool.Enums"
|
||||
|
|
@ -18,21 +21,31 @@
|
|||
<ResourceDictionary Source="..\Globalization\en-US\en-US.xaml"/>
|
||||
<ResourceDictionary Source="..\Styles\Default.xaml"/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
|
||||
|
||||
<sm:ScrollToBottomAction x:Key="ScrollToBottomAction" />
|
||||
<vm:MapNameValueConverter x:Key="MapNameValueConverter"/>
|
||||
</ResourceDictionary>
|
||||
</Window.Resources>
|
||||
|
||||
|
||||
<Grid Background="{StaticResource BeigeGradient}" MouseLeftButtonUp="OnMouseLeftButtonUp" MouseMove="OnMouseMove">
|
||||
<DockPanel x:Name="dockPanel">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="10*"/>
|
||||
<RowDefinition Height="*" MinHeight="200"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto" MinHeight="100"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="200*"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
|
@ -41,12 +54,95 @@
|
|||
<Image Source="{com:Icon Path=/Ark Server Manager;component/Art/Shortcut.ico,Size=32}"/>
|
||||
</Button>
|
||||
|
||||
<StackPanel Grid.Row="0" Grid.Column="1" Orientation="Horizontal">
|
||||
<Button Grid.Row="0" Grid.Column="1" Width="22" Height="22" Margin="10,5,5,0" HorizontalAlignment="Left" VerticalAlignment="Top" Click="StartServers_Click" ToolTip="{DynamicResource ServerMonitor_StartServersButtonTooltip}">
|
||||
<Button.Style>
|
||||
<Style TargetType="{x:Type Button}">
|
||||
<Setter Property="IsEnabled" Value="False"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding CancellationTokenSource}" Value="{x:Null}">
|
||||
<Setter Property="IsEnabled" Value="True"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</Button.Style>
|
||||
|
||||
<Image Source="{com:Icon Path=/Ark Server Manager;component/Art/Start.ico,Size=32}"/>
|
||||
</Button>
|
||||
|
||||
<Button Grid.Row="0" Grid.Column="2" Width="22" Height="22" Margin="0,5,5,0" HorizontalAlignment="Left" VerticalAlignment="Top" Click="StopServers_Click" ToolTip="{DynamicResource ServerMonitor_StopServersButtonTooltip}">
|
||||
<Button.Style>
|
||||
<Style TargetType="{x:Type Button}">
|
||||
<Setter Property="IsEnabled" Value="False"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding CancellationTokenSource}" Value="{x:Null}">
|
||||
<Setter Property="IsEnabled" Value="True"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</Button.Style>
|
||||
|
||||
<Image Source="{com:Icon Path=/Ark Server Manager;component/Art/Stop.ico,Size=32}"/>
|
||||
</Button>
|
||||
|
||||
<Button Grid.Row="0" Grid.Column="3" Width="22" Height="22" Margin="0,5,5,0" HorizontalAlignment="Left" VerticalAlignment="Top" Click="RestartServers_Click" ToolTip="{DynamicResource ServerMonitor_RestartServersButtonTooltip}">
|
||||
<Button.Style>
|
||||
<Style TargetType="{x:Type Button}">
|
||||
<Setter Property="IsEnabled" Value="False"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding CancellationTokenSource}" Value="{x:Null}">
|
||||
<Setter Property="IsEnabled" Value="True"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</Button.Style>
|
||||
|
||||
<Image Source="{com:Icon Path=/Ark Server Manager;component/Art/Restart.ico,Size=32}"/>
|
||||
</Button>
|
||||
|
||||
<Button Grid.Row="0" Grid.Column="4" Width="22" Height="22" Margin="0,5,5,0" HorizontalAlignment="Left" VerticalAlignment="Top" Click="UpdateServers_Click" ToolTip="{DynamicResource ServerMonitor_UpdateServersButtonTooltip}">
|
||||
<Button.Style>
|
||||
<Style TargetType="{x:Type Button}">
|
||||
<Setter Property="IsEnabled" Value="False"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding CancellationTokenSource}" Value="{x:Null}">
|
||||
<Setter Property="IsEnabled" Value="True"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</Button.Style>
|
||||
|
||||
<Image Source="{com:Icon Path=/Ark Server Manager;component/Art/Download.ico,Size=32}"/>
|
||||
</Button>
|
||||
|
||||
<Button Grid.Row="0" Grid.Column="5" Width="22" Height="22" Margin="0,5,5,0" HorizontalAlignment="Left" VerticalAlignment="Top" Click="BackupServers_Click" ToolTip="{DynamicResource ServerMonitor_BackupServersButtonTooltip}">
|
||||
<Button.Style>
|
||||
<Style TargetType="{x:Type Button}">
|
||||
<Setter Property="IsEnabled" Value="False"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding CancellationTokenSource}" Value="{x:Null}">
|
||||
<Setter Property="IsEnabled" Value="True"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</Button.Style>
|
||||
|
||||
<Image Source="{com:Icon Path=/Ark Server Manager;component/Art/Save.ico,Size=32}"/>
|
||||
</Button>
|
||||
|
||||
<Button Grid.Row="0" Grid.Column="6" Width="22" Height="22" Margin="10,5,5,0" HorizontalAlignment="Left" VerticalAlignment="Top" Click="SelectAllServers_Click" ToolTip="{DynamicResource ServerMonitor_SelectAllServersButtonTooltip}">
|
||||
<Image Source="{com:Icon Path=/Ark Server Manager;component/Art/Checked.ico,Size=32}"/>
|
||||
</Button>
|
||||
|
||||
<Button Grid.Row="0" Grid.Column="7" Width="22" Height="22" Margin="0,5,5,0" HorizontalAlignment="Left" VerticalAlignment="Top" Click="UnselectAllServers_Click" ToolTip="{DynamicResource ServerMonitor_UnselectAllServersButtonTooltip}">
|
||||
<Image Source="{com:Icon Path=/Ark Server Manager;component/Art/Unchecked.ico,Size=32}"/>
|
||||
</Button>
|
||||
|
||||
<StackPanel Grid.Row="0" Grid.Column="8" Orientation="Horizontal">
|
||||
<TextBlock Margin="30,5,5,0" Text="{DynamicResource ServerMonitor_TotalCountLabel}" VerticalAlignment="Center" />
|
||||
<TextBlock Margin="5,5,5,0" Text="{Binding ServerManager.Servers.Count}" VerticalAlignment="Center" />
|
||||
</StackPanel>
|
||||
|
||||
<Button Grid.Row="0" Grid.Column="2" Height="22" Margin="5,5,5,0" Background="#00AA00" Foreground="White" Padding="1" BorderThickness="1" BorderBrush="White" ContentStringFormat="{DynamicResource MainWindow_UpdateToLabelFormat}" Content="{Binding LatestServerManagerVersion}" Click="UpgradeApplication_Click" VerticalAlignment="Center" >
|
||||
<Button Grid.Row="0" Grid.Column="9" Height="22" Margin="5,5,5,0" Background="#00AA00" Foreground="White" Padding="1" BorderThickness="1" BorderBrush="White" ContentStringFormat="{DynamicResource MainWindow_UpdateToLabelFormat}" Content="{Binding LatestServerManagerVersion}" Click="UpgradeApplication_Click" VerticalAlignment="Center" >
|
||||
<Button.Style>
|
||||
<Style TargetType="{x:Type Button}">
|
||||
<Style.Triggers>
|
||||
|
|
@ -61,7 +157,7 @@
|
|||
</Button.Style>
|
||||
</Button>
|
||||
|
||||
<Button Grid.Row="0" Grid.Column="3" Width="22" Height="22" Margin="5,5,5,0" HorizontalAlignment="Left" VerticalAlignment="Top" Click="PatchNotes_Click" ToolTip="{DynamicResource ServerSettings_PatchNotesTooltip}">
|
||||
<Button Grid.Row="0" Grid.Column="10" Width="22" Height="22" Margin="5,5,5,0" HorizontalAlignment="Left" VerticalAlignment="Top" Click="PatchNotes_Click" ToolTip="{DynamicResource ServerSettings_PatchNotesTooltip}">
|
||||
<Button.Style>
|
||||
<Style TargetType="{x:Type Button}">
|
||||
<Style.Triggers>
|
||||
|
|
@ -74,11 +170,11 @@
|
|||
</Style.Triggers>
|
||||
</Style>
|
||||
</Button.Style>
|
||||
|
||||
|
||||
<Image Source="{com:Icon Path=/Ark Server Manager;component/Art/ChangeNotes.ico,Size=32}"/>
|
||||
</Button>
|
||||
|
||||
<DataGrid Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="4" Margin="5" Name="ServersGrid" ItemsSource="{Binding ServerManager.Servers}" GridLinesVisibility="Horizontal" HeadersVisibility="All" AutoGenerateColumns="False" CanUserAddRows="False" CanUserReorderColumns="False" CanUserSortColumns="False" CanUserResizeRows="False" RowHeaderWidth="25" SelectionMode="Single" PreviewMouseLeftButtonDown="OnMouseLeftButtonDown">
|
||||
<DataGrid Name="ServersGrid" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="11" Margin="5,5,5,0" HorizontalAlignment="Stretch" ItemsSource="{Binding ServerManager.Servers}" GridLinesVisibility="Horizontal" HeadersVisibility="All" AutoGenerateColumns="False" CanUserAddRows="False" CanUserReorderColumns="False" CanUserSortColumns="False" CanUserResizeRows="False" RowHeaderWidth="25" SelectionMode="Single" PreviewMouseLeftButtonDown="OnMouseLeftButtonDown">
|
||||
<DataGrid.Resources>
|
||||
<ResourceDictionary>
|
||||
<Style TargetType="{x:Type DataGridCell}">
|
||||
|
|
@ -140,6 +236,14 @@
|
|||
|
||||
<DataGrid.Columns>
|
||||
|
||||
<DataGridTemplateColumn Width="Auto" Header="{DynamicResource ServerMonitor_SelectedColumnLabel}">
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<CheckBox IsChecked="{Binding Selected, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, NotifyOnSourceUpdated=True}" HorizontalAlignment="Center" VerticalAlignment="Center" />
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
|
||||
<DataGridTemplateColumn Width="*">
|
||||
<DataGridTemplateColumn.Header>
|
||||
<TextBlock Text="{DynamicResource ServerMonitor_ServerColumnLabel}" />
|
||||
|
|
@ -530,11 +634,27 @@
|
|||
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
|
||||
<GridSplitter Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="11" Height="5" ShowsPreview="True" HorizontalAlignment="Stretch" VerticalAlignment="Center" Opacity="0"/>
|
||||
|
||||
<RichTextBox Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="11" Margin="5,0,5,5" BorderBrush="LightGray" HorizontalAlignment="Stretch" VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Auto" IsReadOnlyCaretVisible="True" IsReadOnly="True" IsTabStop="False">
|
||||
<i:Interaction.Triggers>
|
||||
<i:EventTrigger EventName="TextChanged" >
|
||||
<sm:ScrollToBottomAction IsEnabled="True"/>
|
||||
</i:EventTrigger>
|
||||
</i:Interaction.Triggers>
|
||||
<RichTextBox.Resources>
|
||||
<Style TargetType="{x:Type Paragraph}">
|
||||
<Setter Property="Margin" Value="0"/>
|
||||
</Style>
|
||||
</RichTextBox.Resources>
|
||||
<FlowDocument Name="ConsoleContent"/>
|
||||
</RichTextBox>
|
||||
</Grid>
|
||||
</DockPanel>
|
||||
|
||||
<!-- Drag and Drop Popup -->
|
||||
<Popup Grid.Row="0" Grid.Column="0" x:Name="popup" IsHitTestVisible="False" Placement="RelativePoint" PlacementTarget="{Binding ElementName=ServerMonitorUI}" AllowsTransparency="True">
|
||||
<Popup x:Name="popup" IsHitTestVisible="False" Placement="RelativePoint" PlacementTarget="{Binding ElementName=ServerMonitorUI}" AllowsTransparency="True" Grid.ColumnSpan="2">
|
||||
<Border BorderBrush="LightSteelBlue" BorderThickness="2" Background="White" Opacity="0.75">
|
||||
<StackPanel Orientation="Horizontal" Margin="4,3,8,3">
|
||||
<Image Source="{com:Icon Path=/Ark Server Manager;component/Art/Drag.ico,Size=32}" Width="16" Height="16"/>
|
||||
|
|
@ -544,7 +664,7 @@
|
|||
</Popup>
|
||||
|
||||
<!-- It's important that this is in the end of the XAML as it needs to be on top of everything else! -->
|
||||
<Grid x:Name="OverlayGrid" Visibility="Collapsed" DockPanel.Dock="Top" >
|
||||
<Grid x:Name="OverlayGrid" Visibility="Collapsed" DockPanel.Dock="Top">
|
||||
<Grid Background="Black" Opacity="0.5"/>
|
||||
<Border MinWidth="250" Background="Orange" BorderBrush="Black" BorderThickness="1" CornerRadius="0,0,0,0" HorizontalAlignment="Center" VerticalAlignment="Center">
|
||||
<StackPanel>
|
||||
|
|
@ -557,7 +677,7 @@
|
|||
Visibility="{Binding IsStandAloneWindow, Converter={StaticResource BooleanToVisibilityConverter}}"
|
||||
ToolTipText="{Binding Title}"
|
||||
IconSource="../Art/favicon.ico"
|
||||
LeftClickCommand="{Binding ShowWindowCommand, ElementName=ServerMonitorUI}">
|
||||
LeftClickCommand="{Binding ShowWindowCommand, ElementName=ServerMonitorUI}" Grid.ColumnSpan="2">
|
||||
|
||||
<tb:TaskbarIcon.Resources>
|
||||
<clib:BindingProxy x:Key="proxy" Data="{Binding ElementName=ServerMonitorUI}"/>
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
using NLog;
|
||||
using ServerManagerTool.Common.Lib;
|
||||
using ServerManagerTool.Common.Utils;
|
||||
using ServerManagerTool.DiscordBot.Enums;
|
||||
using ServerManagerTool.Enums;
|
||||
using ServerManagerTool.Lib;
|
||||
using ServerManagerTool.Plugin.Common;
|
||||
|
|
@ -16,7 +17,9 @@ using System.Threading;
|
|||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using WPFSharp.Globalizer;
|
||||
|
||||
namespace ServerManagerTool.Windows
|
||||
|
|
@ -26,17 +29,39 @@ namespace ServerManagerTool.Windows
|
|||
/// </summary>
|
||||
public partial class ServerMonitorWindow : Window
|
||||
{
|
||||
public class ServerMonitorOutput_Error : Run
|
||||
{
|
||||
public ServerMonitorOutput_Error(string value)
|
||||
: base(value)
|
||||
{
|
||||
Foreground = Brushes.Red;
|
||||
}
|
||||
}
|
||||
|
||||
public class ServerMonitorOutput_Success : Run
|
||||
{
|
||||
public ServerMonitorOutput_Success(string value)
|
||||
: base(value)
|
||||
{
|
||||
Foreground = Brushes.Green;
|
||||
}
|
||||
}
|
||||
|
||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||
private static readonly List<ServerMonitorWindow> Windows = new List<ServerMonitorWindow>();
|
||||
|
||||
private readonly GlobalizedApplication _globalizer = GlobalizedApplication.Instance;
|
||||
private CancellationTokenSource _upgradeCancellationSource = null;
|
||||
private ActionQueue _versionChecker;
|
||||
private readonly Dictionary<string, CommandType> _currentProfileCommands = new Dictionary<string, CommandType>();
|
||||
|
||||
private bool HasRunningCommands => _currentProfileCommands.Count > 0;
|
||||
|
||||
public static readonly DependencyProperty ServerManagerProperty = DependencyProperty.Register(nameof(ServerManager), typeof(ServerManager), typeof(ServerMonitorWindow), new PropertyMetadata(null));
|
||||
public static readonly DependencyProperty LatestServerManagerVersionProperty = DependencyProperty.Register(nameof(LatestServerManagerVersion), typeof(Version), typeof(ServerMonitorWindow), new PropertyMetadata(new Version()));
|
||||
public static readonly DependencyProperty ShowUpdateButtonProperty = DependencyProperty.Register(nameof(ShowUpdateButton), typeof(bool), typeof(ServerMonitorWindow), new PropertyMetadata(false));
|
||||
public static readonly DependencyProperty IsStandAloneWindowProperty = DependencyProperty.Register(nameof(IsStandAloneWindow), typeof(bool), typeof(ServerMonitorWindow), new PropertyMetadata(false));
|
||||
public static readonly DependencyProperty CancellationTokenSourceProperty = DependencyProperty.Register(nameof(CancellationTokenSource), typeof(CancellationTokenSource), typeof(ServerMonitorWindow));
|
||||
|
||||
public ServerMonitorWindow() : this(null)
|
||||
{
|
||||
|
|
@ -89,6 +114,12 @@ namespace ServerManagerTool.Windows
|
|||
set { SetValue(IsStandAloneWindowProperty, value); }
|
||||
}
|
||||
|
||||
public CancellationTokenSource CancellationTokenSource
|
||||
{
|
||||
get { return (CancellationTokenSource)GetValue(CancellationTokenSourceProperty); }
|
||||
set { SetValue(CancellationTokenSourceProperty, value); }
|
||||
}
|
||||
|
||||
private void ServerMonitorWindow_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (ServerManager == null)
|
||||
|
|
@ -156,6 +187,14 @@ namespace ServerManagerTool.Windows
|
|||
|
||||
protected override void OnClosing(CancelEventArgs e)
|
||||
{
|
||||
if (HasRunningCommands)
|
||||
{
|
||||
MessageBox.Show(_globalizer.GetResourceString("ServerMonitor_RunningProcesses_ConfirmLabel"), _globalizer.GetResourceString("ServerMonitor_RunningProcesses_ConfirmTitle"), MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
|
||||
e.Cancel = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.OwnedWindows.OfType<ProgressWindow>().Any())
|
||||
{
|
||||
if (MessageBox.Show(_globalizer.GetResourceString("ServerMonitor_CloseWindow_ConfirmLabel"), _globalizer.GetResourceString("ServerMonitor_CloseWindow_ConfirmTitle"), MessageBoxButton.YesNo, MessageBoxImage.Warning) != MessageBoxResult.Yes)
|
||||
|
|
@ -409,6 +448,29 @@ namespace ServerManagerTool.Windows
|
|||
}
|
||||
}
|
||||
|
||||
public void AddErrorBlockContent(string message)
|
||||
{
|
||||
var p = new Paragraph();
|
||||
|
||||
p.Inlines.Add(new ServerMonitorOutput_Error(message));
|
||||
|
||||
ConsoleContent.Blocks.Add(p);
|
||||
}
|
||||
|
||||
public void AddMessageBlockContent(string message)
|
||||
{
|
||||
var p = new Paragraph();
|
||||
|
||||
p.Inlines.Add(new ServerMonitorOutput_Success(message));
|
||||
|
||||
ConsoleContent.Blocks.Add(p);
|
||||
}
|
||||
|
||||
public void ClearBlockContents()
|
||||
{
|
||||
ConsoleContent.Blocks.Clear();
|
||||
}
|
||||
|
||||
private async Task CheckForUpdates()
|
||||
{
|
||||
string url = App.Instance.BetaVersion ? Config.Default.LatestASMBetaVersionUrl : Config.Default.LatestASMVersionUrl;
|
||||
|
|
@ -816,5 +878,511 @@ namespace ServerManagerTool.Windows
|
|||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private async void BackupServers_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (CancellationTokenSource != null)
|
||||
return;
|
||||
|
||||
var serverList = ServerManager.Servers.Where(s => s.Selected);
|
||||
if (serverList.IsEmpty())
|
||||
{
|
||||
MessageBox.Show(_globalizer.GetResourceString("ServerMonitor_NoServersSelected_ErrorLabel"), _globalizer.GetResourceString("ServerMonitor_NoServersSelected_ErrorTitle"), MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
var result = MessageBox.Show(_globalizer.GetResourceString("ServerMonitor_BackupServers_ConfirmLabel"), _globalizer.GetResourceString("ServerMonitor_BackupServers_ConfirmTitle"), MessageBoxButton.YesNo, MessageBoxImage.Question);
|
||||
if (result != MessageBoxResult.Yes)
|
||||
return;
|
||||
|
||||
ClearBlockContents();
|
||||
|
||||
var profileList = new List<ServerProfileSnapshot>();
|
||||
|
||||
foreach (var server in serverList)
|
||||
{
|
||||
// check if another command is being run against the profile
|
||||
if (_currentProfileCommands.ContainsKey(server.Profile.ProfileID))
|
||||
{
|
||||
AddErrorBlockContent(string.Format(_globalizer.GetResourceString("DiscordBot_CommandRunningProfile"), _currentProfileCommands[server.Profile.ProfileID], server.Profile.ProfileName));
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (server.Runtime.Status)
|
||||
{
|
||||
case ServerStatus.Initializing:
|
||||
case ServerStatus.Stopping:
|
||||
case ServerStatus.Uninstalled:
|
||||
case ServerStatus.Unknown:
|
||||
case ServerStatus.Updating:
|
||||
AddErrorBlockContent(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileBadStatus"), server.Profile.ProfileName, server.Runtime.StatusString));
|
||||
continue;
|
||||
}
|
||||
|
||||
_currentProfileCommands.Add(server.Profile.ProfileID, CommandType.Backup);
|
||||
profileList.Add(ServerProfileSnapshot.Create(server.Profile));
|
||||
}
|
||||
|
||||
CancellationTokenSource = new CancellationTokenSource();
|
||||
var token = CancellationTokenSource.Token;
|
||||
var tasks = new List<Task>();
|
||||
|
||||
foreach (var profile in profileList)
|
||||
{
|
||||
var app = new ServerApp(true)
|
||||
{
|
||||
DeleteOldBackupFiles = !Config.Default.AutoBackup_EnableBackup,
|
||||
OutputLogs = false,
|
||||
SendAlerts = true,
|
||||
SendEmails = false,
|
||||
ServerProcess = ServerProcessType.Backup,
|
||||
ServerStatusChangeCallback = (ServerStatus serverStatus) =>
|
||||
{
|
||||
TaskUtils.RunOnUIThreadAsync(() =>
|
||||
{
|
||||
var server = ServerManager.Instance.Servers.FirstOrDefault(s => string.Equals(profile.ProfileId, s.Profile.ProfileID, StringComparison.OrdinalIgnoreCase));
|
||||
if (server != null)
|
||||
{
|
||||
server.Runtime.UpdateServerStatus(serverStatus, serverStatus != ServerStatus.Unknown);
|
||||
}
|
||||
}).Wait(token);
|
||||
}
|
||||
};
|
||||
|
||||
var task = Task.Run(() =>
|
||||
{
|
||||
app.PerformProfileBackup(profile, token);
|
||||
_currentProfileCommands.Remove(profile.ProfileId);
|
||||
}, token);
|
||||
|
||||
tasks.Add(task);
|
||||
|
||||
AddMessageBlockContent(string.Format(_globalizer.GetResourceString("DiscordBot_BackupRequested"), profile.ServerName));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
await Task.WhenAll(tasks);
|
||||
}
|
||||
catch { }
|
||||
finally
|
||||
{
|
||||
CancellationTokenSource?.Dispose();
|
||||
CancellationTokenSource = null;
|
||||
}
|
||||
}
|
||||
|
||||
private async void RestartServers_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (CancellationTokenSource != null)
|
||||
return;
|
||||
|
||||
var serverList = ServerManager.Servers.Where(s => s.Selected);
|
||||
if (serverList.IsEmpty())
|
||||
{
|
||||
MessageBox.Show(_globalizer.GetResourceString("ServerMonitor_NoServersSelected_ErrorLabel"), _globalizer.GetResourceString("ServerMonitor_NoServersSelected_ErrorTitle"), MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
var result = MessageBox.Show(_globalizer.GetResourceString("ServerMonitor_RestartServers_ConfirmLabel"), _globalizer.GetResourceString("ServerMonitor_RestartServers_ConfirmTitle"), MessageBoxButton.YesNo, MessageBoxImage.Question);
|
||||
if (result != MessageBoxResult.Yes)
|
||||
return;
|
||||
|
||||
ClearBlockContents();
|
||||
|
||||
var profileList = new List<ServerProfileSnapshot>();
|
||||
|
||||
foreach (var server in serverList)
|
||||
{
|
||||
// check if another command is being run against the profile
|
||||
if (_currentProfileCommands.ContainsKey(server.Profile.ProfileID))
|
||||
{
|
||||
AddErrorBlockContent(string.Format(_globalizer.GetResourceString("DiscordBot_CommandRunningProfile"), _currentProfileCommands[server.Profile.ProfileID], server.Profile.ProfileName));
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (server.Runtime.Status)
|
||||
{
|
||||
case ServerStatus.Initializing:
|
||||
case ServerStatus.Stopping:
|
||||
case ServerStatus.Uninstalled:
|
||||
case ServerStatus.Unknown:
|
||||
AddErrorBlockContent(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileBadStatus"), server.Profile.ProfileName, server.Runtime.StatusString));
|
||||
continue;
|
||||
|
||||
case ServerStatus.Updating:
|
||||
AddErrorBlockContent(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileUpdating"), server.Profile.ProfileName));
|
||||
continue;
|
||||
}
|
||||
|
||||
_currentProfileCommands.Add(server.Profile.ProfileID, CommandType.Restart);
|
||||
var profile = ServerProfileSnapshot.Create(server.Profile);
|
||||
profile.AutoRestartIfShutdown = true;
|
||||
profileList.Add(profile);
|
||||
}
|
||||
|
||||
CancellationTokenSource = new CancellationTokenSource();
|
||||
var token = CancellationTokenSource.Token;
|
||||
var tasks = new List<Task>();
|
||||
|
||||
foreach (var profile in profileList)
|
||||
{
|
||||
var app = new ServerApp(true)
|
||||
{
|
||||
DeleteOldBackupFiles = !Config.Default.AutoBackup_EnableBackup,
|
||||
OutputLogs = false,
|
||||
SendAlerts = true,
|
||||
SendEmails = false,
|
||||
ServerProcess = ServerProcessType.Restart,
|
||||
ServerStatusChangeCallback = (ServerStatus serverStatus) =>
|
||||
{
|
||||
TaskUtils.RunOnUIThreadAsync(() =>
|
||||
{
|
||||
var server = ServerManager.Instance.Servers.FirstOrDefault(s => string.Equals(profile.ProfileId, s.Profile.ProfileID, StringComparison.OrdinalIgnoreCase));
|
||||
if (server != null)
|
||||
{
|
||||
server.Runtime.UpdateServerStatus(serverStatus, serverStatus != ServerStatus.Unknown);
|
||||
}
|
||||
}).Wait(token);
|
||||
}
|
||||
};
|
||||
|
||||
var task = Task.Run(() =>
|
||||
{
|
||||
app.PerformProfileShutdown(profile, true, false, false, false, token);
|
||||
_currentProfileCommands.Remove(profile.ProfileId);
|
||||
}, token);
|
||||
|
||||
tasks.Add(task);
|
||||
|
||||
AddMessageBlockContent(string.Format(_globalizer.GetResourceString("DiscordBot_RestartRequested"), profile.ServerName));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
await Task.WhenAll(tasks);
|
||||
}
|
||||
catch { }
|
||||
finally
|
||||
{
|
||||
CancellationTokenSource?.Dispose();
|
||||
CancellationTokenSource = null;
|
||||
}
|
||||
}
|
||||
|
||||
private async void StartServers_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (CancellationTokenSource != null)
|
||||
return;
|
||||
|
||||
var serverList = ServerManager.Servers.Where(s => s.Selected);
|
||||
if (serverList.IsEmpty())
|
||||
{
|
||||
MessageBox.Show(_globalizer.GetResourceString("ServerMonitor_NoServersSelected_ErrorLabel"), _globalizer.GetResourceString("ServerMonitor_NoServersSelected_ErrorTitle"), MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
var result = MessageBox.Show(_globalizer.GetResourceString("ServerMonitor_StartServers_ConfirmLabel"), _globalizer.GetResourceString("ServerMonitor_StartServers_ConfirmTitle"), MessageBoxButton.YesNo, MessageBoxImage.Question);
|
||||
if (result != MessageBoxResult.Yes)
|
||||
return;
|
||||
|
||||
ClearBlockContents();
|
||||
|
||||
var profileList = new List<ServerProfileSnapshot>();
|
||||
|
||||
foreach (var server in serverList)
|
||||
{
|
||||
// check if another command is being run against the profile
|
||||
if (_currentProfileCommands.ContainsKey(server.Profile.ProfileID))
|
||||
{
|
||||
AddErrorBlockContent(string.Format(_globalizer.GetResourceString("DiscordBot_CommandRunningProfile"), _currentProfileCommands[server.Profile.ProfileID], server.Profile.ProfileName));
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (server.Runtime.Status)
|
||||
{
|
||||
case ServerStatus.Initializing:
|
||||
case ServerStatus.Stopping:
|
||||
case ServerStatus.Running:
|
||||
case ServerStatus.Uninstalled:
|
||||
case ServerStatus.Unknown:
|
||||
AddErrorBlockContent(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileBadStatus"), server.Profile.ProfileName, server.Runtime.StatusString));
|
||||
continue;
|
||||
|
||||
case ServerStatus.Updating:
|
||||
AddErrorBlockContent(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileUpdating"), server.Profile.ProfileName));
|
||||
continue;
|
||||
}
|
||||
|
||||
_currentProfileCommands.Add(server.Profile.ProfileID, CommandType.Start);
|
||||
var profile = ServerProfileSnapshot.Create(server.Profile);
|
||||
profile.AutoRestartIfShutdown = true;
|
||||
profileList.Add(profile);
|
||||
}
|
||||
|
||||
CancellationTokenSource = new CancellationTokenSource();
|
||||
var token = CancellationTokenSource.Token;
|
||||
var tasks = new List<Task>();
|
||||
|
||||
foreach (var profile in profileList)
|
||||
{
|
||||
var app = new ServerApp(true)
|
||||
{
|
||||
DeleteOldBackupFiles = !Config.Default.AutoBackup_EnableBackup,
|
||||
OutputLogs = false,
|
||||
SendAlerts = true,
|
||||
SendEmails = false,
|
||||
ServerProcess = ServerProcessType.Restart,
|
||||
ServerStatusChangeCallback = (ServerStatus serverStatus) =>
|
||||
{
|
||||
TaskUtils.RunOnUIThreadAsync(() =>
|
||||
{
|
||||
var server = ServerManager.Instance.Servers.FirstOrDefault(s => string.Equals(profile.ProfileId, s.Profile.ProfileID, StringComparison.OrdinalIgnoreCase));
|
||||
if (server != null)
|
||||
{
|
||||
server.Runtime.UpdateServerStatus(serverStatus, serverStatus != ServerStatus.Unknown);
|
||||
}
|
||||
}).Wait(token);
|
||||
}
|
||||
};
|
||||
|
||||
var task = Task.Run(() =>
|
||||
{
|
||||
app.PerformProfileShutdown(profile, true, false, false, false, token);
|
||||
_currentProfileCommands.Remove(profile.ProfileId);
|
||||
}, token);
|
||||
|
||||
tasks.Add(task);
|
||||
|
||||
AddMessageBlockContent(string.Format(_globalizer.GetResourceString("DiscordBot_StartRequested"), profile.ServerName));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
await Task.WhenAll(tasks);
|
||||
}
|
||||
catch { }
|
||||
finally
|
||||
{
|
||||
CancellationTokenSource?.Dispose();
|
||||
CancellationTokenSource = null;
|
||||
}
|
||||
}
|
||||
|
||||
private async void StopServers_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (CancellationTokenSource != null)
|
||||
return;
|
||||
|
||||
var serverList = ServerManager.Servers.Where(s => s.Selected);
|
||||
if (serverList.IsEmpty())
|
||||
{
|
||||
MessageBox.Show(_globalizer.GetResourceString("ServerMonitor_NoServersSelected_ErrorLabel"), _globalizer.GetResourceString("ServerMonitor_NoServersSelected_ErrorTitle"), MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
var result = MessageBox.Show(_globalizer.GetResourceString("ServerMonitor_StopServers_ConfirmLabel"), _globalizer.GetResourceString("ServerMonitor_StopServers_ConfirmTitle"), MessageBoxButton.YesNo, MessageBoxImage.Question);
|
||||
if (result != MessageBoxResult.Yes)
|
||||
return;
|
||||
|
||||
ClearBlockContents();
|
||||
|
||||
var profileList = new List<ServerProfileSnapshot>();
|
||||
|
||||
foreach (var server in serverList)
|
||||
{
|
||||
// check if another command is being run against the profile
|
||||
if (_currentProfileCommands.ContainsKey(server.Profile.ProfileID))
|
||||
{
|
||||
AddErrorBlockContent(string.Format(_globalizer.GetResourceString("DiscordBot_CommandRunningProfile"), _currentProfileCommands[server.Profile.ProfileID], server.Profile.ProfileName));
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (server.Runtime.Status)
|
||||
{
|
||||
case ServerStatus.Initializing:
|
||||
case ServerStatus.Stopping:
|
||||
case ServerStatus.Stopped:
|
||||
case ServerStatus.Uninstalled:
|
||||
case ServerStatus.Unknown:
|
||||
AddErrorBlockContent(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileBadStatus"), server.Profile.ProfileName, server.Runtime.StatusString));
|
||||
continue;
|
||||
|
||||
case ServerStatus.Updating:
|
||||
AddErrorBlockContent(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileUpdating"), server.Profile.ProfileName));
|
||||
continue;
|
||||
}
|
||||
|
||||
_currentProfileCommands.Add(server.Profile.ProfileID, CommandType.Stop);
|
||||
profileList.Add(ServerProfileSnapshot.Create(server.Profile));
|
||||
}
|
||||
|
||||
CancellationTokenSource = new CancellationTokenSource();
|
||||
var token = CancellationTokenSource.Token;
|
||||
var tasks = new List<Task>();
|
||||
|
||||
foreach (var profile in profileList)
|
||||
{
|
||||
var app = new ServerApp(true)
|
||||
{
|
||||
DeleteOldBackupFiles = !Config.Default.AutoBackup_EnableBackup,
|
||||
OutputLogs = false,
|
||||
SendAlerts = true,
|
||||
SendEmails = false,
|
||||
ServerProcess = ServerProcessType.Shutdown,
|
||||
ServerStatusChangeCallback = (ServerStatus serverStatus) =>
|
||||
{
|
||||
TaskUtils.RunOnUIThreadAsync(() =>
|
||||
{
|
||||
var server = ServerManager.Instance.Servers.FirstOrDefault(s => string.Equals(profile.ProfileId, s.Profile.ProfileID, StringComparison.OrdinalIgnoreCase));
|
||||
if (server != null)
|
||||
{
|
||||
server.Runtime.UpdateServerStatus(serverStatus, serverStatus != ServerStatus.Unknown);
|
||||
}
|
||||
}).Wait(token);
|
||||
}
|
||||
};
|
||||
|
||||
var task = Task.Run(() =>
|
||||
{
|
||||
app.PerformProfileShutdown(profile, false, false, false, false, token);
|
||||
_currentProfileCommands.Remove(profile.ProfileId);
|
||||
}, token);
|
||||
|
||||
tasks.Add(task);
|
||||
|
||||
AddMessageBlockContent(string.Format(_globalizer.GetResourceString("DiscordBot_ShutdownRequested"), profile.ServerName));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
await Task.WhenAll(tasks);
|
||||
}
|
||||
catch { }
|
||||
finally
|
||||
{
|
||||
CancellationTokenSource?.Dispose();
|
||||
CancellationTokenSource = null;
|
||||
}
|
||||
}
|
||||
|
||||
private async void UpdateServers_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (CancellationTokenSource != null)
|
||||
return;
|
||||
|
||||
var serverList = ServerManager.Servers.Where(s => s.Selected);
|
||||
if (serverList.IsEmpty())
|
||||
{
|
||||
MessageBox.Show(_globalizer.GetResourceString("ServerMonitor_NoServersSelected_ErrorLabel"), _globalizer.GetResourceString("ServerMonitor_NoServersSelected_ErrorTitle"), MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
var result = MessageBox.Show(_globalizer.GetResourceString("ServerMonitor_UpdateServers_ConfirmLabel"), _globalizer.GetResourceString("ServerMonitor_UpdateServers_ConfirmTitle"), MessageBoxButton.YesNo, MessageBoxImage.Question);
|
||||
if (result != MessageBoxResult.Yes)
|
||||
return;
|
||||
|
||||
ClearBlockContents();
|
||||
|
||||
var profileList = new List<ServerProfileSnapshot>();
|
||||
|
||||
foreach (var server in serverList)
|
||||
{
|
||||
var performRestart = false;
|
||||
|
||||
// check if another command is being run against the profile
|
||||
if (_currentProfileCommands.ContainsKey(server.Profile.ProfileID))
|
||||
{
|
||||
AddErrorBlockContent(string.Format(_globalizer.GetResourceString("DiscordBot_CommandRunningProfile"), _currentProfileCommands[server.Profile.ProfileID], server.Profile.ProfileName));
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (server.Runtime.Status)
|
||||
{
|
||||
case ServerStatus.Running:
|
||||
performRestart = true;
|
||||
break;
|
||||
|
||||
case ServerStatus.Initializing:
|
||||
case ServerStatus.Stopping:
|
||||
case ServerStatus.Unknown:
|
||||
AddErrorBlockContent(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileBadStatus"), server.Profile.ProfileName, server.Runtime.StatusString));
|
||||
continue;
|
||||
|
||||
case ServerStatus.Updating:
|
||||
AddErrorBlockContent(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileUpdating"), server.Profile.ProfileName));
|
||||
continue;
|
||||
}
|
||||
|
||||
_currentProfileCommands.Add(server.Profile.ProfileID, CommandType.Update);
|
||||
var profile = ServerProfileSnapshot.Create(server.Profile);
|
||||
profile.RestartAfterShutdown1 = performRestart; // use this property to trigger a restart
|
||||
profileList.Add(profile);
|
||||
}
|
||||
|
||||
CancellationTokenSource = new CancellationTokenSource();
|
||||
var token = CancellationTokenSource.Token;
|
||||
var tasks = new List<Task>();
|
||||
|
||||
foreach (var profile in profileList)
|
||||
{
|
||||
var app = new ServerApp(true)
|
||||
{
|
||||
DeleteOldBackupFiles = !Config.Default.AutoBackup_EnableBackup,
|
||||
OutputLogs = false,
|
||||
SendAlerts = true,
|
||||
SendEmails = false,
|
||||
ServerProcess = ServerProcessType.Update,
|
||||
ServerStatusChangeCallback = (ServerStatus serverStatus) =>
|
||||
{
|
||||
TaskUtils.RunOnUIThreadAsync(() =>
|
||||
{
|
||||
var server = ServerManager.Instance.Servers.FirstOrDefault(s => string.Equals(profile.ProfileId, s.Profile.ProfileID, StringComparison.OrdinalIgnoreCase));
|
||||
if (server != null)
|
||||
{
|
||||
server.Runtime.UpdateServerStatus(serverStatus, serverStatus != ServerStatus.Unknown);
|
||||
}
|
||||
}).Wait(token);
|
||||
}
|
||||
};
|
||||
|
||||
var task = Task.Run(() =>
|
||||
{
|
||||
app.PerformProfileShutdown(profile, profile.RestartAfterShutdown1, true, false, false, token);
|
||||
_currentProfileCommands.Remove(profile.ProfileId);
|
||||
}, token);
|
||||
|
||||
tasks.Add(task);
|
||||
|
||||
AddMessageBlockContent(string.Format(_globalizer.GetResourceString("DiscordBot_UpdateRequested"), profile.ServerName));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
await Task.WhenAll(tasks);
|
||||
}
|
||||
catch { }
|
||||
finally
|
||||
{
|
||||
CancellationTokenSource?.Dispose();
|
||||
CancellationTokenSource = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void SelectAllServers_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
foreach (var server in ServerManager.Servers)
|
||||
{
|
||||
server.Selected = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void UnselectAllServers_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
foreach (var server in ServerManager.Servers)
|
||||
{
|
||||
server.Selected = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
BIN
src/ConanServerManager/Art/Restart.ico
Normal file
BIN
src/ConanServerManager/Art/Restart.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 100 KiB |
|
|
@ -297,6 +297,7 @@
|
|||
</Content>
|
||||
<Resource Include="Art\Filter.ico" />
|
||||
<Resource Include="Art\DropArrow.ico" />
|
||||
<Resource Include="Art\Restart.ico" />
|
||||
<Content Include="Globalization\en-US\en-US.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
|
|
|
|||
|
|
@ -400,6 +400,7 @@
|
|||
<!--#region Server Monitor Window -->
|
||||
<sys:String x:Key="ServerMonitor_Title">Server Monitor</sys:String>
|
||||
|
||||
<sys:String x:Key="ServerMonitor_SelectedColumnLabel">Selected</sys:String>
|
||||
<sys:String x:Key="ServerMonitor_TotalCountLabel">Total Servers:</sys:String>
|
||||
<sys:String x:Key="ServerMonitor_ServerColumnLabel">Server</sys:String>
|
||||
<sys:String x:Key="ServerMonitor_MapColumnLabel">Map</sys:String>
|
||||
|
|
@ -409,6 +410,13 @@
|
|||
<sys:String x:Key="ServerMonitor_StatusColumnLabel">Status</sys:String>
|
||||
|
||||
<sys:String x:Key="ServerMonitor_CreateShortcutButtonTooltip">Create a desktop shortcut to open this form directly.</sys:String>
|
||||
<sys:String x:Key="ServerMonitor_StartServersButtonTooltip">Start the selected servers.</sys:String>
|
||||
<sys:String x:Key="ServerMonitor_StopServersButtonTooltip">Stop the selected servers.</sys:String>
|
||||
<sys:String x:Key="ServerMonitor_RestartServersButtonTooltip">Restart the selected servers.</sys:String>
|
||||
<sys:String x:Key="ServerMonitor_UpdateServersButtonTooltip">Update the selected servers.</sys:String>
|
||||
<sys:String x:Key="ServerMonitor_BackupServersButtonTooltip">Backup the selected servers.</sys:String>
|
||||
<sys:String x:Key="ServerMonitor_SelectAllServersButtonTooltip">Select all servers.</sys:String>
|
||||
<sys:String x:Key="ServerMonitor_UnselectAllServersButtonTooltip">Unselect all servers.</sys:String>
|
||||
<sys:String x:Key="ServerMonitor_PlayerListButtonTooltip">Open the Player List window.</sys:String>
|
||||
<sys:String x:Key="ServerMonitor_RCONButtonTooltip">Open the RCON window.</sys:String>
|
||||
<sys:String x:Key="ServerMonitor_StartServerTooltip">Start the server.</sys:String>
|
||||
|
|
@ -419,7 +427,21 @@
|
|||
<sys:String x:Key="ServerMonitor_UpgradeServer_FailedTitle">Server Update Error</sys:String>
|
||||
<sys:String x:Key="ServerMonitor_UpgradeServer_FailedLabel">Another server is being upgraded, wait until the upgrade has finished and try again.</sys:String>
|
||||
<sys:String x:Key="ServerMonitor_CloseWindow_ConfirmTitle">Confirm Window Close</sys:String>
|
||||
<sys:String x:Key="ServerMonitor_CloseWindow_ConfirmLabel">You are currently perform a server update, closing the window with disconnect you from steamcmd. Do you want to continue closing the window?</sys:String>
|
||||
<sys:String x:Key="ServerMonitor_CloseWindow_ConfirmLabel">You are currently performing a server update, closing the window will disconnect you from steamcmd. Do you want to continue closing the window?</sys:String>
|
||||
<sys:String x:Key="ServerMonitor_StartServers_ConfirmTitle">Confirm Start Servers</sys:String>
|
||||
<sys:String x:Key="ServerMonitor_StartServers_ConfirmLabel">You are about to start the selected servers. Do you want to continue?</sys:String>
|
||||
<sys:String x:Key="ServerMonitor_StopServers_ConfirmTitle">Confirm Stop Servers</sys:String>
|
||||
<sys:String x:Key="ServerMonitor_StopServers_ConfirmLabel">You are about to stop the selected servers. Do you want to continue?</sys:String>
|
||||
<sys:String x:Key="ServerMonitor_RestartServers_ConfirmTitle">Confirm Restart Servers</sys:String>
|
||||
<sys:String x:Key="ServerMonitor_RestartServers_ConfirmLabel">You are about to restart the selected servers. Do you want to continue?</sys:String>
|
||||
<sys:String x:Key="ServerMonitor_UpdateServers_ConfirmTitle">Confirm Update Servers</sys:String>
|
||||
<sys:String x:Key="ServerMonitor_UpdateServers_ConfirmLabel">You are about to update the selected servers. Do you want to continue?</sys:String>
|
||||
<sys:String x:Key="ServerMonitor_BackupServers_ConfirmTitle">Confirm Backup Servers</sys:String>
|
||||
<sys:String x:Key="ServerMonitor_BackupServers_ConfirmLabel">You are about to backup the selected servers. Do you want to continue?</sys:String>
|
||||
<sys:String x:Key="ServerMonitor_NoServersSelected_ErrorTitle">Selected Servers Error</sys:String>
|
||||
<sys:String x:Key="ServerMonitor_NoServersSelected_ErrorLabel">You have not selected any servers. Selected one or more servers in the list and try again.</sys:String>
|
||||
<sys:String x:Key="ServerMonitor_RunningProcesses_ConfirmTitle">Close Server Monitor Error</sys:String>
|
||||
<sys:String x:Key="ServerMonitor_RunningProcesses_ConfirmLabel">The server monitor window cannot be closed at this time. One or more of the servers is currently starting, shutting down or restarting.</sys:String>
|
||||
<!--#endregion-->
|
||||
|
||||
<!--#region Shutdown Window -->
|
||||
|
|
|
|||
|
|
@ -4,6 +4,9 @@
|
|||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:tb="http://www.hardcodet.net/taskbar"
|
||||
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
|
||||
xmlns:sm="clr-namespace:ServerManagerTool"
|
||||
xmlns:smw="clr-namespace:ServerManagerTool.Windows"
|
||||
xmlns:clib="clr-namespace:ServerManagerTool.Common.Lib;assembly=ServerManager.Common"
|
||||
xmlns:com="clr-namespace:ServerManagerTool.Common;assembly=ServerManager.Common"
|
||||
xmlns:enum="clr-namespace:ServerManagerTool.Enums"
|
||||
|
|
@ -19,6 +22,7 @@
|
|||
<ResourceDictionary Source="..\Styles\Default.xaml"/>
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
|
||||
<sm:ScrollToBottomAction x:Key="ScrollToBottomAction" />
|
||||
<vm:MapNameValueConverter x:Key="MapNameValueConverter"/>
|
||||
</ResourceDictionary>
|
||||
</Window.Resources>
|
||||
|
|
@ -28,11 +32,20 @@
|
|||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="10*"/>
|
||||
<RowDefinition Height="*" MinHeight="200"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto" MinHeight="100"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="200*"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
|
@ -41,12 +54,95 @@
|
|||
<Image Source="{com:Icon Path=/ConanServerManager;component/Art/Shortcut.ico,Size=32}"/>
|
||||
</Button>
|
||||
|
||||
<StackPanel Grid.Row="0" Grid.Column="1" Orientation="Horizontal">
|
||||
<Button Grid.Row="0" Grid.Column="1" Width="22" Height="22" Margin="10,5,5,0" HorizontalAlignment="Left" VerticalAlignment="Top" Click="StartServers_Click" ToolTip="{DynamicResource ServerMonitor_StartServersButtonTooltip}">
|
||||
<Button.Style>
|
||||
<Style TargetType="{x:Type Button}">
|
||||
<Setter Property="IsEnabled" Value="False"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding CancellationTokenSource}" Value="{x:Null}">
|
||||
<Setter Property="IsEnabled" Value="True"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</Button.Style>
|
||||
|
||||
<Image Source="{com:Icon Path=/ConanServerManager;component/Art/Start.ico,Size=32}"/>
|
||||
</Button>
|
||||
|
||||
<Button Grid.Row="0" Grid.Column="2" Width="22" Height="22" Margin="0,5,5,0" HorizontalAlignment="Left" VerticalAlignment="Top" Click="StopServers_Click" ToolTip="{DynamicResource ServerMonitor_StopServersButtonTooltip}">
|
||||
<Button.Style>
|
||||
<Style TargetType="{x:Type Button}">
|
||||
<Setter Property="IsEnabled" Value="False"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding CancellationTokenSource}" Value="{x:Null}">
|
||||
<Setter Property="IsEnabled" Value="True"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</Button.Style>
|
||||
|
||||
<Image Source="{com:Icon Path=/ConanServerManager;component/Art/Stop.ico,Size=32}"/>
|
||||
</Button>
|
||||
|
||||
<Button Grid.Row="0" Grid.Column="3" Width="22" Height="22" Margin="0,5,5,0" HorizontalAlignment="Left" VerticalAlignment="Top" Click="RestartServers_Click" ToolTip="{DynamicResource ServerMonitor_RestartServersButtonTooltip}">
|
||||
<Button.Style>
|
||||
<Style TargetType="{x:Type Button}">
|
||||
<Setter Property="IsEnabled" Value="False"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding CancellationTokenSource}" Value="{x:Null}">
|
||||
<Setter Property="IsEnabled" Value="True"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</Button.Style>
|
||||
|
||||
<Image Source="{com:Icon Path=/ConanServerManager;component/Art/Restart.ico,Size=32}"/>
|
||||
</Button>
|
||||
|
||||
<Button Grid.Row="0" Grid.Column="4" Width="22" Height="22" Margin="0,5,5,0" HorizontalAlignment="Left" VerticalAlignment="Top" Click="UpdateServers_Click" ToolTip="{DynamicResource ServerMonitor_UpdateServersButtonTooltip}">
|
||||
<Button.Style>
|
||||
<Style TargetType="{x:Type Button}">
|
||||
<Setter Property="IsEnabled" Value="False"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding CancellationTokenSource}" Value="{x:Null}">
|
||||
<Setter Property="IsEnabled" Value="True"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</Button.Style>
|
||||
|
||||
<Image Source="{com:Icon Path=/ConanServerManager;component/Art/Download.ico,Size=32}"/>
|
||||
</Button>
|
||||
|
||||
<Button Grid.Row="0" Grid.Column="5" Width="22" Height="22" Margin="0,5,5,0" HorizontalAlignment="Left" VerticalAlignment="Top" Click="BackupServers_Click" ToolTip="{DynamicResource ServerMonitor_BackupServersButtonTooltip}">
|
||||
<Button.Style>
|
||||
<Style TargetType="{x:Type Button}">
|
||||
<Setter Property="IsEnabled" Value="False"/>
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding CancellationTokenSource}" Value="{x:Null}">
|
||||
<Setter Property="IsEnabled" Value="True"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</Button.Style>
|
||||
|
||||
<Image Source="{com:Icon Path=/ConanServerManager;component/Art/Save.ico,Size=32}"/>
|
||||
</Button>
|
||||
|
||||
<Button Grid.Row="0" Grid.Column="6" Width="22" Height="22" Margin="10,5,5,0" HorizontalAlignment="Left" VerticalAlignment="Top" Click="SelectAllServers_Click" ToolTip="{DynamicResource ServerMonitor_SelectAllServersButtonTooltip}">
|
||||
<Image Source="{com:Icon Path=/ConanServerManager;component/Art/Checked.ico,Size=32}"/>
|
||||
</Button>
|
||||
|
||||
<Button Grid.Row="0" Grid.Column="7" Width="22" Height="22" Margin="0,5,5,0" HorizontalAlignment="Left" VerticalAlignment="Top" Click="UnselectAllServers_Click" ToolTip="{DynamicResource ServerMonitor_UnselectAllServersButtonTooltip}">
|
||||
<Image Source="{com:Icon Path=/ConanServerManager;component/Art/Unchecked.ico,Size=32}"/>
|
||||
</Button>
|
||||
|
||||
<StackPanel Grid.Row="0" Grid.Column="8" Orientation="Horizontal">
|
||||
<TextBlock Margin="30,5,5,0" Text="{DynamicResource ServerMonitor_TotalCountLabel}" VerticalAlignment="Center" />
|
||||
<TextBlock Margin="5,5,5,0" Text="{Binding ServerManager.Servers.Count}" VerticalAlignment="Center" />
|
||||
</StackPanel>
|
||||
|
||||
<Button Grid.Row="0" Grid.Column="2" Height="22" Margin="5,5,5,0" Background="#00AA00" Foreground="White" Padding="1" BorderThickness="1" BorderBrush="White" ContentStringFormat="{DynamicResource MainWindow_UpdateToLabelFormat}" Content="{Binding LatestServerManagerVersion}" Click="UpgradeApplication_Click" VerticalAlignment="Center" >
|
||||
<Button Grid.Row="0" Grid.Column="9" Height="22" Margin="5,5,5,0" Background="#00AA00" Foreground="White" Padding="1" BorderThickness="1" BorderBrush="White" ContentStringFormat="{DynamicResource MainWindow_UpdateToLabelFormat}" Content="{Binding LatestServerManagerVersion}" Click="UpgradeApplication_Click" VerticalAlignment="Center" >
|
||||
<Button.Style>
|
||||
<Style TargetType="{x:Type Button}">
|
||||
<Style.Triggers>
|
||||
|
|
@ -61,7 +157,7 @@
|
|||
</Button.Style>
|
||||
</Button>
|
||||
|
||||
<Button Grid.Row="0" Grid.Column="3" Width="22" Height="22" Margin="5,5,5,0" HorizontalAlignment="Left" VerticalAlignment="Top" Click="PatchNotes_Click" ToolTip="{DynamicResource ServerSettings_PatchNotesTooltip}">
|
||||
<Button Grid.Row="0" Grid.Column="10" Width="22" Height="22" Margin="5,5,5,0" HorizontalAlignment="Left" VerticalAlignment="Top" Click="PatchNotes_Click" ToolTip="{DynamicResource ServerSettings_PatchNotesTooltip}">
|
||||
<Button.Style>
|
||||
<Style TargetType="{x:Type Button}">
|
||||
<Style.Triggers>
|
||||
|
|
@ -78,7 +174,7 @@
|
|||
<Image Source="{com:Icon Path=/ConanServerManager;component/Art/ChangeNotes.ico,Size=32}"/>
|
||||
</Button>
|
||||
|
||||
<DataGrid Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="4" Margin="5" Name="ServersGrid" ItemsSource="{Binding ServerManager.Servers}" GridLinesVisibility="Horizontal" HeadersVisibility="All" AutoGenerateColumns="False" CanUserAddRows="False" CanUserReorderColumns="False" CanUserSortColumns="False" CanUserResizeRows="False" RowHeaderWidth="25" SelectionMode="Single" PreviewMouseLeftButtonDown="OnMouseLeftButtonDown">
|
||||
<DataGrid Name="ServersGrid" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="11" Margin="5,5,5,0" HorizontalAlignment="Stretch" ItemsSource="{Binding ServerManager.Servers}" GridLinesVisibility="Horizontal" HeadersVisibility="All" AutoGenerateColumns="False" CanUserAddRows="False" CanUserReorderColumns="False" CanUserSortColumns="False" CanUserResizeRows="False" RowHeaderWidth="25" SelectionMode="Single" PreviewMouseLeftButtonDown="OnMouseLeftButtonDown">
|
||||
<DataGrid.Resources>
|
||||
<ResourceDictionary>
|
||||
<Style TargetType="{x:Type DataGridCell}">
|
||||
|
|
@ -140,6 +236,14 @@
|
|||
|
||||
<DataGrid.Columns>
|
||||
|
||||
<DataGridTemplateColumn Width="Auto" Header="{DynamicResource ServerMonitor_SelectedColumnLabel}">
|
||||
<DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<CheckBox IsChecked="{Binding Selected, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, NotifyOnSourceUpdated=True}" HorizontalAlignment="Center" VerticalAlignment="Center" />
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellTemplate>
|
||||
</DataGridTemplateColumn>
|
||||
|
||||
<DataGridTemplateColumn Width="*">
|
||||
<DataGridTemplateColumn.Header>
|
||||
<TextBlock Text="{DynamicResource ServerMonitor_ServerColumnLabel}" />
|
||||
|
|
@ -530,11 +634,27 @@
|
|||
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
|
||||
<GridSplitter Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="11" Height="5" ShowsPreview="True" HorizontalAlignment="Stretch" VerticalAlignment="Center" Opacity="0"/>
|
||||
|
||||
<RichTextBox Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="11" Margin="5,0,5,5" BorderBrush="LightGray" HorizontalAlignment="Stretch" VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Auto" IsReadOnlyCaretVisible="True" IsReadOnly="True" IsTabStop="False">
|
||||
<i:Interaction.Triggers>
|
||||
<i:EventTrigger EventName="TextChanged" >
|
||||
<sm:ScrollToBottomAction IsEnabled="True"/>
|
||||
</i:EventTrigger>
|
||||
</i:Interaction.Triggers>
|
||||
<RichTextBox.Resources>
|
||||
<Style TargetType="{x:Type Paragraph}">
|
||||
<Setter Property="Margin" Value="0"/>
|
||||
</Style>
|
||||
</RichTextBox.Resources>
|
||||
<FlowDocument Name="ConsoleContent"/>
|
||||
</RichTextBox>
|
||||
</Grid>
|
||||
</DockPanel>
|
||||
|
||||
<!-- Drag and Drop Popup -->
|
||||
<Popup Grid.Row="0" Grid.Column="0" x:Name="popup" IsHitTestVisible="False" Placement="RelativePoint" PlacementTarget="{Binding ElementName=ServerMonitorUI}" AllowsTransparency="True">
|
||||
<Popup x:Name="popup" IsHitTestVisible="False" Placement="RelativePoint" PlacementTarget="{Binding ElementName=ServerMonitorUI}" AllowsTransparency="True">
|
||||
<Border BorderBrush="LightSteelBlue" BorderThickness="2" Background="White" Opacity="0.75">
|
||||
<StackPanel Orientation="Horizontal" Margin="4,3,8,3">
|
||||
<Image Source="{com:Icon Path=/ConanServerManager;component/Art/Drag.ico,Size=32}" Width="16" Height="16"/>
|
||||
|
|
@ -544,7 +664,7 @@
|
|||
</Popup>
|
||||
|
||||
<!-- It's important that this is in the end of the XAML as it needs to be on top of everything else! -->
|
||||
<Grid x:Name="OverlayGrid" Visibility="Collapsed" DockPanel.Dock="Top" >
|
||||
<Grid x:Name="OverlayGrid" Visibility="Collapsed" DockPanel.Dock="Top">
|
||||
<Grid Background="Black" Opacity="0.5"/>
|
||||
<Border MinWidth="250" Background="Orange" BorderBrush="Black" BorderThickness="1" CornerRadius="0,0,0,0" HorizontalAlignment="Center" VerticalAlignment="Center">
|
||||
<StackPanel>
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
using NLog;
|
||||
using ServerManagerTool.Common.Lib;
|
||||
using ServerManagerTool.Common.Utils;
|
||||
using ServerManagerTool.DiscordBot.Enums;
|
||||
using ServerManagerTool.Enums;
|
||||
using ServerManagerTool.Lib;
|
||||
using ServerManagerTool.Plugin.Common;
|
||||
|
|
@ -16,7 +17,9 @@ using System.Threading;
|
|||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using WPFSharp.Globalizer;
|
||||
|
||||
namespace ServerManagerTool.Windows
|
||||
|
|
@ -26,19 +29,41 @@ namespace ServerManagerTool.Windows
|
|||
/// </summary>
|
||||
public partial class ServerMonitorWindow : Window
|
||||
{
|
||||
public class ServerMonitorOutput_Error : Run
|
||||
{
|
||||
public ServerMonitorOutput_Error(string value)
|
||||
: base(value)
|
||||
{
|
||||
Foreground = Brushes.Red;
|
||||
}
|
||||
}
|
||||
|
||||
public class ServerMonitorOutput_Success : Run
|
||||
{
|
||||
public ServerMonitorOutput_Success(string value)
|
||||
: base(value)
|
||||
{
|
||||
Foreground = Brushes.Green;
|
||||
}
|
||||
}
|
||||
|
||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||
private static readonly List<ServerMonitorWindow> Windows = new List<ServerMonitorWindow>();
|
||||
|
||||
private readonly GlobalizedApplication _globalizer = GlobalizedApplication.Instance;
|
||||
private CancellationTokenSource _upgradeCancellationSource = null;
|
||||
private ActionQueue _versionChecker;
|
||||
private readonly Dictionary<string, CommandType> _currentProfileCommands = new Dictionary<string, CommandType>();
|
||||
|
||||
private bool HasRunningCommands => _currentProfileCommands.Count > 0;
|
||||
|
||||
public static readonly DependencyProperty ServerManagerProperty = DependencyProperty.Register(nameof(ServerManager), typeof(ServerManager), typeof(ServerMonitorWindow), new PropertyMetadata(null));
|
||||
public static readonly DependencyProperty LatestServerManagerVersionProperty = DependencyProperty.Register(nameof(LatestServerManagerVersion), typeof(Version), typeof(ServerMonitorWindow), new PropertyMetadata(new Version()));
|
||||
public static readonly DependencyProperty ShowUpdateButtonProperty = DependencyProperty.Register(nameof(ShowUpdateButton), typeof(bool), typeof(ServerMonitorWindow), new PropertyMetadata(false));
|
||||
public static readonly DependencyProperty IsStandAloneWindowProperty = DependencyProperty.Register(nameof(IsStandAloneWindow), typeof(bool), typeof(ServerMonitorWindow), new PropertyMetadata(false));
|
||||
public static readonly DependencyProperty CancellationTokenSourceProperty = DependencyProperty.Register(nameof(CancellationTokenSource), typeof(CancellationTokenSource), typeof(ServerMonitorWindow));
|
||||
|
||||
public ServerMonitorWindow() : this(null)
|
||||
public ServerMonitorWindow(): this(null)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -89,6 +114,12 @@ namespace ServerManagerTool.Windows
|
|||
set { SetValue(IsStandAloneWindowProperty, value); }
|
||||
}
|
||||
|
||||
public CancellationTokenSource CancellationTokenSource
|
||||
{
|
||||
get { return (CancellationTokenSource)GetValue(CancellationTokenSourceProperty); }
|
||||
set { SetValue(CancellationTokenSourceProperty, value); }
|
||||
}
|
||||
|
||||
private void ServerMonitorWindow_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (ServerManager == null)
|
||||
|
|
@ -156,6 +187,14 @@ namespace ServerManagerTool.Windows
|
|||
|
||||
protected override void OnClosing(CancelEventArgs e)
|
||||
{
|
||||
if (HasRunningCommands)
|
||||
{
|
||||
MessageBox.Show(_globalizer.GetResourceString("ServerMonitor_RunningProcesses_ConfirmLabel"), _globalizer.GetResourceString("ServerMonitor_RunningProcesses_ConfirmTitle"), MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
|
||||
e.Cancel = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.OwnedWindows.OfType<ProgressWindow>().Any())
|
||||
{
|
||||
if (MessageBox.Show(_globalizer.GetResourceString("ServerMonitor_CloseWindow_ConfirmLabel"), _globalizer.GetResourceString("ServerMonitor_CloseWindow_ConfirmTitle"), MessageBoxButton.YesNo, MessageBoxImage.Warning) != MessageBoxResult.Yes)
|
||||
|
|
@ -409,6 +448,29 @@ namespace ServerManagerTool.Windows
|
|||
}
|
||||
}
|
||||
|
||||
public void AddErrorBlockContent(string message)
|
||||
{
|
||||
var p = new Paragraph();
|
||||
|
||||
p.Inlines.Add(new ServerMonitorOutput_Error(message));
|
||||
|
||||
ConsoleContent.Blocks.Add(p);
|
||||
}
|
||||
|
||||
public void AddMessageBlockContent(string message)
|
||||
{
|
||||
var p = new Paragraph();
|
||||
|
||||
p.Inlines.Add(new ServerMonitorOutput_Success(message));
|
||||
|
||||
ConsoleContent.Blocks.Add(p);
|
||||
}
|
||||
|
||||
public void ClearBlockContents()
|
||||
{
|
||||
ConsoleContent.Blocks.Clear();
|
||||
}
|
||||
|
||||
private async Task CheckForUpdates()
|
||||
{
|
||||
string url = App.Instance.BetaVersion ? Config.Default.LatestServerManagerBetaVersionUrl : Config.Default.LatestServerManagerVersionUrl;
|
||||
|
|
@ -813,5 +875,511 @@ namespace ServerManagerTool.Windows
|
|||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private async void BackupServers_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (CancellationTokenSource != null)
|
||||
return;
|
||||
|
||||
var serverList = ServerManager.Servers.Where(s => s.Selected);
|
||||
if (serverList.IsEmpty())
|
||||
{
|
||||
MessageBox.Show(_globalizer.GetResourceString("ServerMonitor_NoServersSelected_ErrorLabel"), _globalizer.GetResourceString("ServerMonitor_NoServersSelected_ErrorTitle"), MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
var result = MessageBox.Show(_globalizer.GetResourceString("ServerMonitor_BackupServers_ConfirmLabel"), _globalizer.GetResourceString("ServerMonitor_BackupServers_ConfirmTitle"), MessageBoxButton.YesNo, MessageBoxImage.Question);
|
||||
if (result != MessageBoxResult.Yes)
|
||||
return;
|
||||
|
||||
ClearBlockContents();
|
||||
|
||||
var profileList = new List<ServerProfileSnapshot>();
|
||||
|
||||
foreach (var server in serverList)
|
||||
{
|
||||
// check if another command is being run against the profile
|
||||
if (_currentProfileCommands.ContainsKey(server.Profile.ProfileID))
|
||||
{
|
||||
AddErrorBlockContent(string.Format(_globalizer.GetResourceString("DiscordBot_CommandRunningProfile"), _currentProfileCommands[server.Profile.ProfileID], server.Profile.ProfileName));
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (server.Runtime.Status)
|
||||
{
|
||||
case ServerStatus.Initializing:
|
||||
case ServerStatus.Stopping:
|
||||
case ServerStatus.Uninstalled:
|
||||
case ServerStatus.Unknown:
|
||||
case ServerStatus.Updating:
|
||||
AddErrorBlockContent(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileBadStatus"), server.Profile.ProfileName, server.Runtime.StatusString));
|
||||
continue;
|
||||
}
|
||||
|
||||
_currentProfileCommands.Add(server.Profile.ProfileID, CommandType.Backup);
|
||||
profileList.Add(ServerProfileSnapshot.Create(server.Profile));
|
||||
}
|
||||
|
||||
CancellationTokenSource = new CancellationTokenSource();
|
||||
var token = CancellationTokenSource.Token;
|
||||
var tasks = new List<Task>();
|
||||
|
||||
foreach (var profile in profileList)
|
||||
{
|
||||
var app = new ServerApp(true)
|
||||
{
|
||||
DeleteOldBackupFiles = !Config.Default.AutoBackup_EnableBackup,
|
||||
OutputLogs = false,
|
||||
SendAlerts = true,
|
||||
SendEmails = false,
|
||||
ServerProcess = ServerProcessType.Backup,
|
||||
ServerStatusChangeCallback = (ServerStatus serverStatus) =>
|
||||
{
|
||||
TaskUtils.RunOnUIThreadAsync(() =>
|
||||
{
|
||||
var server = ServerManager.Instance.Servers.FirstOrDefault(s => string.Equals(profile.ProfileId, s.Profile.ProfileID, StringComparison.OrdinalIgnoreCase));
|
||||
if (server != null)
|
||||
{
|
||||
server.Runtime.UpdateServerStatus(serverStatus, serverStatus != ServerStatus.Unknown);
|
||||
}
|
||||
}).Wait(token);
|
||||
}
|
||||
};
|
||||
|
||||
var task = Task.Run(() =>
|
||||
{
|
||||
app.PerformProfileBackup(profile, token);
|
||||
_currentProfileCommands.Remove(profile.ProfileId);
|
||||
}, token);
|
||||
|
||||
tasks.Add(task);
|
||||
|
||||
AddMessageBlockContent(string.Format(_globalizer.GetResourceString("DiscordBot_BackupRequested"), profile.ServerName));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
await Task.WhenAll(tasks);
|
||||
}
|
||||
catch { }
|
||||
finally
|
||||
{
|
||||
CancellationTokenSource?.Dispose();
|
||||
CancellationTokenSource = null;
|
||||
}
|
||||
}
|
||||
|
||||
private async void RestartServers_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (CancellationTokenSource != null)
|
||||
return;
|
||||
|
||||
var serverList = ServerManager.Servers.Where(s => s.Selected);
|
||||
if (serverList.IsEmpty())
|
||||
{
|
||||
MessageBox.Show(_globalizer.GetResourceString("ServerMonitor_NoServersSelected_ErrorLabel"), _globalizer.GetResourceString("ServerMonitor_NoServersSelected_ErrorTitle"), MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
var result = MessageBox.Show(_globalizer.GetResourceString("ServerMonitor_RestartServers_ConfirmLabel"), _globalizer.GetResourceString("ServerMonitor_RestartServers_ConfirmTitle"), MessageBoxButton.YesNo, MessageBoxImage.Question);
|
||||
if (result != MessageBoxResult.Yes)
|
||||
return;
|
||||
|
||||
ClearBlockContents();
|
||||
|
||||
var profileList = new List<ServerProfileSnapshot>();
|
||||
|
||||
foreach (var server in serverList)
|
||||
{
|
||||
// check if another command is being run against the profile
|
||||
if (_currentProfileCommands.ContainsKey(server.Profile.ProfileID))
|
||||
{
|
||||
AddErrorBlockContent(string.Format(_globalizer.GetResourceString("DiscordBot_CommandRunningProfile"), _currentProfileCommands[server.Profile.ProfileID], server.Profile.ProfileName));
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (server.Runtime.Status)
|
||||
{
|
||||
case ServerStatus.Initializing:
|
||||
case ServerStatus.Stopping:
|
||||
case ServerStatus.Uninstalled:
|
||||
case ServerStatus.Unknown:
|
||||
AddErrorBlockContent(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileBadStatus"), server.Profile.ProfileName, server.Runtime.StatusString));
|
||||
continue;
|
||||
|
||||
case ServerStatus.Updating:
|
||||
AddErrorBlockContent(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileUpdating"), server.Profile.ProfileName));
|
||||
continue;
|
||||
}
|
||||
|
||||
_currentProfileCommands.Add(server.Profile.ProfileID, CommandType.Restart);
|
||||
var profile = ServerProfileSnapshot.Create(server.Profile);
|
||||
profile.AutoRestartIfShutdown = true;
|
||||
profileList.Add(profile);
|
||||
}
|
||||
|
||||
CancellationTokenSource = new CancellationTokenSource();
|
||||
var token = CancellationTokenSource.Token;
|
||||
var tasks = new List<Task>();
|
||||
|
||||
foreach (var profile in profileList)
|
||||
{
|
||||
var app = new ServerApp(true)
|
||||
{
|
||||
DeleteOldBackupFiles = !Config.Default.AutoBackup_EnableBackup,
|
||||
OutputLogs = false,
|
||||
SendAlerts = true,
|
||||
SendEmails = false,
|
||||
ServerProcess = ServerProcessType.Restart,
|
||||
ServerStatusChangeCallback = (ServerStatus serverStatus) =>
|
||||
{
|
||||
TaskUtils.RunOnUIThreadAsync(() =>
|
||||
{
|
||||
var server = ServerManager.Instance.Servers.FirstOrDefault(s => string.Equals(profile.ProfileId, s.Profile.ProfileID, StringComparison.OrdinalIgnoreCase));
|
||||
if (server != null)
|
||||
{
|
||||
server.Runtime.UpdateServerStatus(serverStatus, serverStatus != ServerStatus.Unknown);
|
||||
}
|
||||
}).Wait(token);
|
||||
}
|
||||
};
|
||||
|
||||
var task = Task.Run(() =>
|
||||
{
|
||||
app.PerformProfileShutdown(profile, true, false, false, false, token);
|
||||
_currentProfileCommands.Remove(profile.ProfileId);
|
||||
}, token);
|
||||
|
||||
tasks.Add(task);
|
||||
|
||||
AddMessageBlockContent(string.Format(_globalizer.GetResourceString("DiscordBot_RestartRequested"), profile.ServerName));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
await Task.WhenAll(tasks);
|
||||
}
|
||||
catch { }
|
||||
finally
|
||||
{
|
||||
CancellationTokenSource?.Dispose();
|
||||
CancellationTokenSource = null;
|
||||
}
|
||||
}
|
||||
|
||||
private async void StartServers_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (CancellationTokenSource != null)
|
||||
return;
|
||||
|
||||
var serverList = ServerManager.Servers.Where(s => s.Selected);
|
||||
if (serverList.IsEmpty())
|
||||
{
|
||||
MessageBox.Show(_globalizer.GetResourceString("ServerMonitor_NoServersSelected_ErrorLabel"), _globalizer.GetResourceString("ServerMonitor_NoServersSelected_ErrorTitle"), MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
var result = MessageBox.Show(_globalizer.GetResourceString("ServerMonitor_StartServers_ConfirmLabel"), _globalizer.GetResourceString("ServerMonitor_StartServers_ConfirmTitle"), MessageBoxButton.YesNo, MessageBoxImage.Question);
|
||||
if (result != MessageBoxResult.Yes)
|
||||
return;
|
||||
|
||||
ClearBlockContents();
|
||||
|
||||
var profileList = new List<ServerProfileSnapshot>();
|
||||
|
||||
foreach (var server in serverList)
|
||||
{
|
||||
// check if another command is being run against the profile
|
||||
if (_currentProfileCommands.ContainsKey(server.Profile.ProfileID))
|
||||
{
|
||||
AddErrorBlockContent(string.Format(_globalizer.GetResourceString("DiscordBot_CommandRunningProfile"), _currentProfileCommands[server.Profile.ProfileID], server.Profile.ProfileName));
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (server.Runtime.Status)
|
||||
{
|
||||
case ServerStatus.Initializing:
|
||||
case ServerStatus.Stopping:
|
||||
case ServerStatus.Running:
|
||||
case ServerStatus.Uninstalled:
|
||||
case ServerStatus.Unknown:
|
||||
AddErrorBlockContent(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileBadStatus"), server.Profile.ProfileName, server.Runtime.StatusString));
|
||||
continue;
|
||||
|
||||
case ServerStatus.Updating:
|
||||
AddErrorBlockContent(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileUpdating"), server.Profile.ProfileName));
|
||||
continue;
|
||||
}
|
||||
|
||||
_currentProfileCommands.Add(server.Profile.ProfileID, CommandType.Start);
|
||||
var profile = ServerProfileSnapshot.Create(server.Profile);
|
||||
profile.AutoRestartIfShutdown = true;
|
||||
profileList.Add(profile);
|
||||
}
|
||||
|
||||
CancellationTokenSource = new CancellationTokenSource();
|
||||
var token = CancellationTokenSource.Token;
|
||||
var tasks = new List<Task>();
|
||||
|
||||
foreach (var profile in profileList)
|
||||
{
|
||||
var app = new ServerApp(true)
|
||||
{
|
||||
DeleteOldBackupFiles = !Config.Default.AutoBackup_EnableBackup,
|
||||
OutputLogs = false,
|
||||
SendAlerts = true,
|
||||
SendEmails = false,
|
||||
ServerProcess = ServerProcessType.Restart,
|
||||
ServerStatusChangeCallback = (ServerStatus serverStatus) =>
|
||||
{
|
||||
TaskUtils.RunOnUIThreadAsync(() =>
|
||||
{
|
||||
var server = ServerManager.Instance.Servers.FirstOrDefault(s => string.Equals(profile.ProfileId, s.Profile.ProfileID, StringComparison.OrdinalIgnoreCase));
|
||||
if (server != null)
|
||||
{
|
||||
server.Runtime.UpdateServerStatus(serverStatus, serverStatus != ServerStatus.Unknown);
|
||||
}
|
||||
}).Wait(token);
|
||||
}
|
||||
};
|
||||
|
||||
var task = Task.Run(() =>
|
||||
{
|
||||
app.PerformProfileShutdown(profile, true, false, false, false, token);
|
||||
_currentProfileCommands.Remove(profile.ProfileId);
|
||||
}, token);
|
||||
|
||||
tasks.Add(task);
|
||||
|
||||
AddMessageBlockContent(string.Format(_globalizer.GetResourceString("DiscordBot_StartRequested"), profile.ServerName));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
await Task.WhenAll(tasks);
|
||||
}
|
||||
catch { }
|
||||
finally
|
||||
{
|
||||
CancellationTokenSource?.Dispose();
|
||||
CancellationTokenSource = null;
|
||||
}
|
||||
}
|
||||
|
||||
private async void StopServers_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (CancellationTokenSource != null)
|
||||
return;
|
||||
|
||||
var serverList = ServerManager.Servers.Where(s => s.Selected);
|
||||
if (serverList.IsEmpty())
|
||||
{
|
||||
MessageBox.Show(_globalizer.GetResourceString("ServerMonitor_NoServersSelected_ErrorLabel"), _globalizer.GetResourceString("ServerMonitor_NoServersSelected_ErrorTitle"), MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
var result = MessageBox.Show(_globalizer.GetResourceString("ServerMonitor_StopServers_ConfirmLabel"), _globalizer.GetResourceString("ServerMonitor_StopServers_ConfirmTitle"), MessageBoxButton.YesNo, MessageBoxImage.Question);
|
||||
if (result != MessageBoxResult.Yes)
|
||||
return;
|
||||
|
||||
ClearBlockContents();
|
||||
|
||||
var profileList = new List<ServerProfileSnapshot>();
|
||||
|
||||
foreach (var server in serverList)
|
||||
{
|
||||
// check if another command is being run against the profile
|
||||
if (_currentProfileCommands.ContainsKey(server.Profile.ProfileID))
|
||||
{
|
||||
AddErrorBlockContent(string.Format(_globalizer.GetResourceString("DiscordBot_CommandRunningProfile"), _currentProfileCommands[server.Profile.ProfileID], server.Profile.ProfileName));
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (server.Runtime.Status)
|
||||
{
|
||||
case ServerStatus.Initializing:
|
||||
case ServerStatus.Stopping:
|
||||
case ServerStatus.Stopped:
|
||||
case ServerStatus.Uninstalled:
|
||||
case ServerStatus.Unknown:
|
||||
AddErrorBlockContent(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileBadStatus"), server.Profile.ProfileName, server.Runtime.StatusString));
|
||||
continue;
|
||||
|
||||
case ServerStatus.Updating:
|
||||
AddErrorBlockContent(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileUpdating"), server.Profile.ProfileName));
|
||||
continue;
|
||||
}
|
||||
|
||||
_currentProfileCommands.Add(server.Profile.ProfileID, CommandType.Stop);
|
||||
profileList.Add(ServerProfileSnapshot.Create(server.Profile));
|
||||
}
|
||||
|
||||
CancellationTokenSource = new CancellationTokenSource();
|
||||
var token = CancellationTokenSource.Token;
|
||||
var tasks = new List<Task>();
|
||||
|
||||
foreach (var profile in profileList)
|
||||
{
|
||||
var app = new ServerApp(true)
|
||||
{
|
||||
DeleteOldBackupFiles = !Config.Default.AutoBackup_EnableBackup,
|
||||
OutputLogs = false,
|
||||
SendAlerts = true,
|
||||
SendEmails = false,
|
||||
ServerProcess = ServerProcessType.Shutdown,
|
||||
ServerStatusChangeCallback = (ServerStatus serverStatus) =>
|
||||
{
|
||||
TaskUtils.RunOnUIThreadAsync(() =>
|
||||
{
|
||||
var server = ServerManager.Instance.Servers.FirstOrDefault(s => string.Equals(profile.ProfileId, s.Profile.ProfileID, StringComparison.OrdinalIgnoreCase));
|
||||
if (server != null)
|
||||
{
|
||||
server.Runtime.UpdateServerStatus(serverStatus, serverStatus != ServerStatus.Unknown);
|
||||
}
|
||||
}).Wait(token);
|
||||
}
|
||||
};
|
||||
|
||||
var task = Task.Run(() =>
|
||||
{
|
||||
app.PerformProfileShutdown(profile, false, false, false, false, token);
|
||||
_currentProfileCommands.Remove(profile.ProfileId);
|
||||
}, token);
|
||||
|
||||
tasks.Add(task);
|
||||
|
||||
AddMessageBlockContent(string.Format(_globalizer.GetResourceString("DiscordBot_ShutdownRequested"), profile.ServerName));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
await Task.WhenAll(tasks);
|
||||
}
|
||||
catch { }
|
||||
finally
|
||||
{
|
||||
CancellationTokenSource?.Dispose();
|
||||
CancellationTokenSource = null;
|
||||
}
|
||||
}
|
||||
|
||||
private async void UpdateServers_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (CancellationTokenSource != null)
|
||||
return;
|
||||
|
||||
var serverList = ServerManager.Servers.Where(s => s.Selected);
|
||||
if (serverList.IsEmpty())
|
||||
{
|
||||
MessageBox.Show(_globalizer.GetResourceString("ServerMonitor_NoServersSelected_ErrorLabel"), _globalizer.GetResourceString("ServerMonitor_NoServersSelected_ErrorTitle"), MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
var result = MessageBox.Show(_globalizer.GetResourceString("ServerMonitor_UpdateServers_ConfirmLabel"), _globalizer.GetResourceString("ServerMonitor_UpdateServers_ConfirmTitle"), MessageBoxButton.YesNo, MessageBoxImage.Question);
|
||||
if (result != MessageBoxResult.Yes)
|
||||
return;
|
||||
|
||||
ClearBlockContents();
|
||||
|
||||
var profileList = new List<ServerProfileSnapshot>();
|
||||
|
||||
foreach (var server in serverList)
|
||||
{
|
||||
var performRestart = false;
|
||||
|
||||
// check if another command is being run against the profile
|
||||
if (_currentProfileCommands.ContainsKey(server.Profile.ProfileID))
|
||||
{
|
||||
AddErrorBlockContent(string.Format(_globalizer.GetResourceString("DiscordBot_CommandRunningProfile"), _currentProfileCommands[server.Profile.ProfileID], server.Profile.ProfileName));
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (server.Runtime.Status)
|
||||
{
|
||||
case ServerStatus.Running:
|
||||
performRestart = true;
|
||||
break;
|
||||
|
||||
case ServerStatus.Initializing:
|
||||
case ServerStatus.Stopping:
|
||||
case ServerStatus.Unknown:
|
||||
AddErrorBlockContent(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileBadStatus"), server.Profile.ProfileName, server.Runtime.StatusString));
|
||||
continue;
|
||||
|
||||
case ServerStatus.Updating:
|
||||
AddErrorBlockContent(string.Format(_globalizer.GetResourceString("DiscordBot_ProfileUpdating"), server.Profile.ProfileName));
|
||||
continue;
|
||||
}
|
||||
|
||||
_currentProfileCommands.Add(server.Profile.ProfileID, CommandType.Update);
|
||||
var profile = ServerProfileSnapshot.Create(server.Profile);
|
||||
profile.RestartAfterShutdown1 = performRestart; // use this property to trigger a restart
|
||||
profileList.Add(profile);
|
||||
}
|
||||
|
||||
CancellationTokenSource = new CancellationTokenSource();
|
||||
var token = CancellationTokenSource.Token;
|
||||
var tasks = new List<Task>();
|
||||
|
||||
foreach (var profile in profileList)
|
||||
{
|
||||
var app = new ServerApp(true)
|
||||
{
|
||||
DeleteOldBackupFiles = !Config.Default.AutoBackup_EnableBackup,
|
||||
OutputLogs = false,
|
||||
SendAlerts = true,
|
||||
SendEmails = false,
|
||||
ServerProcess = ServerProcessType.Update,
|
||||
ServerStatusChangeCallback = (ServerStatus serverStatus) =>
|
||||
{
|
||||
TaskUtils.RunOnUIThreadAsync(() =>
|
||||
{
|
||||
var server = ServerManager.Instance.Servers.FirstOrDefault(s => string.Equals(profile.ProfileId, s.Profile.ProfileID, StringComparison.OrdinalIgnoreCase));
|
||||
if (server != null)
|
||||
{
|
||||
server.Runtime.UpdateServerStatus(serverStatus, serverStatus != ServerStatus.Unknown);
|
||||
}
|
||||
}).Wait(token);
|
||||
}
|
||||
};
|
||||
|
||||
var task = Task.Run(() =>
|
||||
{
|
||||
app.PerformProfileShutdown(profile, profile.RestartAfterShutdown1, true, false, false, token);
|
||||
_currentProfileCommands.Remove(profile.ProfileId);
|
||||
}, token);
|
||||
|
||||
tasks.Add(task);
|
||||
|
||||
AddMessageBlockContent(string.Format(_globalizer.GetResourceString("DiscordBot_UpdateRequested"), profile.ServerName));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
await Task.WhenAll(tasks);
|
||||
}
|
||||
catch { }
|
||||
finally
|
||||
{
|
||||
CancellationTokenSource?.Dispose();
|
||||
CancellationTokenSource = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void SelectAllServers_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
foreach (var server in ServerManager.Servers)
|
||||
{
|
||||
server.Selected = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void UnselectAllServers_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
foreach (var server in ServerManager.Servers)
|
||||
{
|
||||
server.Selected = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue