/// <inheritdoc />
        /// <remarks>
        /// To avoid problems with writing to an existing file, the export is done to a temp file first.
        /// When the export was successful the file is moved to the given <see cref="filePath"/>.
        /// </remarks>
        public bool Export()
        {
            ValidateData();

            PersistableDataModel persistableDataModel = PersistableDataModelFactory.Create(calculation, generalInput, getNormativeAssessmentLevelFunc, filePath);

            string tempFilePath = $"{filePath}.temp";

            try
            {
                using (IPersister persister = persistenceFactory.CreateArchivePersister(tempFilePath, persistableDataModel))
                {
                    persister.Persist();
                }

                MoveTempFileToFinal(tempFilePath);
            }
            catch (Exception)
            {
                File.Delete(tempFilePath);

                log.ErrorFormat("{0} {1}", string.Format(CoreCommonUtilResources.Error_General_output_error_0, filePath), Resources.MacroStabilityInwardsCalculationExporter_Export_no_stability_project_exported);
                return(false);
            }

            return(true);
        }
示例#2
0
        public void Create_WithValidData_ReturnsPersistableDataModel()
        {
            // Setup
            const string filePath = "ValidFilePath";
            MacroStabilityInwardsCalculationScenario calculation = MacroStabilityInwardsCalculationScenarioTestFactory.CreateMacroStabilityInwardsCalculationScenarioWithValidInput(new TestHydraulicBoundaryLocation());

            calculation.Output = MacroStabilityInwardsOutputTestFactory.CreateRandomOutput();

            using (new MacroStabilityInwardsCalculatorFactoryConfig())
            {
                // Call
                PersistableDataModel persistableDataModel = PersistableDataModelFactory.Create(calculation, new GeneralMacroStabilityInwardsInput(), AssessmentSectionTestHelper.GetTestAssessmentLevel, filePath);

                // Assert
                PersistableDataModelTestHelper.AssertPersistableDataModel(calculation, filePath, persistableDataModel);
            }
        }
示例#3
0
        public IPersister CreateArchivePersister(string path, PersistableDataModel dataModel)
        {
            if (ThrowException)
            {
                throw new Exception("Exception in persister.");
            }

            FilePath             = path;
            PersistableDataModel = dataModel;

            if (WriteFile)
            {
                FileStream stream = File.OpenWrite(FilePath);
                stream.Close();
            }

            return(CreatedPersister ?? (CreatedPersister = new MacroStabilityInwardsTestPersister()));
        }
        /// <summary>
        /// Asserts whether the <see cref="PersistableDataModel"/> contains the data
        /// that is representative for the <paramref name="calculation"/>
        /// and the <paramref name="filePath"/>.
        /// </summary>
        /// <param name="calculation">The calculation that contains the original data.</param>
        /// <param name="filePath">The file path that is used.</param>
        /// <param name="persistableDataModel">The <see cref="PersistableDataModel"/> that needs to be asserted.</param>
        /// <exception cref="AssertionException">Thrown when the data in <paramref name="persistableDataModel"/>
        /// is not correct.</exception>
        public static void AssertPersistableDataModel(MacroStabilityInwardsCalculation calculation, string filePath, PersistableDataModel persistableDataModel)
        {
            AssertProjectInfo(calculation, filePath, persistableDataModel.Info);
            AssertCalculationSettings(calculation.Output.SlidingCurve, persistableDataModel.CalculationSettings);

            IEnumerable <MacroStabilityInwardsSoilLayer2D> layers = MacroStabilityInwardsSoilProfile2DLayersHelper.GetLayersRecursively(calculation.InputParameters.SoilProfileUnderSurfaceLine.Layers);

            AssertPersistableSoils(layers, persistableDataModel.Soils.Soils);
            AssertPersistableGeometry(layers, persistableDataModel.Geometry);
            AssertPersistableSoilLayers(layers, persistableDataModel.SoilLayers, persistableDataModel.Soils.Soils, persistableDataModel.Geometry);
            AssertWaternets(new[]
            {
                DerivedMacroStabilityInwardsInput.GetWaternetDaily(calculation.InputParameters, new GeneralMacroStabilityInwardsInput()),
                DerivedMacroStabilityInwardsInput.GetWaternetExtreme(calculation.InputParameters, new GeneralMacroStabilityInwardsInput(), RoundedDouble.NaN)
            }, persistableDataModel.Waternets);
            AssertWaternetCreatorSettings(calculation.InputParameters, persistableDataModel.WaternetCreatorSettings, AssessmentSectionTestHelper.GetTestAssessmentLevel(), new[]
            {
                MacroStabilityInwardsExportStageType.Daily,
                MacroStabilityInwardsExportStageType.Extreme
            });
            AssertStates(calculation.InputParameters.SoilProfileUnderSurfaceLine, persistableDataModel.States);

            Assert.IsNull(persistableDataModel.AssessmentResults);
            Assert.IsNull(persistableDataModel.Decorations);
            Assert.IsNull(persistableDataModel.Loads);
            Assert.IsNull(persistableDataModel.NailPropertiesForSoils);
            Assert.IsNull(persistableDataModel.Reinforcements);
            Assert.IsNull(persistableDataModel.SoilCorrelations);
            Assert.IsNull(persistableDataModel.SoilVisualizations);
            Assert.IsNull(persistableDataModel.StateCorrelations);

            AssertStages(persistableDataModel.Stages, persistableDataModel.CalculationSettings, persistableDataModel.Geometry, persistableDataModel.SoilLayers,
                         persistableDataModel.Waternets, persistableDataModel.WaternetCreatorSettings, persistableDataModel.States);
        }