-
Notifications
You must be signed in to change notification settings - Fork 4.5k
/
UserEventRequest.cs
67 lines (60 loc) · 2.49 KB
/
UserEventRequest.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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
using System.Text.Json.Serialization;
namespace Microsoft.Azure.Functions.Worker
{
/// <summary>
/// User message event request.
/// </summary>
public sealed class UserEventRequest : WebPubSubEventRequest
{
/// <summary>
/// Message content.
/// </summary>
[JsonConverter(typeof(BinaryDataJsonConverter))]
[JsonPropertyName("data")]
public BinaryData Data { get; set; }
/// <summary>
/// Message data type.
/// </summary>
[JsonPropertyName("dataType")]
public WebPubSubDataType DataType { get; set; }
/// <summary>
/// Create <see cref="UserEventResponse"/>.
/// </summary>
/// <param name="data">String message to return caller.</param>
/// <param name="dataType">Message <see cref="WebPubSubDataType"/>, default as Text.</param>
/// <returns>A message response to return caller.</returns>
public static UserEventResponse CreateResponse(string data, WebPubSubDataType dataType = WebPubSubDataType.Text)
{
return new UserEventResponse(data, dataType);
}
/// <summary>
/// Create <see cref="UserEventResponse"/>.
/// </summary>
/// <param name="data">BinaryData message to return caller.</param>
/// <param name="dataType">Message <see cref="WebPubSubDataType"/>.</param>
/// <returns>A message response to return caller.</returns>
public static UserEventResponse CreateResponse(BinaryData data, WebPubSubDataType dataType)
{
return new UserEventResponse(data, dataType);
}
/// <summary>
/// Create <see cref="EventErrorResponse"/>.
/// Methods works for Function Extensions. And AspNetCore SDK Hub methods can directly throw exception for error cases.
/// </summary>
/// <param name="code"><see cref="WebPubSubErrorCode"/>.</param>
/// <param name="message">Detail error message.</param>
/// <returns>A error response to return caller and will drop connection.</returns>
public static EventErrorResponse CreateErrorResponse(WebPubSubErrorCode code, string message)
{
return new EventErrorResponse(code, message);
}
/// <summary>
/// Constructor for Json serialize.
/// </summary>
public UserEventRequest()
{ }
}
}