-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathContentStreamResponse.cs
More file actions
74 lines (66 loc) · 1.67 KB
/
ContentStreamResponse.cs
File metadata and controls
74 lines (66 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using System;
using Waher.Runtime.Temporary;
namespace Waher.Content
{
/// <summary>
/// Contains information about a stream response to a content request.
/// </summary>
public class ContentStreamResponse : IDisposable
{
/// <summary>
/// Contains information about a success stream response to a content request.
/// </summary>
/// <param name="ContentType">Internet Content-Type of encoded object.</param>
/// <param name="Encoded">Encoded object.</param>
public ContentStreamResponse(string ContentType, TemporaryStream Encoded)
{
this.ContentType = ContentType;
this.Encoded = Encoded;
this.HasError = false;
this.Error = null;
}
/// <summary>
/// Contains information about an error stream response to a content request.
/// </summary>
/// <param name="Error">Encoded error.</param>
public ContentStreamResponse(Exception Error)
{
this.ContentType = null;
this.Encoded = null;
this.HasError = true;
this.Error = Error;
}
/// <summary>
/// Internet Content-Type of encoded object.
/// </summary>
public string ContentType { get; }
/// <summary>
/// Encoded object.
/// </summary>
public TemporaryStream Encoded { get; private set; }
/// <summary>
/// If an error occurred.
/// </summary>
public bool HasError { get; }
/// <summary>
/// Error response.
/// </summary>
public Exception Error { get; }
/// <summary>
/// <see cref="IDisposable.Dispose"/>
/// </summary>
public void Dispose()
{
this.Encoded?.Dispose();
this.Encoded = null;
}
/// <summary>
/// Asserts response is OK.
/// </summary>
public void AssertOk()
{
if (this.HasError)
throw this.Error;
}
}
}