Resolve Device ID Automatically
Uses the Windows machine name as the default Device ID, saves it when missing, and logs the resolved value on startup.feature/centralized-offline-canteen
parent
3e91cfaba8
commit
11ab230d87
|
|
@ -66,8 +66,23 @@ public sealed class ClientConfigService : IConfigService
|
|||
SaveConfig();
|
||||
}
|
||||
|
||||
public string GetDeviceId() => _config.DeviceId ?? string.Empty;
|
||||
public void SetDeviceId(string deviceId) { _config.DeviceId = deviceId ?? string.Empty; SaveConfig(); }
|
||||
public string GetDeviceId()
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(_config.DeviceId))
|
||||
return _config.DeviceId.Trim();
|
||||
|
||||
_config.DeviceId = ResolveMachineDeviceId();
|
||||
SaveConfig();
|
||||
return _config.DeviceId;
|
||||
}
|
||||
|
||||
public void SetDeviceId(string deviceId)
|
||||
{
|
||||
_config.DeviceId = string.IsNullOrWhiteSpace(deviceId)
|
||||
? ResolveMachineDeviceId()
|
||||
: deviceId.Trim();
|
||||
SaveConfig();
|
||||
}
|
||||
|
||||
public bool GetRememberAdminCredentials() => _config.RememberAdminCredentials;
|
||||
public void SetRememberAdminCredentials(bool remember) { _config.RememberAdminCredentials = remember; SaveConfig(); }
|
||||
|
|
@ -133,6 +148,14 @@ public sealed class ClientConfigService : IConfigService
|
|||
}
|
||||
}
|
||||
|
||||
private static string ResolveMachineDeviceId()
|
||||
{
|
||||
var machineName = Environment.MachineName;
|
||||
return string.IsNullOrWhiteSpace(machineName)
|
||||
? Guid.NewGuid().ToString("N")
|
||||
: machineName.Trim();
|
||||
}
|
||||
|
||||
private static string EncryptPassword(string plain)
|
||||
{
|
||||
if (string.IsNullOrEmpty(plain)) return string.Empty;
|
||||
|
|
|
|||
|
|
@ -34,7 +34,10 @@ public partial class App : Application
|
|||
}
|
||||
|
||||
var configService = new ClientConfigService();
|
||||
FileLogger.Info("ClientApp", $"Backend base URL={configService.GetBackendBaseUrl()}");
|
||||
FileLogger.Info("ClientApp", $"BackendBaseUrl = {configService.GetBackendBaseUrl()}");
|
||||
FileLogger.Info(
|
||||
"ClientApp",
|
||||
$"Device ID resolved. MachineName={Environment.MachineName}, DeviceId={configService.GetDeviceId()}");
|
||||
FileLogger.Info("ClientApp", $"Logs directory={LogPaths.ClientLogsDirectory}");
|
||||
|
||||
var httpClient = new HttpClient { Timeout = TimeSpan.FromMinutes(5) };
|
||||
|
|
|
|||
Loading…
Reference in New Issue