Add config file and refactor windows
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System.Windows;
|
||||
|
||||
namespace PamhagenSysCtrl.Helpers {
|
||||
public class Config {
|
||||
|
||||
private static readonly string[] TrueValues = ["1", "true", "yes", "on"];
|
||||
|
||||
private readonly string FileName;
|
||||
|
||||
public string PlcPort = "COM1";
|
||||
|
||||
public Config(string filename) {
|
||||
FileName = filename;
|
||||
Read();
|
||||
}
|
||||
|
||||
public void Read() {
|
||||
try {
|
||||
var config = new ConfigurationBuilder().AddIniFile(FileName).Build();
|
||||
PlcPort = config["plc:port"] ?? "COM1";
|
||||
} catch (Exception exc) {
|
||||
MessageBox.Show($"Die Konfigurationsdatei konnte nicht gelesen werden:\n\n{exc.Message}", "Konfigurationsdatei lesen", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
App.Current.Shutdown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user