-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMemoryRegionException.cs
More file actions
275 lines (250 loc) · 10.9 KB
/
MemoryRegionException.cs
File metadata and controls
275 lines (250 loc) · 10.9 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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
namespace S7Tools.Core.Exceptions;
/// <summary>
/// Base exception for all memory region related errors.
/// </summary>
/// <remarks>
/// This exception serves as the base for all memory region profiling specific exceptions,
/// providing a way to catch all memory region related errors uniformly.
/// </remarks>
public class MemoryRegionException : Exception
{
/// <summary>
/// Initializes a new instance of the <see cref="MemoryRegionException"/> class.
/// </summary>
public MemoryRegionException()
{
}
/// <summary>
/// Initializes a new instance of the <see cref="MemoryRegionException"/> class with a specified error message.
/// </summary>
/// <param name="message">The error message that explains the reason for the exception.</param>
public MemoryRegionException(string message) : base(message)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="MemoryRegionException"/> class with a specified error message
/// and a reference to the inner exception that is the cause of this exception.
/// </summary>
/// <param name="message">The error message that explains the reason for the exception.</param>
/// <param name="innerException">The exception that is the cause of the current exception.</param>
public MemoryRegionException(string message, Exception innerException) : base(message, innerException)
{
}
}
/// <summary>
/// Exception thrown when a memory segment has invalid properties.
/// </summary>
/// <remarks>
/// This exception is thrown when validation fails for a memory segment due to invalid
/// address format, negative size, or other property validation failures.
/// </remarks>
public class InvalidMemorySegmentException : MemoryRegionException
{
/// <summary>
/// Gets the name of the segment that caused the exception.
/// </summary>
public string SegmentName { get; }
/// <summary>
/// Gets the property name that failed validation.
/// </summary>
public string? PropertyName { get; }
/// <summary>
/// Initializes a new instance of the <see cref="InvalidMemorySegmentException"/> class.
/// </summary>
/// <param name="segmentName">The name of the segment that caused the exception.</param>
/// <param name="reason">The reason for the validation failure.</param>
public InvalidMemorySegmentException(string segmentName, string reason)
: base($"Invalid memory segment '{segmentName}': {reason}")
{
SegmentName = segmentName;
}
/// <summary>
/// Initializes a new instance of the <see cref="InvalidMemorySegmentException"/> class.
/// </summary>
/// <param name="segmentName">The name of the segment that caused the exception.</param>
/// <param name="propertyName">The property name that failed validation.</param>
/// <param name="reason">The reason for the validation failure.</param>
public InvalidMemorySegmentException(string segmentName, string propertyName, string reason)
: base($"Invalid memory segment '{segmentName}' property '{propertyName}': {reason}")
{
SegmentName = segmentName;
PropertyName = propertyName;
}
/// <summary>
/// Initializes a new instance of the <see cref="InvalidMemorySegmentException"/> class.
/// </summary>
/// <param name="segmentName">The name of the segment that caused the exception.</param>
/// <param name="reason">The reason for the validation failure.</param>
/// <param name="innerException">The inner exception that caused this exception.</param>
public InvalidMemorySegmentException(string segmentName, string reason, Exception innerException)
: base($"Invalid memory segment '{segmentName}': {reason}", innerException)
{
SegmentName = segmentName;
}
}
/// <summary>
/// Exception thrown when memory segments have overlapping address ranges.
/// </summary>
/// <remarks>
/// This exception is thrown when two or more memory segments in a profile have
/// overlapping address ranges, which is not allowed in memory region profiles.
/// </remarks>
public class OverlappingMemorySegmentsException : MemoryRegionException
{
/// <summary>
/// Gets the name of the first overlapping segment.
/// </summary>
public string FirstSegmentName { get; }
/// <summary>
/// Gets the name of the second overlapping segment.
/// </summary>
public string SecondSegmentName { get; }
/// <summary>
/// Gets the start address of the overlap region.
/// </summary>
public string? OverlapStart { get; }
/// <summary>
/// Gets the end address of the overlap region.
/// </summary>
public string? OverlapEnd { get; }
/// <summary>
/// Initializes a new instance of the <see cref="OverlappingMemorySegmentsException"/> class.
/// </summary>
/// <param name="firstSegmentName">The name of the first overlapping segment.</param>
/// <param name="secondSegmentName">The name of the second overlapping segment.</param>
public OverlappingMemorySegmentsException(string firstSegmentName, string secondSegmentName)
: base($"Memory segments '{firstSegmentName}' and '{secondSegmentName}' have overlapping address ranges")
{
FirstSegmentName = firstSegmentName;
SecondSegmentName = secondSegmentName;
}
/// <summary>
/// Initializes a new instance of the <see cref="OverlappingMemorySegmentsException"/> class.
/// </summary>
/// <param name="firstSegmentName">The name of the first overlapping segment.</param>
/// <param name="secondSegmentName">The name of the second overlapping segment.</param>
/// <param name="overlapStart">The start address of the overlap region.</param>
/// <param name="overlapEnd">The end address of the overlap region.</param>
public OverlappingMemorySegmentsException(string firstSegmentName, string secondSegmentName,
string overlapStart, string overlapEnd)
: base($"Memory segments '{firstSegmentName}' and '{secondSegmentName}' overlap in range {overlapStart} - {overlapEnd}")
{
FirstSegmentName = firstSegmentName;
SecondSegmentName = secondSegmentName;
OverlapStart = overlapStart;
OverlapEnd = overlapEnd;
}
}
/// <summary>
/// Exception thrown when a memory address format is invalid.
/// </summary>
/// <remarks>
/// This exception is thrown when parsing a hexadecimal memory address fails
/// due to invalid format or characters.
/// </remarks>
public class InvalidMemoryAddressException : MemoryRegionException
{
/// <summary>
/// Gets the invalid address string.
/// </summary>
public string InvalidAddress { get; }
/// <summary>
/// Initializes a new instance of the <see cref="InvalidMemoryAddressException"/> class.
/// </summary>
/// <param name="invalidAddress">The invalid address string.</param>
public InvalidMemoryAddressException(string invalidAddress)
: base($"Invalid memory address format: '{invalidAddress}'. Expected hexadecimal format (e.g., '0x08000000' or '08000000').")
{
InvalidAddress = invalidAddress;
}
/// <summary>
/// Initializes a new instance of the <see cref="InvalidMemoryAddressException"/> class.
/// </summary>
/// <param name="invalidAddress">The invalid address string.</param>
/// <param name="reason">The specific reason for the validation failure.</param>
public InvalidMemoryAddressException(string invalidAddress, string reason)
: base($"Invalid memory address '{invalidAddress}': {reason}")
{
InvalidAddress = invalidAddress;
}
/// <summary>
/// Initializes a new instance of the <see cref="InvalidMemoryAddressException"/> class.
/// </summary>
/// <param name="invalidAddress">The invalid address string.</param>
/// <param name="innerException">The inner exception that caused this exception.</param>
public InvalidMemoryAddressException(string invalidAddress, Exception innerException)
: base($"Invalid memory address format: '{invalidAddress}'. Expected hexadecimal format.", innerException)
{
InvalidAddress = invalidAddress;
}
}
/// <summary>
/// Exception thrown when a memory mapping profile is not found.
/// </summary>
/// <remarks>
/// This exception is thrown when attempting to access a memory mapping profile
/// by ID or name that does not exist in the profile collection.
/// </remarks>
public class MemoryRegionProfileNotFoundException : MemoryRegionException
{
/// <summary>
/// Gets the profile identifier that was not found.
/// </summary>
public object ProfileIdentifier { get; }
/// <summary>
/// Initializes a new instance of the <see cref="MemoryRegionProfileNotFoundException"/> class.
/// </summary>
/// <param name="profileId">The profile ID that was not found.</param>
public MemoryRegionProfileNotFoundException(int profileId)
: base($"Memory mapping profile with ID {profileId} not found")
{
ProfileIdentifier = profileId;
}
/// <summary>
/// Initializes a new instance of the <see cref="MemoryRegionProfileNotFoundException"/> class.
/// </summary>
/// <param name="profileName">The profile name that was not found.</param>
public MemoryRegionProfileNotFoundException(string profileName)
: base($"Memory mapping profile with name '{profileName}' not found")
{
ProfileIdentifier = profileName;
}
}
/// <summary>
/// Exception thrown when attempting to create a memory mapping profile with a duplicate name.
/// </summary>
/// <remarks>
/// This exception is thrown when trying to create or rename a profile to a name
/// that already exists within the same profile collection.
/// </remarks>
public class DuplicateMemoryRegionProfileNameException : MemoryRegionException
{
/// <summary>
/// Gets the duplicate profile name.
/// </summary>
public string DuplicateName { get; }
/// <summary>
/// Gets the existing profile name that conflicts.
/// </summary>
public string? ExistingName { get; }
/// <summary>
/// Initializes a new instance of the <see cref="DuplicateMemoryRegionProfileNameException"/> class.
/// </summary>
/// <param name="duplicateName">The duplicate profile name.</param>
public DuplicateMemoryRegionProfileNameException(string duplicateName)
: base($"Memory mapping profile with name '{duplicateName}' already exists")
{
DuplicateName = duplicateName;
}
/// <summary>
/// Initializes a new instance of the <see cref="DuplicateMemoryRegionProfileNameException"/> class.
/// </summary>
/// <param name="duplicateName">The duplicate profile name.</param>
/// <param name="existingName">The existing profile name that conflicts.</param>
public DuplicateMemoryRegionProfileNameException(string duplicateName, string existingName)
: base($"Memory mapping profile with name '{duplicateName}' already exists (conflicts with '{existingName}')")
{
DuplicateName = duplicateName;
ExistingName = existingName;
}
}