Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
GraphStoreFileSource.cs
1using System;
2using System.IO;
3using System.Threading.Tasks;
4using Waher.Content;
9using Waher.Things;
10
12{
17 {
18 private readonly GraphReference reference;
19
24 {
25 this.reference = Reference;
26 }
27
33 public Grade Supports(Uri _)
34 {
35 return Grade.NotAtAll; // Explicitly selected by processor.
36 }
37
46 public Task<ISemanticCube> LoadGraph(Uri Source, ScriptNode Node, bool NullIfNotFound,
47 RequestOrigin Caller)
48 {
49 // TODO: Check access privileges
50
51 return this.LoadGraph(Source, NullIfNotFound);
52 }
53
60 public async Task<ISemanticCube> LoadGraph(Uri Source, bool NullIfNotFound)
61 {
62 string[] Files = Directory.GetFiles(this.reference.Folder, "*.*", SearchOption.TopDirectoryOnly);
63 ISemanticCube Result = null;
64 InMemorySemanticCube Union = null;
65
66 foreach (string FileName in Files)
67 {
68 string Extension = Path.GetExtension(FileName);
69 string ContentType = InternetContent.GetContentType(Extension);
70 if (string.IsNullOrEmpty(ContentType) || ContentType == BinaryCodec.DefaultContentType)
71 continue;
72
73 byte[] Bin = await Resources.ReadAllBytesAsync(FileName);
74 object Decoded = await InternetContent.DecodeAsync(ContentType, Bin, Source);
75
76 if (Union is null && !(Result is null))
77 {
78 Union = new InMemorySemanticCube();
79 await Union.Add(Result);
80 }
81
82 if (Union is null)
83 {
84 Result = Decoded as ISemanticCube;
85 if (Result is null)
86 {
87 if (Decoded is ISemanticModel Model)
88 Result = await InMemorySemanticCube.Create(Model);
89 else
90 continue;
91 }
92 }
93 else
94 {
95 if (Decoded is ISemanticModel Model)
96 await Union.Add(Model);
97 }
98 }
99
100 return Union ?? Result ?? (NullIfNotFound ? null : new InMemorySemanticCube());
101 }
102
103 }
104}
const string DefaultContentType
text/plain
Definition: BinaryCodec.cs:24
Static class managing encoding and decoding of internet content.
static Task< object > DecodeAsync(string ContentType, byte[] Data, Encoding Encoding, KeyValuePair< string, string >[] Fields, Uri BaseUri)
Decodes an object.
static string GetContentType(string FileExtension)
Gets the content type of an item, given its file extension. It uses the TryGetContentType to see if a...
Static class managing loading of resources stored as embedded resources or in content files.
Definition: Resources.cs:15
static async Task< byte[]> ReadAllBytesAsync(string FileName)
Reads a binary file asynchronously.
Definition: Resources.cs:183
static async Task< InMemorySemanticCube > Create(ISemanticModel Model)
Creates an in-memory semantic cube from a semantic model.
Base class for all nodes in a parsed script tree.
Definition: ScriptNode.cs:69
Contains a reference to a graph in the graph store.
Graph source in the local graph store, based on files.
async Task< ISemanticCube > LoadGraph(Uri Source, bool NullIfNotFound)
Loads the graph
Grade Supports(Uri _)
How well a source with a given URI can be loaded by the class.
GraphStoreFileSource(GraphReference Reference)
Graph source in the local graph store, based on files.
Task< ISemanticCube > LoadGraph(Uri Source, ScriptNode Node, bool NullIfNotFound, RequestOrigin Caller)
Loads the graph
Tokens available in request.
Definition: RequestOrigin.cs:9
Interface for semantic cubes.
Interface for semantic models.
Grade
Grade enumeration
Definition: Grade.cs:7