feature/Enhanced_Writer_NoSeparator_AndName

This commit is contained in:
Michal Buzik 2025-09-26 15:10:34 +02:00
parent 4b33da565c
commit 357df87f49
6 changed files with 631 additions and 407 deletions

View File

@ -127,11 +127,16 @@ namespace TBF.Rig.Output.FileWriters.Enhanced
/// </summary>
/// <param name="time">Date and time</param>
/// <returns>File name</returns>
string GetFilename(string destinationPath, Results.Entities.Batch batch)
public string GetFilename(string destinationPath, Results.Entities.Batch batch, DateTime now)
{
string directory = destinationPath; /// Ends with "\\";
DateTime time = batch.EndTime;
if (writerCfg.FileNameFormat.Contains("{5:"))
{
time = now; //define path and file name now
}
switch (writerCfg.YearFolders)
{
case YearFolders.FourDigit:
@ -195,7 +200,7 @@ namespace TBF.Rig.Output.FileWriters.Enhanced
else
{
TBF.Rig.GenericDevices.IBenchInfo bi = TBF.Rig.Sequences.ProcessData.BenchInfo;
return directory + string.Format(writerCfg.FileNameFormat, batch.EndTime, batch.StartTime, batch.BatchNr, bi.TestBenchName, bi.TestBenchId);
return directory + string.Format(writerCfg.FileNameFormat, batch.EndTime, batch.StartTime, batch.BatchNr, bi.TestBenchName, bi.TestBenchId, time);
}
}
catch
@ -248,6 +253,7 @@ namespace TBF.Rig.Output.FileWriters.Enhanced
}
void WriteRslts(Results.Entities.Batch batch, string destination)
{
if (batch == null || batch.WaterMeters == null || batch.WaterMeters.Count <= 0) return;
@ -257,8 +263,9 @@ namespace TBF.Rig.Output.FileWriters.Enhanced
StreamWriter writer = StreamWriter.Null;
try
{
writer = File.AppendText(GetFilename(destination, batch));
WriteRsltsEx(batch, writer);
DateTime now = DateTime.Now; // Common time for '{5:' possibility of output
writer = File.AppendText(GetFilename(destination, batch, now));
WriteRsltsEx(batch, writer,now);
log.WarnFormat("Batch {0} written by {1} to file {2}", batch.BatchNr, Name, destination);
}
catch
@ -273,7 +280,7 @@ namespace TBF.Rig.Output.FileWriters.Enhanced
}
void WriteRsltsEx(Results.Entities.Batch batch, StreamWriter wrtr)
public void WriteRsltsEx(Results.Entities.Batch batch, StreamWriter wrtr, DateTime now)
{
///----------
/// Header
@ -291,7 +298,15 @@ namespace TBF.Rig.Output.FileWriters.Enhanced
foreach (var v in commonItems)
{
leftColumn[cnt] = v.Caption;
rightColumn[cnt] = (batch.WaterMeters.Count > 0) ? v.Print(batch.WaterMeters[0]) : string.Empty;
if (v.Uid == 72 && writerCfg.FileNameFormat.Contains("{5:"))
{
rightColumn[cnt] = string.Format(v.Format, now);
}
else
{
rightColumn[cnt] = (batch.WaterMeters.Count > 0) ? v.Print(batch.WaterMeters[0]) : string.Empty;
}
cnt++;
}
@ -308,7 +323,11 @@ namespace TBF.Rig.Output.FileWriters.Enhanced
{
wrtr.Write(new string(' ', maxLen - leftColumn[i].Length + 3));
}
wrtr.Write(separatorStr);
if (!writerCfg.NoSeparatorBetweenItems)
{
wrtr.Write(separatorStr);
}
wrtr.WriteLine(rightColumn[i]);
}

View File

@ -33,6 +33,13 @@ namespace TBF.Rig.Output.FileWriters.Enhanced
public string[] SelectedItems;
public string Footer;
[XmlIgnore]
private bool? noSeparatorBetweenItems;
public bool NoSeparatorBetweenItems {
get { return noSeparatorBetweenItems.HasValue ? noSeparatorBetweenItems.Value : false; }
set { noSeparatorBetweenItems = value;}
}
[XmlIgnore]
public MetersKind MetersKind;
@ -61,11 +68,12 @@ namespace TBF.Rig.Output.FileWriters.Enhanced
SaveGoodOnly = false;
Header = string.Empty;
Footer = string.Empty;
NoSeparatorBetweenItems = false;
}
public string ToString(int i)
{
return string.Format("{0}, Path={1}, Y={2}, M={3}, D={4}, FNameFmt={5}, Separator={6}, NoSpaces={7}, GoodOnly={8}",
return string.Format("{0}, Path={1}, Y={2}, M={3}, D={4}, FNameFmt={5}, Separator={6}, NoSpaces={7}, GoodOnly={8}, NoSeparatorBetweenItems={9}",
Name,
DestinationPath,
YearFolders,
@ -74,7 +82,8 @@ namespace TBF.Rig.Output.FileWriters.Enhanced
FileNameFormat,
Separator,
EliminateSpaces,
SaveGoodOnly);
SaveGoodOnly,
NoSeparatorBetweenItems);
}
}
}

View File

@ -69,6 +69,7 @@ namespace TBF.Rig.Output.FileWriters.Enhanced
separatorLabel.Text = "Separator";
eliminateSpacesCheckBox.Text = "No spaces";
goodOnlyCheckBox.Text = "Good only";
noSeparatorCICheckBox.Text = "No separ. `Common i`";
headerButton.Text = Strings.Header;
commonItemsButton.Text = "Common items";
testItemsButton.Text = "Test items";
@ -96,7 +97,8 @@ namespace TBF.Rig.Output.FileWriters.Enhanced
separatorComboBox.Text = config.Separator.ToString();
eliminateSpacesCheckBox.Checked = config.EliminateSpaces;
goodOnlyCheckBox.Checked = config.SaveGoodOnly;
}
noSeparatorCICheckBox.Checked = config.NoSeparatorBetweenItems;
}
public void Unlock()
{
@ -118,6 +120,7 @@ namespace TBF.Rig.Output.FileWriters.Enhanced
commonItemsButton.Enabled = true;
testItemsButton.Enabled = true;
footerButton.Enabled = true;
noSeparatorCICheckBox.Enabled = true;
}
public CfgUpdateFlags VerifyCfg(ref string message)
@ -255,6 +258,12 @@ namespace TBF.Rig.Output.FileWriters.Enhanced
config.SaveGoodOnly = goodOnlyCheckBox.Checked;
flags |= (CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
}
if (config.NoSeparatorBetweenItems != noSeparatorCICheckBox.Checked)
{
config.NoSeparatorBetweenItems = noSeparatorCICheckBox.Checked;
flags |= (CfgUpdateFlags.InvokeCfgChange | CfgUpdateFlags.AnyChange);
}
if (config.Header != header)
{

View File

@ -25,409 +25,459 @@ namespace TBF.Rig.Output.FileWriters.Enhanced
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.nameTextBox = new System.Windows.Forms.TextBox();
this.nameLabel = new System.Windows.Forms.Label();
this.classNameLabel = new System.Windows.Forms.Label();
this.destinationTextBox = new System.Windows.Forms.TextBox();
this.destinationLabel = new System.Windows.Forms.Label();
this.destinationButton = new System.Windows.Forms.Button();
this.separatorLabel = new System.Windows.Forms.Label();
this.separatorComboBox = new System.Windows.Forms.ComboBox();
this.testItemsButton = new System.Windows.Forms.Button();
this.yearFoldersLabel = new System.Windows.Forms.Label();
this.monthFoldersLabel = new System.Windows.Forms.Label();
this.dayFoldersLabel = new System.Windows.Forms.Label();
this.yearFoldersComboBox = new System.Windows.Forms.ComboBox();
this.monthFoldersComboBox = new System.Windows.Forms.ComboBox();
this.dayFoldersComboBox = new System.Windows.Forms.ComboBox();
this.destination2Button = new System.Windows.Forms.Button();
this.destination2TextBox = new System.Windows.Forms.TextBox();
this.destination2Label = new System.Windows.Forms.Label();
this.fileNameFmtTextBox = new System.Windows.Forms.TextBox();
this.fileNameFmtLabel = new System.Windows.Forms.Label();
this.eliminateSpacesCheckBox = new System.Windows.Forms.CheckBox();
this.headerButton = new System.Windows.Forms.Button();
this.footerButton = new System.Windows.Forms.Button();
this.commonItemsButton = new System.Windows.Forms.Button();
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.subtitleFmtTextBox = new System.Windows.Forms.TextBox();
this.subtitleFmtLabel = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// nameTextBox
//
this.nameTextBox.Enabled = false;
this.nameTextBox.Location = new System.Drawing.Point(108, 28);
this.nameTextBox.Name = "nameTextBox";
this.nameTextBox.Size = new System.Drawing.Size(146, 20);
this.nameTextBox.TabIndex = 2;
//
// nameLabel
//
this.nameLabel.AutoSize = true;
this.nameLabel.Location = new System.Drawing.Point(17, 31);
this.nameLabel.Name = "nameLabel";
this.nameLabel.Size = new System.Drawing.Size(35, 13);
this.nameLabel.TabIndex = 1;
this.nameLabel.Text = "Name";
//
// classNameLabel
//
this.classNameLabel.AutoSize = true;
this.classNameLabel.Location = new System.Drawing.Point(105, 6);
this.classNameLabel.Name = "classNameLabel";
this.classNameLabel.Size = new System.Drawing.Size(83, 13);
this.classNameLabel.TabIndex = 0;
this.classNameLabel.Text = "ComonentName";
//
// destinationTextBox
//
this.destinationTextBox.Enabled = false;
this.destinationTextBox.Location = new System.Drawing.Point(108, 49);
this.destinationTextBox.Name = "destinationTextBox";
this.destinationTextBox.Size = new System.Drawing.Size(146, 20);
this.destinationTextBox.TabIndex = 4;
//
// destinationLabel
//
this.destinationLabel.AutoSize = true;
this.destinationLabel.Location = new System.Drawing.Point(17, 52);
this.destinationLabel.Name = "destinationLabel";
this.destinationLabel.Size = new System.Drawing.Size(60, 13);
this.destinationLabel.TabIndex = 3;
this.destinationLabel.Text = "Destination";
//
// destinationButton
//
this.destinationButton.Enabled = false;
this.destinationButton.Location = new System.Drawing.Point(269, 49);
this.destinationButton.Name = "destinationButton";
this.destinationButton.Size = new System.Drawing.Size(30, 20);
this.destinationButton.TabIndex = 5;
this.destinationButton.Text = "...";
this.destinationButton.UseVisualStyleBackColor = true;
this.destinationButton.Click += new System.EventHandler(this.destinationButton_Click);
//
// separatorLabel
//
this.separatorLabel.AutoSize = true;
this.separatorLabel.Location = new System.Drawing.Point(17, 224);
this.separatorLabel.Name = "separatorLabel";
this.separatorLabel.Size = new System.Drawing.Size(53, 13);
this.separatorLabel.TabIndex = 19;
this.separatorLabel.Text = "Separator";
//
// separatorComboBox
//
this.separatorComboBox.Enabled = false;
this.separatorComboBox.FormattingEnabled = true;
this.separatorComboBox.Location = new System.Drawing.Point(108, 221);
this.separatorComboBox.Name = "separatorComboBox";
this.separatorComboBox.Size = new System.Drawing.Size(146, 21);
this.separatorComboBox.TabIndex = 20;
//
// testItemsButton
//
this.testItemsButton.Enabled = false;
this.testItemsButton.Location = new System.Drawing.Point(108, 296);
this.testItemsButton.Name = "testItemsButton";
this.testItemsButton.Size = new System.Drawing.Size(146, 23);
this.testItemsButton.TabIndex = 25;
this.testItemsButton.Text = "Test items";
this.testItemsButton.UseVisualStyleBackColor = true;
this.testItemsButton.Click += new System.EventHandler(this.testItemsButton_Click);
//
// yearFoldersLabel
//
this.yearFoldersLabel.AutoSize = true;
this.yearFoldersLabel.Location = new System.Drawing.Point(17, 94);
this.yearFoldersLabel.Name = "yearFoldersLabel";
this.yearFoldersLabel.Size = new System.Drawing.Size(63, 13);
this.yearFoldersLabel.TabIndex = 9;
this.yearFoldersLabel.Text = "Year folders";
//
// monthFoldersLabel
//
this.monthFoldersLabel.AutoSize = true;
this.monthFoldersLabel.Location = new System.Drawing.Point(17, 116);
this.monthFoldersLabel.Name = "monthFoldersLabel";
this.monthFoldersLabel.Size = new System.Drawing.Size(71, 13);
this.monthFoldersLabel.TabIndex = 11;
this.monthFoldersLabel.Text = "Month folders";
//
// dayFoldersLabel
//
this.dayFoldersLabel.AutoSize = true;
this.dayFoldersLabel.Location = new System.Drawing.Point(17, 138);
this.dayFoldersLabel.Name = "dayFoldersLabel";
this.dayFoldersLabel.Size = new System.Drawing.Size(60, 13);
this.dayFoldersLabel.TabIndex = 13;
this.dayFoldersLabel.Text = "Day folders";
//
// yearFoldersComboBox
//
this.yearFoldersComboBox.Enabled = false;
this.yearFoldersComboBox.FormattingEnabled = true;
this.yearFoldersComboBox.Location = new System.Drawing.Point(108, 91);
this.yearFoldersComboBox.Name = "yearFoldersComboBox";
this.yearFoldersComboBox.Size = new System.Drawing.Size(146, 21);
this.yearFoldersComboBox.TabIndex = 10;
//
// monthFoldersComboBox
//
this.monthFoldersComboBox.Enabled = false;
this.monthFoldersComboBox.FormattingEnabled = true;
this.monthFoldersComboBox.Location = new System.Drawing.Point(108, 113);
this.monthFoldersComboBox.Name = "monthFoldersComboBox";
this.monthFoldersComboBox.Size = new System.Drawing.Size(146, 21);
this.monthFoldersComboBox.TabIndex = 12;
//
// dayFoldersComboBox
//
this.dayFoldersComboBox.Enabled = false;
this.dayFoldersComboBox.FormattingEnabled = true;
this.dayFoldersComboBox.Location = new System.Drawing.Point(108, 135);
this.dayFoldersComboBox.Name = "dayFoldersComboBox";
this.dayFoldersComboBox.Size = new System.Drawing.Size(146, 21);
this.dayFoldersComboBox.TabIndex = 14;
//
// destination2Button
//
this.destination2Button.Enabled = false;
this.destination2Button.Location = new System.Drawing.Point(269, 70);
this.destination2Button.Name = "destination2Button";
this.destination2Button.Size = new System.Drawing.Size(30, 20);
this.destination2Button.TabIndex = 8;
this.destination2Button.Text = "...";
this.destination2Button.UseVisualStyleBackColor = true;
//
// destination2TextBox
//
this.destination2TextBox.Enabled = false;
this.destination2TextBox.Location = new System.Drawing.Point(108, 70);
this.destination2TextBox.Name = "destination2TextBox";
this.destination2TextBox.Size = new System.Drawing.Size(146, 20);
this.destination2TextBox.TabIndex = 7;
//
// destination2Label
//
this.destination2Label.AutoSize = true;
this.destination2Label.Location = new System.Drawing.Point(17, 73);
this.destination2Label.Name = "destination2Label";
this.destination2Label.Size = new System.Drawing.Size(69, 13);
this.destination2Label.TabIndex = 6;
this.destination2Label.Text = "Destination 2";
//
// fileNameFmtTextBox
//
this.fileNameFmtTextBox.Enabled = false;
this.fileNameFmtTextBox.Location = new System.Drawing.Point(108, 157);
this.fileNameFmtTextBox.Name = "fileNameFmtTextBox";
this.fileNameFmtTextBox.Size = new System.Drawing.Size(146, 20);
this.fileNameFmtTextBox.TabIndex = 16;
//
// fileNameFmtLabel
//
this.fileNameFmtLabel.AutoSize = true;
this.fileNameFmtLabel.Location = new System.Drawing.Point(17, 160);
this.fileNameFmtLabel.Name = "fileNameFmtLabel";
this.fileNameFmtLabel.Size = new System.Drawing.Size(84, 13);
this.fileNameFmtLabel.TabIndex = 15;
this.fileNameFmtLabel.Text = "File name format";
//
// eliminateSpacesCheckBox
//
this.eliminateSpacesCheckBox.AutoSize = true;
this.eliminateSpacesCheckBox.Location = new System.Drawing.Point(20, 262);
this.eliminateSpacesCheckBox.Name = "eliminateSpacesCheckBox";
this.eliminateSpacesCheckBox.Size = new System.Drawing.Size(77, 17);
this.eliminateSpacesCheckBox.TabIndex = 21;
this.eliminateSpacesCheckBox.Text = "No spaces";
this.eliminateSpacesCheckBox.UseVisualStyleBackColor = true;
//
// headerButton
//
this.headerButton.Enabled = false;
this.headerButton.Location = new System.Drawing.Point(108, 246);
this.headerButton.Name = "headerButton";
this.headerButton.Size = new System.Drawing.Size(146, 23);
this.headerButton.TabIndex = 23;
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, 321);
this.footerButton.Name = "footerButton";
this.footerButton.Size = new System.Drawing.Size(146, 23);
this.footerButton.TabIndex = 26;
this.footerButton.Text = "Footer";
this.footerButton.UseVisualStyleBackColor = true;
this.footerButton.Click += new System.EventHandler(this.footerButton_Click);
//
// commonItemsButton
//
this.commonItemsButton.Enabled = false;
this.commonItemsButton.Location = new System.Drawing.Point(108, 271);
this.commonItemsButton.Name = "commonItemsButton";
this.commonItemsButton.Size = new System.Drawing.Size(146, 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, 271);
this.upgradeWizardButton.Name = "upgradeWizardButton";
this.upgradeWizardButton.Size = new System.Drawing.Size(80, 48);
this.upgradeWizardButton.TabIndex = 27;
this.upgradeWizardButton.Text = "Upgrade wizard";
this.upgradeWizardButton.UseVisualStyleBackColor = true;
this.upgradeWizardButton.Click += new System.EventHandler(this.upgradeWizardButton_Click);
//
// cultureComboBox
//
this.cultureComboBox.Enabled = false;
this.cultureComboBox.FormattingEnabled = true;
this.cultureComboBox.Location = new System.Drawing.Point(108, 178);
this.cultureComboBox.Name = "cultureComboBox";
this.cultureComboBox.Size = new System.Drawing.Size(146, 21);
this.cultureComboBox.TabIndex = 18;
//
// cultureLabel
//
this.cultureLabel.AutoSize = true;
this.cultureLabel.Location = new System.Drawing.Point(17, 181);
this.cultureLabel.Name = "cultureLabel";
this.cultureLabel.Size = new System.Drawing.Size(42, 13);
this.cultureLabel.TabIndex = 17;
this.cultureLabel.Text = "Cullture";
//
// goodOnlyCheckBox
//
this.goodOnlyCheckBox.AutoSize = true;
this.goodOnlyCheckBox.Location = new System.Drawing.Point(20, 285);
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;
//
// subtitleFmtTextBox
//
this.subtitleFmtTextBox.Enabled = false;
this.subtitleFmtTextBox.Location = new System.Drawing.Point(108, 200);
this.subtitleFmtTextBox.Name = "subtitleFmtTextBox";
this.subtitleFmtTextBox.Size = new System.Drawing.Size(146, 20);
this.subtitleFmtTextBox.TabIndex = 29;
//
// subtitleFmtLabel
//
this.subtitleFmtLabel.AutoSize = true;
this.subtitleFmtLabel.Location = new System.Drawing.Point(17, 203);
this.subtitleFmtLabel.Name = "subtitleFmtLabel";
this.subtitleFmtLabel.Size = new System.Drawing.Size(74, 13);
this.subtitleFmtLabel.TabIndex = 28;
this.subtitleFmtLabel.Text = "Subtitle format";
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(257, 211);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(174, 13);
this.label1.TabIndex = 30;
this.label1.Text = "4:wmStr 5:s/n 6:main s/n 7:aux.s/n";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(257, 198);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(168, 13);
this.label2.TabIndex = 31;
this.label2.Text = "0:pos 1:s/n 2:aux.s/n 3:compl.s/n";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(257, 155);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(138, 13);
this.label3.TabIndex = 32;
this.label3.Text = "0:end t. 1:start t. 2:batch nr.";
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(257, 168);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(128, 13);
this.label4.TabIndex = 33;
this.label4.Text = "3:bench name 4:bench id";
//
// WriterCfgCtrl
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.label4);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.subtitleFmtTextBox);
this.Controls.Add(this.subtitleFmtLabel);
this.Controls.Add(this.goodOnlyCheckBox);
this.Controls.Add(this.cultureComboBox);
this.Controls.Add(this.cultureLabel);
this.Controls.Add(this.upgradeWizardButton);
this.Controls.Add(this.commonItemsButton);
this.Controls.Add(this.footerButton);
this.Controls.Add(this.headerButton);
this.Controls.Add(this.eliminateSpacesCheckBox);
this.Controls.Add(this.fileNameFmtTextBox);
this.Controls.Add(this.fileNameFmtLabel);
this.Controls.Add(this.destination2Button);
this.Controls.Add(this.destination2TextBox);
this.Controls.Add(this.destination2Label);
this.Controls.Add(this.dayFoldersComboBox);
this.Controls.Add(this.monthFoldersComboBox);
this.Controls.Add(this.yearFoldersComboBox);
this.Controls.Add(this.dayFoldersLabel);
this.Controls.Add(this.monthFoldersLabel);
this.Controls.Add(this.yearFoldersLabel);
this.Controls.Add(this.testItemsButton);
this.Controls.Add(this.separatorComboBox);
this.Controls.Add(this.separatorLabel);
this.Controls.Add(this.destinationButton);
this.Controls.Add(this.destinationTextBox);
this.Controls.Add(this.destinationLabel);
this.Controls.Add(this.nameTextBox);
this.Controls.Add(this.nameLabel);
this.Controls.Add(this.classNameLabel);
this.Name = "WriterCfgCtrl";
this.Size = new System.Drawing.Size(440, 350);
this.Load += new System.EventHandler(this.WriterCfgCtrl_Load);
this.ResumeLayout(false);
this.PerformLayout();
this.nameTextBox = new System.Windows.Forms.TextBox();
this.nameLabel = new System.Windows.Forms.Label();
this.classNameLabel = new System.Windows.Forms.Label();
this.destinationTextBox = new System.Windows.Forms.TextBox();
this.destinationLabel = new System.Windows.Forms.Label();
this.destinationButton = new System.Windows.Forms.Button();
this.separatorLabel = new System.Windows.Forms.Label();
this.separatorComboBox = new System.Windows.Forms.ComboBox();
this.testItemsButton = new System.Windows.Forms.Button();
this.yearFoldersLabel = new System.Windows.Forms.Label();
this.monthFoldersLabel = new System.Windows.Forms.Label();
this.dayFoldersLabel = new System.Windows.Forms.Label();
this.yearFoldersComboBox = new System.Windows.Forms.ComboBox();
this.monthFoldersComboBox = new System.Windows.Forms.ComboBox();
this.dayFoldersComboBox = new System.Windows.Forms.ComboBox();
this.destination2Button = new System.Windows.Forms.Button();
this.destination2TextBox = new System.Windows.Forms.TextBox();
this.destination2Label = new System.Windows.Forms.Label();
this.fileNameFmtTextBox = new System.Windows.Forms.TextBox();
this.fileNameFmtLabel = new System.Windows.Forms.Label();
this.eliminateSpacesCheckBox = new System.Windows.Forms.CheckBox();
this.headerButton = new System.Windows.Forms.Button();
this.footerButton = new System.Windows.Forms.Button();
this.commonItemsButton = new System.Windows.Forms.Button();
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.subtitleFmtTextBox = new System.Windows.Forms.TextBox();
this.subtitleFmtLabel = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.noSeparatorCICheckBox = new System.Windows.Forms.CheckBox();
this.SuspendLayout();
//
// nameTextBox
//
this.nameTextBox.Enabled = false;
this.nameTextBox.Location = new System.Drawing.Point(162, 43);
this.nameTextBox.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.nameTextBox.Name = "nameTextBox";
this.nameTextBox.Size = new System.Drawing.Size(217, 26);
this.nameTextBox.TabIndex = 2;
//
// nameLabel
//
this.nameLabel.AutoSize = true;
this.nameLabel.Location = new System.Drawing.Point(26, 48);
this.nameLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.nameLabel.Name = "nameLabel";
this.nameLabel.Size = new System.Drawing.Size(51, 20);
this.nameLabel.TabIndex = 1;
this.nameLabel.Text = "Name";
//
// classNameLabel
//
this.classNameLabel.AutoSize = true;
this.classNameLabel.Location = new System.Drawing.Point(158, 9);
this.classNameLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.classNameLabel.Name = "classNameLabel";
this.classNameLabel.Size = new System.Drawing.Size(125, 20);
this.classNameLabel.TabIndex = 0;
this.classNameLabel.Text = "ComonentName";
//
// destinationTextBox
//
this.destinationTextBox.Enabled = false;
this.destinationTextBox.Location = new System.Drawing.Point(162, 75);
this.destinationTextBox.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.destinationTextBox.Name = "destinationTextBox";
this.destinationTextBox.Size = new System.Drawing.Size(217, 26);
this.destinationTextBox.TabIndex = 4;
//
// destinationLabel
//
this.destinationLabel.AutoSize = true;
this.destinationLabel.Location = new System.Drawing.Point(26, 80);
this.destinationLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.destinationLabel.Name = "destinationLabel";
this.destinationLabel.Size = new System.Drawing.Size(90, 20);
this.destinationLabel.TabIndex = 3;
this.destinationLabel.Text = "Destination";
//
// destinationButton
//
this.destinationButton.Enabled = false;
this.destinationButton.Location = new System.Drawing.Point(404, 75);
this.destinationButton.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.destinationButton.Name = "destinationButton";
this.destinationButton.Size = new System.Drawing.Size(45, 31);
this.destinationButton.TabIndex = 5;
this.destinationButton.Text = "...";
this.destinationButton.UseVisualStyleBackColor = true;
this.destinationButton.Click += new System.EventHandler(this.destinationButton_Click);
//
// separatorLabel
//
this.separatorLabel.AutoSize = true;
this.separatorLabel.Location = new System.Drawing.Point(26, 345);
this.separatorLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.separatorLabel.Name = "separatorLabel";
this.separatorLabel.Size = new System.Drawing.Size(80, 20);
this.separatorLabel.TabIndex = 19;
this.separatorLabel.Text = "Separator";
//
// separatorComboBox
//
this.separatorComboBox.Enabled = false;
this.separatorComboBox.FormattingEnabled = true;
this.separatorComboBox.Location = new System.Drawing.Point(162, 340);
this.separatorComboBox.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.separatorComboBox.Name = "separatorComboBox";
this.separatorComboBox.Size = new System.Drawing.Size(217, 28);
this.separatorComboBox.TabIndex = 20;
//
// testItemsButton
//
this.testItemsButton.Enabled = false;
this.testItemsButton.Location = new System.Drawing.Point(162, 455);
this.testItemsButton.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.testItemsButton.Name = "testItemsButton";
this.testItemsButton.Size = new System.Drawing.Size(219, 35);
this.testItemsButton.TabIndex = 25;
this.testItemsButton.Text = "Test items";
this.testItemsButton.UseVisualStyleBackColor = true;
this.testItemsButton.Click += new System.EventHandler(this.testItemsButton_Click);
//
// yearFoldersLabel
//
this.yearFoldersLabel.AutoSize = true;
this.yearFoldersLabel.Location = new System.Drawing.Point(26, 145);
this.yearFoldersLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.yearFoldersLabel.Name = "yearFoldersLabel";
this.yearFoldersLabel.Size = new System.Drawing.Size(95, 20);
this.yearFoldersLabel.TabIndex = 9;
this.yearFoldersLabel.Text = "Year folders";
//
// monthFoldersLabel
//
this.monthFoldersLabel.AutoSize = true;
this.monthFoldersLabel.Location = new System.Drawing.Point(26, 178);
this.monthFoldersLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.monthFoldersLabel.Name = "monthFoldersLabel";
this.monthFoldersLabel.Size = new System.Drawing.Size(106, 20);
this.monthFoldersLabel.TabIndex = 11;
this.monthFoldersLabel.Text = "Month folders";
//
// dayFoldersLabel
//
this.dayFoldersLabel.AutoSize = true;
this.dayFoldersLabel.Location = new System.Drawing.Point(26, 212);
this.dayFoldersLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.dayFoldersLabel.Name = "dayFoldersLabel";
this.dayFoldersLabel.Size = new System.Drawing.Size(89, 20);
this.dayFoldersLabel.TabIndex = 13;
this.dayFoldersLabel.Text = "Day folders";
//
// yearFoldersComboBox
//
this.yearFoldersComboBox.Enabled = false;
this.yearFoldersComboBox.FormattingEnabled = true;
this.yearFoldersComboBox.Location = new System.Drawing.Point(162, 140);
this.yearFoldersComboBox.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.yearFoldersComboBox.Name = "yearFoldersComboBox";
this.yearFoldersComboBox.Size = new System.Drawing.Size(217, 28);
this.yearFoldersComboBox.TabIndex = 10;
//
// monthFoldersComboBox
//
this.monthFoldersComboBox.Enabled = false;
this.monthFoldersComboBox.FormattingEnabled = true;
this.monthFoldersComboBox.Location = new System.Drawing.Point(162, 174);
this.monthFoldersComboBox.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.monthFoldersComboBox.Name = "monthFoldersComboBox";
this.monthFoldersComboBox.Size = new System.Drawing.Size(217, 28);
this.monthFoldersComboBox.TabIndex = 12;
//
// dayFoldersComboBox
//
this.dayFoldersComboBox.Enabled = false;
this.dayFoldersComboBox.FormattingEnabled = true;
this.dayFoldersComboBox.Location = new System.Drawing.Point(162, 208);
this.dayFoldersComboBox.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.dayFoldersComboBox.Name = "dayFoldersComboBox";
this.dayFoldersComboBox.Size = new System.Drawing.Size(217, 28);
this.dayFoldersComboBox.TabIndex = 14;
//
// destination2Button
//
this.destination2Button.Enabled = false;
this.destination2Button.Location = new System.Drawing.Point(404, 108);
this.destination2Button.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.destination2Button.Name = "destination2Button";
this.destination2Button.Size = new System.Drawing.Size(45, 31);
this.destination2Button.TabIndex = 8;
this.destination2Button.Text = "...";
this.destination2Button.UseVisualStyleBackColor = true;
//
// destination2TextBox
//
this.destination2TextBox.Enabled = false;
this.destination2TextBox.Location = new System.Drawing.Point(162, 108);
this.destination2TextBox.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.destination2TextBox.Name = "destination2TextBox";
this.destination2TextBox.Size = new System.Drawing.Size(217, 26);
this.destination2TextBox.TabIndex = 7;
//
// destination2Label
//
this.destination2Label.AutoSize = true;
this.destination2Label.Location = new System.Drawing.Point(26, 112);
this.destination2Label.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.destination2Label.Name = "destination2Label";
this.destination2Label.Size = new System.Drawing.Size(103, 20);
this.destination2Label.TabIndex = 6;
this.destination2Label.Text = "Destination 2";
//
// fileNameFmtTextBox
//
this.fileNameFmtTextBox.Enabled = false;
this.fileNameFmtTextBox.Location = new System.Drawing.Point(162, 242);
this.fileNameFmtTextBox.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.fileNameFmtTextBox.Name = "fileNameFmtTextBox";
this.fileNameFmtTextBox.Size = new System.Drawing.Size(217, 26);
this.fileNameFmtTextBox.TabIndex = 16;
//
// fileNameFmtLabel
//
this.fileNameFmtLabel.AutoSize = true;
this.fileNameFmtLabel.Location = new System.Drawing.Point(26, 246);
this.fileNameFmtLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.fileNameFmtLabel.Name = "fileNameFmtLabel";
this.fileNameFmtLabel.Size = new System.Drawing.Size(128, 20);
this.fileNameFmtLabel.TabIndex = 15;
this.fileNameFmtLabel.Text = "File name format";
//
// eliminateSpacesCheckBox
//
this.eliminateSpacesCheckBox.AutoSize = true;
this.eliminateSpacesCheckBox.Enabled = false;
this.eliminateSpacesCheckBox.Location = new System.Drawing.Point(30, 403);
this.eliminateSpacesCheckBox.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.eliminateSpacesCheckBox.Name = "eliminateSpacesCheckBox";
this.eliminateSpacesCheckBox.Size = new System.Drawing.Size(110, 24);
this.eliminateSpacesCheckBox.TabIndex = 21;
this.eliminateSpacesCheckBox.Text = "No spaces";
this.eliminateSpacesCheckBox.UseVisualStyleBackColor = true;
//
// headerButton
//
this.headerButton.Enabled = false;
this.headerButton.Location = new System.Drawing.Point(162, 378);
this.headerButton.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.headerButton.Name = "headerButton";
this.headerButton.Size = new System.Drawing.Size(219, 35);
this.headerButton.TabIndex = 23;
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(162, 494);
this.footerButton.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.footerButton.Name = "footerButton";
this.footerButton.Size = new System.Drawing.Size(219, 35);
this.footerButton.TabIndex = 26;
this.footerButton.Text = "Footer";
this.footerButton.UseVisualStyleBackColor = true;
this.footerButton.Click += new System.EventHandler(this.footerButton_Click);
//
// commonItemsButton
//
this.commonItemsButton.Enabled = false;
this.commonItemsButton.Location = new System.Drawing.Point(162, 417);
this.commonItemsButton.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.commonItemsButton.Name = "commonItemsButton";
this.commonItemsButton.Size = new System.Drawing.Size(219, 35);
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(404, 417);
this.upgradeWizardButton.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.upgradeWizardButton.Name = "upgradeWizardButton";
this.upgradeWizardButton.Size = new System.Drawing.Size(120, 74);
this.upgradeWizardButton.TabIndex = 27;
this.upgradeWizardButton.Text = "Upgrade wizard";
this.upgradeWizardButton.UseVisualStyleBackColor = true;
this.upgradeWizardButton.Click += new System.EventHandler(this.upgradeWizardButton_Click);
//
// cultureComboBox
//
this.cultureComboBox.Enabled = false;
this.cultureComboBox.FormattingEnabled = true;
this.cultureComboBox.Location = new System.Drawing.Point(162, 274);
this.cultureComboBox.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.cultureComboBox.Name = "cultureComboBox";
this.cultureComboBox.Size = new System.Drawing.Size(217, 28);
this.cultureComboBox.TabIndex = 18;
//
// cultureLabel
//
this.cultureLabel.AutoSize = true;
this.cultureLabel.Location = new System.Drawing.Point(26, 278);
this.cultureLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.cultureLabel.Name = "cultureLabel";
this.cultureLabel.Size = new System.Drawing.Size(63, 20);
this.cultureLabel.TabIndex = 17;
this.cultureLabel.Text = "Cullture";
//
// goodOnlyCheckBox
//
this.goodOnlyCheckBox.AutoSize = true;
this.goodOnlyCheckBox.Enabled = false;
this.goodOnlyCheckBox.Location = new System.Drawing.Point(30, 438);
this.goodOnlyCheckBox.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.goodOnlyCheckBox.Name = "goodOnlyCheckBox";
this.goodOnlyCheckBox.Size = new System.Drawing.Size(107, 24);
this.goodOnlyCheckBox.TabIndex = 22;
this.goodOnlyCheckBox.Text = "Good only";
this.goodOnlyCheckBox.UseVisualStyleBackColor = false;
//
// subtitleFmtTextBox
//
this.subtitleFmtTextBox.Enabled = false;
this.subtitleFmtTextBox.Location = new System.Drawing.Point(162, 308);
this.subtitleFmtTextBox.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.subtitleFmtTextBox.Name = "subtitleFmtTextBox";
this.subtitleFmtTextBox.Size = new System.Drawing.Size(217, 26);
this.subtitleFmtTextBox.TabIndex = 29;
//
// subtitleFmtLabel
//
this.subtitleFmtLabel.AutoSize = true;
this.subtitleFmtLabel.Location = new System.Drawing.Point(26, 312);
this.subtitleFmtLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.subtitleFmtLabel.Name = "subtitleFmtLabel";
this.subtitleFmtLabel.Size = new System.Drawing.Size(113, 20);
this.subtitleFmtLabel.TabIndex = 28;
this.subtitleFmtLabel.Text = "Subtitle format";
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(386, 325);
this.label1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(248, 20);
this.label1.TabIndex = 30;
this.label1.Text = "4:wmStr 5:s/n 6:main s/n 7:aux.s/n";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(386, 305);
this.label2.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(237, 20);
this.label2.TabIndex = 31;
this.label2.Text = "0:pos 1:s/n 2:aux.s/n 3:compl.s/n";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(386, 238);
this.label3.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(203, 20);
this.label3.TabIndex = 32;
this.label3.Text = "0:end t. 1:start t. 2:batch nr.";
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(386, 258);
this.label4.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(239, 20);
this.label4.TabIndex = 33;
this.label4.Text = "3:bench name 4:bench id, 5:Now";
//
// noSeparatorCICheckBox
//
this.noSeparatorCICheckBox.Enabled = false;
this.noSeparatorCICheckBox.Location = new System.Drawing.Point(30, 470);
this.noSeparatorCICheckBox.Name = "noSeparatorCICheckBox";
this.noSeparatorCICheckBox.Size = new System.Drawing.Size(125, 59);
this.noSeparatorCICheckBox.TabIndex = 34;
this.noSeparatorCICheckBox.Text = "No separ. \"Common i.\"";
this.noSeparatorCICheckBox.UseVisualStyleBackColor = true;
//
// WriterCfgCtrl
//
this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.noSeparatorCICheckBox);
this.Controls.Add(this.label4);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.subtitleFmtTextBox);
this.Controls.Add(this.subtitleFmtLabel);
this.Controls.Add(this.goodOnlyCheckBox);
this.Controls.Add(this.cultureComboBox);
this.Controls.Add(this.cultureLabel);
this.Controls.Add(this.upgradeWizardButton);
this.Controls.Add(this.commonItemsButton);
this.Controls.Add(this.footerButton);
this.Controls.Add(this.headerButton);
this.Controls.Add(this.eliminateSpacesCheckBox);
this.Controls.Add(this.fileNameFmtTextBox);
this.Controls.Add(this.fileNameFmtLabel);
this.Controls.Add(this.destination2Button);
this.Controls.Add(this.destination2TextBox);
this.Controls.Add(this.destination2Label);
this.Controls.Add(this.dayFoldersComboBox);
this.Controls.Add(this.monthFoldersComboBox);
this.Controls.Add(this.yearFoldersComboBox);
this.Controls.Add(this.dayFoldersLabel);
this.Controls.Add(this.monthFoldersLabel);
this.Controls.Add(this.yearFoldersLabel);
this.Controls.Add(this.testItemsButton);
this.Controls.Add(this.separatorComboBox);
this.Controls.Add(this.separatorLabel);
this.Controls.Add(this.destinationButton);
this.Controls.Add(this.destinationTextBox);
this.Controls.Add(this.destinationLabel);
this.Controls.Add(this.nameTextBox);
this.Controls.Add(this.nameLabel);
this.Controls.Add(this.classNameLabel);
this.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.Name = "WriterCfgCtrl";
this.Size = new System.Drawing.Size(660, 538);
this.Load += new System.EventHandler(this.WriterCfgCtrl_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
private System.Windows.Forms.CheckBox noSeparatorCICheckBox;
#endregion
private System.Windows.Forms.TextBox nameTextBox;

View File

@ -0,0 +1,128 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using JetBrains.Annotations;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using Results;
using TBF.Rig.GenericDevices;
using TBF.Rig.Output.FileWriters.Enhanced;
using TBF.Rig.Sequences;
namespace TBFTests.Rig.Output.FileWriters.Enhanced
{
[TestClass]
[TestSubject(typeof(Writer))]
public class WriterTest
{
[TestInitialize]
public void Setup()
{
// Mock IBenchInfo and assign it to static field
var mockBenchInfo = new Mock<IBenchInfo>();
// Optional: Setup mock behavior if GetName or similar is used
mockBenchInfo.Setup(b => b.TestBenchName).Returns("TestBench");
mockBenchInfo.Setup(b => b.TestBenchId).Returns(1);
ProcessData.BenchInfo = mockBenchInfo.Object;
}
[TestCleanup]
public void Cleanup()
{
// Clean up the static reference
ProcessData.BenchInfo = null;
}
[TestMethod]
public void GetFilenameTest()
{
FactorySingle factory = new FactorySingle();
WriterCfg defaultConfig = factory.DefaultConfig() as WriterCfg;
string dateFormat = "yyMMdd-HHmm";
defaultConfig.FileNameFormat = $"{{5:{dateFormat}}}.txt";
Writer writer = new Writer( defaultConfig);
Results.Entities.Batch batch = new Results.Entities.Batch();
DateTime time = DateTime.Now;
batch.EndTime = time;
string filename = writer.GetFilename("C:\\TBF\\Results\\", batch, time);
// Assert
Assert.IsNotNull(filename, "Filename should not be null.");
Assert.IsTrue(filename.StartsWith("C:\\TBF\\Results\\"), "Filename should start with base path.");
//test extension
Assert.IsTrue(filename.EndsWith(".txt") , "Filename should have correct extension.");
//test path - Format path like \2025\7\28\
string path = $@"\{time.Year}\{time.Month}\{time.Day}\";
Assert.IsTrue( filename.Contains(path));
//test file name
string expected = string.Format($"{{0:{dateFormat}}}.txt", time);
Assert.IsTrue( filename.Contains(expected));
}
[TestMethod]
public void WriteRsltsExTest()
{
FactorySingle factory = new FactorySingle();
WriterCfg defaultConfig = factory.DefaultConfig() as WriterCfg;
string dateFormat = "yyMMdd-HHmm";
defaultConfig.FileNameFormat = $"{{5:{dateFormat}}}.txt";
defaultConfig.Header = "Header :)";
Writer writer = new Writer( defaultConfig);
var field = typeof(Writer).GetField("commonItems", BindingFlags.NonPublic | BindingFlags.Instance);
var fieldHeader = typeof(Writer).GetField("header", BindingFlags.NonPublic | BindingFlags.Instance);
fieldHeader?.SetValue(writer, defaultConfig.Header);
var mockList = new List<Results.WMeterRsltItemSpec>
{
new WMeterRsltItemSpec (ItemID.Batch_end_time, "End", null,Common.Quantity.DateTime, Common.ItemCategory.Other, null)
};
mockList[0].Caption = "Date and time";
string formatCommonTime = "yyyy.MM.dd HH:mm";
mockList[0].Format = $"{{0:{formatCommonTime}}}";
field?.SetValue(writer, mockList);
Results.Entities.Batch batch = new Results.Entities.Batch();
DateTime time = DateTime.Now;
batch.EndTime = time;
using (var memStream = new MemoryStream())
using (var writerStream = new StreamWriter(memStream))
{
writer.WriteRsltsEx(batch, writerStream, time);
writerStream.Flush();
// Get the actual content
memStream.Position = 0;
using (var reader = new StreamReader(memStream))
{
string content = reader.ReadToEnd();
// Assert on the actual content
Assert.IsNotNull(content);
Assert.IsTrue(content.Contains(defaultConfig.Header));
Assert.IsTrue(content.Contains("Date and time"));
string expectedCommonTime = string.Format($"{{0:{formatCommonTime}}}", time);
Assert.IsTrue(content.Contains(expectedCommonTime));
}
}
}
}
}

View File

@ -101,6 +101,7 @@
<Compile Include="Rig\Network\Camera\CJMS11\CameraTest.cs" />
<Compile Include="Rig\Network\Camera\KeyenceIV3G120\CameraTest.cs" />
<Compile Include="Rig\Network\Camera\RoiForFixedStartKeyence\RoiTest.cs" />
<Compile Include="Rig\Output\FileWriters\Enhanced\WriterTest.cs" />
<Compile Include="Rig\RegisterReaders\PoseidonCmdStartStop\CliRunnerTest.cs" />
<Compile Include="Rig\RegisterReaders\PoseidonCmdStartStop\PoseidonReaderTest.cs" />
</ItemGroup>
@ -109,10 +110,18 @@
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Common\Common.csproj">
<Project>{c8939821-ba5c-4988-a3d0-bf53b74865c7}</Project>
<Name>Common</Name>
</ProjectReference>
<ProjectReference Include="..\Config\Config.csproj">
<Project>{743df7db-c7b6-42eb-986d-0f485e5588e4}</Project>
<Name>Config</Name>
</ProjectReference>
<ProjectReference Include="..\Results\Results.csproj">
<Project>{9d0dcc88-dc81-47eb-9fdd-4c3907871bfb}</Project>
<Name>Results</Name>
</ProjectReference>
<ProjectReference Include="..\TBF\TBF.csproj">
<Project>{8648FD92-CDA1-4C3A-B5F9-FE547CE1FA48}</Project>
<Name>TBF</Name>