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

Skip to content
Snippets Groups Projects
Commit f7b8152c authored by Harald MARTINI's avatar Harald MARTINI
Browse files

Added TempFileOutputWriter, using TempFileOutputWriter for first simulation...

Added TempFileOutputWriter, using TempFileOutputWriter for first simulation step when simulating an Primary + Stage Input job
parent 34820ab6
No related branches found
No related tags found
No related merge requests found
......@@ -225,11 +225,20 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl
{
System.Diagnostics.Debug.Assert(multiStagePrimaryAndStageInputData.PrimaryVehicle.JobInputData.Vehicle.VehicleCategory == VehicleCategory.HeavyBusPrimaryVehicle);
//var msOutputWriter = new MemoryStreamOutputWriter();
var tempOutputWriter = new TempFileOutputWriter(ReportWriter.JobFile);
var originalReportWriter = ReportWriter;
ReportWriter = tempOutputWriter;
var tempPrimaryReport = new XMLDeclarationReportPrimaryVehicle(tempOutputWriter, true);
DataReader = new DeclarationModePrimaryBusVectoRunDataFactory(multiStagePrimaryAndStageInputData.PrimaryVehicle, tempPrimaryReport);
var reportPrimary = declarationReport ??
new XMLDeclarationReportPrimaryVehicle(ReportWriter,
true);
DataReader = new DeclarationModePrimaryBusVectoRunDataFactory(multiStagePrimaryAndStageInputData.PrimaryVehicle, reportPrimary);
CreateFollowUpSimulatorFactory = true;
_followingSimulatorFactoryCreator = (() => {
......@@ -237,22 +246,30 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl
var container = new StandardKernel(
new VectoNinjectModule()
);
var inputDataReader = container.Get<IXMLInputDataReader>();
var primaryInputData = inputDataReader.CreateDeclaration(((FileOutputWriter)ReportWriter).XMLPrimaryVehicleReportName);
var vifInputData = new XMLDeclarationVIFInputData(primaryInputData as IMultistageBusInputDataProvider,
multiStagePrimaryAndStageInputData.StageInputData);
var manStagesCount = vifInputData.MultistageJobInputData.JobInputData.ManufacturingStages?.Count ?? 0;
(ReportWriter as FileOutputWriter).NumberOfManufacturingStages = manStagesCount;
//TODO add manufacturing stages to ReportWriter
var factory = new SimulatorFactory(_mode,
vifInputData, ReportWriter,
declarationReport,
vtpReport,
Validate) {
CreateFollowUpSimulatorFactory = true,
};
return factory;
try {
var inputDataReader = container.Get<IXMLInputDataReader>();
var primaryInputData = inputDataReader.CreateDeclaration(tempOutputWriter
.GetDocument(ReportType.DeclarationReportPrimaryVehicleXML).CreateReader());
//var primaryInputData = inputDataReader.CreateDeclaration(((FileOutputWriter)ReportWriter).XMLPrimaryVehicleReportName);
var vifInputData = new XMLDeclarationVIFInputData(
primaryInputData as IMultistageBusInputDataProvider,
multiStagePrimaryAndStageInputData.StageInputData);
var manStagesCount =
vifInputData.MultistageJobInputData.JobInputData.ManufacturingStages?.Count ?? 0;
(ReportWriter as FileOutputWriter).NumberOfManufacturingStages = manStagesCount;
var factory = new SimulatorFactory(_mode,
vifInputData, originalReportWriter,
null,
vtpReport,
Validate) {
CreateFollowUpSimulatorFactory = true,
};
return factory;
} catch (Exception ex) {
Log.Error($"Failed to create additional Simulation run: {ex.Message}");
return null;
}
});
return;
}
......
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Xml.Linq;
using TUGraz.VectoCommon.Models;
namespace TUGraz.VectoCore.OutputData.FileIO
{
public class TempFileOutputWriter : FileOutputWriter, IOutputDataWriter
{
private Dictionary<ReportType, XDocument> _writtenReports = new Dictionary<ReportType, XDocument>();
public TempFileOutputWriter(string jobFile) : base(jobFile)
{
}
protected TempFileOutputWriter(string jobFile, int numberOfManufacturingStages) : base(jobFile,
numberOfManufacturingStages)
{
}
#region Overrides of FileOutputWriter
public override void WriteReport(ReportType type, XDocument data)
{
if (type == ReportType.DeclarationReportPdf) {
throw new ArgumentOutOfRangeException("PDF is not supported by TempFileOutputWriter");
}
_writtenReports.Add(type, data);
}
public override void WriteReport(ReportType type, Stream data)
{
throw new NotImplementedException("PDF is not supported by TempFileOutputWriter");
}
#endregion
public XDocument GetDocument(ReportType type)
{
var docStored = _writtenReports.TryGetValue(type, out var report);
if (!docStored) {
Log.Warn($"No Document with type {type} stored");
}
return report;
}
}
}
\ No newline at end of file
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