HanvonAttendanceService/EmployeePhotoSourceSettings.cs

62 lines
1.6 KiB
C#

using System;
using System.Configuration;
namespace HanvonF710XAttendanceService
{
internal static class EmployeePhotoSourceSettings
{
public static bool IsEnabled()
{
return GetBool("EnableEmployeePhotoSource", false);
}
public static string GetBaseUrl()
{
return ConfigurationManager.AppSettings["EmployeePhotoBaseUrl"]?.Trim() ?? "";
}
public static int GetMinShortSide()
{
return GetInt("HRMS_PHOTO_MIN_SHORT_SIDE", 80);
}
public static int GetMaxShortSide()
{
return GetInt("HRMS_PHOTO_MAX_SHORT_SIDE", 4096);
}
public static int GetTimeoutMs()
{
return GetInt("HRMS_PHOTO_HTTP_TIMEOUT_MS", 30000);
}
private static bool GetBool(string key, bool defaultValue)
{
try
{
var raw = ConfigurationManager.AppSettings[key];
if (string.IsNullOrWhiteSpace(raw)) return defaultValue;
return bool.TryParse(raw.Trim(), out var v) ? v : defaultValue;
}
catch
{
return defaultValue;
}
}
private static int GetInt(string key, int defaultValue)
{
try
{
var raw = ConfigurationManager.AppSettings[key];
if (string.IsNullOrWhiteSpace(raw)) return defaultValue;
return int.TryParse(raw.Trim(), out var v) && v > 0 ? v : defaultValue;
}
catch
{
return defaultValue;
}
}
}
}