diff --git a/common/Models/ExtensionJsonData/DevHomeExtensionJsonData.cs b/common/Models/ExtensionJsonData/DevHomeExtensionContentData.cs similarity index 90% rename from common/Models/ExtensionJsonData/DevHomeExtensionJsonData.cs rename to common/Models/ExtensionJsonData/DevHomeExtensionContentData.cs index 74056ddb56..5b03b91829 100644 --- a/common/Models/ExtensionJsonData/DevHomeExtensionJsonData.cs +++ b/common/Models/ExtensionJsonData/DevHomeExtensionContentData.cs @@ -9,7 +9,7 @@ namespace DevHome.Common.Models.ExtensionJsonData; /// Root class that will contain the deserialized data located in the /// src\Assets\Schemas\ExtensionInformation.schema.json file. /// -public class DevHomeExtensionJsonData +public class DevHomeExtensionContentData { public List Products { get; set; } = new(); } diff --git a/common/Models/ExtensionJsonData/JsonSourceGenerationContext.cs b/common/Models/ExtensionJsonData/JsonSourceGenerationContext.cs index b0bf040b23..a93ad10e59 100644 --- a/common/Models/ExtensionJsonData/JsonSourceGenerationContext.cs +++ b/common/Models/ExtensionJsonData/JsonSourceGenerationContext.cs @@ -17,7 +17,7 @@ namespace DevHome.Common.Models.ExtensionJsonData; [JsonSerializable(typeof(ProviderSpecificProperty))] [JsonSerializable(typeof(Properties))] [JsonSerializable(typeof(Product))] -[JsonSerializable(typeof(DevHomeExtensionJsonData))] +[JsonSerializable(typeof(DevHomeExtensionContentData))] [JsonSerializable(typeof(DevHomeExtension))] [JsonSerializable(typeof(JsonSchema))] [JsonSerializable(typeof(EvaluationResults))] diff --git a/common/Services/IExtensionService.cs b/common/Services/IExtensionService.cs index 198b0df121..89368ff0e9 100644 --- a/common/Services/IExtensionService.cs +++ b/common/Services/IExtensionService.cs @@ -41,5 +41,5 @@ public interface IExtensionService /// Gets known extension information from internal extension json file. /// /// An object that holds a list of extension information based on the internal json file. - public Task GetExtensionJsonDataAsync(); + public Task GetExtensionJsonDataAsync(); } diff --git a/src/Assets/Schemas/ExtensionInformation.schema.json b/src/Assets/Schemas/ExtensionInformation.schema.json index e8539671be..60d28729f3 100644 --- a/src/Assets/Schemas/ExtensionInformation.schema.json +++ b/src/Assets/Schemas/ExtensionInformation.schema.json @@ -61,6 +61,7 @@ "required": [ "DisplayNameKey" ] }, "ProviderType": { + "$comment": "Enum values should be kept in sync with the provider type enum values located in the Dev Home SDK.", "type": "string", "enum": [ "ComputeSystem", diff --git a/src/Services/ExtensionService.cs b/src/Services/ExtensionService.cs index f7a9f3fe1a..e3fdeccb43 100644 --- a/src/Services/ExtensionService.cs +++ b/src/Services/ExtensionService.cs @@ -47,9 +47,9 @@ public class ExtensionService : IExtensionService, IDisposable private readonly IStringResource _stringResource; - private string? _localExtensionJsonSchemaAbsoluteFilePath; + private readonly Lazy _localExtensionJsonSchemaAbsoluteFilePath; - private string? _localExtensionJsonAbsoluteFilePath; + private readonly Lazy _localExtensionJsonAbsoluteFilePath; public ExtensionService(ILocalSettingsService settingsService, IStringResource stringResource) { @@ -58,6 +58,18 @@ public ExtensionService(ILocalSettingsService settingsService, IStringResource s _catalog.PackageUpdating += Catalog_PackageUpdating; _localSettingsService = settingsService; _stringResource = stringResource; + _localExtensionJsonSchemaAbsoluteFilePath = new Lazy(GetExtensionJsonSchemaAbsoluteFilePath); + _localExtensionJsonAbsoluteFilePath = new Lazy(GetExtensionJsonAbsoluteFilePath); + } + + private string GetExtensionJsonSchemaAbsoluteFilePath() + { + return Path.Combine(_localSettingsService.GetPathToPackageLocation(), LocalExtensionJsonSchemaRelativeFilePath); + } + + private string GetExtensionJsonAbsoluteFilePath() + { + return Path.Combine(_localSettingsService.GetPathToPackageLocation(), LocalExtensionJsonRelativeFilePath); } private void Catalog_PackageInstalling(PackageCatalog sender, PackageInstallingEventArgs args) @@ -415,18 +427,15 @@ public async Task DisableExtensionIfWindowsFeatureNotAvailable(IExtensionW return true; } - public async Task GetExtensionJsonDataAsync() + public async Task GetExtensionJsonDataAsync() { try { - _localExtensionJsonSchemaAbsoluteFilePath ??= Path.Combine(_localSettingsService.GetPathToPackageLocation(), LocalExtensionJsonRelativeFilePath); - _localExtensionJsonAbsoluteFilePath ??= Path.Combine(_localSettingsService.GetPathToPackageLocation(), LocalExtensionJsonRelativeFilePath); - - _log.Information($"Getting extension information from file: '{_localExtensionJsonAbsoluteFilePath}'"); - var extensionJson = await File.ReadAllTextAsync(_localExtensionJsonAbsoluteFilePath); + _log.Information($"Getting extension information from file: '{_localExtensionJsonAbsoluteFilePath.Value}'"); + var extensionJson = await File.ReadAllTextAsync(_localExtensionJsonAbsoluteFilePath.Value); var serializerOptions = ExtensionJsonSerializerOptions; serializerOptions.Converters.Add(new LocalizedPropertiesConverter(_stringResource)); - return JsonSerializer.Deserialize(extensionJson, serializerOptions); + return JsonSerializer.Deserialize(extensionJson, serializerOptions); } catch (Exception ex) { diff --git a/test/FunctionalTests/ExtensionServiceTests.cs b/test/FunctionalTests/ExtensionServiceTests.cs index 87a4784a6b..aa1bb550b3 100644 --- a/test/FunctionalTests/ExtensionServiceTests.cs +++ b/test/FunctionalTests/ExtensionServiceTests.cs @@ -35,6 +35,6 @@ public async Task ExtensionServiceReturnsValidExtensionJsonDataObject() var extensionJsonData = await extensionService.GetExtensionJsonDataAsync(); Assert.IsNotNull(extensionJsonData); - Assert.IsInstanceOfType(extensionJsonData, typeof(DevHomeExtensionJsonData)); + Assert.IsInstanceOfType(extensionJsonData, typeof(DevHomeExtensionContentData)); } }