-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathThingError.cs
More file actions
105 lines (91 loc) · 3.02 KB
/
ThingError.cs
File metadata and controls
105 lines (91 loc) · 3.02 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
using System;
using System.Text;
namespace Waher.Things
{
/// <summary>
/// Contains information about an error on a thing
/// </summary>
public class ThingError : ThingReference
{
private readonly DateTime timestamp;
private readonly string errorMessage;
/// <summary>
/// Contains information about an error on a thing
/// </summary>
/// <param name="Thing">Thing reference.</param>
/// <param name="ErrorMessage">Error message.</param>
public ThingError(IThingReference Thing, string ErrorMessage)
: this(Thing.NodeId, Thing.SourceId, Thing.Partition, DateTime.Now, ErrorMessage)
{
}
/// <summary>
/// Contains information about an error on a thing
/// </summary>
/// <param name="NodeId">ID of node.</param>
/// <param name="SourceId">Optional ID of source containing node.</param>
/// <param name="Partition">Optional partition in which the Node ID is unique.</param>
/// <param name="ErrorMessage">Error message.</param>
public ThingError(string NodeId, string SourceId, string Partition, string ErrorMessage)
: this(NodeId, SourceId, Partition, DateTime.Now, ErrorMessage)
{
}
/// <summary>
/// Contains information about an error on a thing
/// </summary>
/// <param name="Thing">Thing reference.</param>
/// <param name="Timestamp">Timestamp.</param>
/// <param name="ErrorMessage">Error message.</param>
public ThingError(IThingReference Thing, DateTime Timestamp, string ErrorMessage)
: this(Thing.NodeId, Thing.SourceId, Thing.Partition, Timestamp, ErrorMessage)
{
}
/// <summary>
/// Contains information about an error on a thing
/// </summary>
/// <param name="NodeId">ID of node.</param>
/// <param name="SourceId">Optional ID of source containing node.</param>
/// <param name="Partition">Optional partition in which the Node ID is unique.</param>
/// <param name="Timestamp">Timestamp.</param>
/// <param name="ErrorMessage">Error message.</param>
public ThingError(string NodeId, string SourceId, string Partition, DateTime Timestamp, string ErrorMessage)
: base(NodeId, SourceId, Partition)
{
this.timestamp = Timestamp;
this.errorMessage = ErrorMessage;
}
/// <summary>
/// Timestamp of error.
/// </summary>
public DateTime Timestamp => this.timestamp;
/// <summary>
/// Error message.
/// </summary>
public string ErrorMessage => this.errorMessage;
/// <inheritdoc/>
public override string ToString()
{
StringBuilder Output = new StringBuilder();
Output.Append(this.timestamp.ToString("d"));
Output.Append(", ");
Output.Append(this.timestamp.ToString("T"));
if (!string.IsNullOrEmpty(this.NodeId))
{
Output.Append(", ");
Output.Append(this.NodeId);
if (!string.IsNullOrEmpty(this.SourceId))
{
Output.Append(", ");
Output.Append(this.SourceId);
if (!string.IsNullOrEmpty(this.Partition))
{
Output.Append(", ");
Output.Append(this.Partition);
}
}
}
Output.Append(": ");
Output.Append(this.errorMessage);
return Output.ToString();
}
}
}