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;
2using System.Collections.Generic;
3using System.Threading.Tasks;
4using Waher.Content;
6
8{
13 {
17 public CssxDecoder()
18 {
19 }
20
24 public static readonly string[] CssxContentTypes = new string[] { "text/x-cssx" };
25
29 public static readonly string[] CssxFileExtensions = new string[] { "cssx" };
30
34 public string[] ContentTypes => CssxContentTypes;
35
40
47 public bool Decodes(string ContentType, out Grade Grade)
48 {
49 if (ContentType == "text/x-cssx")
50 {
51 Grade = Grade.Excellent;
52 return true;
53 }
54 else
55 {
56 Grade = Grade.NotAtAll;
57 return false;
58 }
59 }
60
71 public Task<object> DecodeAsync(string ContentType, byte[] Data, System.Text.Encoding Encoding, KeyValuePair<string, string>[] Fields, Uri BaseUri)
72 {
73 return Task.FromResult<object>(CommonTypes.GetString(Data, Encoding));
74 }
75
82 public bool TryGetContentType(string FileExtension, out string ContentType)
83 {
84 switch (FileExtension.ToLower())
85 {
86 case "cssx":
87 ContentType = "text/x-cssx";
88 return true;
89
90 default:
91 ContentType = string.Empty;
92 return false;
93 }
94 }
95
102 public bool TryGetFileExtension(string ContentType, out string FileExtension)
103 {
104 switch (ContentType.ToLower())
105 {
106 case "text/x-cssx":
107 FileExtension = "cssx";
108 return true;
109
110 default:
111 FileExtension = string.Empty;
112 return false;
113 }
114 }
115
116 }
117}
Helps with parsing of commong data types.
Definition: CommonTypes.cs:13
static string GetString(byte[] Data, Encoding DefaultEncoding)
Gets a string from its binary representation, taking any Byte Order Mark (BOM) into account.
static readonly string[] CssxContentTypes
Plain text content types.
Definition: CssxDecoder.cs:24
CssxDecoder()
CSSX encoder/decoder.
Definition: CssxDecoder.cs:17
string[] ContentTypes
Supported content types.
Definition: CssxDecoder.cs:34
static readonly string[] CssxFileExtensions
Plain text file extensions.
Definition: CssxDecoder.cs:29
Task< object > DecodeAsync(string ContentType, byte[] Data, System.Text.Encoding Encoding, KeyValuePair< string, string >[] Fields, Uri BaseUri)
Decodes an object.
Definition: CssxDecoder.cs:71
bool TryGetFileExtension(string ContentType, out string FileExtension)
Tries to get the file extension of an item, given its Content-Type.
Definition: CssxDecoder.cs:102
bool Decodes(string ContentType, out Grade Grade)
If the decoder decodes an object with a given content type.
Definition: CssxDecoder.cs:47
string[] FileExtensions
Supported file extensions.
Definition: CssxDecoder.cs:39
bool TryGetContentType(string FileExtension, out string ContentType)
Tries to get the content type of an item, given its file extension.
Definition: CssxDecoder.cs:82
Basic interface for Internet Content decoders. A class implementing this interface and having a defau...
Grade
Grade enumeration
Definition: Grade.cs:7