4using System.Threading.Tasks;
36 private static readonly
string[] contentTypes =
new string[] {
ContentType };
74 KeyValuePair<string, string>[] Fields, Uri BaseUri,
ICodecProgress Progress)
82 string Type =
string.Empty;
84 foreach (KeyValuePair<string, string> P
in Fields)
86 switch (P.Key.ToUpper())
89 Type = P.Value.Trim();
105 if (
string.Compare(FileExtension,
"related",
true) == 0)
128 FileExtension =
"related";
132 FileExtension =
string.Empty;
167 public async Task<ContentResponse>
EncodeAsync(
object Object, Encoding Encoding,
173 string Boundary = Guid.NewGuid().ToString();
174 string ContentType = RelatedCodec.ContentType +
"; boundary=\"" + Boundary +
"\"; type=\"" + Related.Type.Replace(
"\"",
"\\\"") +
"\"";
178 return new ContentResponse(
new ArgumentException(
"Unable to encode object, or content type not accepted.", nameof(Object)));
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.
static async Task< KeyValuePair< byte[], string > > Encode(IEnumerable< EmbeddedContent > Content, ICodecProgress Progress)
Encodes multi-part form data
static async Task< Exception > Decode(byte[] Data, KeyValuePair< string, string >[] Fields, Dictionary< string, object > Form, ChunkedList< EmbeddedContent > List, Uri BaseUri, ICodecProgress Progress)
Decodes a multipart object
const string ContentType
multipart/related
string[] ContentTypes
Supported content types.
async Task< ContentResponse > DecodeAsync(string ContentType, byte[] Data, Encoding Encoding, KeyValuePair< string, string >[] Fields, Uri BaseUri, ICodecProgress Progress)
Decodes an object.
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.
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.
async Task< ContentResponse > EncodeAsync(object Object, Encoding Encoding, ICodecProgress Progress, params string[] AcceptedContentTypes)
Encodes an object.
Represents related content, encoded with multipart/related
A chunked list is a linked list of chunks of objects of type T .
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...