Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/SiteMonitor/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ internal sealed class Program {
/// The logger.
/// </summary>
private static readonly ILog LOG = LogManager.GetLogger(typeof(Program));

// Initialization code. Don't use any Avalonia, third-party APIs or any
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
// yet and stuff might break.
Expand All @@ -25,13 +25,13 @@ public static void Main(string[] args) {
#else
XmlConfigurator.Configure(new FileInfo("log4net.config"));
#endif

LOG.Info("Started application");

AppDomain.CurrentDomain.UnhandledException += (_, exceptArgs) => {
LOG.Fatal("Unhandled exception", exceptArgs.ExceptionObject as Exception);
};

BuildAvaloniaApp()
.StartWithClassicDesktopLifetime(args);
}
Expand Down
27 changes: 14 additions & 13 deletions src/SiteMonitor/SiteMonitor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,28 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Avalonia" Version="11.3.6" />
<PackageReference Include="Avalonia.Desktop" Version="11.3.6" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.3.6" />
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.3.6" />
<PackageReference Include="Avalonia" Version="11.3.6"/>
<PackageReference Include="Avalonia.Desktop" Version="11.3.6"/>
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.3.6"/>
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.3.6"/>
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.3.1"/>
<PackageReference Include="Avalonia.ReactiveUI" Version="11.3.6" />
<PackageReference Include="Avalonia.ReactiveUI" Version="11.3.6"/>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\nullinside-api\src\Nullinside.Api.Common\Nullinside.Api.Common.csproj"/>
</ItemGroup>

<ItemGroup>
<None Remove="log4net.config" />
<Content Include="log4net.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<None Remove="log4net.debug.config" />
<Content Include="log4net.debug.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<None Remove="log4net.config"/>
<Content Include="log4net.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<None Remove="log4net.debug.config"/>
<Content Include="log4net.debug.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>
114 changes: 26 additions & 88 deletions src/SiteMonitor/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
using System.Net.NetworkInformation;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Input;

using Avalonia.Controls;

using ReactiveUI;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;

using Renci.SshNet;

Expand All @@ -20,26 +20,32 @@ namespace SiteMonitor.ViewModels;
/// <summary>
/// The view model for the main UI.
/// </summary>
public class MainWindowViewModel : ViewModelBase {
private bool _apiUp = true;
private string? _chatTimestamp;
private bool _isDisplayingAdvancedCommands;
private bool _isMinimized;
private bool _nullUp = true;
public partial class MainWindowViewModel : ViewModelBase {
[ObservableProperty] private bool _apiUp = true;

[ObservableProperty] private string? _chatTimestamp;

[ObservableProperty] private bool _isDisplayingAdvancedCommands;

[ObservableProperty] private bool _isMinimized;

[ObservableProperty] private bool _nullUp = true;

private string? _serverAddress;
private bool _serverUp = true;

[ObservableProperty] private bool _serverUp = true;

private string? _sshPassword;
private string? _sshUsername;
private bool _websiteUp = true;

[ObservableProperty] private bool _websiteUp = true;

private WindowState _windowState;

/// <summary>
/// Initializes a new instance of the <see cref="MainWindowViewModel" /> class.
/// </summary>
public MainWindowViewModel() {
OnShowCommandsCommand = ReactiveCommand.Create(OnShowCommands);
OnRestartCommand = ReactiveCommand.Create(OnRestart);
OnRestartImagesCommand = ReactiveCommand.Create(OnRestartImages);
Task.Factory.StartNew(PingServer);
Task.Factory.StartNew(PingSite);
ServerAddress = Configuration.Instance.ServerAddress;
Expand All @@ -53,7 +59,7 @@ public MainWindowViewModel() {
public string? ServerAddress {
get => _serverAddress;
set {
this.RaiseAndSetIfChanged(ref _serverAddress, value);
SetProperty(ref _serverAddress, value);

try {
Configuration.Instance.ServerAddress = value;
Expand All @@ -63,86 +69,25 @@ public string? ServerAddress {
}
}

/// <summary>
/// The timestamp of the last chat message that was received.
/// </summary>
public string? ChatTimestamp {
get => _chatTimestamp;
set => this.RaiseAndSetIfChanged(ref _chatTimestamp, value);
}

/// <summary>
/// True if the server is online.
/// </summary>
public bool ServerUp {
get => _serverUp;
set => this.RaiseAndSetIfChanged(ref _serverUp, value);
}

/// <summary>
/// True if the website is returning a 200.
/// </summary>
public bool WebsiteUp {
get => _websiteUp;
set => this.RaiseAndSetIfChanged(ref _websiteUp, value);
}

/// <summary>
/// True if the API is online.
/// </summary>
public bool ApiUp {
get => _apiUp;
set => this.RaiseAndSetIfChanged(ref _apiUp, value);
}

/// <summary>
/// True if the null API is online.
/// </summary>
public bool NullUp {
get => _nullUp;
set => this.RaiseAndSetIfChanged(ref _nullUp, value);
}

/// <summary>
/// Sets the window to normal, minimized, maximized, etc.
/// </summary>
public WindowState WindowState {
get => _windowState;
set {
this.RaiseAndSetIfChanged(ref _windowState, value);
SetProperty(ref _windowState, value);
IsMinimized = _windowState == WindowState.Minimized;
}
}

/// <summary>
/// True if the application is minimized, false otherwise.
/// </summary>
public bool IsMinimized {
get => _isMinimized;
set => this.RaiseAndSetIfChanged(ref _isMinimized, value);
}

/// <summary>
/// Shows the commands in the UI.
/// </summary>
public ICommand OnShowCommandsCommand { get; set; }

/// <summary>
/// True if displaying advanced commands, false otherwise.
/// </summary>
public bool IsDisplayingAdvancedCommands {
get => _isDisplayingAdvancedCommands;
set => this.RaiseAndSetIfChanged(ref _isDisplayingAdvancedCommands, value);
}

/// <summary>
/// The username to use for the SSH session for commands.
/// </summary>
public string? SshUsername {
get => _sshUsername;
set {
Configuration.Instance.ServerUsername = value;
this.RaiseAndSetIfChanged(ref _sshUsername, value);
SetProperty(ref _sshUsername, value);
try {
Configuration.WriteConfiguration();
}
Expand All @@ -157,7 +102,7 @@ public string? SshPassword {
get => _sshPassword;
set {
Configuration.Instance.ServerPassword = value;
this.RaiseAndSetIfChanged(ref _sshPassword, value);
SetProperty(ref _sshPassword, value);
try {
Configuration.WriteConfiguration();
}
Expand All @@ -168,16 +113,7 @@ public string? SshPassword {
/// <summary>
/// Restarts the remote machine.
/// </summary>
public ICommand OnRestartCommand { get; set; }

/// <summary>
/// Restarts the remote docker images.
/// </summary>
public ICommand OnRestartImagesCommand { get; set; }

/// <summary>
/// Restarts the remote machine.
/// </summary>
[RelayCommand]
private async Task OnRestart() {
using SshClient client = new(_serverAddress!, _sshUsername!, _sshPassword!);
await client.ConnectAsync(CancellationToken.None).ConfigureAwait(false);
Expand All @@ -188,6 +124,7 @@ private async Task OnRestart() {
/// <summary>
/// Restarts the docker images.
/// </summary>
[RelayCommand]
private async Task OnRestartImages() {
await Task.Run(async () => {
using SshClient client = new(_serverAddress!, _sshUsername!, _sshPassword!);
Expand All @@ -208,6 +145,7 @@ await Task.Run(async () => {
/// <summary>
/// Handles showing the server commands.
/// </summary>
[RelayCommand]
private void OnShowCommands() {
IsDisplayingAdvancedCommands = true;
}
Expand Down
24 changes: 5 additions & 19 deletions src/SiteMonitor/ViewModels/NewVersionWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using Avalonia.Controls;
using Avalonia.Threading;

using CommunityToolkit.Mvvm.ComponentModel;

using Nullinside.Api.Common.Desktop;

using ReactiveUI;
Expand All @@ -16,11 +18,11 @@ namespace SiteMonitor.ViewModels;
/// <summary>
/// The view model for the <seealso cref="NewVersionWindow" /> class.
/// </summary>
public class NewVersionWindowViewModel : ViewModelBase {
public partial class NewVersionWindowViewModel : ViewModelBase {
/// <summary>
/// True if updating the application currently, false otherwise.
/// </summary>
private bool _isUpdating;
[ObservableProperty] private bool _isUpdating;

/// <summary>
/// The local version of the software.
Expand All @@ -35,7 +37,7 @@ public class NewVersionWindowViewModel : ViewModelBase {
/// <summary>
/// The version of the application on the GitHub server.
/// </summary>
private string? _serverVersion;
[ObservableProperty] private string? _serverVersion;

/// <summary>
/// Initializes a new instance of the <see cref="NewVersionWindowViewModel" /> class.
Expand Down Expand Up @@ -66,22 +68,6 @@ public string? LocalVersion {
set => _localVersion = value;
}

/// <summary>
/// The version of the software on the GitHub server.
/// </summary>
public string? ServerVersion {
get => _serverVersion;
set => this.RaiseAndSetIfChanged(ref _serverVersion, value);
}

/// <summary>
/// True if updating the application currently, false otherwise.
/// </summary>
public bool IsUpdating {
get => _isUpdating;
set => this.RaiseAndSetIfChanged(ref _isUpdating, value);
}

/// <summary>
/// A command to update the software.
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions src/SiteMonitor/ViewModels/ViewModelBase.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using ReactiveUI;
using CommunityToolkit.Mvvm.ComponentModel;

namespace SiteMonitor.ViewModels;

/// <summary>
/// A base class for all view models.
/// </summary>
public class ViewModelBase : ReactiveObject {
public class ViewModelBase : ObservableObject {
}
6 changes: 3 additions & 3 deletions src/SiteMonitor/Views/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<StackPanel Grid.Row="2">
<Button HorizontalAlignment="Right"
IsVisible="{Binding !IsDisplayingAdvancedCommands}"
Command="{Binding OnShowCommandsCommand}">
Command="{Binding ShowCommandsCommand}">
Show Advanced Commands
</Button>
<StackPanel IsVisible="{Binding IsDisplayingAdvancedCommands}">
Expand Down Expand Up @@ -81,11 +81,11 @@
</Grid>
<StackPanel Orientation="Horizontal">
<Button HorizontalAlignment="Right"
Command="{Binding OnRestartCommand}">
Command="{Binding RestartCommand}">
Restart Computer
</Button>
<Button HorizontalAlignment="Right"
Command="{Binding OnRestartImagesCommand}">
Command="{Binding RestartImagesCommand}">
Restart Services
</Button>
</StackPanel>
Expand Down
15 changes: 7 additions & 8 deletions src/SiteMonitor/Views/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
#if !DEBUG
using Avalonia.Threading;

using SiteMonitor.ViewModels;
#else
using Avalonia;
#endif
using System;
using System.Linq;
using System.Threading.Tasks;
Expand All @@ -8,14 +15,6 @@
using Microsoft.Extensions.DependencyInjection;

using Nullinside.Api.Common.Desktop;
#if !DEBUG
using Avalonia.Threading;

using SiteMonitor.ViewModels;

#else
using Avalonia;
#endif


namespace SiteMonitor.Views;
Expand Down