-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathMessageRoutingResult.cs
90 lines (78 loc) · 2.48 KB
/
MessageRoutingResult.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
using Newtonsoft.Json;
using System;
using System.Text;
using Underscore.Bot.MessageRouting.Models;
namespace Underscore.Bot.MessageRouting.Results
{
/// <summary>
/// The message routing result type:
/// - NoActionTaken: Nothing needed to be done - The result handler should ignore results with this type,
/// - MessageRouted: The message was routed successfully,
/// - FailedToRouteMessage: Failed to route the message, see the error message for more information,
/// - Error: Generic error, see the error message.
/// </summary>
public enum MessageRoutingResultType
{
NoActionTaken = 0,
MessageRouted,
FailedToRouteMessage,
Error
}
[Serializable]
public class MessageRoutingResult : AbstractMessageRouterResult
{
public MessageRoutingResultType Type
{
get;
set;
}
/// <summary>
/// The connection associated with this result.
/// </summary>
public Connection Connection
{
get;
set;
}
public MessageRoutingResult() : base()
{
}
public static MessageRoutingResult FromJson(string resultAsJsonString)
{
MessageRoutingResult messageRoutingResult = null;
try
{
messageRoutingResult =
JsonConvert.DeserializeObject<MessageRoutingResult>(resultAsJsonString);
}
catch (Exception e)
{
System.Diagnostics.Debug.WriteLine($"Failed to deserialize from JSON: {e.Message}");
}
return messageRoutingResult;
}
public override string ToJson()
{
return JsonConvert.SerializeObject(this);
}
public override string ToString()
{
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.Append(Type);
stringBuilder.Append("; ");
if (Connection != null)
{
stringBuilder.Append("Connection: ");
stringBuilder.Append(Connection.ToString());
stringBuilder.Append(";");
}
if (!string.IsNullOrEmpty(ErrorMessage))
{
stringBuilder.Append("; Error message: \"");
stringBuilder.Append(ErrorMessage);
stringBuilder.Append("\"");
}
return stringBuilder.ToString();
}
}
}