Refactor name for ProgramConfigs
This commit is contained in:
parent
95d49e62fb
commit
0ca165c6bb
@ -2,65 +2,9 @@
|
||||
|
||||
namespace BenchtopParser {
|
||||
public class I28 {
|
||||
public static Dictionary<String, ProgramConfig> Load_ProgramConfig(String program_config_value) {
|
||||
Dictionary<String, ProgramConfig> programConfigs = new Dictionary<String, ProgramConfig>();
|
||||
ProgramConfig? current = null;
|
||||
|
||||
foreach (var line in program_config_value.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)) {
|
||||
var configLine = line.Split("\t").ToList();
|
||||
if (configLine.Count() < 2) {
|
||||
throw new Exception("Invalid Program Config, please provide an I28 Program Config file data");
|
||||
}
|
||||
configLine.RemoveAt(0); // Remove random hex value
|
||||
configLine.RemoveAt(0); // Remove L column
|
||||
|
||||
if (configLine[0].StartsWith("Start,")) {
|
||||
// initialize programconfig
|
||||
current = new ProgramConfig();
|
||||
continue;
|
||||
}
|
||||
if (configLine[0].StartsWith("Stop,")) {
|
||||
// Short circuit early when stop comes.
|
||||
if (current != null && current.ProgramNumber != null) {
|
||||
programConfigs.Add(current.ProgramNumber, current);
|
||||
}
|
||||
current = null;
|
||||
// TODO: What if multiple configs how to handle start and stop?
|
||||
break;
|
||||
}
|
||||
var config = configLine[0].Split(",", 2).ToList();
|
||||
if (configLine.Count() == 1) {
|
||||
// Set Program Number
|
||||
if (current == null) {
|
||||
throw new Exception("Setting Program Number Before Start. Error In Config");
|
||||
}
|
||||
Console.WriteLine(config[1]);
|
||||
current.ProgramNumber = config[1];
|
||||
continue;
|
||||
}
|
||||
|
||||
// Skip numbers, keep value
|
||||
var value = config[1];
|
||||
|
||||
var programnumber_group_data = value.Split('\\'); // snake case as its three values
|
||||
var data = programnumber_group_data[2];
|
||||
if (data.StartsWith("=")) { continue; /* comment line */ }
|
||||
|
||||
var lineConfig = new Configuration(configLine, data);
|
||||
|
||||
// Deal with this group logic
|
||||
var group = programnumber_group_data[1];
|
||||
if (current != null && !current.Group.ContainsKey(group)) {
|
||||
current.Group.Add(group, new Dictionary<String, Configuration> { { lineConfig.name, lineConfig } });
|
||||
} else if (current != null) {
|
||||
current.Group[group].Add(lineConfig.name, lineConfig);
|
||||
} else {
|
||||
throw new Exception("Config list is null, something broke");
|
||||
}
|
||||
}
|
||||
// TODO: What if multiple configs how to handle start and stop?
|
||||
|
||||
return programConfigs;
|
||||
public static ProgramConfig Load_ProgramConfig(String program_config_value) {
|
||||
ProgramConfig pc = new ProgramConfig(program_config_value);
|
||||
return pc;
|
||||
}
|
||||
|
||||
public static TransducerVerify Load_TransducerVerify(String transducer_verify_value) {
|
||||
|
@ -5,11 +5,11 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BenchtopParser {
|
||||
public class ProgramConfig {
|
||||
public class Program {
|
||||
public String? ProgramNumber { get; set; }
|
||||
public Dictionary<String, Dictionary<String, Configuration>> Group { get; set; }
|
||||
|
||||
public ProgramConfig() {
|
||||
public Program() {
|
||||
this.Group = new Dictionary<String, Dictionary<String, Configuration>>();
|
||||
}
|
||||
}
|
||||
@ -19,15 +19,83 @@ namespace BenchtopParser {
|
||||
public String? type { get; set; }
|
||||
public String? unit { get; set; }
|
||||
|
||||
public Configuration(List<String> config, string data) {
|
||||
var nameValue = data.Split("=");
|
||||
public Configuration(List<String> config, String data) {
|
||||
String[] nameValue = data.Split("=");
|
||||
name = nameValue[0].Trim();
|
||||
value = nameValue[1].Trim();
|
||||
|
||||
unit = config[1].Trim();
|
||||
type = config[2].Trim(); //a, c, f, i
|
||||
}
|
||||
}
|
||||
|
||||
public class ProgramConfig {
|
||||
public Dictionary<String, Program> programs = new Dictionary<String, Program>();
|
||||
public ProgramConfig (String program_config_value) {
|
||||
Program? current = null;
|
||||
|
||||
foreach (var line in program_config_value.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)) {
|
||||
List<String> configLine = line.Split("\t").ToList();
|
||||
if (configLine.Count < 2) {
|
||||
throw new Exception("Invalid Program Config, please provide an I28 Program Config file data");
|
||||
}
|
||||
|
||||
// Remove the first two items because they seem to be a checksum and an unneeded type.
|
||||
// Then we can start at 0 like normal, not have the first important bit be at 2.
|
||||
configLine.RemoveAt(0); // Remove random hex value
|
||||
configLine.RemoveAt(0); // Remove L column
|
||||
|
||||
/* LOOP CONTROL */
|
||||
if (configLine[0].StartsWith("Start,")) {
|
||||
// initialize programconfig
|
||||
current = new Program();
|
||||
continue;
|
||||
}
|
||||
if (configLine[0].StartsWith("Stop,")) {
|
||||
// Short circuit early when stop comes.
|
||||
if (current != null && current.ProgramNumber != null) {
|
||||
programs.Add(current.ProgramNumber, current);
|
||||
}
|
||||
current = null;
|
||||
// TODO: What if multiple configs how to handle start and stop?
|
||||
break;
|
||||
}
|
||||
var config = configLine[0].Split(",", 2).ToList();
|
||||
if (configLine.Count == 1) {
|
||||
// Set Program Number
|
||||
if (current == null) {
|
||||
throw new Exception("Setting Program Number Before Start. Error In Config");
|
||||
}
|
||||
current.ProgramNumber = config[1];
|
||||
continue;
|
||||
}
|
||||
/* CREATE A CONFIGURATION */
|
||||
|
||||
var value = config[1];
|
||||
|
||||
var programnumber_group_data = value.Split('\\'); // snake case as its three values
|
||||
var data = programnumber_group_data[2];
|
||||
if (data.StartsWith("=")) { continue; /* comment line */ }
|
||||
|
||||
Configuration lineConfig = new Configuration(configLine, data);
|
||||
|
||||
// Deal with this group logic
|
||||
var group = programnumber_group_data[1];
|
||||
if (current != null && !current.Group.ContainsKey(group)) {
|
||||
current.Group.Add(group, new Dictionary<String, Configuration> {
|
||||
{ lineConfig.name, lineConfig }
|
||||
});
|
||||
} else if (current != null) {
|
||||
current.Group[group].Add(lineConfig.name, lineConfig);
|
||||
} else {
|
||||
throw new Exception("Config list is null, something broke");
|
||||
}
|
||||
}
|
||||
// TODO: What if multiple configs how to handle start and stop?
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -9,16 +9,16 @@ namespace BenchtopParserTests {
|
||||
String program_config = File.ReadAllText(
|
||||
Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestFiles\Program Config.txt")
|
||||
);
|
||||
var configs = BenchtopParser.I28.Load_ProgramConfig(program_config);
|
||||
Assert.IsNotNull(configs);
|
||||
var programConfigs = BenchtopParser.I28.Load_ProgramConfig(program_config);
|
||||
Assert.IsNotNull(programConfigs);
|
||||
|
||||
// Check that group collecting works -
|
||||
Assert.That(configs["P1"].Group["I"]["3"].value, Is.EqualTo("Unassigned"));
|
||||
Assert.That(configs["P1"].Group["O"]["3"].value, Is.EqualTo("Test Passed"));
|
||||
Assert.That(programConfigs.programs["P1"].Group["I"]["3"].value, Is.EqualTo("Unassigned"));
|
||||
Assert.That(programConfigs.programs["P1"].Group["O"]["3"].value, Is.EqualTo("Test Passed"));
|
||||
|
||||
Assert.That(configs["P1"].Group["P"]["Minimum Pressure"].value, Is.EqualTo("95.000"));
|
||||
Assert.That(configs["P1"].Group["P"]["Minimum Pressure"].unit, Is.EqualTo("mbar"));
|
||||
Assert.That(configs["P1"].Group["P"]["Minimum Pressure"].type, Is.EqualTo("f"));
|
||||
Assert.That(programConfigs.programs["P1"].Group["P"]["Minimum Pressure"].value, Is.EqualTo("95.000"));
|
||||
Assert.That(programConfigs.programs["P1"].Group["P"]["Minimum Pressure"].unit, Is.EqualTo("mbar"));
|
||||
Assert.That(programConfigs.programs["P1"].Group["P"]["Minimum Pressure"].type, Is.EqualTo("f"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
Loading…
Reference in New Issue
Block a user