2using System.Collections.Generic;
4using System.Threading.Tasks;
70 public async Task<object>
DecodeAsync(
string ContentType,
byte[] Data, Encoding Encoding, KeyValuePair<string, string>[] Fields, Uri BaseUri)
72 List<EmbeddedContent> List =
new List<EmbeddedContent>();
75 string Type =
string.Empty;
77 foreach (KeyValuePair<string, string> P
in Fields)
79 switch (P.Key.ToUpper())
82 Type = P.Value.Trim();
98 if (
string.Compare(FileExtension,
"related",
true) == 0)
121 FileExtension =
"related";
125 FileExtension =
string.Empty;
160 public async Task<KeyValuePair<byte[], string>>
EncodeAsync(
object Object, Encoding Encoding, params
string[] AcceptedContentTypes)
165 string Boundary = Guid.NewGuid().ToString();
166 string ContentType = RelatedCodec.ContentType +
"; boundary=\"" + Boundary +
"\"; type=\"" + Related.Type.Replace(
"\"",
"\\\"") +
"\"";
170 throw new ArgumentException(
"Unable to encode object, or content type not accepted.", nameof(Object));
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.
static async Task Decode(byte[] Data, KeyValuePair< string, string >[] Fields, Dictionary< string, object > Form, List< EmbeddedContent > List, Uri BaseUri)
Decodes a multipart object
static async Task< KeyValuePair< byte[], string > > Encode(IEnumerable< EmbeddedContent > Content)
Encodes multi-part form data
const string ContentType
multipart/related
async Task< KeyValuePair< byte[], string > > EncodeAsync(object Object, Encoding Encoding, params string[] AcceptedContentTypes)
Encodes an object.
string[] ContentTypes
Supported content types.
bool TryGetContentType(string FileExtension, out string ContentType)
Tries to get the content type of an item, given its file extension.
bool TryGetFileExtension(string ContentType, out string FileExtension)
Tries to get the file extension of an item, given its Content-Type.
async Task< object > DecodeAsync(string ContentType, byte[] Data, Encoding Encoding, KeyValuePair< string, string >[] Fields, Uri BaseUri)
Decodes an object.
RelatedCodec()
Codec of related data.
string[] FileExtensions
Supported file extensions.
bool Decodes(string ContentType, out Grade Grade)
If the decoder decodes an object with a given content type.
bool Encodes(object Object, out Grade Grade, params string[] AcceptedContentTypes)
If the encoder encodes a given object.
Represents related content, encoded with multipart/related
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...