Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
SparqlResultSetHtmlEncoder.cs
1using System;
2using System.Text;
3using System.Threading.Tasks;
8
10{
15 {
20 {
21 }
22
26 public string[] ContentTypes => Array.Empty<string>();
27
31 public string[] FileExtensions => Array.Empty<string>();
32
40 public bool Encodes(object Object, out Grade Grade, params string[] AcceptedContentTypes)
41 {
42 if (Object is SparqlResultSet &&
44 {
45 Grade = Grade.Excellent;
46 return true;
47 }
48 else if (Object is ObjectMatrix M && M.HasColumnNames &&
50 {
51 Grade = Grade.Ok;
52 return true;
53 }
54 else if (Object is bool &&
56 {
57 Grade = Grade.Barely;
58 return true;
59 }
60 else
61 {
62 Grade = Grade.NotAtAll;
63 return false;
64 }
65 }
66
75 public async Task<ContentResponse> EncodeAsync(object Object, Encoding Encoding, ICodecProgress Progress, params string[] AcceptedContentTypes)
76 {
77 string Html;
78
79 if (Encoding is null)
80 Encoding = Encoding.UTF8;
81
82 if (Object is SparqlResultSet Result)
83 {
84 if (Result.BooleanResult.HasValue)
85 Html = CommonTypes.Encode(Result.BooleanResult.Value);
86 else
87 {
89 {
90 await Renderer.RenderObject(Result.ToMatrix(true), true, new Script.Variables());
91 Html = Renderer.ToString();
92 }
93 }
94 }
95 else if (Object is ObjectMatrix M)
96 {
98 {
99 await Renderer.RenderObject(M, true, new Script.Variables());
100 Html = Renderer.ToString();
101 }
102 }
103 else if (Object is bool b)
104 Html = CommonTypes.Encode(b);
105 else
106 return new ContentResponse(new ArgumentException("Unable to encode object.", nameof(Object)));
107
108 byte[] Bin = Encoding.GetBytes(Html);
109 string ContentType = HtmlCodec.HtmlContentTypes[0] + "; charset=" + Encoding.WebName;
110
111 return new ContentResponse(ContentType, Object, Bin);
112 }
113
120 public bool TryGetContentType(string FileExtension, out string ContentType)
121 {
122 ContentType = null;
123 return false;
124 }
125
132 public bool TryGetFileExtension(string ContentType, out string FileExtension)
133 {
134 FileExtension = null;
135 return false;
136 }
137 }
138}
Helps with parsing of commong data types.
Definition: CommonTypes.cs:15
static string Encode(bool x)
Encodes a Boolean for use in XML and other formats.
Definition: CommonTypes.cs:596
Contains information about a response to a content request.
HTML encoder/decoder.
Definition: HtmlCodec.cs:15
static readonly string[] HtmlContentTypes
HTML content types.
Definition: HtmlCodec.cs:31
Static class managing encoding and decoding of internet content.
static bool IsAccepted(string ContentType, params string[] AcceptedContentTypes)
Checks if a given content type is acceptable.
Renders HTML from a Markdown document.
Definition: HtmlRenderer.cs:25
Contains settings that the HTML export uses to customize HTML output.
Definition: HtmlSettings.cs:7
Abstract base class for Markdown renderers.
Definition: Renderer.cs:15
override string ToString()
Returns the renderer output.
Definition: Renderer.cs:130
Contains the results of a SPARQL query. https://www.w3.org/TR/2023/WD-sparql12-results-xml-20230516/ ...
Encoder of semantic information from SPARQL queries using HTML.
bool TryGetContentType(string FileExtension, out string ContentType)
Tries to get the content type of content of a given file extension.
bool Encodes(object Object, out Grade Grade, params string[] AcceptedContentTypes)
If the encoder encodes a specific object.
string[] ContentTypes
Supported Internet Content Types.
SparqlResultSetHtmlEncoder()
Encoder and Decoder of semantic information from SPARQL queries using HTML.
bool TryGetFileExtension(string ContentType, out string FileExtension)
Tries to get the file extension of content of a given content type.
async Task< ContentResponse > EncodeAsync(object Object, Encoding Encoding, ICodecProgress Progress, params string[] AcceptedContentTypes)
Encodes an object
bool HasColumnNames
If the matrix has column names defined.
Interface for reporting progress about an encoding or decoding.
Basic interface for Internet Content encoders. A class implementing this interface and having a defau...
Grade
Grade enumeration
Definition: Grade.cs:7