AIParkingApplication/AIParkingApplication/ConfigurationForm.cs

68 lines
2.5 KiB
C#

using NLog;
using System;
using System.Configuration;
using System.Windows.Forms;
namespace AIParkingApplication
{
public partial class ConfigurationForm : Form
{
private Logger appLogger;
private string doorAccessControlDeviceIP;
private bool allowAutoOpenDoor1;
private bool allowAutoOpenDoor2;
private bool allowUsePrinter;
private bool allowChangeROIRect;
public ConfigurationForm(Logger appLogger)
{
InitializeComponent();
this.appLogger = appLogger;
}
private void btnClose_Click(object sender, EventArgs e)
{
Close();
}
private void btnSaveSettings_Click(object sender, EventArgs e)
{
}
private void ConfigurationForm_Load(object sender, EventArgs e)
{
LoadConfiguration();
txtDoorDeviceControlAccessIP.Text = doorAccessControlDeviceIP;
chkAllowAutoDoor1.Checked = allowAutoOpenDoor1;
chkAllowAutoDoor2.Checked = allowAutoOpenDoor2;
chkAllowUsePrinter.Checked = allowUsePrinter;
chkAllowChangeROIRect.Checked = allowChangeROIRect;
}
private void LoadConfiguration()
{
doorAccessControlDeviceIP = ReadConfigurationFromAppSettings("DOOR_ACCESS_DEVICE_CONTROL_IP", string.Empty);
bool.TryParse(ReadConfigurationFromAppSettings("AUTO_OPEN_DOOR_1", "false"), out allowAutoOpenDoor1);
bool.TryParse(ReadConfigurationFromAppSettings("AUTO_OPEN_DOOR_2", "false"), out allowAutoOpenDoor2);
bool.TryParse(ReadConfigurationFromAppSettings("USE_PRINTER", "false"), out allowUsePrinter);
bool.TryParse(ReadConfigurationFromAppSettings("ALLOW_CHANGE_ROI_RECT", "false"), out allowChangeROIRect);
}
private string ReadConfigurationFromAppSettings(string configurationKey, string defaultValueIfReadFailed)
{
try
{
return ConfigurationManager.AppSettings[configurationKey].Trim();
}
catch (Exception ex)
{
Util.UpsertAppSettings(configurationKey, defaultValueIfReadFailed);
Console.WriteLine($"ReadDoorDeviceControlAccessConfiguration. ex: {ex.Message}");
appLogger.Log(LogLevel.Info, $"ConfigurationForm - ReadConfigurationFromAppSettings. Key: {configurationKey} - DefaultValue: {defaultValueIfReadFailed}. ex: {ex.Message}");
return defaultValueIfReadFailed;
}
}
}
}