Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/maintenance #24

Merged
merged 6 commits into from
May 27, 2024
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
7 changes: 5 additions & 2 deletions .github/workflows/post-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@ jobs:
with:
setAllVars: true

- name: ⚙️ Setup dotnet 8.0.x
- name: ⚙️ Setup dotnet 8.0.1xx
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
dotnet-version: '8.0.1xx'

- name: 📐 Clear NuGet Cache
run: dotnet nuget locals all --clear

- name: ⚙️ Set up JDK 17
uses: actions/setup-java@v3
Expand Down
11 changes: 7 additions & 4 deletions .github/workflows/pre-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ jobs:
with:
fetch-depth: 0

- name: ⚙️ Setup dotnet 8.0.x
- name: ⚙️ Setup dotnet 8.0.1xx
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
dotnet-version: '8.0.1xx'

- name: 📐 Clear NuGet Cache
run: dotnet nuget locals all --clear

- name: 📐 Ensure nuget.org added as package source on Windows
run: dotnet nuget add source https://api.nuget.org/v3/index.json -n nuget.org --configfile $env:APPDATA\NuGet\NuGet.Config
Expand All @@ -46,10 +49,10 @@ jobs:
# with:
# fetch-depth: 0

# - name: ⚙️ Setup dotnet 8.0.x
# - name: ⚙️ Setup dotnet 8.0.1xx
# uses: actions/setup-dotnet@v4
# with:
# dotnet-version: '8.0.x'
# dotnet-version: '8.0.1xx'

# - name: 📐 Ensure nuget.org added as package source on Windows
# run: dotnet nuget add source https://api.nuget.org/v3/index.json -n nuget.org --configfile $env:APPDATA\NuGet\NuGet.Config
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ jobs:
with:
setAllVars: true

- name: ⚙️ Setup dotnet 8.0.x
- name: ⚙️ Setup dotnet 8.0.1xx
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
dotnet-version: '8.0.1xx'

- name: 📐 Ensure nuget.org added as package source on Windows
run: dotnet nuget add source https://api.nuget.org/v3/index.json -n nuget.org --configfile $env:APPDATA\NuGet\NuGet.Config
Expand Down
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@
<ItemGroup Label="Code Analyzers">
<PackageReference Include="AsyncFixer" Version="1.6.0" PrivateAssets="All" />
<PackageReference Include="Asyncify" Version="0.9.7" PrivateAssets="All" />
<PackageReference Include="Meziantou.Analyzer" Version="2.0.150" PrivateAssets="All" />
<PackageReference Include="Meziantou.Analyzer" Version="2.0.153" PrivateAssets="All" />
<PackageReference Include="SecurityCodeScan.VS2019" Version="5.6.7" PrivateAssets="All" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.507" PrivateAssets="All" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="9.24.0.89429" PrivateAssets="All" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="9.25.1.91650" PrivateAssets="All" />
</ItemGroup>

</Project>
5 changes: 5 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"sdk": {
"version": "8.0.100"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

<ItemGroup>
<PackageReference Include="Atc" Version="2.0.472" />
<PackageReference Include="Azure.Identity" Version="1.11.2" />
<PackageReference Include="Azure.Storage.Blobs" Version="12.19.1" />
<PackageReference Include="Azure.Identity" Version="1.11.3" />
<PackageReference Include="Azure.Storage.Blobs" Version="12.20.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Npgsql" Version="8.0.2" />
<PackageReference Include="Npgsql" Version="8.0.3" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/Atc.Installer.Wpf.App/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public static JsonSerializerOptions JsonSerializerOptions

public App()
{
RestoreInstallerCustomAppSettingsIfNeeded();

host = Host.CreateDefaultBuilder()
.ConfigureLogging((_, logging) =>
{
Expand Down Expand Up @@ -66,8 +68,6 @@ public App()

EnsureInstallerDirectoriesIsCreated();

RestoreInstallerCustomAppSettingsIfNeeded();

TaskHelper.RunSync(UpdateProjectsInstallerFilesIfNeeded);
}

Expand Down
10 changes: 5 additions & 5 deletions src/Atc.Installer.Wpf.App/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
[assembly: AssemblyCompany("atc-net")]
[assembly: AssemblyProduct("Atc.Installer")]
[assembly: AssemblyTitle("Atc.Installer")]
[assembly: AssemblyVersion("1.0.22.0")]
[assembly: AssemblyInformationalVersion("1.0.22.0")]
[assembly: AssemblyFileVersion("1.0.22.0")]
[assembly: AssemblyVersion("1.0.23.0")]
[assembly: AssemblyInformationalVersion("1.0.23.0")]
[assembly: AssemblyFileVersion("1.0.23.0")]
[assembly: System.Resources.NeutralResourcesLanguage("en")]
[assembly: System.Runtime.Versioning.TargetPlatform("Windows7.0")]
[assembly: System.Runtime.Versioning.SupportedOSPlatform("Windows7.0")]
[assembly: System.Runtime.Versioning.TargetPlatform("Windows8.0")]
[assembly: System.Runtime.Versioning.SupportedOSPlatform("Windows8.0")]
44 changes: 44 additions & 0 deletions src/Atc.Installer.Wpf.App/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public partial class MainWindowViewModel : MainWindowViewModelBase, IMainWindowV
private readonly IAzureStorageAccountInstallerService azureStorageAccountInstallerService;
private readonly ICheckForUpdatesBoxDialogViewModel checkForUpdatesBoxDialogViewModel;
private readonly ToastNotificationManager notificationManager = new();
private DateTime lastUserActionTimestamp = DateTime.Now;
private string? newVersionIsAvailable;
private AzureOptionsViewModel? azureOptions;
private ApplicationOptionsViewModel applicationOptions = new();
Expand Down Expand Up @@ -131,6 +132,7 @@ public MainWindowViewModel(

LoadRecentOpenFiles();

Messenger.Default.Register<UpdateUserActionTimestampMessage>(this, HandleUpdateUserActionTimestampMessage);
Messenger.Default.Register<ToastNotificationMessage>(this, HandleToastNotificationMessage);
Messenger.Default.Register<RefreshSelectedComponentProviderMessage>(this, HandleRefreshSelectedComponentProviderMessage);
Messenger.Default.Register<UpdateDefaultApplicationSettingsMessage>(this, HandleUpdateDefaultApplicationSettingsMessage);
Expand All @@ -148,6 +150,12 @@ public MainWindowViewModel(
CancellationToken.None,
TaskCreationOptions.LongRunning,
TaskScheduler.Default);

Task.Factory.StartNew(
async () => await CheckInactivityAndShutdown().ConfigureAwait(false),
CancellationToken.None,
TaskCreationOptions.LongRunning,
TaskScheduler.Default);
}

public string? NewVersionIsAvailable
Expand Down Expand Up @@ -280,6 +288,12 @@ public string? ComponentProviderFilter
}
}

private void HandleUpdateUserActionTimestampMessage(
UpdateUserActionTimestampMessage obj)
{
lastUserActionTimestamp = DateTime.Now;
}

private void HandleToastNotificationMessage(
ToastNotificationMessage obj)
{
Expand Down Expand Up @@ -359,6 +373,36 @@ private async Task CheckForUpdates()
}
}

private async Task CheckInactivityAndShutdown()
{
while (true)
{
if (cancellationTokenSource is null)
{
continue;
}

if (cancellationTokenSource.Token.IsCancellationRequested)
{
break;
}

await Task
.Delay(TimeSpan.FromSeconds(30), cancellationTokenSource.Token)
.ConfigureAwait(false);

if (lastUserActionTimestamp.DateTimeDiff(
DateTime.Now,
DateTimeDiffCompareType.Minutes) <= 30)
{
continue;
}

logger.Log(LogLevel.Information, "Shutdown due to inactivity");
await Application.Current.Dispatcher.InvokeAsync(() => Application.Current.Shutdown());
}
}

[SuppressMessage("Blocker Bug", "S2930:\"IDisposables\" should be disposed", Justification = "OK.")]
private void StartMonitoringServices()
{
Expand Down
20 changes: 20 additions & 0 deletions src/Atc.Installer.Wpf.App/MainWindowViewModel_Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ public IRelayCommandAsync ServiceStartSelectedCommand

private async Task OpenConfigurationFileCommandHandler()
{
lastUserActionTimestamp = DateTime.Now;

var openFileDialog = new OpenFileDialog
{
InitialDirectory = App.InstallerProgramDataProjectsDirectory.FullName,
Expand All @@ -88,6 +90,8 @@ await LoadConfigurationFile(

private void OpenApplicationSettingsCommandHandler()
{
lastUserActionTimestamp = DateTime.Now;

var vm = new ApplicationSettingsDialogViewModel(ApplicationOptions);
var dialogResult = new ApplicationSettingsDialog(vm).ShowDialog();
if (!dialogResult.HasValue)
Expand Down Expand Up @@ -135,6 +139,8 @@ private bool CanDownloadInstallationFilesFromAzureStorageAccountCommandHandler()

private async Task DownloadInstallationFilesFromAzureStorageAccountCommandHandler()
{
lastUserActionTimestamp = DateTime.Now;

if (!CanDownloadInstallationFilesFromAzureStorageAccountCommandHandler())
{
return;
Expand Down Expand Up @@ -245,6 +251,8 @@ private bool CanReportingToExcelCommandHandler()

private async Task ReportingToExcelCommandHandler()
{
lastUserActionTimestamp = DateTime.Now;

if (!CanReportingToExcelCommandHandler())
{
return;
Expand Down Expand Up @@ -332,6 +340,8 @@ private void OpenApplicationCheckForUpdatesCommandHandler()

private void OpenApplicationAboutCommandHandler()
{
lastUserActionTimestamp = DateTime.Now;

// ReSharper disable once UseObjectOrCollectionInitializer
var aboutBoxDialog = new AboutBoxDialog();
aboutBoxDialog.IconImage.Source = ApplicationOptions.Icon ?? App.DefaultIcon;
Expand All @@ -343,6 +353,8 @@ private bool CanServiceStopSelectedCommandHandler()

private Task ServiceStopSelectedCommandHandler()
{
lastUserActionTimestamp = DateTime.Now;

var tasks = new List<Task>();
foreach (var vm in ComponentProviders)
{
Expand All @@ -360,6 +372,8 @@ private bool CanServiceDeploySelectedCommandHandler()

private Task ServiceDeploySelectedCommandHandler()
{
lastUserActionTimestamp = DateTime.Now;

var tasks = new List<Task>();
foreach (var vm in ComponentProviders)
{
Expand All @@ -377,6 +391,8 @@ private bool CanServiceRemoveSelectedCommandHandler()

private Task ServiceRemoveSelectedCommandHandler()
{
lastUserActionTimestamp = DateTime.Now;

var tasks = new List<Task>();
foreach (var vm in ComponentProviders)
{
Expand All @@ -394,6 +410,8 @@ private bool CanServiceStartSelectedCommandHandler()

private Task ServiceStartSelectedCommandHandler()
{
lastUserActionTimestamp = DateTime.Now;

var tasks = new List<Task>();
foreach (var vm in ComponentProviders)
{
Expand All @@ -408,6 +426,8 @@ private Task ServiceStartSelectedCommandHandler()

private void ApplicationExitCommandHandler()
{
lastUserActionTimestamp = DateTime.Now;

if (CanSaveConfigurationFileCommandHandler())
{
var dialogBox = new QuestionDialogBox(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ private bool CanTestConnectionCommandHandler()

private async Task TestConnectionCommandHandler()
{
Messenger.Default.Send(new UpdateUserActionTimestampMessage());

AddLogItem(LogLevel.Trace, "Test connection");

IsBusy = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
global using Atc.Installer.Integration.InstallationConfigurations;
global using Atc.Installer.Integration.WindowsApplication;
global using Atc.Installer.Wpf.ComponentProvider.ElasticSearch.Controls;
global using Atc.Installer.Wpf.ComponentProvider.Messages;
global using Atc.Installer.Wpf.ComponentProvider.ViewModels;
global using Atc.Wpf.Collections;
global using Atc.Wpf.Command;
global using Atc.Wpf.Controls.Notifications;
global using Atc.Wpf.Messaging;
global using Atc.Wpf.Mvvm;

global using Microsoft.Extensions.Logging;
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,8 @@ public override bool CanServiceStopCommandHandler()

public override async Task ServiceStopCommandHandler()
{
Messenger.Default.Send(new UpdateUserActionTimestampMessage());

if (!CanServiceStopCommandHandler())
{
return;
Expand Down Expand Up @@ -346,6 +348,8 @@ public override bool CanServiceStartCommandHandler()

public override async Task ServiceStartCommandHandler()
{
Messenger.Default.Send(new UpdateUserActionTimestampMessage());

if (!CanServiceStartCommandHandler())
{
return;
Expand Down Expand Up @@ -697,6 +701,8 @@ private void ApplyToRunningStateIssues(
private async Task ServiceDeployAndStart(
bool useAutoStart)
{
Messenger.Default.Send(new UpdateUserActionTimestampMessage());

if (!CanServiceDeployCommandHandler())
{
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
global using Atc.Installer.Integration.InstallationConfigurations;
global using Atc.Installer.Integration.PostgreSql;
global using Atc.Installer.Integration.WindowsApplication;
global using Atc.Installer.Wpf.ComponentProvider.Messages;
global using Atc.Installer.Wpf.ComponentProvider.PostgreSql.Controls;
global using Atc.Installer.Wpf.ComponentProvider.ViewModels;
global using Atc.Wpf.Collections;
global using Atc.Wpf.Command;
global using Atc.Wpf.Controls.Notifications;
global using Atc.Wpf.Messaging;
global using Atc.Wpf.Mvvm;

global using Microsoft.Extensions.Logging;
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ private bool CanTestConnectionCommandHandler()

private async Task TestConnectionCommandHandler()
{
Messenger.Default.Send(new UpdateUserActionTimestampMessage());

AddLogItem(LogLevel.Trace, "Test connection");

IsBusy = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
global using Atc.Installer.Integration;
global using Atc.Installer.Integration.InstallationConfigurations;
global using Atc.Installer.Integration.WindowsApplication;
global using Atc.Installer.Wpf.ComponentProvider.Messages;
global using Atc.Installer.Wpf.ComponentProvider.ViewModels;
global using Atc.Serialization;
global using Atc.Wpf.Collections;
global using Atc.Wpf.Controls.Notifications;
global using Atc.Wpf.Messaging;

global using Microsoft.Extensions.Logging;
Loading
Loading