editable app settings, publish to ..\auftrag\Actuelle Anwendungen
This commit is contained in:
@@ -0,0 +1,112 @@
|
||||
namespace CordonelAssemblyLine.Model
|
||||
{
|
||||
using System.Configuration;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
public class ExeConfig
|
||||
{
|
||||
public int PickingSlot
|
||||
{
|
||||
get
|
||||
{
|
||||
_ = int.TryParse(GetValue(), out var value);
|
||||
|
||||
return value;
|
||||
}
|
||||
set => SetValue(value);
|
||||
}
|
||||
|
||||
public string PickingBarcode
|
||||
{
|
||||
get => GetValue();
|
||||
set => SetValue(value);
|
||||
}
|
||||
|
||||
public int LeakSlot
|
||||
{
|
||||
get
|
||||
{
|
||||
_ = int.TryParse(GetValue(), out var value);
|
||||
|
||||
return value;
|
||||
}
|
||||
set => SetValue(value);
|
||||
}
|
||||
|
||||
public int LeakStationId
|
||||
{
|
||||
get
|
||||
{
|
||||
_ = int.TryParse(GetValue(), out var value);
|
||||
|
||||
return value;
|
||||
}
|
||||
set => SetValue(value);
|
||||
}
|
||||
|
||||
public string LeakTester
|
||||
{
|
||||
get => GetValue();
|
||||
set => SetValue(value);
|
||||
}
|
||||
|
||||
public int MarriageSlot
|
||||
{
|
||||
get
|
||||
{
|
||||
_ = int.TryParse(GetValue(), out var value);
|
||||
|
||||
return value;
|
||||
}
|
||||
set => SetValue(value);
|
||||
}
|
||||
|
||||
public string MarriageBarcode
|
||||
{
|
||||
get => GetValue();
|
||||
set => SetValue(value);
|
||||
}
|
||||
|
||||
private static string GetValue([CallerMemberName] string key = "")
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(key))
|
||||
{
|
||||
return default(string);
|
||||
}
|
||||
|
||||
var dll = typeof(ExeConfig).Assembly.Location;
|
||||
var configuration = ConfigurationManager.OpenExeConfiguration(dll);
|
||||
var settings = configuration?.AppSettings?.Settings ?? new KeyValueConfigurationCollection();
|
||||
|
||||
if (!settings.AllKeys.Contains(key))
|
||||
{
|
||||
return default(string);
|
||||
}
|
||||
|
||||
return settings[key].Value;
|
||||
}
|
||||
|
||||
private static void SetValue(object value, [CallerMemberName] string key = "")
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(key))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var dll = typeof(ExeConfig).Assembly.Location;
|
||||
var configuration = ConfigurationManager.OpenExeConfiguration(dll);
|
||||
var settings = configuration?.AppSettings?.Settings ?? new KeyValueConfigurationCollection();
|
||||
|
||||
if (!settings.AllKeys.Contains(key))
|
||||
{
|
||||
settings.Add(key, string.Empty);
|
||||
}
|
||||
|
||||
settings[key].Value = $"{value}";
|
||||
|
||||
configuration.Save(ConfigurationSaveMode.Modified);
|
||||
ConfigurationManager.RefreshSection("appSettings");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user