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

Improve source generator usage #301

Merged
merged 11 commits into from
Jun 22, 2021
40,191 changes: 40,191 additions & 0 deletions Data/schemaorg-all-https.jsonld

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions Schema.NET.sln
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{
.github\workflows\release-drafter.yml = .github\workflows\release-drafter.yml
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Schema.NET.Updater", "Tools\Schema.NET.Updater\Schema.NET.Updater.csproj", "{8923F9E2-4BB8-45F9-9A85-863F381B46EE}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Data", "Data", "{A208CE34-D2DF-4BD2-B6CF-3047883BC820}"
ProjectSection(SolutionItems) = preProject
Data\schemaorg-all-https.jsonld = Data\schemaorg-all-https.jsonld
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -113,6 +120,10 @@ Global
{379FE111-579B-4A3A-9E49-40D8E2904883}.Debug|Any CPU.Build.0 = Debug|Any CPU
{379FE111-579B-4A3A-9E49-40D8E2904883}.Release|Any CPU.ActiveCfg = Release|Any CPU
{379FE111-579B-4A3A-9E49-40D8E2904883}.Release|Any CPU.Build.0 = Release|Any CPU
{8923F9E2-4BB8-45F9-9A85-863F381B46EE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8923F9E2-4BB8-45F9-9A85-863F381B46EE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8923F9E2-4BB8-45F9-9A85-863F381B46EE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8923F9E2-4BB8-45F9-9A85-863F381B46EE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -126,6 +137,7 @@ Global
{379FE111-579B-4A3A-9E49-40D8E2904883} = {1D81D082-9C25-4D4E-890E-9CD173532307}
{040F8F6D-9144-42FD-9B0D-7F88EF0C26C5} = {F20E2797-D1E3-4321-91BB-FAE54954D2A0}
{9444439E-8476-4BAB-AE1E-DBC24B58865F} = {040F8F6D-9144-42FD-9B0D-7F88EF0C26C5}
{8923F9E2-4BB8-45F9-9A85-863F381B46EE} = {1D81D082-9C25-4D4E-890E-9CD173532307}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {73F36209-F8D6-4066-8951-D97729F773CF}
Expand Down
8 changes: 8 additions & 0 deletions Tools/Schema.NET.Tool/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"profiles": {
"Schema.NET.Tool": {
"commandName": "DebugRoslynComponent",
"targetProject": "..\\..\\Source\\Schema.NET\\Schema.NET.csproj"
}
}
}
18 changes: 3 additions & 15 deletions Tools/Schema.NET.Tool/Repositories/SchemaRepository.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
namespace Schema.NET.Tool.Repositories
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using Schema.NET.Tool.Models;

public class SchemaRepository : ISchemaRepository
{
private readonly HttpClient httpClient;
private readonly Stream fileStream;

public SchemaRepository(HttpClient httpClient) => this.httpClient = httpClient;
public SchemaRepository(Stream fileStream) => this.fileStream = fileStream;

public async Task<(IEnumerable<SchemaClass> Classes, IEnumerable<SchemaProperty> Properties, IEnumerable<SchemaEnumerationValue> EnumerationValues)> GetObjectsAsync()
{
Expand All @@ -33,17 +31,7 @@ public class SchemaRepository : ISchemaRepository
schemaObjects.OfType<SchemaEnumerationValue>().ToArray());
}

public async Task<IEnumerable<SchemaObject>?> GetSchemaObjectsAsync()
{
using (var response = await this.httpClient
.GetAsync(new Uri("/version/latest/schemaorg-all-https.jsonld", UriKind.Relative), HttpCompletionOption.ResponseHeadersRead)
.ConfigureAwait(false))
{
response.EnsureSuccessStatusCode();
var jsonStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
return await DeserializeAsync<List<SchemaObject>>(jsonStream, new SchemaPropertyJsonConverter()).ConfigureAwait(false);
}
}
public async Task<IEnumerable<SchemaObject>?> GetSchemaObjectsAsync() => await DeserializeAsync<List<SchemaObject>>(this.fileStream, new SchemaPropertyJsonConverter()).ConfigureAwait(false);

private static async Task<T?> DeserializeAsync<T>(Stream jsonStream, JsonConverter converter)
{
Expand Down
Loading