Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
SparqlResultSetHtmlCodec.cs
1using System;
2using System.Collections.Generic;
3using System.Text;
4using System.Threading.Tasks;
9
11{
16 {
21 {
22 }
23
27 public string[] ContentTypes => new string[0];
28
32 public string[] FileExtensions => new string[0];
33
41 public bool Encodes(object Object, out Grade Grade, params string[] AcceptedContentTypes)
42 {
43 if (Object is SparqlResultSet &&
45 {
46 Grade = Grade.Excellent;
47 return true;
48 }
49 else if (Object is ObjectMatrix M && M.HasColumnNames &&
51 {
52 Grade = Grade.Ok;
53 return true;
54 }
55 else if (Object is bool &&
57 {
58 Grade = Grade.Barely;
59 return true;
60 }
61 else
62 {
63 Grade = Grade.NotAtAll;
64 return false;
65 }
66 }
67
75 public async Task<KeyValuePair<byte[], string>> EncodeAsync(object Object, Encoding Encoding, 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, 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 throw 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 KeyValuePair<byte[], string>(Bin, ContentType);
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:13
static string Encode(bool x)
Encodes a Boolean for use in XML and other formats.
Definition: CommonTypes.cs:594
HTML encoder/decoder.
Definition: HtmlCodec.cs:13
static readonly string[] HtmlContentTypes
HTML content types.
Definition: HtmlCodec.cs:29
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:24
Contains settings that the HTML export uses to customize HTML output.
Definition: HtmlSettings.cs:7
Abstract base class for Markdown renderers.
Definition: Renderer.cs:14
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 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.
bool Encodes(object Object, out Grade Grade, params string[] AcceptedContentTypes)
If the encoder encodes a specific object.
async Task< KeyValuePair< byte[], string > > EncodeAsync(object Object, Encoding Encoding, params string[] AcceptedContentTypes)
Encodes an object
string[] ContentTypes
Supported Internet Content Types.
bool TryGetContentType(string FileExtension, out string ContentType)
Tries to get the content type of content of a given file extension.
SparqlResultSetHtmlCodec()
Encoder and Decoder of semantic information from SPARQL queries using HTML.
bool HasColumnNames
If the matrix has column names defined.
Basic interface for Internet Content encoders. A class implementing this interface and having a defau...
Grade
Grade enumeration
Definition: Grade.cs:7