Improved file name formatting for Output.FileWrites.Basic/Enhanced/Xml/XmlBatch components.

This commit is contained in:
Milan Hanajik 2020-10-14 09:33:27 +02:00
parent 1cf2eb8e06
commit b145c71ee3
4 changed files with 52 additions and 20 deletions

View File

@ -1,5 +1,5 @@
///
/// Copyright (c) 2013-2017 Sensus Metering Systems
/// Copyright (c) 2013-2020 Sensus Metering Systems
///
using System;
using System.Collections.Generic;
@ -126,9 +126,10 @@ namespace TBF.BenchControl.Output.FileWriters.Basic
/// </summary>
/// <param name="time">Date and time</param>
/// <returns>File name</returns>
string GetFilename(string destinationPath, DateTime time)
string GetFilename(string destinationPath, Results.Entities.Batch batch)
{
string directory = destinationPath; /// Ends with "\\";
DateTime time = batch.EndTime;
switch (writerCfg.YearFolders)
{
@ -186,8 +187,15 @@ namespace TBF.BenchControl.Output.FileWriters.Basic
try
{
if (string.IsNullOrEmpty(writerCfg.FileNameFormat)) throw new Exception();
return directory + string.Format(writerCfg.FileNameFormat, time);
if (string.IsNullOrEmpty(writerCfg.FileNameFormat))
{
return string.Format("{0}{1:yyMMdd-HHmm}.txt", directory, time);
}
else
{
TBF.BenchControl.GenericDevices.IBenchInfo bi = TBF.BenchControl.Sequences.ProcessData.BenchInfo;
return directory + string.Format(writerCfg.FileNameFormat, batch.EndTime, batch.StartTime, batch.BatchNr, bi.TestBenchName, bi.TestBenchId);
}
}
catch
{
@ -251,7 +259,7 @@ namespace TBF.BenchControl.Output.FileWriters.Basic
StreamWriter writer = StreamWriter.Null;
try
{
writer = File.AppendText(GetFilename(destination, batch.EndTime));
writer = File.AppendText(GetFilename(destination, batch));
WriteRsltsEx(batch, writer);
log.WarnFormat("Batch {0} written by {1} to file {2}", batch.BatchNr, Name, destination);
}

View File

@ -1,5 +1,5 @@
///
/// Copyright (c) 2016-2017 Sensus Metering Systems
/// Copyright (c) 2016-2020 Sensus Metering Systems
///
using System;
using System.Collections.Generic;
@ -124,9 +124,10 @@ namespace TBF.BenchControl.Output.FileWriters.Enhanced
/// </summary>
/// <param name="time">Date and time</param>
/// <returns>File name</returns>
string GetFilename(string destinationPath, DateTime time)
string GetFilename(string destinationPath, Results.Entities.Batch batch)
{
string directory = destinationPath; /// Ends with "\\";
DateTime time = batch.EndTime;
switch (writerCfg.YearFolders)
{
@ -184,8 +185,15 @@ namespace TBF.BenchControl.Output.FileWriters.Enhanced
try
{
if (string.IsNullOrEmpty(writerCfg.FileNameFormat)) throw new Exception();
return directory + string.Format(writerCfg.FileNameFormat, time);
if (string.IsNullOrEmpty(writerCfg.FileNameFormat))
{
return string.Format("{0}{1:yyMMdd-HHmm}.txt", directory, time);
}
else
{
TBF.BenchControl.GenericDevices.IBenchInfo bi = TBF.BenchControl.Sequences.ProcessData.BenchInfo;
return directory + string.Format(writerCfg.FileNameFormat, batch.EndTime, batch.StartTime, batch.BatchNr, bi.TestBenchName, bi.TestBenchId);
}
}
catch
{
@ -247,7 +255,7 @@ namespace TBF.BenchControl.Output.FileWriters.Enhanced
StreamWriter writer = StreamWriter.Null;
try
{
writer = File.AppendText(GetFilename(destination, batch.EndTime));
writer = File.AppendText(GetFilename(destination, batch));
WriteRsltsEx(batch, writer);
log.WarnFormat("Batch {0} written by {1} to file {2}", batch.BatchNr, Name, destination);
}

View File

@ -104,9 +104,10 @@ namespace TBF.BenchControl.Output.FileWriters.Xml
/// </summary>
/// <param name="time">Date and time</param>
/// <returns>File name</returns>
string GetFilename(string destinationPath, DateTime time, int wmPosition)
string GetFilename(string destinationPath, Results.Entities.Batch batch, Results.Entities.WaterMeter wm)
{
string directory = destinationPath; /// Ends with "\\";
DateTime time = batch.EndTime;
switch (writerCfg.YearFolders)
{
@ -164,12 +165,19 @@ namespace TBF.BenchControl.Output.FileWriters.Xml
try
{
if (string.IsNullOrEmpty(writerCfg.FileNameFormat)) throw new Exception();
return directory + string.Format(writerCfg.FileNameFormat, time, wmPosition);
if (string.IsNullOrEmpty(writerCfg.FileNameFormat))
{
return string.Format("{0}{1:yyMMdd-HHmm}-{2:D2}.xml", directory, time, wm.WMPosition);
}
else
{
TBF.BenchControl.GenericDevices.IBenchInfo bi = TBF.BenchControl.Sequences.ProcessData.BenchInfo;
return directory + string.Format(writerCfg.FileNameFormat, batch.EndTime, batch.StartTime, batch.BatchNr, bi.TestBenchName, bi.TestBenchId, wm.WMPosition, wm.SerialNr);
}
}
catch
{
return string.Format("{0}{1:yyMMdd-HHmm}-{2:D2}.xml", directory, time, wmPosition);
return string.Format("{0}{1:yyMMdd-HHmm}-{2:D2}.xml", directory, time, wm.WMPosition);
}
}
@ -225,7 +233,7 @@ namespace TBF.BenchControl.Output.FileWriters.Xml
StreamWriter writer = StreamWriter.Null;
try
{
writer = File.AppendText(GetFilename(destination, batch.EndTime, wm.WMPosition));
writer = File.AppendText(GetFilename(destination, batch, wm));
WriteWM(writer, wm);
log.WarnFormat("Batch {0}/watermeter {1} written by {2} to file {3}", batch.BatchNr, wm.WMPosition, Name, destination);
}

View File

@ -1,5 +1,5 @@
///
/// Copyright (c) 2018 Sensus Slovensko a.s.
/// Copyright (c) 2018-2020 Sensus Slovensko a.s.
///
using System;
using System.Collections.Generic;
@ -110,9 +110,10 @@ namespace TBF.BenchControl.Output.FileWriters.XmlBatch
/// </summary>
/// <param name="time">Date and time</param>
/// <returns>File name</returns>
string GetFilename(string destinationPath, DateTime time)
string GetFilename(string destinationPath, Results.Entities.Batch batch)
{
string directory = destinationPath; /// Ends with "\\";
DateTime time = batch.EndTime;
switch (writerCfg.YearFolders)
{
@ -170,8 +171,15 @@ namespace TBF.BenchControl.Output.FileWriters.XmlBatch
try
{
if (string.IsNullOrEmpty(writerCfg.FileNameFormat)) throw new Exception();
return directory + string.Format(writerCfg.FileNameFormat, time);
if (string.IsNullOrEmpty(writerCfg.FileNameFormat))
{
return string.Format("{0}{1:yyMMdd-HHmm}.xml", directory, time);
}
else
{
TBF.BenchControl.GenericDevices.IBenchInfo bi = TBF.BenchControl.Sequences.ProcessData.BenchInfo;
return directory + string.Format(writerCfg.FileNameFormat, batch.EndTime, batch.StartTime, batch.BatchNr, bi.TestBenchName, bi.TestBenchId);
}
}
catch
{
@ -230,7 +238,7 @@ namespace TBF.BenchControl.Output.FileWriters.XmlBatch
StreamWriter writer = StreamWriter.Null;
try
{
writer = File.AppendText(GetFilename(destination, batch.EndTime));
writer = File.AppendText(GetFilename(destination, batch));
WriteBatch(writer);
log.WarnFormat("Batch {0} written by {1} to file {2}", batch.BatchNr, Name, destination);
}