blob: 0d2ba6c364ac43d61419898e5c8b757841683d7e (
plain)
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive.Subjects;
using System.Text;
using System.Threading.Tasks;
using Tango.Core;
using Tango.PMR;
using Tango.PMR.Common;
using Tango.PMR.Integration;
namespace Tango.Transport
{
/// <summary>
/// Represents a base transport message.
/// </summary>
internal abstract class TransportMessageBase : ExtendedObject
{
public bool AtLeastOneResponseReceived { get; set; }
public String TransportComponentName { get; set; }
public QueuePriority Priority { get; set; }
public TransportThreadingMode ThreadingMode { get; set; }
/// <summary>
/// Gets or sets a value indicating whether this instance is multi response.
/// </summary>
public bool IsContinuous { get; set; }
/// <summary>
/// Gets or sets the message token.
/// </summary>
public String Token { get; set; }
/// <summary>
/// Gets or sets the message direction.
/// </summary>
public TransportMessageDirection Direction { get; set; }
/// <summary>
/// Gets or sets method to serial the message to byte array.
/// </summary>
public Func<byte[]> Serialize { get; set; }
/// <summary>
/// Gets or sets the activate timeout callback.
/// </summary>
public Action ActivateTimeout { get; set; }
/// <summary>
/// Gets or sets the message.
/// </summary>
public Object Message { get; set; }
/// <summary>
/// Gets or sets a value indicating whether log the message before sending.
/// </summary>
public bool ShouldLog { get; set; }
public bool Immidiate { get; set; }
/// <summary>
/// Notifies the message observer of the new result.
/// </summary>
/// <param name="result">The result.</param>
public abstract void SetResult(object result, bool completed);
/// <summary>
/// Notifies the message observer of an exception.
/// </summary>
/// <param name="ex">The ex.</param>
public abstract void SetException(Exception ex);
public abstract String GetActualMessageTypeName();
public abstract Object GetActualMessage();
/// <summary>
/// Initializes a new instance of the <see cref="TransportMessageBase"/> class.
/// </summary>
/// <param name="token">The token.</param>
/// <param name="message">The message.</param>
/// <param name="direction">The direction.</param>
/// <param name="toBytes">To bytes.</param>
public TransportMessageBase(String token, object message, TransportMessageDirection direction, Func<byte[]> toBytes)
{
Token = token;
Message = message;
Direction = direction;
Serialize = toBytes;
}
public static String GetActualMessageTypeName(Object obj)
{
String name = String.Empty;
if (obj is ITangoMessage)
{
var message = obj.GetType().GetProperty("Message").GetValue(obj);
if (message.GetType() == typeof(GenericRequest))
{
try
{
name = (message as GenericRequest).GetTypeName();
}
catch
{
name = message.GetType().Name;
}
}
else if (message.GetType() == typeof(GenericResponse))
{
try
{
name = (message as GenericResponse).GetTypeName();
}
catch
{
name = message.GetType().Name;
}
}
else
{
name = message.GetType().Name;
}
}
else if (obj is MessageContainer)
{
name = (obj as MessageContainer).Type.ToString();
}
else
{
name = obj.GetType().Name;
}
return name;
}
}
}
|