Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
SemanticModule.cs
1using System;
2using System.Threading.Tasks;
9
11{
15 public class SemanticModule : IModule
16 {
20 public Task Start()
21 {
22 Gateway.Root.FileNotFound += this.CheckDynamicGraphs;
23 return Task.CompletedTask;
24 }
25
29 public Task Stop()
30 {
31 Gateway.Root.FileNotFound -= this.CheckDynamicGraphs;
32 return Task.CompletedTask;
33 }
34
35 private async Task CheckDynamicGraphs(object Sender, FileNotFoundEventArgs e)
36 {
37 if (e.Exception is null)
38 return; // Already processed.
39
40 RequestOrigin Caller;
41
42 if (e.Request.User is IRequestOrigin Origin)
43 Caller = await Origin.GetOrigin();
44 else
45 Caller = RequestOrigin.Empty;
46
48 if (Graph is null)
49 return;
50
51 e.Exception = null;
52
53 _ = Task.Run(async () =>
54 {
55 try
56 {
57
59 Language Language = await Translator.GetDefaultLanguageAsync(); // TODO: Check Accept-Language HTTP header.
60
61 await Graph.GenerateGraph(Result, Language, Caller);
62 await e.Response.Return(Result);
63 }
64 catch (Exception ex)
65 {
66 await e.Response.SendResponse(ex);
67 }
68 finally
69 {
70 await e.Response.DisposeAsync();
71 }
72 });
73 }
74 }
75}
Event arguments for file not found events.
HttpResponse Response
Current response object.
HttpRequest Request
Current request object.
NotFoundException Exception
Exception that will be returned to client. Change, if a custom exception is to be returned....
string SubPath
Sub-path. If a resource is found handling the request, this property contains the trailing sub-path o...
Definition: HttpRequest.cs:194
IUser User
Authenticated user, if available, or null if not available.
Definition: HttpRequest.cs:203
async Task DisposeAsync()
Closes the connection and disposes of all resources.
async Task SendResponse()
Sends the response back to the client. If the resource is synchronous, there's no need to call this m...
Task Return(Exception ex)
Returns an error to the client.
Contains information about a language.
Definition: Language.cs:17
Basic access point for runtime language localization.
Definition: Translator.cs:16
static async Task< Language > GetDefaultLanguageAsync()
Gets the default language.
Definition: Translator.cs:223
Tokens available in request.
Definition: RequestOrigin.cs:9
static readonly RequestOrigin Empty
Empty request origin.
Task< RequestOrigin > GetOrigin()
Origin of request.
Module for semantic things.
Task Start()
Starts the module.
Makes harmonized data sources and nodes available as semantic information.
static async Task< IDynamicGraph > FindDynamicGraph(string Path, RequestOrigin Caller)
Finds a dynamic graph, based on its relative path.
Interface for late-bound modules loaded at runtime.
Definition: IModule.cs:9
Interface for requestors that can act as an origin for distributed requests.
Interface for dynamic graphs.
Task GenerateGraph(InMemorySemanticCube Result, Language Language, RequestOrigin Caller)
Generates the semantic graph.
Definition: ImplTypes.g.cs:58