2using System.Collections.Generic;
4using System.Threading.Tasks;
28 private static readonly
string[] SparqlQueryContentTypes =
new string[]
30 "application/sparql-query"
38 private static readonly
string[] SparqlQueryFileExtensions =
new string[]
51 if (Array.IndexOf(SparqlQueryContentTypes, ContentType) >= 0)
72 public Task<object>
DecodeAsync(
string ContentType,
byte[] Data, Encoding Encoding, KeyValuePair<string, string>[] Fields, Uri BaseUri)
78 throw new Exception(
"Invalid SPARQL query.");
80 return Task.FromResult<
object>(Query);
119 public Task<KeyValuePair<byte[], string>>
EncodeAsync(
object Object, Encoding Encoding, params
string[] AcceptedContentTypes)
121 if (Encoding is
null)
122 Encoding = Encoding.UTF8;
129 throw new ArgumentException(
"Unable to encode object.", nameof(Object));
132 string Text =
JSON.
Encode(Query.SubExpression,
false);
133 byte[] Bin = Encoding.GetBytes(Text);
134 string ContentType = SparqlQueryContentTypes[0] +
"; charset=" + Encoding.WebName;
136 return Task.FromResult(
new KeyValuePair<
byte[],
string>(Bin, ContentType));
147 if (
string.Compare(FileExtension, SparqlQueryFileExtensions[0],
true) == 0)
149 ContentType = SparqlQueryContentTypes[0];
167 if (Array.IndexOf(SparqlQueryContentTypes, ContentType) >= 0)
169 FileExtension = SparqlQueryFileExtensions[0];
174 FileExtension =
null;
Helps with parsing of commong data types.
static string GetString(byte[] Data, Encoding DefaultEncoding)
Gets a string from its binary representation, taking any Byte Order Mark (BOM) into account.
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.
Helps with common JSON-related tasks.
static string Encode(string s)
Encodes a string for inclusion in JSON.
Class managing a script expression.
ScriptNode Root
Root script node.
Encoder and Decoder of SPARQL queries. https://www.w3.org/TR/sparql12-query/
Task< object > DecodeAsync(string ContentType, byte[] Data, Encoding Encoding, KeyValuePair< string, string >[] Fields, Uri BaseUri)
Decodes an object
bool Decodes(string ContentType, out Grade Grade)
If the decoder decodes content of a given Internet Content Type.
Task< KeyValuePair< byte[], string > > EncodeAsync(object Object, Encoding Encoding, params string[] AcceptedContentTypes)
Encodes an object
string[] FileExtensions
Supported file extensions.
bool Encodes(object Object, out Grade Grade, params string[] AcceptedContentTypes)
If the encoder encodes a specific object.
SparqlQueryCodec()
Encoder and Decoder of SPARQL queries.
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.
bool TryGetFileExtension(string ContentType, out string FileExtension)
Tries to get the file extension of content of a given content type.
Basic interface for Internet Content decoders. A class implementing this interface and having a defau...
Basic interface for Internet Content encoders. A class implementing this interface and having a defau...