Files
HawkeyeVision/VisionBuilder.UI.Common/UIConfiguration.cs
2025-07-28 09:52:29 +02:00

68 lines
1.9 KiB
C#

using Inspectron.Settings;
using System.ComponentModel;
using System.Globalization;
using VisionBuilder.UI.Common.Utils;
namespace VisionBuilder.UI.Common;
public class UIConfiguration: ISettings
{
/// <summary>
/// Max errors to be displayed in the UI.
/// </summary>
public int MaxErrorCount { get; set; } = 100;
public string AdminPassword { get; set; } = "";
public List<ErrorShortName> ErrorShortNames { get; set; } = new List<ErrorShortName>();
public void RegisterSettings(InspectronSettings settings)
{
settings.RegisterSimple(this, () => this.MaxErrorCount, "Errors", "Max errors count", "UI");
settings.RegisterSimple(this, () => this.AdminPassword, "System", "Password", "UI");
settings.RegisterSimple(this, () => this.ErrorShortNames, "Errors", "Error short names", "UI");
}
}
public class ErrorShortName
{
public string FullName { get; set; }
public string ShortName { get; set; }
public override string ToString()
{
return $"{FullName} -> {ShortName}";
}
}
public class ErrorShortNameConverter : GeneralListTypeConverter<ErrorShortName>
{
protected override ErrorShortName ConvertFromString(ITypeDescriptorContext context, CultureInfo culture, string stringValue)
{
if (string.IsNullOrEmpty(stringValue))
return null;
var parts = stringValue.Split(',');
if (parts.Length == 2)
{
return new ErrorShortName
{
FullName = parts[0].Trim(),
ShortName = parts[1].Trim()
};
}
return null;
}
protected override string ConvertToString(ITypeDescriptorContext context, CultureInfo culture, ErrorShortName errorShortName)
{
if (errorShortName == null)
return null;
return $"{errorShortName.FullName},{errorShortName.ShortName}";
}
}