Code development platform for open source projects from the European Union institutions

Skip to content
Snippets Groups Projects
Commit 07553784 authored by Markus QUARITSCH's avatar Markus QUARITSCH
Browse files

hack in TemFileOutpurWriter to allow working with DEA and FileOutputWriter

parent 39cc3776
No related branches found
No related tags found
No related merge requests found
......@@ -50,7 +50,7 @@ namespace TUGraz.VectoCore.OutputData.FileIO
public string JobFile => _jobFile;
private ConcurrentDictionary<ReportType, string> _writtenReports = new ConcurrentDictionary<ReportType, string>();
protected ConcurrentDictionary<ReportType, string> _writtenReports = new ConcurrentDictionary<ReportType, string>();
public virtual IDictionary<ReportType, string> GetWrittenFiles()
{
return _writtenReports;
......@@ -151,6 +151,22 @@ namespace TUGraz.VectoCore.OutputData.FileIO
}
public virtual void WriteReport(ReportType type, XDocument data)
{
var fileName = GetReportFilename(type);
using (var writer = new FileStream(fileName, FileMode.Create)) {
using (var xmlWriter = new XmlTextWriter(writer, Encoding.UTF8)) {
xmlWriter.Formatting = Formatting.Indented;
data.WriteTo(xmlWriter);
xmlWriter.Flush();
xmlWriter.Close();
}
}
var added = _writtenReports.TryAdd(type, fileName);
System.Diagnostics.Debug.Assert(added);
}
protected virtual string GetReportFilename(ReportType type)
{
string fileName = null;
switch (type) {
......@@ -175,20 +191,10 @@ namespace TUGraz.VectoCore.OutputData.FileIO
default:
throw new ArgumentOutOfRangeException("ReportType");
}
using (var writer = new FileStream(fileName, FileMode.Create)) {
using (var xmlWriter = new XmlTextWriter(writer, Encoding.UTF8)) {
xmlWriter.Formatting = Formatting.Indented;
data.WriteTo(xmlWriter);
xmlWriter.Flush();
xmlWriter.Close();
}
}
var added = _writtenReports.TryAdd(type, fileName);
System.Diagnostics.Debug.Assert(added);
return fileName;
}
public virtual void WriteReport(ReportType type, Stream data)
{
......
......@@ -8,7 +8,7 @@ using TUGraz.VectoCommon.Models;
namespace TUGraz.VectoCore.OutputData.FileIO
{
public class TempFileOutputWriter : LoggingObject, IOutputDataWriter //: FileOutputWriter
public class TempFileOutputWriter : FileOutputWriter
{
private readonly Dictionary<ReportType, XDocument> _storedReports = new Dictionary<ReportType, XDocument>();
private readonly HashSet<ReportType> _reportsToWrite;
......@@ -16,7 +16,7 @@ namespace TUGraz.VectoCore.OutputData.FileIO
#region Overrides of FileOutputWriter
public string XMLFullReportName => Path.ChangeExtension(BaseWriter.JobFile, "RSLT_MANUFACTURER_PRIMARY.xml");
public override string XMLFullReportName => Path.ChangeExtension(BaseWriter.JobFile, "RSLT_MANUFACTURER_PRIMARY.xml");
#endregion
......@@ -25,7 +25,7 @@ namespace TUGraz.VectoCore.OutputData.FileIO
/// </summary>
/// <param name="jobFile"></param>
/// <param name="reportsToWrite">ReportTypes specified here are written to disk</param>
public TempFileOutputWriter(IOutputDataWriter baseWriter, params ReportType[] reportsToWrite)
public TempFileOutputWriter(IOutputDataWriter baseWriter, params ReportType[] reportsToWrite) : base(baseWriter.JobFile)
{
BaseWriter = baseWriter;
_reportsToWrite = new HashSet<ReportType>();
......@@ -38,33 +38,37 @@ namespace TUGraz.VectoCore.OutputData.FileIO
#region Overrides of FileOutputWriter
public IDictionary<ReportType, string> GetWrittenFiles()
public override IDictionary<ReportType, string> GetWrittenFiles()
{
return BaseWriter.GetWrittenFiles();
return BaseWriter is FileOutputWriter ? base.GetWrittenFiles() : BaseWriter.GetWrittenFiles();
}
public int NumberOfManufacturingStages { get; set; }
//public int NumberOfManufacturingStages { get; set; }
public XDocument MultistageXmlReport { get; }
//public XDocument MultistageXmlReport { get; }
#endregion
#region Overrides of FileOutputWriter
public void WriteReport(ReportType type, XDocument data)
public override void WriteReport(ReportType type, XDocument data)
{
if (type == ReportType.DeclarationReportPdf) {
throw new ArgumentOutOfRangeException("PDF is not supported by TempFileOutputWriter");
}
if (_reportsToWrite.Contains(type)) {
BaseWriter.WriteReport(type, data);
if (BaseWriter is FileOutputWriter) {
base.WriteReport(type, data);
} else {
BaseWriter.WriteReport(type, data);
}
}
_storedReports.Add(type, data);
}
public void WriteReport(ReportType type, Stream data)
public override void WriteReport(ReportType type, Stream data)
{
throw new NotImplementedException("PDF is not supported by TempFileOutputWriter");
}
......@@ -82,7 +86,7 @@ namespace TUGraz.VectoCore.OutputData.FileIO
#region Implementation of IModalDataWriter
public void WriteModData(int jobRunId, string runName, string cycleName, string runSuffix, DataTable modData)
public override void WriteModData(int jobRunId, string runName, string cycleName, string runSuffix, DataTable modData)
{
BaseWriter.WriteModData(jobRunId, runName, cycleName, runSuffix, modData);
}
......@@ -91,7 +95,7 @@ namespace TUGraz.VectoCore.OutputData.FileIO
#region Implementation of ISummaryWriter
public void WriteSumData(DataTable sortedAndFilteredTable)
public override void WriteSumData(DataTable sortedAndFilteredTable)
{
BaseWriter.WriteSumData(sortedAndFilteredTable);
}
......@@ -100,7 +104,7 @@ namespace TUGraz.VectoCore.OutputData.FileIO
#region Implementation of IOutputDataWriter
public string JobFile => BaseWriter.JobFile;
//public string JobFile => BaseWriter.JobFile;
#endregion
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment