-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathRemoteDocumentLoader.linq
37 lines (32 loc) · 1.11 KB
/
RemoteDocumentLoader.linq
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<Query Kind="Program">
<Reference Relative="..\..\src\json-ld.net\bin\Debug\netstandard1.1\json-ld.net.dll">json-ld.net.dll</Reference>
<NuGetReference>Newtonsoft.Json</NuGetReference>
<Namespace>JsonLD.Core</Namespace>
<Namespace>Newtonsoft.Json.Linq</Namespace>
</Query>
#load "Utils/Resources"
void Main()
{
var doc = Resources.Doc;
var remoteContext = JObject.Parse("{'@context':'http://example.org/context.jsonld'}");
var opts = new JsonLdOptions { documentLoader = new CustomDocumentLoader() };
var compacted = JsonLdProcessor.Compact(doc, remoteContext, opts);
compacted.ToString().Dump("string");
compacted.Dump("JSON DOM");
}
public class CustomDocumentLoader : DocumentLoader
{
private static readonly string _cachedExampleOrgContext = Resources.Context.ToString();
public override RemoteDocument LoadDocument(string url)
{
if (url == "http://example.org/context.jsonld") // we have this cached locally
{
var doc = new JObject(new JProperty("@context", JObject.Parse(_cachedExampleOrgContext)));
return new RemoteDocument(url, doc);
}
else
{
return base.LoadDocument(url);
}
}
}