-
Notifications
You must be signed in to change notification settings - Fork 75
/
CoapGetDelegateResource.cs
99 lines (89 loc) · 3.32 KB
/
CoapGetDelegateResource.cs
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
using System;
using System.Threading.Tasks;
namespace Waher.Networking.CoAP
{
/// <summary>
/// CoAP resource defined by a GET delegate method.
/// </summary>
public class CoapGetDelegateResource : CoapResource, ICoapGetMethod
{
private readonly CoapMethodHandler get;
private readonly Notifications notifications;
private readonly string title;
private readonly string[] resourceTypes;
private readonly string[] interfaceDescriptions;
private readonly int[] contentFormats;
private readonly int? maximumSizeEstimate;
/// <summary>
/// CoAP resource defined by a GET delegate method.
/// </summary>
/// <param name="ResourceName">Name of resource.</param>
/// <param name="GET">GET Method.</param>
/// <param name="Notifications">If the resource is observable, and how notifications are to be sent.</param>
/// <param name="Title">Optional CoRE title. Can be null.</param>
/// <param name="ResourceTypes">Optional set of CoRE resource types. Can be null or empty.</param>
/// <param name="InterfaceDescriptions">Optional set of CoRE interface descriptions. Can be null or empty.</param>
/// <param name="ContentFormats">Optional set of content format representations supported by the resource. Can be null or empty.</param>
/// <param name="MaximumSizeEstimate">Optional maximum size estimate of resource. Can be null.</param>
public CoapGetDelegateResource(string ResourceName, CoapMethodHandler GET,
Notifications Notifications, string Title, string[] ResourceTypes,
string[] InterfaceDescriptions, int[] ContentFormats, int? MaximumSizeEstimate)
: base(ResourceName)
{
this.get = GET;
this.notifications = Notifications;
this.title = Title;
this.resourceTypes = ResourceTypes;
this.interfaceDescriptions = InterfaceDescriptions;
this.contentFormats = ContentFormats;
this.maximumSizeEstimate = MaximumSizeEstimate;
}
/// <summary>
/// Optional title of resource.
/// </summary>
public override string Title => this.title;
/// <summary>
/// Optional resource type.
/// </summary>
public override string[] ResourceTypes => this.resourceTypes;
/// <summary>
/// Optional interface descriptions.
/// </summary>
public override string[] InterfaceDescriptions => this.interfaceDescriptions;
/// <summary>
/// If the resource is observable, and how notifications are to be sent.
/// </summary>
public override Notifications Notifications => this.notifications;
/// <summary>
/// Optional maximum size estimate.
/// </summary>
public override int? MaximumSizeEstimate => this.maximumSizeEstimate;
/// <summary>
/// Optional array of supported content formats.
/// </summary>
public override int[] ContentFormats => this.contentFormats;
/// <summary>
/// If the GET method is allowed.
/// </summary>
public bool AllowsGET
{
get
{
return !(this.get is null);
}
}
/// <summary>
/// Executes the GET method on the resource.
/// </summary>
/// <param name="Request">CoAP Request</param>
/// <param name="Response">CoAP Response</param>
/// <exception cref="CoapException">If an error occurred when processing the method.</exception>
public Task GET(CoapMessage Request, CoapResponse Response)
{
if (this.get is null)
throw new CoapException(CoapCode.MethodNotAllowed);
else
return this.get(Request, Response);
}
}
}