ComponentsManager: Creation of FlowMeters, TempMeters, PressureMeters, RegisterReaders and WaterMeters from a script file added.

This commit is contained in:
Milan Hanajik 2017-05-16 13:06:48 +02:00
parent c4d736b7cc
commit e21d9102a2
2 changed files with 88 additions and 29 deletions

View File

@ -337,34 +337,12 @@ namespace TBF
{
string[] words = line.Split(new char[] { ' ', '\t' });
if (cfg is BenchControl.Elde.Valve.ValveCfg)
if (UpdateCfg(ref cfg, words, ref zeroBasedIdx))
{
int bitNr;
if (words.Length >= 2 && words[0].StartsWith("D") && int.TryParse(words[0].Substring(1), out bitNr))
{
zeroBasedIdx = bitNr;
}
if (words[words.Length - 1] != "-")
{
cfg.Name = words[words.Length - 1];
(cfg as BenchControl.Elde.Valve.ValveCfg).BitPosition = zeroBasedIdx;
flags |= CfgUpdateFlags.RestartRqrd;
AddOne(cfg.CreateDbEntity());
}
flags |= CfgUpdateFlags.RestartRqrd;
AddOne(cfg.CreateDbEntity());
}
else if (cfg is BenchControl.Elde.RegisterReader.RegisterReaderCfg)
{
cfg.Name = words[words.Length - 1].Replace("#", (zeroBasedIdx + 1).ToString());
(cfg as IChildComponentCfg).ParentName = "CB";
(cfg as BenchControl.Elde.RegisterReader.RegisterReaderCfg).Position = zeroBasedIdx + 1;
}
else if (cfg is BenchControl.Elde.FixedStartRegisterReader.RegisterReaderCfg)
{
cfg.Name = words[words.Length - 1].Replace("#", (zeroBasedIdx + 1).ToString());
(cfg as IChildComponentCfg).ParentName = "CB";
}
zeroBasedIdx++;
}
@ -536,5 +514,79 @@ namespace TBF
}
}
}
}
/// <summary>
/// Updates component configuration from a script file
/// </summary>
/// <param name="cfg"></param>
/// <param name="words"></param>
/// <param name="zeroBasedIdx"></param>
/// <returns>true = udated component configuration should be saved, new component should be created</returns>
bool UpdateCfg(ref IComponentCfg cfg, string[] words, ref int zeroBasedIdx)
{
string name = words[words.Length - 1]; /// The last word is the component name
cfg.Name = name.Replace("#", (zeroBasedIdx + 1).ToString());
if (cfg is BenchControl.Elde.Valve.ValveCfg)
{
int bitNr = zeroBasedIdx;
if (words.Length >= 2 && words[0].StartsWith("D") && int.TryParse(words[0].Substring(1), out bitNr))
{
zeroBasedIdx = bitNr;
}
if (name != "-")
{
(cfg as BenchControl.Elde.Valve.ValveCfg).BitPosition = bitNr;
(cfg as BenchControl.Elde.Valve.ValveCfg).Category =
name.Contains("L") ? ValveCategory.Bench :
name.Contains("I") ? ValveCategory.Output :
name.Contains("Z") ? ValveCategory.Feeding : ValveCategory.None;
return true;
}
}
else if (cfg is BenchControl.Elde.FlowMeter.FlowMeterCfg)
{
(cfg as IChildComponentCfg).ParentName = "CB";
(cfg as BenchControl.Elde.FlowMeter.FlowMeterCfg).Idx1 = zeroBasedIdx + 1;
return true;
}
else if (cfg is BenchControl.Elde.TempMeter.TempMeterCfg)
{
(cfg as IChildComponentCfg).ParentName = "CB";
(cfg as BenchControl.Elde.TempMeter.TempMeterCfg).Idx0 = zeroBasedIdx;
return true;
}
else if (cfg is BenchControl.Elde.PressureMeter.PressureMeterCfg)
{
(cfg as IChildComponentCfg).ParentName = "CB";
(cfg as BenchControl.Elde.PressureMeter.PressureMeterCfg).Idx0 = zeroBasedIdx;
return true;
}
else if (cfg is BenchControl.Elde.RegisterReader.RegisterReaderCfg)
{
(cfg as IChildComponentCfg).ParentName = "CB";
(cfg as BenchControl.Elde.RegisterReader.RegisterReaderCfg).Position = zeroBasedIdx + 1;
return true;
}
else if (cfg is BenchControl.Elde.RegulValve.RegulValveCfg)
{
(cfg as IChildComponentCfg).ParentName = "CB";
(cfg as BenchControl.Elde.RegulValve.RegulValveCfg).Idx1 = zeroBasedIdx + 1;
return true;
}
else if (cfg is BenchControl.Elde.FixedStartRegisterReader.RegisterReaderCfg)
{
(cfg as IChildComponentCfg).ParentName = "CB";
return true;
}
else if (cfg is BenchControl.WaterMeters.WaterMeter.WaterMeterCfg)
{
return true;
}
return false;
}
}
}

View File

@ -327,9 +327,16 @@ namespace TBF
MessageBox.Show(Strings.Invalid_user_password_or_bench, Strings.Error, MessageBoxButtons.OK);
}
}
catch (Exception)
catch (Exception exc)
{
/// Database connect failed, ask what to do
/// Database connect failed, create a log
log.FatalFormat("Connection to database failed: {0}", exc.Message);
if (exc.InnerException != null && !string.IsNullOrEmpty(exc.InnerException.Message))
{
log.FatalFormat("Inner exception: {0}", exc.InnerException.Message);
}
/// Ask what to do
switch ((new Forms.NoBenchOrDatabaseDlg { Message = Strings.NoDatabaseMsg, ShowRetry = true }).ShowDialog())
{
case DialogResult.Abort: return; /// Exit program