Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ContentResponse.cs
1using System;
2using System.Threading.Tasks;
3using Waher.Events;
4
5namespace Waher.Content
6{
11 {
12 private readonly object decoded;
13 private readonly bool hasError;
14
21 public ContentResponse(string ContentType, object Decoded, byte[] Encoded)
22 {
23 this.decoded = Decoded;
24 this.hasError = false;
25
26 this.ContentType = ContentType;
27 this.Encoded = Encoded;
28 this.Error = null;
29 }
30
35 public ContentResponse(Exception Error)
36 {
37 this.decoded = null;
38 this.hasError = true;
39
40 this.ContentType = null;
41 this.Encoded = null;
42 this.Error = Error;
43 }
44
48 public string ContentType { get; }
49
53 public object Decoded
54 {
55 get
56 {
57 if (this.hasError)
58 throw this.Error;
59 else
60 return this.decoded;
61 }
62 }
63
67 public byte[] Encoded { get; }
68
72 public bool HasError => this.hasError;
73
77 public Exception Error { get; }
78
82 [Obsolete("Use DisposeAsync() instead.")]
83 public void Dispose()
84 {
85 this.DisposeAsync().Wait();
86 }
87
91 public async Task DisposeAsync()
92 {
93 if (this.Decoded is IDisposableAsync DisposableAsync)
94 await DisposableAsync.DisposeAsync();
95 else if (this.Decoded is IDisposable Disposable)
96 Disposable.Dispose();
97 }
98
102 public void AssertOk()
103 {
104 if (this.hasError)
105 throw this.Error;
106 }
107 }
108}
Contains information about a response to a content request.
void Dispose()
IDisposable.Dispose
ContentResponse(Exception Error)
Contains information about an error response to a content request.
byte[] Encoded
Encoded object.
string ContentType
Internet Content-Type of encoded object.
async Task DisposeAsync()
IDisposableAsync.DisposeAsync
bool HasError
If an error occurred.
ContentResponse(string ContentType, object Decoded, byte[] Encoded)
Contains information about a success response to a content request.
object Decoded
Decoded object.
Exception Error
Error response.
void AssertOk()
Asserts response is OK.
Interface for asynchronously disposable objects.