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

Update extension Json to make way for changes on extensions page and environments page #3923

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 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
2 changes: 2 additions & 0 deletions common/Contracts/ILocalSettingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ public interface ILocalSettingsService
Task<T?> ReadSettingAsync<T>(string key);

Task SaveSettingAsync<T>(string key, T value);

public string GetPathToPackageLocation();
}
1 change: 1 addition & 0 deletions common/DevHome.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<PackageReference Include="CommunityToolkit.WinUI.Controls.SettingsControls" Version="8.0.240109" />
<PackageReference Include="LibGit2Sharp" Version="0.30.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="JsonSchema.Net" Version="7.2.3" />
<PackageReference Include="Microsoft.Internal.Windows.DevHome.Helpers" Version="1.0.20240910-x0103" />
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.106">
<PrivateAssets>all</PrivateAssets>
Expand Down
15 changes: 15 additions & 0 deletions common/Helpers/CommonConstants.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System.Text.Json;
using DevHome.Common.Models.ExtensionJsonData;

namespace DevHome.Common.Helpers;

public static class CommonConstants
Expand Down Expand Up @@ -32,4 +35,16 @@ public static class CommonConstants
#endif

public const string HyperVWindowsOptionalFeatureName = "Microsoft-Hyper-V";

public static JsonSerializerOptions ExtensionJsonSerializerOptions => new()
{
PropertyNameCaseInsensitive = true,
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
TypeInfoResolver = new JsonSourceGenerationContext(),
TypeInfoResolverChain = { JsonSourceGenerationContext.Default },
};

public static readonly string LocalExtensionJsonSchemaRelativeFilePath = @"Assets\Schemas\ExtensionInformation.schema.json";

public static readonly string LocalExtensionJsonRelativeFilePath = @"Assets\ExtensionInformation.json";
}
15 changes: 15 additions & 0 deletions common/Models/ExtensionJsonData/DevHomeExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System.Collections.Generic;

namespace DevHome.Common.Models.ExtensionJsonData;

public class DevHomeExtension
{
public required LocalizedProperties LocalizedProperties { get; set; }

public required List<string> SupportedProviderTypes { get; set; } = new();

public required List<ProviderSpecificProperty> ProviderSpecificProperties { get; set; } = new();
}
15 changes: 15 additions & 0 deletions common/Models/ExtensionJsonData/DevHomeExtensionJsonData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System.Collections.Generic;

namespace DevHome.Common.Models.ExtensionJsonData;

/// <summary>
/// Root class that will contain the deserialized data located in the
/// src\Assets\Schemas\ExtensionInformation.schema.json file.
/// </summary>
public class DevHomeExtensionJsonData
bbonaby marked this conversation as resolved.
Show resolved Hide resolved
{
public List<Product> Products { get; set; } = new();
}
26 changes: 26 additions & 0 deletions common/Models/ExtensionJsonData/JsonSourceGenerationContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System.Text.Json.Serialization;
using Json.Schema;

namespace DevHome.Common.Models.ExtensionJsonData;

/// <summary>
/// Used to generate C# classes from the extension json and extension json schema.
/// .Net 8 requires a JsonSerializerContext to be used with the JsonSerializerOptions when
/// deserializing JSON into objects.
/// See : https://learn.microsoft.com/dotnet/standard/serialization/system-text-json/source-generation?pivots=dotnet-8-0
/// for more information
/// </summary>
[JsonSerializable(typeof(LocalizedProperties))]
[JsonSerializable(typeof(ProviderSpecificProperty))]
[JsonSerializable(typeof(Properties))]
[JsonSerializable(typeof(Product))]
[JsonSerializable(typeof(DevHomeExtensionJsonData))]
[JsonSerializable(typeof(DevHomeExtension))]
[JsonSerializable(typeof(JsonSchema))]
[JsonSerializable(typeof(EvaluationResults))]
public partial class JsonSourceGenerationContext : JsonSerializerContext
{
}
15 changes: 15 additions & 0 deletions common/Models/ExtensionJsonData/LocalizedProperties.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

namespace DevHome.Common.Models.ExtensionJsonData;

public class LocalizedProperties
{
public string DisplayNameKey { get; set; } = string.Empty;

public string PublisherDisplayNameKey { get; set; } = string.Empty;

public string DisplayName { get; set; } = string.Empty;

public string PublisherDisplayName { get; set; } = string.Empty;
}
69 changes: 69 additions & 0 deletions common/Models/ExtensionJsonData/LocalizedPropertiesConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System;
using System.Text.Json;
using System.Text.Json.Serialization;
using DevHome.Common.Services;

namespace DevHome.Common.Models.ExtensionJsonData;

/// <summary>
/// Custom JSON converter for <see cref="LocalizedProperties"/>.
/// This should be added directly to a <see cref="JsonSerializerOptions"/> to handle the conversion of a
/// localized key within the extension json to a value in the DevHome.pri resource file.
/// </summary>
public class LocalizedPropertiesConverter : JsonConverter<LocalizedProperties>
{
private readonly IStringResource _stringResource;

public LocalizedPropertiesConverter(IStringResource stringResource)
{
_stringResource = stringResource;
}

public override LocalizedProperties Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
var localizedProperties = new LocalizedProperties();

// Read the JSON and populate the properties
while (reader.Read())
{
if (reader.TokenType == JsonTokenType.EndObject)
{
break;
}

if (reader.TokenType == JsonTokenType.PropertyName)
{
var propertyName = reader.GetString();
reader.Read(); // Move to the value

if (reader.TokenType != JsonTokenType.String)
{
continue;
}

switch (propertyName)
{
case nameof(LocalizedProperties.DisplayNameKey):
localizedProperties.DisplayNameKey = reader.GetString()!;
break;
case nameof(LocalizedProperties.PublisherDisplayNameKey):
localizedProperties.PublisherDisplayNameKey = reader.GetString()!;
break;
}
}
}

localizedProperties.DisplayName = _stringResource.GetLocalized(localizedProperties.DisplayNameKey);
localizedProperties.PublisherDisplayName = _stringResource.GetLocalized(localizedProperties.PublisherDisplayNameKey);

return localizedProperties;
}

public override void Write(Utf8JsonWriter writer, LocalizedProperties value, JsonSerializerOptions options)
{
throw new NotImplementedException();
}
}
11 changes: 11 additions & 0 deletions common/Models/ExtensionJsonData/Product.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

namespace DevHome.Common.Models.ExtensionJsonData;

public class Product
{
public required string ProductId { get; set; }

public required Properties Properties { get; set; }
}
17 changes: 17 additions & 0 deletions common/Models/ExtensionJsonData/Properties.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System.Collections.Generic;

namespace DevHome.Common.Models.ExtensionJsonData;

public class Properties
{
public required string PackageFamilyName { get; set; }

public required bool SupportsWidgets { get; set; }

public required LocalizedProperties LocalizedProperties { get; set; }

public required List<DevHomeExtension> DevHomeExtensions { get; set; } = new();
}
11 changes: 11 additions & 0 deletions common/Models/ExtensionJsonData/ProviderSpecificProperty.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

namespace DevHome.Common.Models.ExtensionJsonData;

public class ProviderSpecificProperty
{
public required LocalizedProperties LocalizedProperties { get; set; }

public required string ProviderType { get; set; }
}
7 changes: 7 additions & 0 deletions common/Services/IExtensionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using DevHome.Common.Models.ExtensionJsonData;
using Windows.Foundation;

namespace DevHome.Common.Services;
Expand Down Expand Up @@ -35,4 +36,10 @@ public interface IExtensionService
/// <param name="extension">The out of proc extension object</param>
/// <returns>True only if the extension was disabled. False otherwise.</returns>
public Task<bool> DisableExtensionIfWindowsFeatureNotAvailable(IExtensionWrapper extension);

/// <summary>
/// Gets known extension information from internal extension json file.
/// </summary>
/// <returns>An object that holds a list of extension information based on the internal json file.</returns>
public Task<DevHomeExtensionJsonData?> GetExtensionJsonDataAsync();
}
6 changes: 6 additions & 0 deletions common/Services/LocalSettingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using DevHome.Common.Helpers;
using DevHome.Common.Models;
using Microsoft.Extensions.Options;
using Windows.ApplicationModel;
using Windows.Storage;

namespace DevHome.Common.Services;
Expand Down Expand Up @@ -106,4 +107,9 @@ public async Task SaveSettingAsync<T>(string key, T value)
await Task.Run(() => _fileService.Save(_applicationDataFolder, _localSettingsFile, _settings));
}
}

public string GetPathToPackageLocation()
{
return Package.Current.EffectivePath;
}
}
103 changes: 103 additions & 0 deletions src/Assets/ExtensionInformation.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
{
bbonaby marked this conversation as resolved.
Show resolved Hide resolved
"Products": [
{
"ProductId": "9MV8F79FGXTR",
"Properties": {
"PackageFamilyName": "Microsoft.Windows.DevHomeAzureExtension_8wekyb3d8bbwe",
"SupportsWidgets": true,
"LocalizedProperties": {
"DisplayNameKey": "DevHomeAzureDisplayName",
"PublisherDisplayNameKey": "MicrosoftPublisher"
},
"DevHomeExtensions": [
{
"LocalizedProperties": {
"DisplayNameKey": "DevHomeAzureDisplayName"
},
"SupportedProviderTypes": [
"ComputeSystem",
"DeveloperId",
"QuickStartProject",
"Repository",
"Settings"
],
"ProviderSpecificProperties": [
{
"LocalizedProperties": {
"DisplayNameKey": "DevBoxProviderDisplayName"
},
"ProviderType": "ComputeSystem"
}
]
}
]
}
},
{
"ProductId": "9NZCC27PR6N6",
"Properties": {
"PackageFamilyName": "Microsoft.Windows.DevHomeGitHubExtension_8wekyb3d8bbwe",
"SupportsWidgets": true,
"LocalizedProperties": {
"DisplayNameKey": "DevHomeGitHubDisplayName",
"PublisherDisplayNameKey": "MicrosoftPublisher"
},
"DevHomeExtensions": [
{
"LocalizedProperties": {
"DisplayNameKey": "DevHomeGitHubDisplayName"
},
"SupportedProviderTypes": [
"DeveloperId",
"Repository",
"Settings"
],
"ProviderSpecificProperties": []
}
]
}
},
{
"ProductId": "9NZ845RW19RW",
"Properties": {
"PackageFamilyName": "Microsoft.DevHomeMicrosoftGameDevExtension_8wekyb3d8bbwe",
"SupportsWidgets": true,
"LocalizedProperties": {
"DisplayNameKey": "DevHomeGameDevDisplayName",
"PublisherDisplayNameKey": "MicrosoftPublisher"
},
"DevHomeExtensions": [
{
"LocalizedProperties": {
"DisplayNameKey": "DevHomeGameDevDisplayName"
},
"SupportedProviderTypes": [
"FeaturedApplications"
],
"ProviderSpecificProperties": []
}
]
}
},
{
"ProductId": "9NB9M5KZ8SLX",
"Properties": {
"PackageFamilyName": "9932MartCliment.WingetUIWidgets_g91dtg5srk15g",
"SupportsWidgets": true,
"LocalizedProperties": {
"DisplayNameKey": "WidgetsForUniGetUIDisplayName",
"PublisherDisplayNameKey": "WidgetsForUniGetUIPublisher"
},
"DevHomeExtensions": [
{
"LocalizedProperties": {
"DisplayNameKey": "WidgetsForUniGetUIDisplayName"
},
"SupportedProviderTypes": [],
"ProviderSpecificProperties": []
}
]
}
}
]
}
Loading
Loading