Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
CssxDecoder.cs
1using System;
3using System.Threading.Tasks;
4using Waher.Content;
7
9{
14 {
18 public CssxDecoder()
19 {
20 }
21
25 public const string DefaultContentType = "text/x-cssx";
26
30 public static readonly string[] CssxContentTypes = new string[] { DefaultContentType };
31
35 public static readonly string[] CssxFileExtensions = new string[] { "cssx" };
36
40 public string[] ContentTypes => CssxContentTypes;
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 "cssx":
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 = "cssx";
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.
static readonly string[] CssxContentTypes
Plain text content types.
Definition: CssxDecoder.cs:30
CssxDecoder()
CSSX encoder/decoder.
Definition: CssxDecoder.cs:18
string[] ContentTypes
Supported content types.
Definition: CssxDecoder.cs:40
static readonly string[] CssxFileExtensions
Plain text file extensions.
Definition: CssxDecoder.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: CssxDecoder.cs:77
const string DefaultContentType
Default Content-Type for CSSX: text/x-cssx
Definition: CssxDecoder.cs:25
bool TryGetFileExtension(string ContentType, out string FileExtension)
Tries to get the file extension of an item, given its Content-Type.
Definition: CssxDecoder.cs:109
bool Decodes(string ContentType, out Grade Grade)
If the decoder decodes an object with a given content type.
Definition: CssxDecoder.cs:53
string[] FileExtensions
Supported file extensions.
Definition: CssxDecoder.cs:45
bool TryGetContentType(string FileExtension, out string ContentType)
Tries to get the content type of an item, given its file extension.
Definition: CssxDecoder.cs:89
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