Skip to content

Commit 351ceb2

Browse files
authored
Merge pull request #301 from Turnerj/improve-source-generator-usage
Improve source generator usage
2 parents cd434a6 + 6418e84 commit 351ceb2

File tree

10 files changed

+40295
-48054
lines changed

10 files changed

+40295
-48054
lines changed

Data/schemaorg-all-https.jsonld

+40,191
Large diffs are not rendered by default.

Schema.NET.sln

+12
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,13 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{
9191
.github\workflows\release-drafter.yml = .github\workflows\release-drafter.yml
9292
EndProjectSection
9393
EndProject
94+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Schema.NET.Updater", "Tools\Schema.NET.Updater\Schema.NET.Updater.csproj", "{8923F9E2-4BB8-45F9-9A85-863F381B46EE}"
95+
EndProject
96+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Data", "Data", "{A208CE34-D2DF-4BD2-B6CF-3047883BC820}"
97+
ProjectSection(SolutionItems) = preProject
98+
Data\schemaorg-all-https.jsonld = Data\schemaorg-all-https.jsonld
99+
EndProjectSection
100+
EndProject
94101
Global
95102
GlobalSection(SolutionConfigurationPlatforms) = preSolution
96103
Debug|Any CPU = Debug|Any CPU
@@ -113,6 +120,10 @@ Global
113120
{379FE111-579B-4A3A-9E49-40D8E2904883}.Debug|Any CPU.Build.0 = Debug|Any CPU
114121
{379FE111-579B-4A3A-9E49-40D8E2904883}.Release|Any CPU.ActiveCfg = Release|Any CPU
115122
{379FE111-579B-4A3A-9E49-40D8E2904883}.Release|Any CPU.Build.0 = Release|Any CPU
123+
{8923F9E2-4BB8-45F9-9A85-863F381B46EE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
124+
{8923F9E2-4BB8-45F9-9A85-863F381B46EE}.Debug|Any CPU.Build.0 = Debug|Any CPU
125+
{8923F9E2-4BB8-45F9-9A85-863F381B46EE}.Release|Any CPU.ActiveCfg = Release|Any CPU
126+
{8923F9E2-4BB8-45F9-9A85-863F381B46EE}.Release|Any CPU.Build.0 = Release|Any CPU
116127
EndGlobalSection
117128
GlobalSection(SolutionProperties) = preSolution
118129
HideSolutionNode = FALSE
@@ -126,6 +137,7 @@ Global
126137
{379FE111-579B-4A3A-9E49-40D8E2904883} = {1D81D082-9C25-4D4E-890E-9CD173532307}
127138
{040F8F6D-9144-42FD-9B0D-7F88EF0C26C5} = {F20E2797-D1E3-4321-91BB-FAE54954D2A0}
128139
{9444439E-8476-4BAB-AE1E-DBC24B58865F} = {040F8F6D-9144-42FD-9B0D-7F88EF0C26C5}
140+
{8923F9E2-4BB8-45F9-9A85-863F381B46EE} = {1D81D082-9C25-4D4E-890E-9CD173532307}
129141
EndGlobalSection
130142
GlobalSection(ExtensibilityGlobals) = postSolution
131143
SolutionGuid = {73F36209-F8D6-4066-8951-D97729F773CF}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"profiles": {
3+
"Schema.NET.Tool": {
4+
"commandName": "DebugRoslynComponent",
5+
"targetProject": "..\\..\\Source\\Schema.NET\\Schema.NET.csproj"
6+
}
7+
}
8+
}

Tools/Schema.NET.Tool/Repositories/SchemaRepository.cs

+3-15
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
namespace Schema.NET.Tool.Repositories
22
{
3-
using System;
43
using System.Collections.Generic;
54
using System.IO;
65
using System.Linq;
7-
using System.Net.Http;
86
using System.Text.Json;
97
using System.Text.Json.Serialization;
108
using System.Threading.Tasks;
119
using Schema.NET.Tool.Models;
1210

1311
public class SchemaRepository : ISchemaRepository
1412
{
15-
private readonly HttpClient httpClient;
13+
private readonly Stream fileStream;
1614

17-
public SchemaRepository(HttpClient httpClient) => this.httpClient = httpClient;
15+
public SchemaRepository(Stream fileStream) => this.fileStream = fileStream;
1816

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

36-
public async Task<IEnumerable<SchemaObject>?> GetSchemaObjectsAsync()
37-
{
38-
using (var response = await this.httpClient
39-
.GetAsync(new Uri("/version/latest/schemaorg-all-https.jsonld", UriKind.Relative), HttpCompletionOption.ResponseHeadersRead)
40-
.ConfigureAwait(false))
41-
{
42-
response.EnsureSuccessStatusCode();
43-
var jsonStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
44-
return await DeserializeAsync<List<SchemaObject>>(jsonStream, new SchemaPropertyJsonConverter()).ConfigureAwait(false);
45-
}
46-
}
34+
public async Task<IEnumerable<SchemaObject>?> GetSchemaObjectsAsync() => await DeserializeAsync<List<SchemaObject>>(this.fileStream, new SchemaPropertyJsonConverter()).ConfigureAwait(false);
4735

4836
private static async Task<T?> DeserializeAsync<T>(Stream jsonStream, JsonConverter converter)
4937
{

0 commit comments

Comments
 (0)