34 lines
1.1 KiB
C#
34 lines
1.1 KiB
C#
using System.Text.RegularExpressions;
|
||
|
||
namespace HikvisionAttendanceService;
|
||
|
||
/// <summary>
|
||
/// Single place for DeviceId trimming and session/fetch lookup keys so config, CLI, and logs stay aligned.
|
||
/// </summary>
|
||
internal static class DeviceIdentity
|
||
{
|
||
private static readonly Regex FMNumericSuffix = new Regex(@"-FM(\d+)$", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);
|
||
|
||
/// <summary>Value stored from JSON after load — trim only; never replace user’s chosen id.</summary>
|
||
public static string NormalizeConfigured(string? raw)
|
||
{
|
||
if (string.IsNullOrWhiteSpace(raw))
|
||
return "";
|
||
return raw.Trim();
|
||
}
|
||
|
||
/// <summary>
|
||
/// Stable key for FindSession / fetch: same physical device if only the "-FM" serial prefix differs
|
||
/// (e.g. DS-K1T642MFW-FM7378360 vs DS-K1T642MFW-7378360).
|
||
/// </summary>
|
||
public static string CanonicalLookupKey(string? raw)
|
||
{
|
||
var s = NormalizeConfigured(raw);
|
||
if (s.Length == 0)
|
||
return "";
|
||
|
||
s = FMNumericSuffix.Replace(s, "-$1");
|
||
return s.ToUpperInvariant();
|
||
}
|
||
}
|