dc9c0c950c
Apply the ZB.MOM.WW. prefix to all gateway-side projects, folders,
.csproj/.sln contents, C# namespaces, using directives, generated proto
C# (csharp_namespace + checked-in generated files), InternalsVisibleTo
attributes, project-name string literals (LoadProject, .sln lookups,
worker exe paths, staticwebassets manifest), and the install/script/doc
references that point at any of the above. Migrate the solution from
.sln to .slnx via `dotnet sln migrate` and delete the old file.
External-runtime identifiers are intentionally NOT prefixed so external
configuration keeps working:
- GatewayMetrics.cs MeterName ("MxGateway.Server")
- DashboardAuthenticationDefaults Scheme/Policy ("MxGateway.Dashboard")
- GatewayRequestLoggingMiddleware logger category ("MxGateway.Request")
- StaRuntime thread name ("MxGateway.Worker.STA")
- appsettings.json root section "MxGateway" + env-var prefix
MxGateway__... and secret-name MxGateway:ApiKeyPepper
- C:\ProgramData\MxGateway\ data dir paths
Also fixes two tests that were not rename-related but became visible
while validating the rename:
- WorkerLiveMxAccessSmokeTests.ShutDownAsync: cancellation that the
gateway service correctly maps to RpcException(Cancelled) per gRPC
convention was being misclassified as a stream fault. Added a sibling
catch on RpcException with StatusCode.Cancelled.
- IntegrationTestEnvironment.ResolveRepositoryRoot: extracted IsRepositoryRoot
and made it accept either a .git marker OR a .sln/.slnx next to src/
so the worker-exe walker works in non-git working copies.
clients/proto/proto-inputs.json's protoRoot updated to point at
src/ZB.MOM.WW.MxGateway.Contracts/Protos.
Verified by `dotnet build` and a full `dotnet test` of the .slnx with
MXGATEWAY_RUN_LIVE_{MXACCESS,LDAP,GALAXY}_TESTS=1:
Tests: 472/472 pass
Worker.Tests: 280/280 pass (4 dev-rig [Fact(Skip=...)] skipped)
IntegrationTests: 18/18 pass
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
111 lines
4.8 KiB
C#
111 lines
4.8 KiB
C#
using System.Globalization;
|
|
using ZB.MOM.WW.MxGateway.Contracts.Proto;
|
|
|
|
namespace ZB.MOM.WW.MxGateway.Server.Dashboard;
|
|
|
|
/// <summary>
|
|
/// Formats an <see cref="MxValue"/> into the short, human-readable text the
|
|
/// dashboard's Browse subscription panel shows. Kept separate from the
|
|
/// view layer so the formatting rules are unit-testable without a worker.
|
|
/// </summary>
|
|
public static class DashboardMxValueFormatter
|
|
{
|
|
/// <summary>Maximum array elements rendered inline before the value is truncated.</summary>
|
|
private const int MaxArrayElements = 24;
|
|
|
|
/// <summary>Formats the value payload of an <see cref="MxValue"/>.</summary>
|
|
/// <param name="value">The value to format; may be null.</param>
|
|
/// <returns>A display string — never null.</returns>
|
|
public static string FormatValue(MxValue? value)
|
|
{
|
|
if (value is null)
|
|
{
|
|
return "-";
|
|
}
|
|
|
|
if (value.IsNull)
|
|
{
|
|
return "(null)";
|
|
}
|
|
|
|
return value.KindCase switch
|
|
{
|
|
MxValue.KindOneofCase.BoolValue => value.BoolValue ? "true" : "false",
|
|
MxValue.KindOneofCase.Int32Value => value.Int32Value.ToString(CultureInfo.InvariantCulture),
|
|
MxValue.KindOneofCase.Int64Value => value.Int64Value.ToString(CultureInfo.InvariantCulture),
|
|
MxValue.KindOneofCase.FloatValue => value.FloatValue.ToString("G7", CultureInfo.InvariantCulture),
|
|
MxValue.KindOneofCase.DoubleValue => value.DoubleValue.ToString("G15", CultureInfo.InvariantCulture),
|
|
MxValue.KindOneofCase.StringValue => value.StringValue,
|
|
MxValue.KindOneofCase.TimestampValue => value.TimestampValue
|
|
.ToDateTimeOffset()
|
|
.UtcDateTime
|
|
.ToString("yyyy-MM-dd HH:mm:ss.fff 'UTC'", CultureInfo.InvariantCulture),
|
|
MxValue.KindOneofCase.ArrayValue => FormatArray(value.ArrayValue),
|
|
MxValue.KindOneofCase.RawValue => $"({value.RawValue.Length} bytes)",
|
|
_ => "-",
|
|
};
|
|
}
|
|
|
|
/// <summary>Formats the MXAccess data type of an <see cref="MxValue"/>.</summary>
|
|
/// <param name="value">The value whose data type to describe; may be null.</param>
|
|
/// <returns>The data-type name — never null. Arrays render as <c>Element[dims]</c>.</returns>
|
|
public static string FormatDataType(MxValue? value)
|
|
{
|
|
if (value is null)
|
|
{
|
|
return "-";
|
|
}
|
|
|
|
// A scalar carries its type in MxValue.DataType, but an array leaves
|
|
// that Unspecified and carries the element type on the MxArray itself.
|
|
return value.KindCase == MxValue.KindOneofCase.ArrayValue
|
|
? FormatArrayDataType(value.ArrayValue)
|
|
: value.DataType.ToString();
|
|
}
|
|
|
|
private static string FormatArrayDataType(MxArray array)
|
|
{
|
|
string dimensions = array.Dimensions.Count > 0
|
|
? string.Join(",", array.Dimensions)
|
|
: string.Empty;
|
|
return $"{array.ElementDataType}[{dimensions}]";
|
|
}
|
|
|
|
private static string FormatArray(MxArray array)
|
|
{
|
|
IReadOnlyList<string> elements = array.ValuesCase switch
|
|
{
|
|
MxArray.ValuesOneofCase.BoolValues =>
|
|
array.BoolValues.Values.Select(item => item ? "true" : "false").ToArray(),
|
|
MxArray.ValuesOneofCase.Int32Values =>
|
|
array.Int32Values.Values.Select(item => item.ToString(CultureInfo.InvariantCulture)).ToArray(),
|
|
MxArray.ValuesOneofCase.Int64Values =>
|
|
array.Int64Values.Values.Select(item => item.ToString(CultureInfo.InvariantCulture)).ToArray(),
|
|
MxArray.ValuesOneofCase.FloatValues =>
|
|
array.FloatValues.Values.Select(item => item.ToString("G7", CultureInfo.InvariantCulture)).ToArray(),
|
|
MxArray.ValuesOneofCase.DoubleValues =>
|
|
array.DoubleValues.Values.Select(item => item.ToString("G15", CultureInfo.InvariantCulture)).ToArray(),
|
|
MxArray.ValuesOneofCase.StringValues =>
|
|
array.StringValues.Values.Select(item => $"\"{item}\"").ToArray(),
|
|
MxArray.ValuesOneofCase.TimestampValues =>
|
|
array.TimestampValues.Values
|
|
.Select(item => item.ToDateTimeOffset().UtcDateTime
|
|
.ToString("yyyy-MM-dd HH:mm:ss 'UTC'", CultureInfo.InvariantCulture))
|
|
.ToArray(),
|
|
MxArray.ValuesOneofCase.RawValues =>
|
|
array.RawValues.Values.Select(item => $"({item.Length} bytes)").ToArray(),
|
|
_ => [],
|
|
};
|
|
|
|
if (elements.Count == 0)
|
|
{
|
|
return "[]";
|
|
}
|
|
|
|
string body = string.Join(", ", elements.Take(MaxArrayElements));
|
|
return elements.Count > MaxArrayElements
|
|
? $"[{body}, … {elements.Count} total]"
|
|
: $"[{body}]";
|
|
}
|
|
}
|