-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMessageProcessingAttemptResult.cs
More file actions
166 lines (154 loc) · 7.75 KB
/
MessageProcessingAttemptResult.cs
File metadata and controls
166 lines (154 loc) · 7.75 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
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
// =================================================================================================================================
// Copyright (c) RapidField LLC. Licensed under the MIT License. See LICENSE.txt in the project root for license information.
// =================================================================================================================================
using RapidField.SolidInstruments.Core;
using RapidField.SolidInstruments.Core.ArgumentValidation;
using RapidField.SolidInstruments.Core.Extensions;
using System;
using System.Runtime.Serialization;
namespace RapidField.SolidInstruments.Messaging
{
/// <summary>
/// Represents information about the result of a message processing attempt by a listener.
/// </summary>
[DataContract]
public sealed class MessageProcessingAttemptResult
{
/// <summary>
/// Initializes a new instance of the <see cref="MessageProcessingAttemptResult" /> class.
/// </summary>
public MessageProcessingAttemptResult()
: this(TimeStamp.Current)
{
return;
}
/// <summary>
/// Initializes a new instance of the <see cref="MessageProcessingAttemptResult" /> class.
/// </summary>
/// <param name="attemptEndTimeStamp">
/// The date and time when the associated attempt ended, successfully or otherwise. The default value is
/// <see cref="TimeStamp.Current" />.
/// </param>
/// <exception cref="ArgumentOutOfRangeException">
/// <paramref name="attemptEndTimeStamp" /> is equal to the default <see cref="DateTime" /> value.
/// </exception>
public MessageProcessingAttemptResult(DateTime attemptEndTimeStamp)
: this(attemptEndTimeStamp, null)
{
return;
}
/// <summary>
/// Initializes a new instance of the <see cref="MessageProcessingAttemptResult" /> class.
/// </summary>
/// <param name="attemptEndTimeStamp">
/// The date and time when the associated attempt ended, successfully or otherwise. The default value is
/// <see cref="TimeStamp.Current" />.
/// </param>
/// <param name="attemptStartTimeStamp">
/// The date and time when the associated attempt began, or <see langword="null" /> if the start date and time were not
/// recorded. The default value is <see langword="null" />.
/// </param>
/// <exception cref="ArgumentOutOfRangeException">
/// <paramref name="attemptEndTimeStamp" /> is equal to the default <see cref="DateTime" /> value.
/// </exception>
public MessageProcessingAttemptResult(DateTime attemptEndTimeStamp, DateTime? attemptStartTimeStamp)
: this(attemptEndTimeStamp, attemptStartTimeStamp, exceptionStackTrace: null)
{
return;
}
/// <summary>
/// Initializes a new instance of the <see cref="MessageProcessingAttemptResult" /> class.
/// </summary>
/// <param name="attemptEndTimeStamp">
/// The date and time when the associated attempt ended, successfully or otherwise. The default value is
/// <see cref="TimeStamp.Current" />.
/// </param>
/// <param name="attemptStartTimeStamp">
/// The date and time when the associated attempt began, or <see langword="null" /> if the start date and time were not
/// recorded. The default value is <see langword="null" />.
/// </param>
/// <param name="raisedException">
/// An exception that was raised during the associated attempt, or <see langword="null" /> if the attempt was successful.
/// The default value is <see langword="null" />.
/// </param>
/// <exception cref="ArgumentOutOfRangeException">
/// <paramref name="attemptEndTimeStamp" /> is equal to the default <see cref="DateTime" /> value.
/// </exception>
public MessageProcessingAttemptResult(DateTime attemptEndTimeStamp, DateTime? attemptStartTimeStamp, Exception raisedException)
: this(attemptEndTimeStamp, attemptStartTimeStamp, raisedException?.StackTrace)
{
return;
}
/// <summary>
/// Initializes a new instance of the <see cref="MessageProcessingAttemptResult" /> class.
/// </summary>
/// <param name="attemptEndTimeStamp">
/// The date and time when the associated attempt ended, successfully or otherwise. The default value is
/// <see cref="TimeStamp.Current" />.
/// </param>
/// <param name="attemptStartTimeStamp">
/// The date and time when the associated attempt began, or <see langword="null" /> if the start date and time were not
/// recorded. The default value is <see langword="null" />.
/// </param>
/// <param name="exceptionStackTrace">
/// The stack trace for an exception that was raised during processing, or <see langword="null" /> if the associated attempt
/// was successful. The default value is <see langword="null" />.
/// </param>
/// <exception cref="ArgumentOutOfRangeException">
/// <paramref name="attemptEndTimeStamp" /> is equal to the default <see cref="DateTime" /> value.
/// </exception>
public MessageProcessingAttemptResult(DateTime attemptEndTimeStamp, DateTime? attemptStartTimeStamp, String exceptionStackTrace)
{
AttemptEndTimeStamp = attemptEndTimeStamp.RejectIf().IsEqualToValue(default, nameof(attemptEndTimeStamp));
AttemptStartTimeStamp = attemptStartTimeStamp;
ExceptionStackTrace = exceptionStackTrace.IsNullOrEmpty() ? null : exceptionStackTrace;
}
/// <summary>
/// Converts the value of the current <see cref="MessageProcessingAttemptResult" /> to its equivalent string representation.
/// </summary>
/// <returns>
/// A string representation of the current <see cref="MessageProcessingAttemptResult" />.
/// </returns>
public override String ToString() => $"{{ \"{nameof(WasSuccessful)}\": {WasSuccessful.ToSerializedString()}, \"{nameof(AttemptEndTimeStamp)}\": \"{AttemptEndTimeStamp.ToSerializedString()}\" }}";
/// <summary>
/// Gets or sets the date and time when the associated attempt ended, successfully or otherwise.
/// </summary>
[DataMember]
public DateTime AttemptEndTimeStamp
{
get;
set;
}
/// <summary>
/// Gets or sets the date and time when the associated attempt began, or <see langword="null" /> if the start date and time
/// were not recorded.
/// </summary>
[DataMember]
public DateTime? AttemptStartTimeStamp
{
get;
set;
}
/// <summary>
/// Gets or sets the stack trace for an exception that was raised during processing, or <see langword="null" /> if the
/// associated attempt was successful.
/// </summary>
[DataMember]
public String ExceptionStackTrace
{
get;
set;
}
/// <summary>
/// Gets the length of time between the start and end of the associated attempt, or <see langword="null" /> if the duration
/// is unknown.
/// </summary>
[IgnoreDataMember]
public TimeSpan? ProcessingDuration => AttemptStartTimeStamp.HasValue ? (TimeSpan?)(AttemptEndTimeStamp - AttemptStartTimeStamp.Value) : null;
/// <summary>
/// Gets a value indicating whether or not the message was successfully processed during the associated attempt.
/// </summary>
[IgnoreDataMember]
public Boolean WasSuccessful => ExceptionStackTrace.IsNullOrEmpty();
}
}