-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathCoapGetPostDelegateResource.cs
More file actions
59 lines (55 loc) · 2.2 KB
/
CoapGetPostDelegateResource.cs
File metadata and controls
59 lines (55 loc) · 2.2 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
using System;
using System.Threading.Tasks;
namespace Waher.Networking.CoAP
{
/// <summary>
/// CoAP resource defined by GET and POST delegate methods.
/// </summary>
public class CoapGetPostDelegateResource : CoapGetDelegateResource, ICoapPostMethod
{
private readonly CoapMethodHandler post;
/// <summary>
/// CoAP resource defined by GET and POST delegate methods.
/// </summary>
/// <param name="ResourceName">Name of resource.</param>
/// <param name="GET">GET Method.</param>
/// <param name="POST">POST 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 CoapGetPostDelegateResource(string ResourceName, CoapMethodHandler GET,
CoapMethodHandler POST, Notifications Notifications, string Title, string[] ResourceTypes,
string[] InterfaceDescriptions, int[] ContentFormats, int? MaximumSizeEstimate)
: base(ResourceName, GET, Notifications, Title, ResourceTypes, InterfaceDescriptions,
ContentFormats, MaximumSizeEstimate)
{
this.post = POST;
}
/// <summary>
/// If the POST method is allowed.
/// </summary>
public bool AllowsPOST
{
get
{
return !(this.post is null);
}
}
/// <summary>
/// Executes the POST 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 POST(CoapMessage Request, CoapResponse Response)
{
if (this.post is null)
throw new CoapException(CoapCode.MethodNotAllowed);
else
return this.post(Request, Response);
}
}
}