private static void validateResults(SimulationResultsImport simulationResultsImport, IndividualResults individualResults)
        {
            var simulationResults = simulationResultsImport.SimulationResults;

            //No entry yet? Set this individual results as base for the import
            if (!simulationResults.Any())
            {
                simulationResults.Time = individualResults.Time;
                individualResults.UpdateQuantityTimeReference();
                return;
            }

            validateTimeResults(simulationResultsImport, individualResults);
            var availableQuantityPaths = simulationResults.AllQuantityPaths();
            var currentQuantityPaths   = individualResults.Select(x => x.QuantityPath).ToList();

            if (availableQuantityPaths.Count != currentQuantityPaths.Count)
            {
                simulationResultsImport.AddError(Error.IndividualResultsDoesNotHaveTheExpectedQuantity(individualResults.IndividualId, availableQuantityPaths, currentQuantityPaths));
                return;
            }

            for (int i = 0; i < availableQuantityPaths.Count; i++)
            {
                if (!string.Equals(availableQuantityPaths[i], currentQuantityPaths[i]))
                {
                    simulationResultsImport.AddError(Error.IndividualResultsDoesNotHaveTheExpectedQuantity(individualResults.IndividualId, availableQuantityPaths, currentQuantityPaths));
                    return;
                }
            }
        }
        private SimulationResultsImport createSimulationResultsFrom(IEnumerable <IndividualResultsImport> importedResults, IModelCoreSimulation simulation)
        {
            var simulationResultsImport = new SimulationResultsImport();

            //First add all available results
            importedResults.Each(import => addIndividualResultsFromSingleFile(simulationResultsImport, import));

            //now check that the defined outputs are actually available in the population simulation
            validateImportedQuantities(simulationResultsImport, simulation);

            return(simulationResultsImport);
        }
        private void addImportedQuantityToLogForSuccessfulImport(SimulationResultsImport simulationResultsImport)
        {
            if (simulationResultsImport.Status.Is(NotificationType.Error))
            {
                return;
            }

            simulationResultsImport.AddInfo(Messages.FollowingOutputsWereSuccessfullyImported(simulationResultsImport.SimulationResults.Count));
            foreach (var quantityPath in simulationResultsImport.SimulationResults.AllQuantityPaths())
            {
                simulationResultsImport.AddInfo(quantityPath);
            }
        }
        private void validateImportedQuantities(SimulationResultsImport simulationResultsImport, IModelCoreSimulation simulation)
        {
            var allQuantities = _quantitiesRetriever.QuantitiesFrom(simulation);

            foreach (var quantityPath in simulationResultsImport.SimulationResults.AllQuantityPaths())
            {
                var quantity = allQuantities[quantityPath];
                if (quantity != null)
                {
                    continue;
                }

                simulationResultsImport.AddError(Error.CouldNotFindQuantityWithPath(quantityPath));
            }
        }
        private void addIndividualResultsFromSingleFile(SimulationResultsImport simulationResultsImport, IndividualResultsImport individualResultsImport)
        {
            var simulationResults = simulationResultsImport.SimulationResults;

            simulationResultsImport.SimulationResultsFiles.Add(individualResultsImport.SimulationResultsFile);

            foreach (var individualResult in individualResultsImport.IndividualResults)
            {
                validateResults(simulationResultsImport, individualResult);

                if (simulationResults.HasResultsFor(individualResult.IndividualId))
                {
                    simulationResultsImport.AddError(Error.DuplicatedIndividualResultsForId(individualResult.IndividualId));
                }
                else
                {
                    simulationResults.Add(individualResult);
                }
            }
        }
        private static void validateTimeResults(SimulationResultsImport simulationResultsImport, IndividualResults individualResults)
        {
            var time           = simulationResultsImport.SimulationResults.Time;
            int expectedLength = time.Values.Length;
            int currentLength  = individualResults.Time.Values.Length;

            if (time.Values.Length != individualResults.Time.Values.Length)
            {
                simulationResultsImport.AddError(Error.TimeArrayLengthDoesNotMatchFirstIndividual(individualResults.IndividualId, expectedLength, currentLength));
                return;
            }

            for (int i = 0; i < currentLength; i++)
            {
                if (!ValueComparer.AreValuesEqual(time[i], individualResults.Time[i]))
                {
                    simulationResultsImport.AddError(Error.TimeArrayValuesDoesNotMatchFirstIndividual(individualResults.IndividualId, i, time[i], individualResults.Time[i]));
                }
            }

            //update reference time to ensure that all results are using the same time
            individualResults.Time = time;
            individualResults.UpdateQuantityTimeReference();
        }