164 lines
6.4 KiB
C#
164 lines
6.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using log4net;
|
|
using TBF.BenchControl;
|
|
|
|
namespace TBF.BenchControl.ResultsWriters.Basic
|
|
{
|
|
public class Writer : ComponentBase, IOperation, GenericDevices.IResultsWriter
|
|
{
|
|
private static readonly ILog log = LogManager.GetLogger(typeof(Writer));
|
|
public override string ToString() { return string.Format("ResultsWriters.Basic({0})", Cfg.ToString(1)); }
|
|
|
|
readonly WriterCfg writerCfg;
|
|
|
|
/// <summary>
|
|
/// Result items to print
|
|
/// </summary>
|
|
IList<TBF.Forms.ResultItemSpec> resultItems;
|
|
bool combined;
|
|
|
|
/// <summary>
|
|
/// Results to print
|
|
/// </summary>
|
|
IList<Entities.TestResult> results;
|
|
DateTime now;
|
|
StreamWriter writer;
|
|
|
|
public Writer(WriterCfg cfg)
|
|
: base(cfg)
|
|
{
|
|
writerCfg = cfg;
|
|
log.Debug(this.ToString());
|
|
}
|
|
|
|
/// <summary>
|
|
/// Writes the test cycle results into a file, Events: Event.ResultsWritten
|
|
/// </summary>
|
|
/// <param name="results">Results to write into the file</param>
|
|
/// <returns>Reference to the operation</returns>
|
|
public IOperation WriteResultsOp(IList<Entities.TestResult> results)
|
|
{
|
|
if ((results == null) || (results.Count == 0) ||
|
|
((results[0].MetersKind != Entities.MetersKind.Single) &&
|
|
(results[0].MetersKind != Entities.MetersKind.Combined)))
|
|
{
|
|
writer = null;
|
|
return this;
|
|
}
|
|
|
|
if (results[0].MetersKind == Entities.MetersKind.Single)
|
|
{
|
|
resultItems = Forms.ResultItemSpec.FromStrArray(Program.LocalSettings.RsltItems_Disk_SingleWM);
|
|
combined = false;
|
|
}
|
|
else
|
|
{
|
|
resultItems = Forms.ResultItemSpec.FromStrArray(Program.LocalSettings.RsltItems_Disk_CombinedWM);
|
|
combined = true;
|
|
}
|
|
|
|
this.results = results;
|
|
now = DateTime.Now;
|
|
try
|
|
{
|
|
string dayDirectory = string.Format("{0}Results\\{1}-{2}-{3}", Program.HomeDir,
|
|
now.Year, now.Month.ToString("D2"), now.Day.ToString("D2"));
|
|
string fileName = string.Format("{0}\\{1}-{2}.txt", dayDirectory,
|
|
now.Hour.ToString("D2"), now.Minute.ToString("D2"));
|
|
Directory.CreateDirectory(dayDirectory);
|
|
writer = new StreamWriter(System.IO.File.Create(fileName));
|
|
}
|
|
catch
|
|
{
|
|
writer = null;
|
|
}
|
|
|
|
return this;
|
|
}
|
|
|
|
/// <summary>Start this operation</summary>
|
|
public void Start()
|
|
{
|
|
if (writer == null) return;
|
|
|
|
writer.WriteLine("Staatlich anerkante Prüfstelle für Meßgeräte für Wasser WB2");
|
|
writer.WriteLine("");
|
|
writer.WriteLine(string.Format(" PROTOKOLL Nummer {0}", 0));
|
|
writer.WriteLine("");
|
|
writer.WriteLine("Ver. 3/13");
|
|
writer.WriteLine(string.Format("Datum / Zeit : {0}.{1}.{2} {3}:{4} Seite : 1/1",
|
|
now.Day.ToString("D2"),
|
|
now.Month.ToString("D2"),
|
|
now.Year.ToString("D4"),
|
|
now.Hour.ToString("D2"),
|
|
now.Minute.ToString("D2")));
|
|
writer.WriteLine(string.Format("Wasserzähler Type : {0}", results[0].ProcedureName));
|
|
writer.WriteLine("Gerät Nr. : 1");
|
|
writer.WriteLine(string.Format("Benutzer : {0}", Entities.User.CurrentUser.Name));
|
|
writer.Write("Impulsrate : ");
|
|
for (int i = 0; i < Program.WMsCount; i++)
|
|
{
|
|
//writer.Write(results[0].
|
|
}
|
|
writer.WriteLine("Bereich : 22,9 °C 947 mbar 43 %");
|
|
writer.WriteLine("");
|
|
|
|
foreach (var item in resultItems) writer.Write(item.ClmnHeaderText);
|
|
writer.WriteLine(string.Empty);
|
|
|
|
writer.WriteLine("---------------------------------------------------------------------------------------------------------------------------------------");
|
|
|
|
foreach (var tr in results)
|
|
{
|
|
foreach (var item in resultItems)
|
|
{
|
|
if (combined)
|
|
{
|
|
writer.Write(item.PrintCombined(tr.CombinedMeters[0], tr.Meters[0], tr.Meters[1]));
|
|
}
|
|
else
|
|
{
|
|
writer.Write(item.Print(tr.Meters[0]));
|
|
}
|
|
}
|
|
writer.WriteLine(string.Empty);
|
|
}
|
|
|
|
writer.WriteLine("---------------------------------------------------------------------------------------------------------------------------------------");
|
|
writer.WriteLine("No| Zähler Nr| Test. Volume [L] | Zählerabweichung [%] | Messunsicherheit k=2 |Prüfergebnis");
|
|
writer.WriteLine("---------------------------------------------------------------------------------------------------------------------------------------");
|
|
writer.WriteLine(" Qmin Qt Qmax Qmin Qt Qmax Qmin Qt Qmax");
|
|
writer.WriteLine("---------------------------------------------------------------------------------------------------------------------------------------");
|
|
}
|
|
|
|
/// <summary>Run this operation</summary>
|
|
/// <returns>Event.ResultsWritten</returns>
|
|
public Event Run()
|
|
{
|
|
return Event.ResultsWritten;
|
|
}
|
|
|
|
/// <summary>Stop this operation</summary>
|
|
public void Stop()
|
|
{
|
|
if (writer == null) return;
|
|
|
|
writer.WriteLine("---------------------------------------------------------------------------------------------------------------------------------------");
|
|
writer.WriteLine("");
|
|
writer.WriteLine("Hersteller : Bemerkung : M - Prüfung gegen Waage");
|
|
writer.WriteLine(" V - Prüfung gegen MID");
|
|
writer.WriteLine(" P - Start / Stopp");
|
|
writer.WriteLine(" F - Fliegender Start");
|
|
writer.WriteLine(" S - Impulskompensation");
|
|
writer.WriteLine(" C - Impulszählung");
|
|
writer.WriteLine("");
|
|
writer.WriteLine("---------------------------------------------------------------------------------------------------------------------------------------");
|
|
|
|
if (writer != null) writer.Close();
|
|
writer = null;
|
|
}
|
|
}
|
|
}
|