4using System.Threading.Tasks;
29 private static readonly
string[] SparqlQueryContentTypes =
new string[]
31 "application/sparql-query"
39 private static readonly
string[] SparqlQueryFileExtensions =
new string[]
52 if (Array.IndexOf(SparqlQueryContentTypes, ContentType) >= 0)
74 public Task<ContentResponse>
DecodeAsync(
string ContentType,
byte[] Data, Encoding Encoding,
75 KeyValuePair<string, string>[] Fields, Uri BaseUri,
ICodecProgress Progress)
81 return Task.FromResult(
new ContentResponse(
new Exception(
"Invalid SPARQL query.")));
123 public Task<ContentResponse>
EncodeAsync(
object Object, Encoding Encoding,
ICodecProgress Progress, params
string[] AcceptedContentTypes)
125 if (Encoding is
null)
126 Encoding = Encoding.UTF8;
133 return Task.FromResult(
new ContentResponse(
new ArgumentException(
"Unable to encode object.", nameof(Object))));
136 string Text =
JSON.
Encode(Query.SubExpression,
false);
137 byte[] Bin = Encoding.GetBytes(Text);
138 string ContentType = SparqlQueryContentTypes[0] +
"; charset=" + Encoding.WebName;
151 if (
string.Compare(FileExtension, SparqlQueryFileExtensions[0],
true) == 0)
153 ContentType = SparqlQueryContentTypes[0];
171 if (Array.IndexOf(SparqlQueryContentTypes, ContentType) >= 0)
173 FileExtension = SparqlQueryFileExtensions[0];
178 FileExtension =
null;
Contains information about a response to a content request.
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.
Static class managing binary representations of strings.
static string GetString(byte[] Data, int Offset, int Count, Encoding DefaultEncoding)
Gets a string from its binary representation, taking any Byte Order Mark (BOM) into account.
Class managing a script expression.
ScriptNode Root
Root script node.
Encoder and Decoder of SPARQL queries. https://www.w3.org/TR/sparql12-query/
bool Decodes(string ContentType, out Grade Grade)
If the decoder decodes content of a given Internet Content Type.
string[] FileExtensions
Supported file extensions.
Task< ContentResponse > DecodeAsync(string ContentType, byte[] Data, Encoding Encoding, KeyValuePair< string, string >[] Fields, Uri BaseUri, ICodecProgress Progress)
Decodes an object
bool Encodes(object Object, out Grade Grade, params string[] AcceptedContentTypes)
If the encoder encodes a specific object.
Task< ContentResponse > EncodeAsync(object Object, Encoding Encoding, ICodecProgress Progress, params string[] AcceptedContentTypes)
Encodes an 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.
Interface for reporting progress about an encoding or decoding.
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...