feat(central-ui): add Galaxy-type to DataType mapper for secured writes
This commit is contained in:
+30
@@ -0,0 +1,30 @@
|
|||||||
|
using ZB.MOM.WW.ScadaBridge.Commons.Types.Enums;
|
||||||
|
|
||||||
|
namespace ZB.MOM.WW.ScadaBridge.CentralUI.Components.Pages.Operations;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Best-effort map from the MxGateway/Galaxy free-form attribute type name
|
||||||
|
/// (<c>GalaxyAttribute.data_type_name</c>, surfaced on <c>BrowseNode.DataType</c>)
|
||||||
|
/// to a ScadaBridge <see cref="DataType"/>. Used by the Secured Writes page to
|
||||||
|
/// pre-fill the data-type dropdown when a tag is picked. Unknown or blank names
|
||||||
|
/// return false so the operator's existing selection is left untouched. Galaxy
|
||||||
|
/// type names are free-form text, not a stable enum — keep this tolerant.
|
||||||
|
/// </summary>
|
||||||
|
internal static class SecuredWriteDataTypeMapper
|
||||||
|
{
|
||||||
|
public static bool TryMap(string? galaxyTypeName, out DataType dataType)
|
||||||
|
{
|
||||||
|
dataType = default;
|
||||||
|
if (string.IsNullOrWhiteSpace(galaxyTypeName)) return false;
|
||||||
|
switch (galaxyTypeName.Trim().ToLowerInvariant())
|
||||||
|
{
|
||||||
|
case "boolean": case "bool": dataType = DataType.Boolean; return true;
|
||||||
|
case "integer": case "int": case "int32": dataType = DataType.Int32; return true;
|
||||||
|
case "float": dataType = DataType.Float; return true;
|
||||||
|
case "double": dataType = DataType.Double; return true;
|
||||||
|
case "string": dataType = DataType.String; return true;
|
||||||
|
case "time": dataType = DataType.DateTime; return true;
|
||||||
|
default: return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+35
@@ -0,0 +1,35 @@
|
|||||||
|
using ZB.MOM.WW.ScadaBridge.CentralUI.Components.Pages.Operations;
|
||||||
|
using ZB.MOM.WW.ScadaBridge.Commons.Types.Enums;
|
||||||
|
|
||||||
|
namespace ZB.MOM.WW.ScadaBridge.CentralUI.Tests.Components;
|
||||||
|
|
||||||
|
public class SecuredWriteDataTypeMapperTests
|
||||||
|
{
|
||||||
|
[Theory]
|
||||||
|
[InlineData("Boolean", DataType.Boolean)]
|
||||||
|
[InlineData("bool", DataType.Boolean)]
|
||||||
|
[InlineData("Integer", DataType.Int32)]
|
||||||
|
[InlineData("int", DataType.Int32)]
|
||||||
|
[InlineData("Int32", DataType.Int32)]
|
||||||
|
[InlineData("Float", DataType.Float)]
|
||||||
|
[InlineData("Double", DataType.Double)]
|
||||||
|
[InlineData("String", DataType.String)]
|
||||||
|
[InlineData("Time", DataType.DateTime)]
|
||||||
|
[InlineData(" double ", DataType.Double)] // trimmed + case-insensitive
|
||||||
|
public void TryMap_known_galaxy_types_map(string galaxy, DataType expected)
|
||||||
|
{
|
||||||
|
Assert.True(SecuredWriteDataTypeMapper.TryMap(galaxy, out var dt));
|
||||||
|
Assert.Equal(expected, dt);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData(null)]
|
||||||
|
[InlineData("")]
|
||||||
|
[InlineData(" ")]
|
||||||
|
[InlineData("ElapsedTime")]
|
||||||
|
[InlineData("SomeVendorType")]
|
||||||
|
public void TryMap_unknown_or_blank_returns_false(string? galaxy)
|
||||||
|
{
|
||||||
|
Assert.False(SecuredWriteDataTypeMapper.TryMap(galaxy, out _));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user