feat: classify Hanvon duplicate-face errors as DUPLICATE_FACE

Parse face is double,id=... separately from upload failures.
main
SYED MUSTUFA AHMED NAQVI 2026-09-04 12:35:14 +05:00
parent 5a1f68077d
commit c41950a22a
2 changed files with 92 additions and 0 deletions

44
DbToDeviceFaceErrors.cs Normal file
View File

@ -0,0 +1,44 @@
using System;
using System.Text.RegularExpressions;
namespace HanvonF710XAttendanceService
{
internal sealed class DbToDeviceDuplicateFaceEntry
{
public DbToDeviceDuplicateFaceEntry(string employeeId, string existingDeviceId, string targetDevice)
{
EmployeeId = employeeId ?? "";
ExistingDeviceId = existingDeviceId ?? "";
TargetDevice = targetDevice ?? "";
}
public string EmployeeId { get; }
public string ExistingDeviceId { get; }
public string TargetDevice { get; }
}
internal static class DbToDeviceFaceErrors
{
private static readonly Regex DuplicateFaceRegex = new Regex(
@"face\s+is\s+double\s*,\s*id\s*=\s*(\d+)",
RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);
public static bool TryParseDuplicateFace(string errorMessage, out string existingDeviceId)
{
existingDeviceId = null;
if (string.IsNullOrWhiteSpace(errorMessage))
{
return false;
}
Match match = DuplicateFaceRegex.Match(errorMessage.Trim());
if (!match.Success || match.Groups.Count < 2)
{
return false;
}
existingDeviceId = match.Groups[1].Value?.Trim();
return !string.IsNullOrWhiteSpace(existingDeviceId);
}
}
}

View File

@ -0,0 +1,48 @@
using System;
namespace HanvonF710XAttendanceService
{
internal static class DbToDeviceFaceErrorsTests
{
public static int RunAll()
{
int failed = 0;
failed += Run("parse duplicate face error", TestParseDuplicateFace);
failed += Run("ignore generic upload error", TestIgnoreGenericError);
return failed;
}
private static int Run(string name, Func<bool> test)
{
try
{
if (!test())
{
Console.WriteLine("FAIL: " + name);
return 1;
}
Console.WriteLine("PASS: " + name);
return 0;
}
catch (Exception ex)
{
Console.WriteLine("FAIL: " + name + " err=" + ex.Message);
return 1;
}
}
private static bool TestParseDuplicateFace()
{
return DbToDeviceFaceErrors.TryParseDuplicateFace("face is double,id=6400", out string existingId)
&& existingId == "6400"
&& DbToDeviceFaceErrors.TryParseDuplicateFace("Face is double, id=6475", out string existingId2)
&& existingId2 == "6475";
}
private static bool TestIgnoreGenericError()
{
return !DbToDeviceFaceErrors.TryParseDuplicateFace("no face in picture", out _);
}
}
}