Skip to content

Commit

Permalink
Fix manager bugs when downloading the dashboard + Refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
SaifAqqad committed Jun 21, 2024
1 parent 579e0ab commit 1b4e9f0
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/AspireRunner.AspNetCore/AspireRunner.AspNetCore.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Version>1.1.4</Version>
<Version>1.1.5</Version>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<LangVersion>latest</LangVersion>

Expand Down
28 changes: 17 additions & 11 deletions src/AspireRunner.Core/AspireDashboardManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public async Task<bool> InitializeAsync()
return false;
}

_nugetPackageName = $"{AspireDashboard.SdkName}.{PlatformHelper.Rid}";
_nugetPackageName = $"{AspireDashboard.SdkName}.{PlatformHelper.Rid()}";
_runnerFolder = Path.Combine(_dotnetCli.DataPath, AspireDashboard.DataFolder);
if (!Directory.Exists(_runnerFolder))
{
Expand Down Expand Up @@ -169,15 +169,17 @@ public async Task TryUpdateAsync(Version[] installedRuntimes, Version? preferred
? installedRuntimes.Where(v => v.IsCompatibleWith(preferredVersion)).Max()
: installedRuntimes.Max();

var latestAvailableVersion = preferredVersion != null
? availableVersions.Where(preferredVersion.IsCompatibleWith).Max()
: availableVersions.Where(v => v.Major == latestRuntimeVersion!.Major).Max();

var latestAvailableVersion = availableVersions
.Where(preferredVersion != null ? preferredVersion.IsCompatibleWith : v => v.Major == latestRuntimeVersion!.Major)
.DefaultIfEmpty()
.Max()
?? availableVersions.First(); // Fallback to the latest version

if (latestAvailableVersion > latestInstalledVersion)
{
_logger.LogWarning("A newer version of the Aspire Dashboard is available, downloading version {Version}", latestAvailableVersion);

var newVersionFolder = Path.Combine(_runnerFolder, AspireDashboard.DownloadFolder, latestAvailableVersion!.ToString());
var newVersionFolder = Path.Combine(_runnerFolder, AspireDashboard.DownloadFolder, latestAvailableVersion.ToString());
var downloadSuccessful = await _nugetHelper.DownloadPackageAsync(_nugetPackageName, latestAvailableVersion, newVersionFolder);
if (downloadSuccessful)
{
Expand Down Expand Up @@ -243,16 +245,20 @@ public async Task TryUpdateAsync(Version[] installedRuntimes, Version? preferred
private async Task<Version> FetchLatestVersionAsync(Version[] installedRuntimes, Version? preferredVersion)
{
var availableVersions = await _nugetHelper.GetPackageVersionsAsync(_nugetPackageName);
if (availableVersions.Length == 0)
{
throw new ApplicationException("No versions of the Aspire Dashboard are available");
}

var latestRuntimeVersion = preferredVersion != null
? installedRuntimes.Where(v => v.IsCompatibleWith(preferredVersion)).Max()
: installedRuntimes.Max();

var versionToDownload = (
preferredVersion != null
? availableVersions.Where(preferredVersion.IsCompatibleWith).Max()
: availableVersions.Where(v => v.Major == latestRuntimeVersion!.Major).Max()
) ?? availableVersions.First(); // Fallback to the latest version
var versionToDownload = availableVersions
.Where(preferredVersion != null ? preferredVersion.IsCompatibleWith : v => v.Major == latestRuntimeVersion!.Major)
.DefaultIfEmpty()
.Max()
?? availableVersions.First(); // Fallback to the latest version

return versionToDownload;
}
Expand Down
2 changes: 1 addition & 1 deletion src/AspireRunner.Core/AspireRunner.Core.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Version>1.1.4</Version>
<Version>1.1.5</Version>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<RuntimeIdentifiers>win;osx;linux</RuntimeIdentifiers>
<langversion>latest</langversion>
Expand Down
2 changes: 1 addition & 1 deletion src/AspireRunner.Core/Helpers/PlatformHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public static bool IsWsl()

if (OsIdentifier() is not "linux")
{
return false;
return (_isWsl = false).Value;
}

var command = Cli.Wrap("uname")
Expand Down
2 changes: 1 addition & 1 deletion src/AspireRunner.Tool/AspireRunner.Tool.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Version>1.1.4</Version>
<Version>1.1.5</Version>
<OutputType>Exe</OutputType>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<RuntimeIdentifiers>win;osx;linux</RuntimeIdentifiers>
Expand Down
26 changes: 17 additions & 9 deletions src/AspireRunner.Tool/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,23 @@ The Aspire Dashboard is not installed.
return ReturnCodes.AspireInstallationError;
}

var aspireDashboard = await aspireDashboardManager.GetDashboardAsync(dashboardOptions, new ConsoleLogger<AspireDashboard>(arguments.Verbose));
aspireDashboard.DashboardStarted += url => logger.LogInformation(Green("The Aspire Dashboard is ready at {Url}"), url);
try
{
var aspireDashboard = await aspireDashboardManager.GetDashboardAsync(dashboardOptions, new ConsoleLogger<AspireDashboard>(arguments.Verbose));
aspireDashboard.DashboardStarted += url => logger.LogInformation(Green("The Aspire Dashboard is ready at {Url}"), url);

var stopHandler = (PosixSignalContext _) => aspireDashboard.Stop();
using var sigInt = PosixSignalRegistration.Create(PosixSignal.SIGINT, stopHandler);
using var sigTerm = PosixSignalRegistration.Create(PosixSignal.SIGTERM, stopHandler);
var stopHandler = (PosixSignalContext _) => aspireDashboard.Stop();
using var sigInt = PosixSignalRegistration.Create(PosixSignal.SIGINT, stopHandler);
using var sigTerm = PosixSignalRegistration.Create(PosixSignal.SIGTERM, stopHandler);

aspireDashboard.Start();
await aspireDashboard.WaitForExitAsync();
aspireDashboard.Start();
await aspireDashboard.WaitForExitAsync();

logger.LogDebug("Aspire Dashboard exited, Errors = {HasErrors}", aspireDashboard.HasErrors);
return aspireDashboard.HasErrors ? ReturnCodes.AspireDashboardError : ReturnCodes.Success;
logger.LogDebug("Aspire Dashboard exited, Errors = {HasErrors}", aspireDashboard.HasErrors);
return aspireDashboard.HasErrors ? ReturnCodes.AspireDashboardError : ReturnCodes.Success;
}
catch (Exception e)
{
logger.LogError("An error occurred while starting the Aspire Dashboard, {Error}", e.Message);
return ReturnCodes.AspireDashboardError;
}

0 comments on commit 1b4e9f0

Please sign in to comment.