| | 1 | | using System.Text.Json; |
| | 2 | | using Dotnet.Installer.Core.Services.Contracts; |
| | 3 | | using Dotnet.Installer.Core.Types; |
| | 4 | |
|
| | 5 | | namespace Dotnet.Installer.Core.Services.Implementations; |
| | 6 | |
|
| | 7 | | public class LimitsService : ILimitsService |
| | 8 | | { |
| 2 | 9 | | public DotnetVersion Runtime { get; } |
| 4 | 10 | | public IEnumerable<DotnetVersion> Sdk { get; } |
| | 11 | |
|
| 5 | 12 | | public LimitsService(IFileService fileService) |
| 5 | 13 | | { |
| | 14 | | // Read limits file |
| 5 | 15 | | var limitsFilePath = Environment.GetEnvironmentVariable("LIMITS_PATH") ?? string.Empty; |
| | 16 | |
|
| 5 | 17 | | if (!fileService.FileExists(limitsFilePath)) throw new ApplicationException("Limits file could not be found."); |
| | 18 | |
|
| 5 | 19 | | using var fs = fileService.OpenRead(limitsFilePath); |
| 5 | 20 | | var limits = JsonDocument.Parse(fs); |
| | 21 | |
|
| 4 | 22 | | Runtime = limits.RootElement.GetProperty("runtime").Deserialize<DotnetVersion>()!; |
| 3 | 23 | | Sdk = limits.RootElement.GetProperty("sdk").Deserialize<IEnumerable<DotnetVersion>>()!; |
| | 24 | |
|
| | 25 | | // Max out the revision to avoid installations failing when a new revision |
| | 26 | | // comes out and the comparison between e.g. 8.0.101+1 <= 8.0.101 fails |
| | 27 | | // when assessing whether that specific version can be installed with |
| | 28 | | // the current host. |
| 1 | 29 | | Runtime.Revision = int.MaxValue; |
| 7 | 30 | | foreach (var sdkVersion in Sdk) |
| 2 | 31 | | { |
| 2 | 32 | | sdkVersion.Revision = int.MaxValue; |
| 2 | 33 | | } |
| 2 | 34 | | } |
| | 35 | | } |