Skip to content

Commit a61a364

Browse files
Added separate DeviceValidationLevel propery and enum to handle MTConnectDevices validation. This allows a device to be validated at a different level than observations/assets
1 parent 05d1bac commit a61a364

4 files changed

Lines changed: 53 additions & 9 deletions

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright (c) 2026 TrakHound Inc., All Rights Reserved.
2+
// TrakHound Inc. licenses this file to you under the MIT license.
3+
4+
namespace MTConnect.Agents
5+
{
6+
/// <summary>
7+
/// Controls how the Agent reacts when Devices data fails validation against
8+
/// the MTConnect Standard.
9+
/// </summary>
10+
public enum DeviceValidationLevel
11+
{
12+
/// <summary>
13+
/// Accept invalid device information; perform no validation action.
14+
/// </summary>
15+
Ignore,
16+
17+
/// <summary>
18+
/// Accept invalid device information but emit a validation warning.
19+
/// </summary>
20+
Warning,
21+
22+
/// <summary>
23+
/// Drop the invalid device information and continue processing the remainder.
24+
/// </summary>
25+
Remove,
26+
27+
/// <summary>
28+
/// Reject the entire device information on the first validation failure.
29+
/// </summary>
30+
Strict
31+
}
32+
}

libraries/MTConnect.NET-Common/Agents/MTConnectAgent.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1312,15 +1312,15 @@ private Device NormalizeDevice(IDevice device)
13121312
foreach (var genericComponent in genericComponents)
13131313
{
13141314
var validationResults = new ValidationResult(false, $"Invalid Component : \"{genericComponent.Type}\" Not Found");
1315-
if (_configuration.InputValidationLevel > InputValidationLevel.Ignore)
1315+
if (_configuration.DeviceValidationLevel > DeviceValidationLevel.Ignore)
13161316
{
13171317
MulticastIsolation.Raise(InvalidComponentAdded, h => h(obj.Uuid, genericComponent, validationResults));
13181318

13191319
// Remove Component from Device
1320-
if (_configuration.InputValidationLevel == InputValidationLevel.Remove) obj.RemoveComponent(genericComponent.Id);
1320+
if (_configuration.DeviceValidationLevel == DeviceValidationLevel.Remove) obj.RemoveComponent(genericComponent.Id);
13211321

13221322
// Invalidate entire Device
1323-
if (_configuration.InputValidationLevel == InputValidationLevel.Strict) return null;
1323+
if (_configuration.DeviceValidationLevel == DeviceValidationLevel.Strict) return null;
13241324
}
13251325
}
13261326
}
@@ -1332,15 +1332,15 @@ private Device NormalizeDevice(IDevice device)
13321332
foreach (var genericComposition in genericCompositions)
13331333
{
13341334
var validationResults = new ValidationResult(false, $"Invalid Composition : \"{genericComposition.Type}\" Not Found");
1335-
if (_configuration.InputValidationLevel > InputValidationLevel.Ignore)
1335+
if (_configuration.DeviceValidationLevel > DeviceValidationLevel.Ignore)
13361336
{
13371337
MulticastIsolation.Raise(InvalidCompositionAdded, h => h(obj.Uuid, genericComposition, validationResults));
13381338

13391339
// Remove Compsition from Device
1340-
if (_configuration.InputValidationLevel == InputValidationLevel.Remove) obj.RemoveComposition(genericComposition.Id);
1340+
if (_configuration.DeviceValidationLevel == DeviceValidationLevel.Remove) obj.RemoveComposition(genericComposition.Id);
13411341

13421342
// Invalidate entire Device
1343-
if (_configuration.InputValidationLevel == InputValidationLevel.Strict) return null;
1343+
if (_configuration.DeviceValidationLevel == DeviceValidationLevel.Strict) return null;
13441344
}
13451345
}
13461346
}
@@ -1352,15 +1352,15 @@ private Device NormalizeDevice(IDevice device)
13521352
foreach (var genericDataItem in genericDataItems)
13531353
{
13541354
var validationResults = new ValidationResult(false, $"Invalid DataItem : \"{genericDataItem.Type}\" Not Found");
1355-
if (_configuration.InputValidationLevel > InputValidationLevel.Ignore)
1355+
if (_configuration.DeviceValidationLevel > DeviceValidationLevel.Ignore)
13561356
{
13571357
MulticastIsolation.Raise(InvalidDataItemAdded, h => h(obj.Uuid, genericDataItem, validationResults));
13581358

13591359
// Remove DataItem from Device
1360-
if (_configuration.InputValidationLevel == InputValidationLevel.Remove) obj.RemoveDataItem(genericDataItem.Id);
1360+
if (_configuration.DeviceValidationLevel == DeviceValidationLevel.Remove) obj.RemoveDataItem(genericDataItem.Id);
13611361

13621362
// Invalidate entire Device
1363-
if (_configuration.InputValidationLevel == InputValidationLevel.Strict) return null;
1363+
if (_configuration.DeviceValidationLevel == DeviceValidationLevel.Strict) return null;
13641364
}
13651365
}
13661366
}

libraries/MTConnect.NET-Common/Configurations/AgentConfiguration.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,12 @@ public string DefaultVersionValue
127127
[JsonPropertyName("enableValidation")]
128128
public bool EnableValidation { get; set; }
129129

130+
/// <summary>
131+
/// Gets or Sets the default Device (MTConnectDevices) validation level. 0 = Ignore, 1 = Warning, 2 = Remove, 3 = Strict
132+
/// </summary>
133+
[JsonPropertyName("deviceValidationLevel")]
134+
public DeviceValidationLevel DeviceValidationLevel { get; set; }
135+
130136
/// <summary>
131137
/// Gets or Sets the default Input (Observation or Asset) validation level. 0 = Ignore, 1 = Warning, 2 = Remove, 3 = Strict
132138
/// </summary>
@@ -155,6 +161,7 @@ public AgentConfiguration()
155161
ObservationBufferSize = 131072;
156162
AssetBufferSize = 1024;
157163
DefaultVersion = MTConnectVersions.Max;
164+
DeviceValidationLevel = DeviceValidationLevel.Warning;
158165
InputValidationLevel = InputValidationLevel.Warning;
159166
ConvertUnits = true;
160167
IgnoreObservationCase = false;

libraries/MTConnect.NET-Common/Configurations/IAgentConfiguration.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ public interface IAgentConfiguration
6565
/// </summary>
6666
bool EnableValidation { get; }
6767

68+
/// <summary>
69+
/// Gets or Sets the default Device (MTConnectDevices) validation level. 0 = Ignore, 1 = Warning, 2 = Remove, 3 = Strict
70+
/// </summary>
71+
DeviceValidationLevel DeviceValidationLevel { get; }
72+
6873
/// <summary>
6974
/// Gets the default Input (Observation or Asset) validation level. 0 = Ignore, 1 = Warning, 2 = Remove, 3 = Strict
7075
/// </summary>

0 commit comments

Comments
 (0)