Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
HtmlxDecoder.cs
1using System;
3using System.Threading.Tasks;
4using Waher.Content;
7
9{
14 {
18 public HtmlxDecoder()
19 {
20 }
21
25 public const string DefaultContentType = "text/x-htmlx";
26
30 public static readonly string[] HtmlxContentTypes = new string[] { DefaultContentType };
31
35 public static readonly string[] HtmlxFileExtensions = new string[] { "htmlx" };
36
40 public string[] ContentTypes => HtmlxContentTypes;
41
46
53 public bool Decodes(string ContentType, out Grade Grade)
54 {
55 if (ContentType == DefaultContentType)
56 {
57 Grade = Grade.Excellent;
58 return true;
59 }
60 else
61 {
62 Grade = Grade.NotAtAll;
63 return false;
64 }
65 }
66
77 public Task<ContentResponse> DecodeAsync(string ContentType, byte[] Data, System.Text.Encoding Encoding,
78 KeyValuePair<string, string>[] Fields, Uri BaseUri, ICodecProgress Progress)
79 {
80 return Task.FromResult(new ContentResponse(ContentType, Strings.GetString(Data, Encoding), Data));
81 }
82
89 public bool TryGetContentType(string FileExtension, out string ContentType)
90 {
91 switch (FileExtension.ToLower())
92 {
93 case "htmlx":
94 ContentType = DefaultContentType;
95 return true;
96
97 default:
98 ContentType = string.Empty;
99 return false;
100 }
101 }
102
109 public bool TryGetFileExtension(string ContentType, out string FileExtension)
110 {
111 switch (ContentType.ToLower())
112 {
114 FileExtension = "htmlx";
115 return true;
116
117 default:
118 FileExtension = string.Empty;
119 return false;
120 }
121 }
122
123 }
124}
Contains information about a response to a content request.
bool Decodes(string ContentType, out Grade Grade)
If the decoder decodes an object with a given content type.
Definition: HtmlxDecoder.cs:53
bool TryGetFileExtension(string ContentType, out string FileExtension)
Tries to get the file extension of an item, given its Content-Type.
static readonly string[] HtmlxContentTypes
Plain text content types.
Definition: HtmlxDecoder.cs:30
string[] FileExtensions
Supported file extensions.
Definition: HtmlxDecoder.cs:45
const string DefaultContentType
Default Content-Type for HTMLX: text/x-htmlx
Definition: HtmlxDecoder.cs:25
static readonly string[] HtmlxFileExtensions
Plain text file extensions.
Definition: HtmlxDecoder.cs:35
Task< ContentResponse > DecodeAsync(string ContentType, byte[] Data, System.Text.Encoding Encoding, KeyValuePair< string, string >[] Fields, Uri BaseUri, ICodecProgress Progress)
Decodes an object.
Definition: HtmlxDecoder.cs:77
string[] ContentTypes
Supported content types.
Definition: HtmlxDecoder.cs:40
bool TryGetContentType(string FileExtension, out string ContentType)
Tries to get the content type of an item, given its file extension.
Definition: HtmlxDecoder.cs:89
HtmlxDecoder()
HTMLX encoder/decoder.
Definition: HtmlxDecoder.cs:18
Static class managing binary representations of strings.
Definition: Strings.cs:10
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.
Definition: Strings.cs:148
Interface for reporting progress about an encoding or decoding.
Basic interface for Internet Content decoders. A class implementing this interface and having a defau...
Grade
Grade enumeration
Definition: Grade.cs:7