45 lines
1.4 KiB
C#
45 lines
1.4 KiB
C#
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);
|
|
}
|
|
}
|
|
}
|