This repository was archived by the owner on Oct 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1k
Allow scaffolders to choose packages/versions by TFM #9215
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e67ebfe
Allow scaffolders to choose packages/versions by TFM
nosami 5f32dd4
deserialize directly from stream
nosami 17a58e0
Implement IComparable<SupportPolicyVersion>
nosami ad4ba91
Timeout if the web request takes too long
nosami 33c9bc2
Ignore scaffolding test
nosami 81dc063
Use HttpClientProvider class
nosami File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
...Develop.AspNetCore/MonoDevelop.AspNetCore.Scaffolding/Configuration/PackageDescription.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| namespace Microsoft.WebTools.Scaffolding.Core.Config | ||
| { | ||
| class PackageDescription | ||
| { | ||
| public string PackageId { get; set; } | ||
| public string MinVersion { get; set; } | ||
| public string MaxVersion { get; set; } | ||
| public bool IsOptionalEfPackage { get; set; } = false; | ||
| public bool IsOptionalIdentityPackage { get; set; } = false; | ||
| } | ||
| } |
98 changes: 98 additions & 0 deletions
98
...oDevelop.AspNetCore/MonoDevelop.AspNetCore.Scaffolding/Configuration/ScaffoldingConfig.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.IO; | ||
| using System.Net; | ||
| using System.Net.Http; | ||
| using System.Threading.Tasks; | ||
| using Newtonsoft.Json; | ||
|
|
||
| namespace Microsoft.WebTools.Scaffolding.Core.Config | ||
| { | ||
| class ScaffoldingConfig | ||
| { | ||
| public static string ConfigPath { get; private set; } = Path.GetDirectoryName (typeof (ScaffoldingConfig).Assembly.Location); | ||
|
|
||
| public string Version { get; set; } | ||
|
|
||
| // LTS10, FTS11, NetStandard20, NetStandard21, and Net22 packages are set up as they are to maintain backwards compat. | ||
| // They were (are) explicitly named sections before the config file format was generalized to support arbitrary support policy versions. | ||
| public PackageDescription [] LTS10Packages { get; set; } | ||
|
|
||
| public PackageDescription [] FTS11Packages { get; set; } | ||
|
|
||
| public PackageDescription [] NetStandard20Packages { get; set; } | ||
|
|
||
| public PackageDescription [] NetStandard21Packages { get; set; } | ||
|
|
||
| public PackageDescription [] Net22Packages { get; set; } | ||
|
|
||
| // This is public so the Json deserialization works (and for testing). | ||
| // The data should be accessed via TryGetPackagesForSupportPolicyVersion | ||
| [JsonProperty] | ||
| public Dictionary<string, PackageDescription []> DynamicVersionedPackages { get; set; } | ||
|
|
||
| public bool TryGetPackagesForSupportPolicyVersion (SupportPolicyVersion supportPolicyVersion, out PackageDescription [] packageDescriptions) | ||
| { | ||
| if (supportPolicyVersion == null || supportPolicyVersion.Version == null) { | ||
| packageDescriptions = null; | ||
| return false; | ||
| } | ||
|
|
||
| if (supportPolicyVersion == SupportPolicyVersion.LTS10) { | ||
| packageDescriptions = LTS10Packages; | ||
| return true; | ||
| } | ||
| if (supportPolicyVersion == SupportPolicyVersion.FTS11) { | ||
| packageDescriptions = FTS11Packages; | ||
| return true; | ||
| } | ||
| if (supportPolicyVersion == SupportPolicyVersion.NetStandard20) { | ||
| packageDescriptions = NetStandard20Packages; | ||
| return true; | ||
| } | ||
| if (supportPolicyVersion == SupportPolicyVersion.NetStandard21) { | ||
| packageDescriptions = NetStandard21Packages; | ||
| return true; | ||
| } | ||
| if (supportPolicyVersion == SupportPolicyVersion.Net220) { | ||
| packageDescriptions = Net22Packages; | ||
| return true; | ||
| } | ||
|
|
||
| if (DynamicVersionedPackages != null && DynamicVersionedPackages.TryGetValue (supportPolicyVersion.Version.ToString (), out packageDescriptions)) { | ||
| return true; | ||
| } | ||
|
|
||
| packageDescriptions = null; | ||
| return false; | ||
| } | ||
|
|
||
| static ScaffoldingConfig fetchedConfig; | ||
| // This url will go live for 16.4 | ||
| static string packageVersionsUrl = "https://webpifeed.blob.core.windows.net/webpifeed/partners/scaffoldingpackageversions_2108718.json"; | ||
|
|
||
| public static async Task<ScaffoldingConfig> LoadFromJsonAsync () | ||
| { | ||
| if(fetchedConfig == null) { | ||
| Stream stream; | ||
| using var httpClient = new HttpClient { | ||
| Timeout = TimeSpan.FromSeconds (2) | ||
| }; | ||
|
|
||
| try { | ||
| stream = await httpClient.GetStreamAsync (packageVersionsUrl); | ||
| } catch { | ||
| // fallback to embedded resource | ||
| stream = typeof (ScaffoldingConfig).Assembly.GetManifestResourceStream ("ScaffoldingPackageVersions.json"); | ||
| } | ||
|
|
||
| var serializer = new JsonSerializer (); | ||
|
|
||
| using var sr = new StreamReader (stream); | ||
| using var jsonTextReader = new JsonTextReader (sr); | ||
| return serializer.Deserialize<ScaffoldingConfig> (jsonTextReader); | ||
| } | ||
| return fetchedConfig; | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.