Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
EmbeddedContent.cs
1using System;
3using System.Text;
4using System.Threading.Tasks;
5
7{
12 {
16 Inline,
17
21 Attachment,
22
26 FormData,
27
31 Unknown
32 }
33
37 public class EmbeddedContent
38 {
39 private ContentDisposition disposition = ContentDisposition.Unknown;
40 private string contentType = null;
41 private string name = null;
42 private string fileName = null;
43 private string transferEncoding = null;
44 private string id = null;
45 private string description = null;
46 private byte[] raw = null;
47 private byte[] transferDecoded = null;
48 private object decoded = null;
49 private int? size = null;
50 private DateTimeOffset? creationDate = null;
51 private DateTimeOffset? modificationDate = null;
52
56 public string ContentType
57 {
58 get => this.contentType;
59 set => this.contentType = value;
60 }
61
66 {
67 get => this.disposition;
68 set => this.disposition = value;
69 }
70
74 public string Name
75 {
76 get => this.name;
77 set => this.name = value;
78 }
79
83 public string FileName
84 {
85 get => this.fileName;
86 set => this.fileName = value;
87 }
88
94 public string TransferEncoding
95 {
96 get => this.transferEncoding;
97 set => this.transferEncoding = value;
98 }
99
103 public byte[] Raw
104 {
105 get => this.raw;
106 set => this.raw = value;
107 }
108
113 public byte[] TransferDecoded
114 {
115 get => this.transferDecoded;
116 set => this.transferDecoded = value;
117 }
118
123 public object Decoded
124 {
125 get => this.decoded;
126 set => this.decoded = value;
127 }
128
132 public string ID
133 {
134 get => this.id;
135 set => this.id = value;
136 }
137
141 public string Description
142 {
143 get => this.description;
144 set => this.description = value;
145 }
146
150 public int? Size
151 {
152 get => this.size;
153 set => this.size = value;
154 }
155
159 public DateTimeOffset? CreationDate
160 {
161 get => this.creationDate;
162 set => this.creationDate = value;
163 }
164
168 public DateTimeOffset? ModificationDate
169 {
170 get => this.modificationDate;
171 set => this.modificationDate = value;
172 }
173
175 public override string ToString()
176 {
177 if (!string.IsNullOrEmpty(this.name))
178 return this.name;
179 else if (!string.IsNullOrEmpty(this.fileName))
180 return this.fileName;
181 else
182 return base.ToString();
183 }
184
185 internal async Task AssertEncoded()
186 {
187 if (!(this.raw is null))
188 return;
189
190 if (this.transferDecoded is null)
191 {
192 ContentResponse P = await InternetContent.EncodeAsync(this.decoded, Encoding.UTF8);
193 P.AssertOk();
194
195 this.transferDecoded = P.Encoded;
196 this.contentType = P.ContentType;
197 this.raw = null;
198 }
199
200 if (this.raw is null)
201 {
202 this.raw = Encoding.ASCII.GetBytes(Convert.ToBase64String(this.transferDecoded));
203 this.transferEncoding = "base64";
204 }
205 }
206
212 public static Task<EmbeddedContent> Encode(object Content)
213 {
214 return Encode(Content, Encoding.UTF8);
215 }
216
223 public static async Task<EmbeddedContent> Encode(object Content, Encoding Encoding)
224 {
225 ContentResponse Encoded = await InternetContent.EncodeAsync(Content, Encoding);
226 Encoded.AssertOk();
227
228 return new EmbeddedContent()
229 {
230 ContentType = Encoded.ContentType,
231 Decoded = Content,
232 Raw = Encoded.Encoded
233 };
234 }
235 }
236}
Contains information about a response to a content request.
byte[] Encoded
Encoded object.
string ContentType
Internet Content-Type of encoded object.
void AssertOk()
Asserts response is OK.
Static class managing encoding and decoding of internet content.
static Task< ContentResponse > EncodeAsync(object Object, Encoding Encoding, params string[] AcceptedContentTypes)
Encodes an object.
Represents content embedded in other content.
string FileName
Filename of embedded object.
ContentDisposition Disposition
Disposition of embedded object.
string Name
Name of embedded object.
string Description
Content-Description of embedded object, if defined.
DateTimeOffset? CreationDate
Creation-Date of content, if available.
string ContentType
Content-Type of embedded object.
object Decoded
Decoded body of embedded object. ContentType defines how TransferDecoded is transformed into Decoded.
static async Task< EmbeddedContent > Encode(object Content, Encoding Encoding)
Encodes an object into an embedded content.
int? Size
Size of content, if available.
byte[] TransferDecoded
Transformed body of embedded object. TransferEncoding defines how Raw is transformed into TransferDec...
static Task< EmbeddedContent > Encode(object Content)
Encodes an object into an embedded content.
byte[] Raw
Raw, untransformed body of embedded object.
string TransferEncoding
Content Transfer Encoding of embedded object, if defined. Affects how Raw is transformed into Transfe...
string ID
Content-ID of embedded object, if defined.
DateTimeOffset? ModificationDate
Modification-Date of content, if available.
ContentDisposition
Content disposition