diff --git a/VectoCore/VectoCore/Models/Simulation/Impl/SimulatorFactory.cs b/VectoCore/VectoCore/Models/Simulation/Impl/SimulatorFactory.cs index 4b04ebedfce0c43c1eacc228409081a1aa2ae77a..4d407871a953d06371c48f4ee1b8342130cf1628 100644 --- a/VectoCore/VectoCore/Models/Simulation/Impl/SimulatorFactory.cs +++ b/VectoCore/VectoCore/Models/Simulation/Impl/SimulatorFactory.cs @@ -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; } diff --git a/VectoCore/VectoCore/OutputData/FileIO/TempFileOutputWriter.cs b/VectoCore/VectoCore/OutputData/FileIO/TempFileOutputWriter.cs new file mode 100644 index 0000000000000000000000000000000000000000..5a280d8c7d63458c4a28e5b102b6a7ceda1e5e8b --- /dev/null +++ b/VectoCore/VectoCore/OutputData/FileIO/TempFileOutputWriter.cs @@ -0,0 +1,53 @@ +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