Refactorization : BenchControl -> Rig
This commit is contained in:
@@ -0,0 +1,364 @@
|
||||
///
|
||||
/// Copyright (c) 2018 Sensus Slovensko a.s.
|
||||
///
|
||||
using System;
|
||||
using System.Windows.Forms;
|
||||
using log4net;
|
||||
using Config.Entities;
|
||||
using TBF.Rig.Generic;
|
||||
using TBF.Resources;
|
||||
|
||||
namespace TBF.Rig.Output.FileWriters.XmlBatch
|
||||
{
|
||||
public partial class WriterCfgCtrl : UserControl, IComponentCfgCtrl
|
||||
{
|
||||
static readonly ILog log = LogManager.GetLogger(typeof(WriterCfgCtrl));
|
||||
|
||||
public bool ShowMore { get { return false; } }
|
||||
|
||||
public bool Compound;
|
||||
|
||||
WriterCfg config;
|
||||
public IComponentCfg Config
|
||||
{
|
||||
get { return config as IComponentCfg; }
|
||||
set
|
||||
{
|
||||
config = value as WriterCfg;
|
||||
Redraw();
|
||||
}
|
||||
}
|
||||
|
||||
string header;
|
||||
string[] commonItems;
|
||||
string[] meterItems;
|
||||
string[] testItems;
|
||||
|
||||
public WriterCfgCtrl()
|
||||
{
|
||||
InitializeComponent();
|
||||
Localize();
|
||||
}
|
||||
|
||||
private void WriterCfgCtrl_Load(object sender, EventArgs e)
|
||||
{
|
||||
for (YearFolders s = 0; s < YearFolders.Count; s++) yearFoldersComboBox.Items.Add(s.ToString());
|
||||
for (MonthFolders s = 0; s < MonthFolders.Count; s++) monthFoldersComboBox.Items.Add(s.ToString());
|
||||
for (DayFolders s = 0; s < DayFolders.Count; s++) dayFoldersComboBox.Items.Add(s.ToString());
|
||||
for (Culture s = 0; s < Culture.Count; s++) cultureComboBox.Items.Add(s.ToString());
|
||||
|
||||
header = config.Header;
|
||||
commonItems = config.CommonItems;
|
||||
meterItems = config.MeterItems;
|
||||
testItems = config.TestItems;
|
||||
|
||||
Redraw();
|
||||
}
|
||||
|
||||
void Localize()
|
||||
{
|
||||
nameLabel.Text = Strings.Name;
|
||||
destinationLabel.Text = "Destination";
|
||||
destination2Label.Text = "Destination" + " 2";
|
||||
yearFoldersLabel.Text = "Year folders";
|
||||
monthFoldersLabel.Text = "Month folders";
|
||||
dayFoldersLabel.Text = "Day folders";
|
||||
fileNameFmtLabel.Text = "File name format";
|
||||
cultureLabel.Text = "Culture";
|
||||
headerButton.Text = Strings.Header;
|
||||
rootTagLabel.Text = "Root tag";
|
||||
commonItemsButton.Text = "Common items";
|
||||
meterTagLabel.Text = "Meter tag";
|
||||
meterItemsButton.Text = "Meter items";
|
||||
testTagLabel.Text = "Test tag";
|
||||
testItemsButton.Text = "Test items";
|
||||
}
|
||||
|
||||
public void Closing()
|
||||
{
|
||||
}
|
||||
|
||||
void Redraw()
|
||||
{
|
||||
if (config == null) return; /// Control was not loaded, settings were not changed
|
||||
classNameLabel.Text = config.Factory.ClassName;
|
||||
nameTextBox.Text = config.Name;
|
||||
destinationTextBox.Text = config.DestinationPath;
|
||||
destination2TextBox.Text = config.DestinationPath2;
|
||||
yearFoldersComboBox.Text = config.YearFolders.ToString();
|
||||
monthFoldersComboBox.Text = config.MonthFolders.ToString();
|
||||
dayFoldersComboBox.Text = config.DayFolders.ToString();
|
||||
fileNameFmtTextBox.Text = config.FileNameFormat;
|
||||
cultureComboBox.Text = config.Culture.ToString();
|
||||
rootTagTextBox.Text = config.RootTag;
|
||||
meterTagTextBox.Text = config.MeterTag;
|
||||
testTagTextBox.Text = config.TestTag;
|
||||
}
|
||||
|
||||
public void Unlock()
|
||||
{
|
||||
nameTextBox.Enabled = true;
|
||||
destinationTextBox.Enabled = true;
|
||||
destinationButton.Enabled = true;
|
||||
destination2TextBox.Enabled = true;
|
||||
destination2Button.Enabled = true;
|
||||
yearFoldersComboBox.Enabled = true;
|
||||
monthFoldersComboBox.Enabled = true;
|
||||
dayFoldersComboBox.Enabled = true;
|
||||
fileNameFmtTextBox.Enabled = true;
|
||||
cultureComboBox.Enabled = true;
|
||||
headerButton.Enabled = true;
|
||||
rootTagTextBox.Enabled = true;
|
||||
commonItemsButton.Enabled = true;
|
||||
meterTagTextBox.Enabled = true;
|
||||
meterItemsButton.Enabled = true;
|
||||
testTagTextBox.Enabled = true;
|
||||
testItemsButton.Enabled = true;
|
||||
}
|
||||
|
||||
public CfgUpdateFlags VerifyCfg(ref string message)
|
||||
{
|
||||
CfgUpdateFlags flags = CfgUpdateFlags.None;
|
||||
|
||||
if (!yearFoldersComboBox.Items.Contains(yearFoldersComboBox.Text))
|
||||
{
|
||||
flags |= CfgUpdateFlags.Error;
|
||||
message += Environment.NewLine + "Invalid year folders selection";
|
||||
}
|
||||
|
||||
if (!monthFoldersComboBox.Items.Contains(monthFoldersComboBox.Text))
|
||||
{
|
||||
flags |= CfgUpdateFlags.Error;
|
||||
message += Environment.NewLine + "Invalid month folders selection";
|
||||
}
|
||||
|
||||
if (!dayFoldersComboBox.Items.Contains(dayFoldersComboBox.Text))
|
||||
{
|
||||
flags |= CfgUpdateFlags.Error;
|
||||
message += Environment.NewLine + "Invalid day folder selection";
|
||||
}
|
||||
|
||||
if (!cultureComboBox.Items.Contains(cultureComboBox.Text))
|
||||
{
|
||||
flags |= CfgUpdateFlags.Error;
|
||||
message += Environment.NewLine + "Invalid culture";
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(rootTagTextBox.Text))
|
||||
{
|
||||
flags |= CfgUpdateFlags.Error;
|
||||
message += Environment.NewLine + "Root tag field is empty";
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(meterTagTextBox.Text))
|
||||
{
|
||||
flags |= CfgUpdateFlags.Error;
|
||||
message += Environment.NewLine + "Meter tag field is empty";
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(testTagTextBox.Text))
|
||||
{
|
||||
flags |= CfgUpdateFlags.Error;
|
||||
message += Environment.NewLine + "Test tag field is empty";
|
||||
}
|
||||
|
||||
return flags;
|
||||
}
|
||||
|
||||
public CfgUpdateFlags UpdateCfg()
|
||||
{
|
||||
CfgUpdateFlags flags = CfgUpdateFlags.None;
|
||||
|
||||
if (config == null) return CfgUpdateFlags.Error; /// Control was not loaded, settings were not changed
|
||||
|
||||
if (config.Name != nameTextBox.Text)
|
||||
{
|
||||
config.Name = nameTextBox.Text;
|
||||
flags |= (CfgUpdateFlags.RestartRqrd | CfgUpdateFlags.AnyChange);
|
||||
}
|
||||
|
||||
if (config.DestinationPath != destinationTextBox.Text)
|
||||
{
|
||||
config.DestinationPath = destinationTextBox.Text;
|
||||
if (!config.DestinationPath.EndsWith("\\")) config.DestinationPath += "\\";
|
||||
flags |= (CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
|
||||
}
|
||||
|
||||
if (config.DestinationPath2 != destination2TextBox.Text)
|
||||
{
|
||||
config.DestinationPath2 = destination2TextBox.Text;
|
||||
if (!config.DestinationPath2.EndsWith("\\")) config.DestinationPath2 += "\\";
|
||||
flags |= (CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
|
||||
}
|
||||
|
||||
for (YearFolders i = 0; i < YearFolders.Count; i++)
|
||||
{
|
||||
if (i.ToString().Equals(yearFoldersComboBox.Text) && (config.YearFolders != i))
|
||||
{
|
||||
config.YearFolders = i;
|
||||
flags |= (CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (MonthFolders i = 0; i < MonthFolders.Count; i++)
|
||||
{
|
||||
if (i.ToString().Equals(monthFoldersComboBox.Text) && (config.MonthFolders != i))
|
||||
{
|
||||
config.MonthFolders = i;
|
||||
flags |= (CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (DayFolders i = 0; i < DayFolders.Count; i++)
|
||||
{
|
||||
if (i.ToString().Equals(dayFoldersComboBox.Text) && (config.DayFolders != i))
|
||||
{
|
||||
config.DayFolders = i;
|
||||
flags |= (CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (config.FileNameFormat != fileNameFmtTextBox.Text)
|
||||
{
|
||||
config.FileNameFormat = fileNameFmtTextBox.Text;
|
||||
flags |= (CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
|
||||
}
|
||||
|
||||
for (Culture i = 0; i < Culture.Count; i++)
|
||||
{
|
||||
if (i.ToString().Equals(cultureComboBox.Text) && (config.Culture != i))
|
||||
{
|
||||
config.Culture = i;
|
||||
flags |= (CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (config.Header != header)
|
||||
{
|
||||
config.Header = header;
|
||||
flags |= (CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
|
||||
}
|
||||
|
||||
if (config.RootTag != rootTagTextBox.Text)
|
||||
{
|
||||
config.RootTag = rootTagTextBox.Text;
|
||||
flags |= (CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
|
||||
}
|
||||
|
||||
if (config.CommonItems != commonItems)
|
||||
{
|
||||
config.CommonItems = commonItems;
|
||||
flags |= (CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
|
||||
}
|
||||
|
||||
if (config.MeterTag != meterTagTextBox.Text)
|
||||
{
|
||||
config.MeterTag = meterTagTextBox.Text;
|
||||
flags |= (CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
|
||||
}
|
||||
|
||||
if (config.MeterItems != meterItems)
|
||||
{
|
||||
config.MeterItems = meterItems;
|
||||
flags |= (CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
|
||||
}
|
||||
|
||||
if (config.TestTag != testTagTextBox.Text)
|
||||
{
|
||||
config.TestTag = testTagTextBox.Text;
|
||||
flags |= (CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
|
||||
}
|
||||
|
||||
if (config.TestItems != testItems)
|
||||
{
|
||||
config.TestItems = testItems;
|
||||
flags |= (CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
|
||||
}
|
||||
|
||||
|
||||
|
||||
if ((flags & CfgUpdateFlags.InvokeCfgChange) != 0)
|
||||
{
|
||||
Writer.OnCfgChange(this, new CfgChangeArgs(CfgChangeCmd.CfgChange, config));
|
||||
}
|
||||
|
||||
return flags;
|
||||
}
|
||||
|
||||
private void destinationButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void headerButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
HeaderFooterDlg dlg = new HeaderFooterDlg(true, string.IsNullOrEmpty(header) ? string.Empty : header.Replace("~", Environment.NewLine));
|
||||
if (dlg.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
header = dlg.EditedText.Replace(Environment.NewLine, "~");
|
||||
}
|
||||
}
|
||||
|
||||
private void commonItemsButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
Results.Forms.ResultsConfigDlg dlg = new Results.Forms.ResultsConfigDlg()
|
||||
{
|
||||
MetersKind = config.MetersKind,
|
||||
SelectedItems = Results.WMeterRsltItemSpec.FromStrArray(commonItems),
|
||||
};
|
||||
|
||||
if (dlg.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
commonItems = Results.WMeterRsltItemSpec.ToStrArray(dlg.SelectedItems);
|
||||
}
|
||||
}
|
||||
|
||||
private void meterItemsButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
Results.Forms.ResultsConfigDlg dlg = new Results.Forms.ResultsConfigDlg()
|
||||
{
|
||||
MetersKind = config.MetersKind,
|
||||
SelectedItems = Results.WMeterRsltItemSpec.FromStrArray(meterItems),
|
||||
};
|
||||
|
||||
if (dlg.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
meterItems = Results.WMeterRsltItemSpec.ToStrArray(dlg.SelectedItems);
|
||||
}
|
||||
}
|
||||
|
||||
private void testItemsButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
Results.Forms.ResultsConfigDlg dlg = new Results.Forms.ResultsConfigDlg(true)
|
||||
{
|
||||
MetersKind = config.MetersKind,
|
||||
SelectedItems = Results.WMeterRsltItemSpec.FromStrArray(testItems),
|
||||
};
|
||||
|
||||
if (dlg.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
testItems = Results.WMeterRsltItemSpec.ToStrArray(dlg.SelectedItems);
|
||||
}
|
||||
}
|
||||
|
||||
#region Configuration Change Handling
|
||||
|
||||
public static void OnCmdResponse(object sender, CmdResponseArgs args)
|
||||
{
|
||||
if (CmdResponseHandler == null) return;
|
||||
try { CmdResponseHandler(sender, args); }
|
||||
catch (Exception e) { log.Error("CmdResponseHandler(...) failed", e); }
|
||||
}
|
||||
|
||||
public static event EventHandler<CmdResponseArgs> CmdResponseHandler;
|
||||
|
||||
public void StartResponseHandler() { }
|
||||
public void StopResponseHandler() { }
|
||||
|
||||
#endregion Configuration Change Handling
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user