From d2b6764aaa1e001f93cdba39aeb56185933a9b9c Mon Sep 17 00:00:00 2001 From: Michael Krisper <michael.krisper@tugraz.at> Date: Fri, 13 Aug 2021 14:43:10 +0200 Subject: [PATCH] JobContainer.AddRuns returns the Runs now directly instead of the IDs only --- VECTO/GUI/MainForm.vb | 5 +++-- .../Utils/StringExtensionMethods.cs | 6 ++++++ .../Models/Simulation/Impl/JobContainer.cs | 12 +++++++----- .../OutputData/ModalDataContainer.cs | 19 ++++++------------- 4 files changed, 22 insertions(+), 20 deletions(-) diff --git a/VECTO/GUI/MainForm.vb b/VECTO/GUI/MainForm.vb index b560e734f5..57b05e87a4 100644 --- a/VECTO/GUI/MainForm.vb +++ b/VECTO/GUI/MainForm.vb @@ -48,6 +48,7 @@ Imports TUGraz.VectoCommon.Resources Imports TUGraz.VectoCommon.Utils Imports TUGraz.VectoCore Imports TUGraz.VectoCore.InputData.FileIO.XML +Imports TUGraz.VectoCore.Models.Simulation Imports TUGraz.VectoCore.Models.SimulationComponent.Data Imports TUGraz.VectoCore.OutputData Imports TUGraz.VectoCore.OutputData.FileIO @@ -1030,8 +1031,8 @@ Imports TUGraz.VectoCore.Utils runsFactory.ActualModalData = cbActVmod.Checked runsFactory.SerializeVectoRunData = cbSaveVectoRunData.Checked - For Each runId As Integer In jobContainer.AddRuns(runsFactory) - fileWriters.Add(runId, fileWriter) + For Each run As IVectoRun In jobContainer.AddRuns(runsFactory) + fileWriters.Add(run.RunIdentifier, fileWriter) Next ' TODO MQ-20200525: Remove the following loop in production (or after evaluation of LAC!! diff --git a/VectoCommon/VectoCommon/Utils/StringExtensionMethods.cs b/VectoCommon/VectoCommon/Utils/StringExtensionMethods.cs index 72c5ebc6e0..fbe60aba54 100644 --- a/VectoCommon/VectoCommon/Utils/StringExtensionMethods.cs +++ b/VectoCommon/VectoCommon/Utils/StringExtensionMethods.cs @@ -39,6 +39,12 @@ namespace TUGraz.VectoCommon.Utils { public static class StringExtensionMethods { + public static string Slice(this string source, int start, int end) { + if (start < 0) start = source.Length + start; + if (end < 0) end = source.Length + end; + return source.Substring(start, end - start); + } + public static double ToDouble(this string self, double? defaultValue = null) { if (string.IsNullOrWhiteSpace(self)) { diff --git a/VectoCore/VectoCore/Models/Simulation/Impl/JobContainer.cs b/VectoCore/VectoCore/Models/Simulation/Impl/JobContainer.cs index 661f32487d..f00c00bae9 100644 --- a/VectoCore/VectoCore/Models/Simulation/Impl/JobContainer.cs +++ b/VectoCore/VectoCore/Models/Simulation/Impl/JobContainer.cs @@ -85,19 +85,21 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl /// Adds the runs from the factory to the job container. /// </summary> /// <returns>A List of Run-Identifiers (unique), int</returns> - public List<int> AddRuns(ISimulatorFactory factory) + public List<IVectoRun> AddRuns(ISimulatorFactory factory) { - var runIDs = new List<int>(); + var createdRuns = new List<IVectoRun>(); factory.SumData = _sumWriter; factory.JobNumber = Interlocked.Increment(ref _jobNumber); foreach (var run in factory.SimulationRuns()) { var entry = new RunEntry { Run = run, JobContainer = this }; - Runs.Add(entry); - runIDs.Add(entry.Run.RunIdentifier); + lock(Runs) + Runs.Add(entry); + createdRuns.Add(entry.Run); } - return runIDs; + + return createdRuns; } /// <summary> diff --git a/VectoCore/VectoCore/OutputData/ModalDataContainer.cs b/VectoCore/VectoCore/OutputData/ModalDataContainer.cs index a45a91b657..3980c3935e 100644 --- a/VectoCore/VectoCore/OutputData/ModalDataContainer.cs +++ b/VectoCore/VectoCore/OutputData/ModalDataContainer.cs @@ -772,21 +772,14 @@ namespace TUGraz.VectoCore.OutputData return dataColumns; } - public IEnumerable<T> GetValues<T>(DataColumn col) - { - return Data.Rows.Cast<DataRow>().Select(x => x.Field<T>(col)); - } + public IEnumerable<T> GetValues<T>(DataColumn col) => + Data.Rows.Cast<DataRow>().Select(x => x.Field<T>(col)); - public IEnumerable<T> GetValues<T>(Func<DataRow, T> selectorFunc) - { - return from DataRow row in Data.Rows select selectorFunc(row); - } + public IEnumerable<T> GetValues<T>(Func<DataRow, T> selectorFunc) => + Data.Rows.Cast<DataRow>().Select(selectorFunc); - public T TimeIntegral<T>(ModalResultField field, Func<SI, bool> filter = null) where T : SIBase<T> - { - - return TimeIntegral<T>(field.GetName(), filter); - } + public T TimeIntegral<T>(ModalResultField field, Func<SI, bool> filter = null) where T : SIBase<T> => + TimeIntegral<T>(field.GetName(), filter); public T TimeIntegral<T>(string field, Func<SI, bool> filter = null) where T : SIBase<T> { -- GitLab