hikvision-sync-service/Tests/run_photo_processor.ps1

50 lines
2.2 KiB
PowerShell

# Manual harness: runs EmployeePhotoFaceProcessor against real HRMS portal photos.
# Run with 32-bit PowerShell (the service targets x86):
# C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe -File Tests\run_photo_processor.ps1 142554 144154
param([string[]]$EmployeeIds = @('142554'))
$ErrorActionPreference = 'Stop'
$dir = Join-Path $PSScriptRoot '..\bin\Debug\net48' | Resolve-Path
$outDir = Join-Path $env:TEMP 'hik_photo_test'
New-Item -ItemType Directory -Force -Path $outDir | Out-Null
[System.AppDomain]::CurrentDomain.add_AssemblyResolve({
param($sender, $e)
$name = ($e.Name -split ',')[0]
$path = Join-Path $dir "$name.dll"
if (Test-Path $path) { return [System.Reflection.Assembly]::LoadFrom($path) }
return $null
})
$asm = [System.Reflection.Assembly]::LoadFrom((Join-Path $dir 'HikvisionAttendanceService.exe'))
$type = $asm.GetType('HikvisionAttendanceService.EmployeePhotoFaceProcessor')
$method = $type.GetMethod('Process', [System.Reflection.BindingFlags]'Static,Public,NonPublic')
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12
$client = New-Object System.Net.WebClient
foreach ($id in $EmployeeIds) {
$url = "https://portal.utopiaindustries.pk/uind/employee-photo/$id.jpeg"
try { $bytes = $client.DownloadData($url) }
catch { Write-Host "$id download failed: $($_.Exception.Message)"; continue }
$result = $method.Invoke($null, @(, $bytes))
$srcPath = Join-Path $outDir "$id.source.jpeg"
[System.IO.File]::WriteAllBytes($srcPath, $bytes)
$line = "id=$id status=$($result.Status) downloaded=$($bytes.Length) " +
"original=$($result.Original.Width)x$($result.Original.Height) " +
"face=$($result.Face.Width)x$($result.Face.Height) " +
"processed=$($result.Processed.Width)x$($result.Processed.Height) " +
"jpegBytes=$($result.JpegBytes.Length) quality=$($result.JpegQuality) " +
"enhance=[$($result.Enhancement)] err=$($result.Error)"
Write-Host $line
if ($result.JpegBytes.Length -gt 0) {
$outPath = Join-Path $outDir "$id.processed.jpeg"
[System.IO.File]::WriteAllBytes($outPath, $result.JpegBytes)
Write-Host " source=$srcPath"
Write-Host " processed=$outPath"
}
}