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

Maintenance #13

Merged
merged 9 commits into from
Nov 11, 2023
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<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.105" PrivateAssets="All" />
<PackageReference Include="Meziantou.Analyzer" Version="2.0.106" 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.12.0.78982" PrivateAssets="All" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
global using System.Diagnostics.CodeAnalysis;
global using System.Runtime.CompilerServices;
global using System.Runtime.Versioning;
global using System.ServiceProcess;
global using System.ServiceProcess;

global using Atc.Helpers;
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ bool StopApplication(
FileInfo applicationFile,
ushort timeoutInSeconds = 60);

bool StartApplication(
string applicationName,
ushort timeoutInSeconds = 60);

bool StartApplication(
FileInfo applicationFile,
ushort timeoutInSeconds = 60);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ public async Task<bool> StopService(
try
{
var services = ServiceController.GetServices();
var service =
services.FirstOrDefault(x => x.ServiceName.Equals(serviceName, StringComparison.OrdinalIgnoreCase));
var service = services.FirstOrDefault(x => x.ServiceName.Equals(serviceName, StringComparison.OrdinalIgnoreCase));

if (service is null ||
service.Status != ServiceControllerStatus.Running)
{
Expand Down Expand Up @@ -93,8 +93,8 @@ public async Task<bool> StartService(
try
{
var services = ServiceController.GetServices();
var service =
services.FirstOrDefault(x => x.ServiceName.Equals(serviceName, StringComparison.OrdinalIgnoreCase));
var service = services.FirstOrDefault(x => x.ServiceName.Equals(serviceName, StringComparison.OrdinalIgnoreCase));

if (service is null ||
service.Status != ServiceControllerStatus.Stopped)
{
Expand Down Expand Up @@ -195,23 +195,6 @@ public bool StopApplication(
return StopApplication(applicationName, timeoutInSeconds);
}

public bool StartApplication(
string applicationName,
ushort timeoutInSeconds = 60)
{
ArgumentException.ThrowIfNullOrEmpty(applicationName);

try
{
Process.Start(applicationName);
return true;
}
catch
{
return false;
}
}

public bool StartApplication(
FileInfo applicationFile,
ushort timeoutInSeconds = 60)
Expand All @@ -220,7 +203,7 @@ public bool StartApplication(

try
{
Process.Start(applicationFile.FullName);
ProcessHelper.Execute(applicationFile.Directory!, applicationFile, string.Empty);
return true;
}
catch
Expand Down
6 changes: 3 additions & 3 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.12.0")]
[assembly: AssemblyInformationalVersion("1.0.12.0")]
[assembly: AssemblyFileVersion("1.0.12.0")]
[assembly: AssemblyVersion("1.0.14.0")]
[assembly: AssemblyInformationalVersion("1.0.14.0")]
[assembly: AssemblyFileVersion("1.0.14.0")]
[assembly: System.Resources.NeutralResourcesLanguage("en")]
[assembly: System.Runtime.Versioning.TargetPlatform("Windows7.0")]
[assembly: System.Runtime.Versioning.SupportedOSPlatform("Windows7.0")]
10 changes: 5 additions & 5 deletions src/Atc.Installer.Wpf.App/Atc.Installer.Wpf.App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,17 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Atc.Wpf" Version="2.0.290" />
<PackageReference Include="Atc.Wpf.Controls" Version="2.0.290" />
<PackageReference Include="Atc.Wpf.FontIcons" Version="2.0.290" />
<PackageReference Include="Atc.Wpf.Theming" Version="2.0.290" />
<PackageReference Include="Atc.Wpf" Version="2.0.297" />
<PackageReference Include="Atc.Wpf.Controls" Version="2.0.297" />
<PackageReference Include="Atc.Wpf.FontIcons" Version="2.0.297" />
<PackageReference Include="Atc.Wpf.Theming" Version="2.0.297" />
<PackageReference Include="ClosedXML" Version="0.104.0-preview2" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0-rc.2.23479.6" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0-rc.2.23479.6" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0-rc.2.23479.6" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.0-rc.2.23479.6" />
<PackageReference Include="Microsoft.Extensions.Options.DataAnnotations" Version="8.0.0-rc.2.23479.6" />
<PackageReference Include="Serilog" Version="3.1.0-dev-02086" />
<PackageReference Include="Serilog" Version="3.1.1" />
<PackageReference Include="Serilog.Exceptions" Version="8.4.0" />
<PackageReference Include="Serilog.Extensions.Hosting" Version="7.0.0" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.1-dev-00968" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Atc.Wpf" Version="2.0.290" />
<PackageReference Include="Atc.Wpf.Controls" Version="2.0.290" />
<PackageReference Include="Atc.Wpf.FontIcons" Version="2.0.290" />
<PackageReference Include="Atc.Wpf.Theming" Version="2.0.290" />
<PackageReference Include="Atc.Wpf" Version="2.0.297" />
<PackageReference Include="Atc.Wpf.Controls" Version="2.0.297" />
<PackageReference Include="Atc.Wpf.FontIcons" Version="2.0.297" />
<PackageReference Include="Atc.Wpf.Theming" Version="2.0.297" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Atc.Wpf" Version="2.0.290" />
<PackageReference Include="Atc.Wpf.Controls" Version="2.0.290" />
<PackageReference Include="Atc.Wpf.FontIcons" Version="2.0.290" />
<PackageReference Include="Atc.Wpf.Theming" Version="2.0.290" />
<PackageReference Include="Atc.Wpf" Version="2.0.297" />
<PackageReference Include="Atc.Wpf.Controls" Version="2.0.297" />
<PackageReference Include="Atc.Wpf.FontIcons" Version="2.0.297" />
<PackageReference Include="Atc.Wpf.Theming" Version="2.0.297" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,7 @@
IsEnabled="{Binding Path=EnableEditingMode}"
Spacing="10">
<Button
Width="70"
Background="Transparent"
BorderBrush="Transparent"
BorderThickness="0"
Width="60"
Command="{Binding Path=EditX509CertificateCommand}"
CommandParameter="{Binding}"
ToolTip="Edit">
Expand All @@ -124,10 +121,7 @@
</StackPanel>
</Button>
<Button
Width="70"
Background="Transparent"
BorderBrush="Transparent"
BorderThickness="0"
Width="60"
Command="{Binding Path=NewX509CertificateCommand}"
CommandParameter="{Binding}"
ToolTip="New">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ private async Task ServiceDeployAndStart(
return;
}

IsBusy = true;
await SetIsBusy(value: true, delayInMs: 500).ConfigureAwait(true);

AddLogItem(LogLevel.Trace, "Deploy");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Atc.Wpf" Version="2.0.290" />
<PackageReference Include="Atc.Wpf.Controls" Version="2.0.290" />
<PackageReference Include="Atc.Wpf.FontIcons" Version="2.0.290" />
<PackageReference Include="Atc.Wpf.Theming" Version="2.0.290" />
<PackageReference Include="Atc.Wpf" Version="2.0.297" />
<PackageReference Include="Atc.Wpf.Controls" Version="2.0.297" />
<PackageReference Include="Atc.Wpf.FontIcons" Version="2.0.297" />
<PackageReference Include="Atc.Wpf.Theming" Version="2.0.297" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Atc.Wpf" Version="2.0.290" />
<PackageReference Include="Atc.Wpf.Controls" Version="2.0.290" />
<PackageReference Include="Atc.Wpf.FontIcons" Version="2.0.290" />
<PackageReference Include="Atc.Wpf.Theming" Version="2.0.290" />
<PackageReference Include="Atc.Wpf" Version="2.0.297" />
<PackageReference Include="Atc.Wpf.Controls" Version="2.0.297" />
<PackageReference Include="Atc.Wpf.FontIcons" Version="2.0.297" />
<PackageReference Include="Atc.Wpf.Theming" Version="2.0.297" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,19 @@ public override void CheckServiceState()
{
base.CheckServiceState();

RunningState = IsWindowsService
? waInstallerService.GetServiceState(ServiceName!)
: waInstallerService.GetApplicationState(Name);
if (IsWindowsService)
{
RunningState = waInstallerService.GetServiceState(ServiceName!);
}
else
{
RunningState = waInstallerService.GetApplicationState(Name);
if (RunningState == ComponentRunningState.NotAvailable &&
InstallationState is ComponentInstallationState.Installed or ComponentInstallationState.InstalledWithOldVersion)
{
RunningState = ComponentRunningState.Stopped;
}
}

if (RunningState is ComponentRunningState.Unknown or ComponentRunningState.Checking)
{
Expand Down Expand Up @@ -77,7 +87,8 @@ public override async Task ServiceStopCommandHandler()
.StopService(ServiceName!)
.ConfigureAwait(true);

if (isStopped)
if (isStopped ||
waInstallerService.GetServiceState(ServiceName!) == ComponentRunningState.Stopped)
{
RunningState = ComponentRunningState.Stopped;
LogAndSendToastNotificationMessage(
Expand Down Expand Up @@ -159,7 +170,7 @@ public override async Task ServiceStartCommandHandler()
else
{
var isStarted = waInstallerService
.StartApplication(InstalledMainFilePath!.GetValueAsString());
.StartApplication(new FileInfo(InstalledMainFilePath!.GetValueAsString()));

if (isStarted)
{
Expand Down Expand Up @@ -559,7 +570,7 @@ private async Task ServiceDeployAndStart(
return;
}

IsBusy = true;
await SetIsBusy(value: true, delayInMs: 500).ConfigureAwait(true);

AddLogItem(LogLevel.Trace, "Deploy");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@

<ItemGroup>
<PackageReference Include="Atc" Version="2.0.386" />
<PackageReference Include="Atc.Wpf" Version="2.0.290" />
<PackageReference Include="Atc.Wpf.Controls" Version="2.0.290" />
<PackageReference Include="Atc.Wpf.FontIcons" Version="2.0.290" />
<PackageReference Include="Atc.Wpf.Theming" Version="2.0.290" />
<PackageReference Include="Atc.Wpf" Version="2.0.297" />
<PackageReference Include="Atc.Wpf.Controls" Version="2.0.297" />
<PackageReference Include="Atc.Wpf.FontIcons" Version="2.0.297" />
<PackageReference Include="Atc.Wpf.Theming" Version="2.0.297" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,8 @@ private string AdjustInstalledMainFilePathIfNeededAndGetInstallationMainPath()
"wwwroot",
"_framework");
}

return tmpInstalledMainFilePath;
}

return UnpackedZipFolderPath;
Expand Down Expand Up @@ -992,25 +994,19 @@ private void WorkOnAnalyzeAndUpdateStatesForDotNetVersion()
return;
}

var installationMainPath = AdjustInstalledMainFilePathIfNeededAndGetInstallationMainPath();

var installationMainFile = Path.Combine(installationMainPath, $"{Name}.exe");
if (!File.Exists(installationMainFile))
{
installationMainFile = Path.Combine(installationMainPath, $"{Name}.dll");
}

var resolvedInstalledMainFilePath = InstalledMainFilePath.GetValueAsString();
if (!File.Exists(resolvedInstalledMainFilePath))
{
InstallationState = ComponentInstallationState.NotInstalled;
}

if (File.Exists(installationMainFile) &&
var installationMainFilePath = GetInstallationMainFilePath();

if (installationMainFilePath is not null &&
File.Exists(resolvedInstalledMainFilePath))
{
Version? sourceVersion = null;
var installationMainFileVersion = FileVersionInfo.GetVersionInfo(installationMainFile);
var installationMainFileVersion = FileVersionInfo.GetVersionInfo(installationMainFilePath);
if (installationMainFileVersion?.FileVersion != null)
{
sourceVersion = new Version(installationMainFileVersion.FileVersion);
Expand All @@ -1027,7 +1023,7 @@ private void WorkOnAnalyzeAndUpdateStatesForDotNetVersion()

if (VersionHelper.IsDefault(sourceVersion, destinationVersion))
{
var sourcePath = new DirectoryInfo(installationMainFile).Parent!;
var sourcePath = new DirectoryInfo(installationMainFilePath).Parent!;
var destinationPath = new DirectoryInfo(resolvedInstalledMainFilePath).Parent!;
if (sourcePath.GetTotalFilesLength("*.dll") != destinationPath.GetTotalFilesLength("*.dll"))
{
Expand Down Expand Up @@ -1097,4 +1093,21 @@ private void WorkOnAnalyzeAndUpdateStatesForNodeJsVersion()
}
}
}

private string? GetInstallationMainFilePath()
{
var installationMainPath = AdjustInstalledMainFilePathIfNeededAndGetInstallationMainPath();
var installationMainFile = installationMainPath.EndsWith(".dll", StringComparison.OrdinalIgnoreCase)
? installationMainPath
: Path.Combine(installationMainPath, $"{Name}.exe");

if (!File.Exists(installationMainFile))
{
installationMainFile = Path.Combine(installationMainPath, $"{Name}.dll");
}

return File.Exists(installationMainFile)
? installationMainFile
: null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,6 @@ namespace Atc.Installer.Integration.WindowsApplication.Tests;
[Trait(Traits.Category, Traits.Categories.SkipWhenLiveUnitTesting)]
public class WindowsApplicationInstallerServiceTests
{
[Fact]
public void StopAndStartApplicationFlow_ApplicationName()
{
var iaInstallerService = new InstalledAppsInstallerService();
var sut = new WindowsApplicationInstallerService(iaInstallerService);

const string applicationName = "notepad";

var runningState = sut.GetApplicationState(applicationName);
Assert.Equal(ComponentRunningState.NotAvailable, runningState);

var isStarted = sut.StartApplication(applicationName);
Assert.True(isStarted);

Thread.Sleep(1_000);

runningState = sut.GetApplicationState(applicationName);
Assert.Equal(ComponentRunningState.Running, runningState);

var isStopped = sut.StopApplication(applicationName);
Assert.True(isStopped);
}

[Fact]
public void StopAndStartApplicationFlow_ApplicationFile()
{
Expand Down
Loading