(1) Output.FileWriters.Basic: header, common, footer, etc., (2) TableRowNr, TableColumnNr in all outputs, ver. 2.17.707

This commit is contained in:
Milan Hanajik 2017-10-18 15:29:37 +02:00
parent 8b321e36db
commit 25fa494b7b
10 changed files with 530 additions and 122 deletions

View File

@ -216,7 +216,8 @@ namespace Results.Output.Printers.Enhanced
for (int wmNr = nextWMNr; wmNr < Math.Min(nextWMNr + nrWMsOnPage, batch.WaterMeters.Count); wmNr++) /// wmNr is 0-based
{
int wmPosition = true ? batch.WaterMeters[wmNr].WMPosition : (wmNr + 1);
nextWmTop += PrintWM(e, batch.WaterMeters[wmNr], wmPosition, nextWmTop);
int sectionHght = PrintWM(e, batch.WaterMeters[wmNr], wmPosition, nextWmTop);
nextWmTop += sectionHght;
}
nextWMNr += nrWMsOnPage;
@ -296,9 +297,12 @@ namespace Results.Output.Printers.Enhanced
{
if ((mtr != null) && (mtr.Publish() == Config.Entities.Publish.Always))
{
testsCount++;
for (int i = 0; i < testItems.Count; i++)
WMeterRsltItemSpec.TableRowNr = ++testsCount;
for (int i = 0; i < testItems.Count; i++)
{
WMeterRsltItemSpec.TableColumnNr = i + 1;
string itemText = testItems[i].Print(wm, mtr.Name());
/// Strip color information

View File

@ -7,9 +7,6 @@ using System.Globalization;
using System.IO;
using System.Threading;
using log4net;
using Config.Entities;
using TBF.BenchControl;
using TBF.Resources;
namespace TBF.BenchControl.Output.FileWriters.Basic
{
@ -19,16 +16,20 @@ namespace TBF.BenchControl.Output.FileWriters.Basic
public override string ToString() { return string.Format("Output.FileWriters.Basic({0})", Cfg.ToString(1)); }
readonly WriterCfg writerCfg;
readonly string separatorStr;
string separatorStr;
/// <summary>
/// Result items to print
/// </summary>
readonly IList<Results.WMeterRsltItemSpec> rsltItems;
string header;
IList<Results.WMeterRsltItemSpec> commonItems;
IList<Results.WMeterRsltItemSpec> rsltItems;
string footer;
Results.Entities.Batch batch;
bool abort; /// Set to 'true' by Stop() operation to abort writing to the file
bool abort;
public Writer() {}
@ -37,24 +38,88 @@ namespace TBF.BenchControl.Output.FileWriters.Basic
: base(cfg)
{
writerCfg = cfg as WriterCfg;
switch (writerCfg.Separator)
{
default:
case Separator.None: separatorStr = string.Empty; break;
case Separator.Space: separatorStr = " "; break;
case Separator.Tabulator: separatorStr = "\t"; break;
case Separator.Comma: separatorStr = ","; break;
case Separator.Semicolon: separatorStr = ";"; break;
}
rsltItems = Results.WMeterRsltItemSpec.FromStrArray(writerCfg.SelectedItems);
ApplyConfig();
log.Debug(this.ToString());
}
/// <summary>
void ApplyConfig()
{
switch (writerCfg.Separator)
{
default:
case Separator.None: separatorStr = string.Empty; break;
case Separator.Space: separatorStr = " "; break;
case Separator.Tabulator: separatorStr = "\t"; break;
case Separator.Comma: separatorStr = ","; break;
case Separator.Semicolon: separatorStr = ";"; break;
}
header = string.IsNullOrEmpty(writerCfg.Header) ? string.Empty : writerCfg.Header.Replace("~", Environment.NewLine);
commonItems = Results.WMeterRsltItemSpec.FromStrArray(writerCfg.CommonItems);
rsltItems = Results.WMeterRsltItemSpec.FromStrArray(writerCfg.SelectedItems);
footer = string.IsNullOrEmpty(writerCfg.Footer) ? string.Empty : writerCfg.Footer.Replace("~", Environment.NewLine);
}
#region Configuration Change Handling
public static void OnCfgChange(object sender, CfgChangeArgs args)
{
if (CfgChangeHandler == null) return;
try { CfgChangeHandler(sender, args); }
catch (Exception e) { log.Error("CfgChangeHandler(...) failed", e); }
}
public static event EventHandler<CfgChangeArgs> CfgChangeHandler;
public override void StartChangeHandler()
{
CfgChangeHandler += delegate(object sender, CfgChangeArgs args)
{
WriterCfg newCfg = args.Cfg as WriterCfg;
if (newCfg != null && newCfg.Name.Equals(Name))
{
if (args.Command == CfgChangeCmd.CfgChange)
{
writerCfg.DestinationPath = newCfg.DestinationPath;
writerCfg.DestinationPath2 = newCfg.DestinationPath2;
writerCfg.YearFolders = newCfg.YearFolders;
writerCfg.MonthFolders = newCfg.MonthFolders;
writerCfg.DayFolders = newCfg.DayFolders;
writerCfg.FileNameFormat = newCfg.FileNameFormat;
writerCfg.Culture = newCfg.Culture;
writerCfg.Separator = newCfg.Separator;
writerCfg.EliminateSpaces = newCfg.EliminateSpaces;
writerCfg.SaveGoodOnly = newCfg.SaveGoodOnly;
writerCfg.Header = newCfg.Header;
writerCfg.CommonItems = newCfg.CommonItems;
writerCfg.SelectedItems = newCfg.SelectedItems;
writerCfg.Footer = newCfg.Footer;
ApplyConfig();
}
}
};
}
#endregion Configuration Change Handling
/// <summary>
/// Eliminate spaces conditionally, depesing on bool WriterCfg.EliminateSpaces
/// </summary>
/// <param name="item">Input string</param>
/// <returns>Output string</returns>
string ElSpaces(string item)
{
if (writerCfg.EliminateSpaces)
return item.Replace(" ", string.Empty);
else
return item;
}
/// <summary>
/// Returns a file name derived from a DateTime structure.
/// Creates directories on this path as a side effect.
/// </summary>
@ -67,10 +132,10 @@ namespace TBF.BenchControl.Output.FileWriters.Basic
switch (writerCfg.YearFolders)
{
case YearFolders.FourDigit:
directory = string.Format("{0}{1}\\", directory, time.Year.ToString("D4"));
directory = string.Format("{0}{1:yyyy}\\", directory, time);
break;
case YearFolders.TwoDigit:
directory = string.Format("{0}{1}\\", directory, (time.Year % 100).ToString("D2"));
directory = string.Format("{0}{1:yy}\\", directory, time);
break;
}
@ -102,7 +167,7 @@ namespace TBF.BenchControl.Output.FileWriters.Basic
directory = string.Format("{0}{1}\\", directory, time.Month.ToString());
break;
case MonthFolders.TwoDigit:
directory = string.Format("{0}{1}\\", directory, time.Month.ToString("D2"));
directory = string.Format("{0}{1:MM}\\", directory, time);
break;
}
@ -112,7 +177,7 @@ namespace TBF.BenchControl.Output.FileWriters.Basic
directory = string.Format("{0}{1}\\", directory, time.Day.ToString());
break;
case DayFolders.TwoDigit:
directory = string.Format("{0}{1}\\", directory, time.Day.ToString("D2"));
directory = string.Format("{0}{1:dd}\\", directory, time);
break;
}
@ -146,12 +211,13 @@ namespace TBF.BenchControl.Output.FileWriters.Basic
/// <summary>Start this operation</summary>
public void Start()
{
CultureInfo oriCulture = Thread.CurrentThread.CurrentCulture;
CultureInfo oriCulture = Thread.CurrentThread.CurrentCulture;
try { Thread.CurrentThread.CurrentCulture = new CultureInfo(writerCfg.Culture.ToString()); }
catch { }
WriteRslts(batch, writerCfg.DestinationPath);
abort = false;
WriteRslts(batch, writerCfg.DestinationPath);
WriteRslts(batch, writerCfg.DestinationPath2);
Thread.CurrentThread.CurrentCulture = oriCulture;
@ -172,54 +238,188 @@ namespace TBF.BenchControl.Output.FileWriters.Basic
void WriteRslts(Results.Entities.Batch batch, string destination)
{
if (batch == null || batch.WaterMeters == null || batch.WaterMeters.Count <= 0) return;
if (rsltItems == null || rsltItems.Count == 0) return;
if (string.IsNullOrEmpty(destination) || batch == null ||
batch.WaterMeters == null ||
batch.WaterMeters.Count == 0)
{
return;
}
StreamWriter writer = StreamWriter.Null;
if (!string.IsNullOrEmpty(writerCfg.DestinationPath))
try
{
try
{
writer = File.AppendText(GetFilename(writerCfg.DestinationPath, batch.EndTime));
}
catch
{
}
writer = File.AppendText(GetFilename(destination, batch.EndTime));
WriteRsltsEx(batch, writer);
}
catch
{
}
finally
{
writer.Close();
}
}
void WriteRsltsEx(Results.Entities.Batch batch, StreamWriter wrtr)
{
///----------
/// Header
///----------
if (!string.IsNullOrEmpty(writerCfg.Header))
{
wrtr.Write(header);
}
foreach (var wm in batch.WaterMeters)
///----------------
/// Common items
///----------------
string[] leftColumn = new string[commonItems.Count];
string[] rightColumn = new string[commonItems.Count];
int cnt = 0;
foreach (var v in commonItems)
{
if (!writerCfg.SaveGoodOnly || wm.Passed)
{
WriteWM(writer, wm);
if (abort) return;
}
leftColumn[cnt] = v.Caption;
rightColumn[cnt] = (batch.WaterMeters.Count > 0) ? v.Print(batch.WaterMeters[0]) : string.Empty;
cnt++;
}
writer.Close();
/// Determine max. left column width in characters
int maxLen = 0;
foreach (var s in leftColumn) if (s.Length > maxLen) maxLen = s.Length;
/// Write aligned columns
for (int i = 0; i < Math.Min(leftColumn.Length, rightColumn.Length); i++)
{
if (abort) return;
wrtr.Write(leftColumn[i]);
if (!writerCfg.EliminateSpaces)
{
wrtr.Write(new string(' ', maxLen - leftColumn[i].Length + 3));
}
wrtr.Write(separatorStr);
wrtr.WriteLine(rightColumn[i]);
}
wrtr.WriteLine();
///--------
/// Body
///--------
WriteWMs(batch, wrtr);
///----------
/// Footer
///----------
if (!string.IsNullOrEmpty(writerCfg.Footer))
{
wrtr.Write(footer);
}
}
/// <summary>
/// Write one water meter results
/// </summary>
/// <param name="wmNr">Water meter number (0-based)</param>
void WriteWM(StreamWriter wr, Results.Entities.WaterMeter wm)
void WriteWMs(Results.Entities.Batch batch, StreamWriter wr)
{
/// Determine column widths
int[] columnWidths = new int[rsltItems.Count];
int totalWidth = 0;
for (int i = 0; i < rsltItems.Count; i++)
{
if (abort) return;
wr.Write(rsltItems[i].Print(wm));
columnWidths[i] = ElSpaces(rsltItems[i].Caption).Length;
foreach (var wm in batch.WaterMeters)
{
if (!writerCfg.SaveGoodOnly || wm.Passed)
{
string itemText = rsltItems[i].Print(wm);
/// Strip color information
string[] texts = itemText.Split(new char[] { '|' });
if (texts.Length == 2) { itemText = texts[0]; }
int len = ElSpaces(itemText).Length;
if (len > columnWidths[i]) columnWidths[i] = len;
}
}
totalWidth += columnWidths[i];
}
totalWidth += 3 * (rsltItems.Count - 1);
if (totalWidth < 0) totalWidth = 0;
string horizontalLine = new String('-', totalWidth);
//wr.WriteLine(horizontalLine); /// Horizontal line above the header
/// Write column headers
for (int i = 0; i < rsltItems.Count; i++)
{
if (abort) return;
string caption = ElSpaces(rsltItems[i].Caption);
wr.Write(caption);
if (i < rsltItems.Count - 1)
{
if (!writerCfg.EliminateSpaces)
{
wr.Write(new string(' ', columnWidths[i] - rsltItems[i].Caption.Length + 3));
}
wr.Write(separatorStr);
}
else
{
wr.WriteLine(string.Empty);
wr.WriteLine();
}
}
}
//wr.WriteLine(horizontalLine); /// Horizontal line between the header and the body
int rowsCount = 0;
foreach (var wm in batch.WaterMeters)
{
if (!writerCfg.SaveGoodOnly || wm.Passed)
{
if (abort) return;
Results.WMeterRsltItemSpec.TableRowNr = ++rowsCount;
for (int i = 0; i < rsltItems.Count; i++)
{
Results.WMeterRsltItemSpec.TableColumnNr = i + 1;
/// Fetch the item
string itemText = rsltItems[i].Print(wm);
/// Strip color information
string[] texts = itemText.Split(new char[] { '|' });
if (texts.Length == 2) { itemText = texts[0]; }
/// Print the item
string itemText2 = ElSpaces(itemText);
wr.Write(itemText2);
if (i < rsltItems.Count - 1)
{
if (!writerCfg.EliminateSpaces)
{
wr.Write(new string(' ', columnWidths[i] - itemText.Length + 3));
}
wr.Write(separatorStr);
}
else
{
wr.WriteLine();
}
}
}
}
//wr.WriteLine(horizontalLine); /// Horizontal line between the header and the body
}
}
}

View File

@ -1,9 +1,6 @@
///
/// Copyright (c) 2013-2017 Sensus Metering Systems
///
using System;
using System.Collections.Generic;
using System.IO;
using System.Xml.Serialization;
using TBF.BenchControl.Generic;
@ -24,8 +21,12 @@ namespace TBF.BenchControl.Output.FileWriters.Basic
public string FileNameFormat;
public Culture Culture;
public Separator Separator;
public bool SaveGoodOnly;
public string[] SelectedItems;
public bool EliminateSpaces;
public bool SaveGoodOnly;
public string Header;
public string[] CommonItems;
public string[] SelectedItems;
public string Footer;
[XmlIgnore]
public Config.Entities.MetersKind MetersKind;
@ -48,14 +49,17 @@ namespace TBF.BenchControl.Output.FileWriters.Basic
YearFolders = YearFolders.FourDigit;
MonthFolders = MonthFolders.Digit;
DayFolders = DayFolders.Digit;
FileNameFormat = "{0:yyyyMMdd}";
FileNameFormat = "{0:yyMMdd-HHmm}.csv";
Separator = Separator.None;
EliminateSpaces = false;
SaveGoodOnly = false;
Header = string.Empty;
Footer = string.Empty;
}
public string ToString(int i)
{
return string.Format("Name={0}, Path={1}, Y={2}, M={3}, D={4}, FNameFmt={5}, Separator={6}, GoodOnly={7}",
return string.Format("{0}, Path={1}, Y={2}, M={3}, D={4}, FNameFmt={5}, Separator={6}, NoSpaces={7}, GoodOnly={8}",
Name,
DestinationPath,
YearFolders,
@ -63,6 +67,7 @@ namespace TBF.BenchControl.Output.FileWriters.Basic
DayFolders,
FileNameFormat,
Separator,
EliminateSpaces,
SaveGoodOnly);
}
}

View File

@ -1,12 +1,11 @@
///
/// Copyright (c) 2016 Sensus Metering Systems
/// Copyright (c) 2016-2017 Sensus Metering Systems
///
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using log4net;
using TBF.BenchControl.Generic;
using Results.Forms;
using TBF.Resources;
namespace TBF.BenchControl.Output.FileWriters.Basic
{
@ -29,12 +28,16 @@ namespace TBF.BenchControl.Output.FileWriters.Basic
}
}
string header;
string[] commonItems;
string[] selectedItems;
string footer;
public WriterCfgCtrl()
{
InitializeComponent();
}
Localize();
}
private void WriterCfgCtrl_Load(object sender, EventArgs e)
{
@ -44,11 +47,33 @@ namespace TBF.BenchControl.Output.FileWriters.Basic
for (Culture s = 0; s < Culture.Count; s++) cultureComboBox.Items.Add(s.ToString());
for (Separator s = 0; s < Separator.Count; s++) separatorComboBox.Items.Add(s.ToString());
header = config.Header;
commonItems = config.CommonItems;
selectedItems = config.SelectedItems;
footer = config.Footer;
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";
separatorLabel.Text = "Separator";
eliminateSpacesCheckBox.Text = "No spaces";
goodOnlyCheckBox.Text = "Good only";
headerButton.Text = Strings.Header;
commonItemsButton.Text = "Common items";
selectItemsButton.Text = "Selected items";
footerButton.Text = Strings.Footer;
}
public void Closing()
{
}
@ -66,8 +91,9 @@ namespace TBF.BenchControl.Output.FileWriters.Basic
fileNameFmtTextBox.Text = config.FileNameFormat;
cultureComboBox.Text = config.Culture.ToString();
separatorComboBox.Text = config.Separator.ToString();
eliminateSpacesCheckBox.Checked = config.EliminateSpaces;
goodOnlyCheckBox.Checked = config.SaveGoodOnly;
}
}
public void Unlock()
{
@ -82,8 +108,12 @@ namespace TBF.BenchControl.Output.FileWriters.Basic
fileNameFmtTextBox.Enabled = true;
cultureComboBox.Enabled = true;
separatorComboBox.Enabled = true;
eliminateSpacesCheckBox.Enabled = true;
goodOnlyCheckBox.Enabled = true;
headerButton.Enabled = true;
commonItemsButton.Enabled = true;
selectItemsButton.Enabled = true;
footerButton.Enabled = true;
}
public CfgUpdateFlags VerifyCfg(ref string message)
@ -128,20 +158,24 @@ namespace TBF.BenchControl.Output.FileWriters.Basic
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; }
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.RestartRqrd;
}
flags |= (CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
}
if (config.DestinationPath2 != destination2TextBox.Text)
{
config.DestinationPath2 = destination2TextBox.Text;
if (!config.DestinationPath2.EndsWith("\\")) config.DestinationPath2 += "\\";
flags = CfgUpdateFlags.RestartRqrd;
flags |= (CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
}
for (YearFolders i = 0; i < YearFolders.Count; i++)
@ -149,7 +183,7 @@ namespace TBF.BenchControl.Output.FileWriters.Basic
if (i.ToString().Equals(yearFoldersComboBox.Text) && (config.YearFolders != i))
{
config.YearFolders = i;
flags = CfgUpdateFlags.RestartRqrd;
flags |= (CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
break;
}
}
@ -159,7 +193,7 @@ namespace TBF.BenchControl.Output.FileWriters.Basic
if (i.ToString().Equals(monthFoldersComboBox.Text) && (config.MonthFolders != i))
{
config.MonthFolders = i;
flags = CfgUpdateFlags.RestartRqrd;
flags |= (CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
break;
}
}
@ -169,7 +203,7 @@ namespace TBF.BenchControl.Output.FileWriters.Basic
if (i.ToString().Equals(dayFoldersComboBox.Text) && (config.DayFolders != i))
{
config.DayFolders = i;
flags = CfgUpdateFlags.RestartRqrd;
flags |= (CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
break;
}
}
@ -177,7 +211,7 @@ namespace TBF.BenchControl.Output.FileWriters.Basic
if (config.FileNameFormat != fileNameFmtTextBox.Text)
{
config.FileNameFormat = fileNameFmtTextBox.Text;
flags = CfgUpdateFlags.RestartRqrd;
flags |= (CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
}
for (Culture i = 0; i < Culture.Count; i++)
@ -195,21 +229,50 @@ namespace TBF.BenchControl.Output.FileWriters.Basic
if (i.ToString().Equals(separatorComboBox.Text) && (config.Separator != i))
{
config.Separator = i;
flags = CfgUpdateFlags.RestartRqrd;
break;
flags |= (CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
break;
}
}
if (config.EliminateSpaces != eliminateSpacesCheckBox.Checked)
{
config.EliminateSpaces = eliminateSpacesCheckBox.Checked;
flags |= (CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
}
if (config.SaveGoodOnly != goodOnlyCheckBox.Checked)
{
config.SaveGoodOnly = goodOnlyCheckBox.Checked;
flags = CfgUpdateFlags.RestartRqrd;
flags |= (CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
}
if (config.Header != header)
{
config.Header = header;
flags |= (CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
}
if (config.CommonItems != commonItems)
{
config.CommonItems = commonItems;
flags |= (CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
}
if (config.SelectedItems != selectedItems)
{
config.SelectedItems = selectedItems;
flags = CfgUpdateFlags.RestartRqrd;
flags |= (CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
}
if (config.Footer != footer)
{
config.Footer = footer;
flags |= (CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
}
if ((flags & CfgUpdateFlags.InvokeCfgChange) != 0)
{
Writer.OnCfgChange(this, new CfgChangeArgs(CfgChangeCmd.CfgChange, config));
}
return flags;
@ -220,9 +283,32 @@ namespace TBF.BenchControl.Output.FileWriters.Basic
}
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 selectItemsButton_Click(object sender, EventArgs e)
{
ResultsConfigDlg dlg = new ResultsConfigDlg()
Results.Forms.ResultsConfigDlg dlg = new Results.Forms.ResultsConfigDlg()
{
MetersKind = config.MetersKind,
SelectedItems = Results.WMeterRsltItemSpec.FromStrArray(selectedItems),
@ -233,5 +319,30 @@ namespace TBF.BenchControl.Output.FileWriters.Basic
selectedItems = Results.WMeterRsltItemSpec.ToStrArray(dlg.SelectedItems);
}
}
}
private void footerButton_Click(object sender, EventArgs e)
{
HeaderFooterDlg dlg = new HeaderFooterDlg(false, string.IsNullOrEmpty(footer) ? string.Empty : footer.Replace("~", Environment.NewLine));
if (dlg.ShowDialog() == DialogResult.OK)
{
footer = dlg.EditedText.Replace(Environment.NewLine, "~");
}
}
#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
}
}

View File

@ -54,6 +54,10 @@ namespace TBF.BenchControl.Output.FileWriters.Basic
this.goodOnlyCheckBox = new System.Windows.Forms.CheckBox();
this.cultureComboBox = new System.Windows.Forms.ComboBox();
this.cultureLabel = new System.Windows.Forms.Label();
this.eliminateSpacesCheckBox = new System.Windows.Forms.CheckBox();
this.commonItemsButton = new System.Windows.Forms.Button();
this.headerButton = new System.Windows.Forms.Button();
this.footerButton = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// nameTextBox
@ -105,7 +109,7 @@ namespace TBF.BenchControl.Output.FileWriters.Basic
this.destinationButton.Location = new System.Drawing.Point(259, 56);
this.destinationButton.Name = "destinationButton";
this.destinationButton.Size = new System.Drawing.Size(30, 20);
this.destinationButton.TabIndex = 18;
this.destinationButton.TabIndex = 25;
this.destinationButton.Text = "...";
this.destinationButton.UseVisualStyleBackColor = true;
this.destinationButton.Click += new System.EventHandler(this.destinationButton_Click);
@ -131,11 +135,11 @@ namespace TBF.BenchControl.Output.FileWriters.Basic
// selectItemsButton
//
this.selectItemsButton.Enabled = false;
this.selectItemsButton.Location = new System.Drawing.Point(108, 225);
this.selectItemsButton.Location = new System.Drawing.Point(108, 277);
this.selectItemsButton.Name = "selectItemsButton";
this.selectItemsButton.Size = new System.Drawing.Size(145, 23);
this.selectItemsButton.TabIndex = 20;
this.selectItemsButton.Text = "Select items";
this.selectItemsButton.Size = new System.Drawing.Size(146, 23);
this.selectItemsButton.TabIndex = 23;
this.selectItemsButton.Text = "Selected items";
this.selectItemsButton.UseVisualStyleBackColor = true;
this.selectItemsButton.Click += new System.EventHandler(this.selectItemsButton_Click);
//
@ -199,7 +203,7 @@ namespace TBF.BenchControl.Output.FileWriters.Basic
this.destination2Button.Location = new System.Drawing.Point(259, 79);
this.destination2Button.Name = "destination2Button";
this.destination2Button.Size = new System.Drawing.Size(30, 20);
this.destination2Button.TabIndex = 19;
this.destination2Button.TabIndex = 26;
this.destination2Button.Text = "...";
this.destination2Button.UseVisualStyleBackColor = true;
//
@ -240,10 +244,10 @@ namespace TBF.BenchControl.Output.FileWriters.Basic
// goodOnlyCheckBox
//
this.goodOnlyCheckBox.AutoSize = true;
this.goodOnlyCheckBox.Location = new System.Drawing.Point(20, 229);
this.goodOnlyCheckBox.Location = new System.Drawing.Point(20, 268);
this.goodOnlyCheckBox.Name = "goodOnlyCheckBox";
this.goodOnlyCheckBox.Size = new System.Drawing.Size(74, 17);
this.goodOnlyCheckBox.TabIndex = 19;
this.goodOnlyCheckBox.TabIndex = 20;
this.goodOnlyCheckBox.Text = "Good only";
this.goodOnlyCheckBox.UseVisualStyleBackColor = true;
//
@ -265,10 +269,57 @@ namespace TBF.BenchControl.Output.FileWriters.Basic
this.cultureLabel.TabIndex = 15;
this.cultureLabel.Text = "Cullture";
//
// eliminateSpacesCheckBox
//
this.eliminateSpacesCheckBox.AutoSize = true;
this.eliminateSpacesCheckBox.Location = new System.Drawing.Point(20, 245);
this.eliminateSpacesCheckBox.Name = "eliminateSpacesCheckBox";
this.eliminateSpacesCheckBox.Size = new System.Drawing.Size(77, 17);
this.eliminateSpacesCheckBox.TabIndex = 19;
this.eliminateSpacesCheckBox.Text = "No spaces";
this.eliminateSpacesCheckBox.UseVisualStyleBackColor = true;
//
// commonItemsButton
//
this.commonItemsButton.Enabled = false;
this.commonItemsButton.Location = new System.Drawing.Point(108, 252);
this.commonItemsButton.Name = "commonItemsButton";
this.commonItemsButton.Size = new System.Drawing.Size(146, 23);
this.commonItemsButton.TabIndex = 22;
this.commonItemsButton.Text = "Common items";
this.commonItemsButton.UseVisualStyleBackColor = true;
this.commonItemsButton.Click += new System.EventHandler(this.commonItemsButton_Click);
//
// headerButton
//
this.headerButton.Enabled = false;
this.headerButton.Location = new System.Drawing.Point(108, 227);
this.headerButton.Name = "headerButton";
this.headerButton.Size = new System.Drawing.Size(146, 23);
this.headerButton.TabIndex = 21;
this.headerButton.Text = "Header";
this.headerButton.UseVisualStyleBackColor = true;
this.headerButton.Click += new System.EventHandler(this.headerButton_Click);
//
// footerButton
//
this.footerButton.Enabled = false;
this.footerButton.Location = new System.Drawing.Point(108, 302);
this.footerButton.Name = "footerButton";
this.footerButton.Size = new System.Drawing.Size(146, 23);
this.footerButton.TabIndex = 24;
this.footerButton.Text = "Footer";
this.footerButton.UseVisualStyleBackColor = true;
this.footerButton.Click += new System.EventHandler(this.footerButton_Click);
//
// WriterCfgCtrl
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.footerButton);
this.Controls.Add(this.commonItemsButton);
this.Controls.Add(this.headerButton);
this.Controls.Add(this.eliminateSpacesCheckBox);
this.Controls.Add(this.cultureComboBox);
this.Controls.Add(this.cultureLabel);
this.Controls.Add(this.goodOnlyCheckBox);
@ -293,7 +344,7 @@ namespace TBF.BenchControl.Output.FileWriters.Basic
this.Controls.Add(this.nameLabel);
this.Controls.Add(this.classNameLabel);
this.Name = "WriterCfgCtrl";
this.Size = new System.Drawing.Size(300, 282);
this.Size = new System.Drawing.Size(400, 350);
this.Load += new System.EventHandler(this.WriterCfgCtrl_Load);
this.ResumeLayout(false);
this.PerformLayout();
@ -325,5 +376,9 @@ namespace TBF.BenchControl.Output.FileWriters.Basic
private System.Windows.Forms.CheckBox goodOnlyCheckBox;
private System.Windows.Forms.ComboBox cultureComboBox;
private System.Windows.Forms.Label cultureLabel;
private System.Windows.Forms.CheckBox eliminateSpacesCheckBox;
private System.Windows.Forms.Button commonItemsButton;
private System.Windows.Forms.Button headerButton;
private System.Windows.Forms.Button footerButton;
}
}

View File

@ -20,9 +20,7 @@ namespace TBF.BenchControl.Output.FileWriters.Enhanced
string separatorStr;
///
/// Items to print
///
string header;
IList<Results.WMeterRsltItemSpec> commonItems;
IList<Results.WMeterRsltItemSpec> testItems;
@ -30,7 +28,7 @@ namespace TBF.BenchControl.Output.FileWriters.Enhanced
Results.Entities.Batch batch;
bool abort; /// Set to 'true' by Stop() operation to abort writing to files
bool abort;
public Writer() {}
@ -92,9 +90,9 @@ namespace TBF.BenchControl.Output.FileWriters.Enhanced
writerCfg.Culture = newCfg.Culture;
writerCfg.Separator = newCfg.Separator;
writerCfg.EliminateSpaces = newCfg.EliminateSpaces;
writerCfg.CommonItems = newCfg.CommonItems;
writerCfg.Header = newCfg.Header;
writerCfg.CommonItems = newCfg.CommonItems;
writerCfg.SelectedItems = newCfg.SelectedItems;
writerCfg.Header = newCfg.Header;
writerCfg.Footer = newCfg.Footer;
ApplyConfig();
@ -213,12 +211,13 @@ namespace TBF.BenchControl.Output.FileWriters.Enhanced
/// <summary>Start this operation</summary>
public void Start()
{
CultureInfo oriCulture = Thread.CurrentThread.CurrentCulture;
CultureInfo oriCulture = Thread.CurrentThread.CurrentCulture;
try { Thread.CurrentThread.CurrentCulture = new CultureInfo(writerCfg.Culture.ToString()); }
catch { }
WriteRslts(batch, writerCfg.DestinationPath);
abort = false;
WriteRslts(batch, writerCfg.DestinationPath);
WriteRslts(batch, writerCfg.DestinationPath2);
Thread.CurrentThread.CurrentCulture = oriCulture;
@ -239,6 +238,8 @@ namespace TBF.BenchControl.Output.FileWriters.Enhanced
void WriteRslts(Results.Entities.Batch batch, string destination)
{
if (batch == null || batch.WaterMeters == null || batch.WaterMeters.Count <= 0) return;
StreamWriter writer = StreamWriter.Null;
if (!string.IsNullOrEmpty(destination))
{
@ -297,8 +298,11 @@ namespace TBF.BenchControl.Output.FileWriters.Enhanced
///--------
foreach (var wm in batch.WaterMeters)
{
WriteWM(wrtr, wm);
if (abort) return;
if (!writerCfg.SaveGoodOnly || wm.Passed)
{
if (abort) return;
WriteWM(wrtr, wm);
}
}
///----------
@ -397,15 +401,20 @@ namespace TBF.BenchControl.Output.FileWriters.Enhanced
wr.WriteLine(horizontalLine); /// Horizontal line between the header and the body
/// Write table data
foreach (var mtr in wm.MeterTestRslts)
int rowsCount = 0;
foreach (var mtr in wm.MeterTestRslts)
{
if (abort) return;
if (mtr != null && mtr.IsPilotRslt() && mtr.Publish() == Config.Entities.Publish.Always)
{
for (int i = 0; i < testItems.Count; i++)
Results.WMeterRsltItemSpec.TableRowNr = ++rowsCount;
for (int i = 0; i < testItems.Count; i++)
{
/// Fetch the item
Results.WMeterRsltItemSpec.TableColumnNr = i + 1;
/// Fetch the item
string itemText = testItems[i].Print(wm, mtr.Name());
/// Strip color information

View File

@ -22,9 +22,10 @@ namespace TBF.BenchControl.Output.FileWriters.Enhanced
public Culture Culture;
public Separator Separator;
public bool EliminateSpaces;
public bool SaveGoodOnly;
public string Header;
public string[] CommonItems;
public string[] SelectedItems;
public string Header;
public string Footer;
[XmlIgnore]
@ -51,13 +52,14 @@ namespace TBF.BenchControl.Output.FileWriters.Enhanced
FileNameFormat = "{0:yyMMdd-HHmm}.txt";
Separator = Separator.None;
EliminateSpaces = false;
SaveGoodOnly = false;
Header = string.Empty;
Footer = string.Empty;
}
public string ToString(int i)
{
return string.Format("Name={0}, Path={1}, Y={2}, M={3}, D={4}, FNameFmt={5}, Separator={6}, EliminateSpaces={7}",
return string.Format("{0}, Path={1}, Y={2}, M={3}, D={4}, FNameFmt={5}, Separator={6}, NoSpaces={7}, GoodOnly={8}",
Name,
DestinationPath,
YearFolders,
@ -65,7 +67,8 @@ namespace TBF.BenchControl.Output.FileWriters.Enhanced
DayFolders,
FileNameFormat,
Separator,
EliminateSpaces);
}
EliminateSpaces,
SaveGoodOnly);
}
}
}

View File

@ -2,7 +2,6 @@
/// Copyright (c) 2016-2017 Sensus Metering Systems
///
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using log4net;
using TBF.BenchControl.Generic;
@ -66,6 +65,7 @@ namespace TBF.BenchControl.Output.FileWriters.Enhanced
cultureLabel.Text = "Culture";
separatorLabel.Text = "Separator";
eliminateSpacesCheckBox.Text = "No spaces";
goodOnlyCheckBox.Text = "Good only";
headerButton.Text = Strings.Header;
commonItemsButton.Text = "Common items";
testItemsButton.Text = "Test items";
@ -91,7 +91,8 @@ namespace TBF.BenchControl.Output.FileWriters.Enhanced
cultureComboBox.Text = config.Culture.ToString();
separatorComboBox.Text = config.Separator.ToString();
eliminateSpacesCheckBox.Checked = config.EliminateSpaces;
}
goodOnlyCheckBox.Checked = config.SaveGoodOnly;
}
public void Unlock()
{
@ -107,6 +108,7 @@ namespace TBF.BenchControl.Output.FileWriters.Enhanced
cultureComboBox.Enabled = true;
separatorComboBox.Enabled = true;
eliminateSpacesCheckBox.Enabled = true;
goodOnlyCheckBox.Enabled = true;
headerButton.Enabled = true;
commonItemsButton.Enabled = true;
testItemsButton.Enabled = true;
@ -237,6 +239,18 @@ namespace TBF.BenchControl.Output.FileWriters.Enhanced
flags |= (CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
}
if (config.SaveGoodOnly != goodOnlyCheckBox.Checked)
{
config.SaveGoodOnly = goodOnlyCheckBox.Checked;
flags |= (CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
}
if (config.Header != header)
{
config.Header = header;
flags |= (CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
}
if (config.CommonItems != commonItems)
{
config.CommonItems = commonItems;
@ -249,12 +263,6 @@ namespace TBF.BenchControl.Output.FileWriters.Enhanced
flags |= (CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
}
if (config.Header != header)
{
config.Header = header;
flags |= (CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
}
if (config.Footer != footer)
{
config.Footer = footer;

View File

@ -58,6 +58,7 @@ namespace TBF.BenchControl.Output.FileWriters.Enhanced
this.upgradeWizardButton = new System.Windows.Forms.Button();
this.cultureComboBox = new System.Windows.Forms.ComboBox();
this.cultureLabel = new System.Windows.Forms.Label();
this.goodOnlyCheckBox = new System.Windows.Forms.CheckBox();
this.SuspendLayout();
//
// nameTextBox
@ -135,10 +136,10 @@ namespace TBF.BenchControl.Output.FileWriters.Enhanced
// testItemsButton
//
this.testItemsButton.Enabled = false;
this.testItemsButton.Location = new System.Drawing.Point(108, 297);
this.testItemsButton.Location = new System.Drawing.Point(108, 275);
this.testItemsButton.Name = "testItemsButton";
this.testItemsButton.Size = new System.Drawing.Size(146, 23);
this.testItemsButton.TabIndex = 24;
this.testItemsButton.TabIndex = 25;
this.testItemsButton.Text = "Test items";
this.testItemsButton.UseVisualStyleBackColor = true;
this.testItemsButton.Click += new System.EventHandler(this.testItemsButton_Click);
@ -244,7 +245,7 @@ namespace TBF.BenchControl.Output.FileWriters.Enhanced
// eliminateSpacesCheckBox
//
this.eliminateSpacesCheckBox.AutoSize = true;
this.eliminateSpacesCheckBox.Location = new System.Drawing.Point(108, 227);
this.eliminateSpacesCheckBox.Location = new System.Drawing.Point(20, 241);
this.eliminateSpacesCheckBox.Name = "eliminateSpacesCheckBox";
this.eliminateSpacesCheckBox.Size = new System.Drawing.Size(77, 17);
this.eliminateSpacesCheckBox.TabIndex = 21;
@ -254,10 +255,10 @@ namespace TBF.BenchControl.Output.FileWriters.Enhanced
// headerButton
//
this.headerButton.Enabled = false;
this.headerButton.Location = new System.Drawing.Point(108, 247);
this.headerButton.Location = new System.Drawing.Point(108, 225);
this.headerButton.Name = "headerButton";
this.headerButton.Size = new System.Drawing.Size(146, 23);
this.headerButton.TabIndex = 22;
this.headerButton.TabIndex = 23;
this.headerButton.Text = "Header";
this.headerButton.UseVisualStyleBackColor = true;
this.headerButton.Click += new System.EventHandler(this.headerButton_Click);
@ -265,10 +266,10 @@ namespace TBF.BenchControl.Output.FileWriters.Enhanced
// footerButton
//
this.footerButton.Enabled = false;
this.footerButton.Location = new System.Drawing.Point(108, 322);
this.footerButton.Location = new System.Drawing.Point(108, 300);
this.footerButton.Name = "footerButton";
this.footerButton.Size = new System.Drawing.Size(146, 23);
this.footerButton.TabIndex = 25;
this.footerButton.TabIndex = 26;
this.footerButton.Text = "Footer";
this.footerButton.UseVisualStyleBackColor = true;
this.footerButton.Click += new System.EventHandler(this.footerButton_Click);
@ -276,20 +277,20 @@ namespace TBF.BenchControl.Output.FileWriters.Enhanced
// commonItemsButton
//
this.commonItemsButton.Enabled = false;
this.commonItemsButton.Location = new System.Drawing.Point(108, 272);
this.commonItemsButton.Location = new System.Drawing.Point(108, 250);
this.commonItemsButton.Name = "commonItemsButton";
this.commonItemsButton.Size = new System.Drawing.Size(146, 23);
this.commonItemsButton.TabIndex = 23;
this.commonItemsButton.TabIndex = 24;
this.commonItemsButton.Text = "Common items";
this.commonItemsButton.UseVisualStyleBackColor = true;
this.commonItemsButton.Click += new System.EventHandler(this.commonItemsButton_Click);
//
// upgradeWizardButton
//
this.upgradeWizardButton.Location = new System.Drawing.Point(269, 272);
this.upgradeWizardButton.Location = new System.Drawing.Point(269, 250);
this.upgradeWizardButton.Name = "upgradeWizardButton";
this.upgradeWizardButton.Size = new System.Drawing.Size(80, 48);
this.upgradeWizardButton.TabIndex = 26;
this.upgradeWizardButton.TabIndex = 27;
this.upgradeWizardButton.Text = "Upgrade wizard";
this.upgradeWizardButton.UseVisualStyleBackColor = true;
this.upgradeWizardButton.Click += new System.EventHandler(this.upgradeWizardButton_Click);
@ -312,10 +313,21 @@ namespace TBF.BenchControl.Output.FileWriters.Enhanced
this.cultureLabel.TabIndex = 17;
this.cultureLabel.Text = "Cullture";
//
// goodOnlyCheckBox
//
this.goodOnlyCheckBox.AutoSize = true;
this.goodOnlyCheckBox.Location = new System.Drawing.Point(20, 264);
this.goodOnlyCheckBox.Name = "goodOnlyCheckBox";
this.goodOnlyCheckBox.Size = new System.Drawing.Size(74, 17);
this.goodOnlyCheckBox.TabIndex = 22;
this.goodOnlyCheckBox.Text = "Good only";
this.goodOnlyCheckBox.UseVisualStyleBackColor = true;
//
// WriterCfgCtrl
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.goodOnlyCheckBox);
this.Controls.Add(this.cultureComboBox);
this.Controls.Add(this.cultureLabel);
this.Controls.Add(this.upgradeWizardButton);
@ -380,5 +392,6 @@ namespace TBF.BenchControl.Output.FileWriters.Enhanced
private System.Windows.Forms.Button upgradeWizardButton;
private System.Windows.Forms.ComboBox cultureComboBox;
private System.Windows.Forms.Label cultureLabel;
private System.Windows.Forms.CheckBox goodOnlyCheckBox;
}
}

View File

@ -29,5 +29,5 @@ using System.Runtime.InteropServices;
// Build Number
// Revision
//
[assembly: AssemblyVersion("2.17.706.1")]
[assembly: AssemblyFileVersion("2.17.706.1")]
[assembly: AssemblyVersion("2.17.707.1")]
[assembly: AssemblyFileVersion("2.17.707.1")]