feat(central-ui): add Galaxy-type to DataType mapper for secured writes

This commit is contained in:
Joseph Doherty
2026-06-27 13:27:32 -04:00
parent c4daf941d2
commit 265f115a1f
2 changed files with 65 additions and 0 deletions
@@ -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;
}
}
}