/// <summary> /// Tries to assign the number of vertical points to the <paramref name="grid"/>. /// </summary> /// <param name="gridConfiguration">The grid configuration read from the imported file.</param> /// <param name="grid">The calculation grid to configure.</param> /// <param name="calculationName">The name of the read calculation.</param> /// <returns><c>true</c> if no number of vertical points was given, or when number of /// vertical points is set to the <paramref name="grid"/>, <c>false</c> otherwise.</returns> private bool TrySetNumberOfVerticalPoints(MacroStabilityInwardsGridConfiguration gridConfiguration, MacroStabilityInwardsGrid grid, string calculationName) { if (!gridConfiguration.NumberOfVerticalPoints.HasValue) { return(true); } int numberOfVerticalPoints = gridConfiguration.NumberOfVerticalPoints.Value; try { grid.NumberOfVerticalPoints = numberOfVerticalPoints; } catch (ArgumentOutOfRangeException e) { Log.LogOutOfRangeException(string.Format(Resources.MacroStabilityInwardsCalculationConfigurationImporter_TrySetNumberOfVerticalPoints_NumberOfVerticalPoints_0_invalid, numberOfVerticalPoints), calculationName, e); return(false); } return(true); }
/// <summary> /// Tries to assign the read grid to the <paramref name="grid"/>. /// </summary> /// <param name="gridConfiguration">The grid configuration read from the imported file.</param> /// <param name="grid">The grid to configure.</param> /// <param name="calculationName">The name of the read calculation.</param> /// <returns><c>true</c> if no grid configuration where given, or set to the <paramref name="grid"/> /// , <c>false</c> otherwise.</returns> private bool TrySetGrid(MacroStabilityInwardsGridConfiguration gridConfiguration, MacroStabilityInwardsGrid grid, string calculationName) { if (gridConfiguration == null) { return(true); } return(TrySetGridZTopZBottom(gridConfiguration, grid, calculationName) && TrySetGridXLeftXRight(gridConfiguration, grid, calculationName) && TrySetNumberOfHorizontalPoints(gridConfiguration, grid, calculationName) && TrySetNumberOfVerticalPoints(gridConfiguration, grid, calculationName)); }
/// <summary> /// Writes a grid configuration in XML format to file when <paramref name="configuration"/> has a value. /// </summary> /// <param name="writer">The writer to use for writing.</param> /// <param name="gridLocationName">The name of the location of the grid.</param> /// <param name="configuration">The configuration for the grid that can be <c>null</c>.</param> /// <exception cref="InvalidOperationException">Thrown when the <paramref name="writer"/> /// is closed.</exception> private static void WriteGridConfigurationWhenAvailable(XmlWriter writer, string gridLocationName, MacroStabilityInwardsGridConfiguration configuration) { if (configuration == null) { return; } writer.WriteStartElement(gridLocationName); if (configuration.XLeft.HasValue) { writer.WriteElementString(MacroStabilityInwardsCalculationConfigurationSchemaIdentifiers.GridXLeftElement, XmlConvert.ToString(configuration.XLeft.Value)); } if (configuration.XRight.HasValue) { writer.WriteElementString(MacroStabilityInwardsCalculationConfigurationSchemaIdentifiers.GridXRightElement, XmlConvert.ToString(configuration.XRight.Value)); } if (configuration.ZTop.HasValue) { writer.WriteElementString(MacroStabilityInwardsCalculationConfigurationSchemaIdentifiers.GridZTopElement, XmlConvert.ToString(configuration.ZTop.Value)); } if (configuration.ZBottom.HasValue) { writer.WriteElementString(MacroStabilityInwardsCalculationConfigurationSchemaIdentifiers.GridZBottomElement, XmlConvert.ToString(configuration.ZBottom.Value)); } if (configuration.NumberOfVerticalPoints.HasValue) { writer.WriteElementString(MacroStabilityInwardsCalculationConfigurationSchemaIdentifiers.GridNumberOfVerticalPointsElement, XmlConvert.ToString(configuration.NumberOfVerticalPoints.Value)); } if (configuration.NumberOfHorizontalPoints.HasValue) { writer.WriteElementString(MacroStabilityInwardsCalculationConfigurationSchemaIdentifiers.GridNumberOfHorizontalPointsElement, XmlConvert.ToString(configuration.NumberOfHorizontalPoints.Value)); } writer.WriteEndElement(); }
/// <summary> /// Tries to assign the grid x left and x right parameters to the <paramref name="grid"/>. /// </summary> /// <param name="gridConfiguration">The grid configuration read from the imported file.</param> /// <param name="grid">The calculation grid to configure.</param> /// <param name="calculationName">The name of the read calculation.</param> /// <returns><c>true</c> if no x left and x right was given, or when x left and x right /// are set to the <paramref name="grid"/>, <c>false</c> otherwise.</returns> private bool TrySetGridXLeftXRight(MacroStabilityInwardsGridConfiguration gridConfiguration, MacroStabilityInwardsGrid grid, string calculationName) { bool hasXLeftValue = gridConfiguration.XLeft.HasValue; bool hasXRightValue = gridConfiguration.XRight.HasValue; if (!hasXLeftValue && !hasXRightValue) { return(true); } RoundedDouble xLeft = hasXLeftValue ? (RoundedDouble)gridConfiguration.XLeft.Value : RoundedDouble.NaN; RoundedDouble xRight = hasXRightValue ? (RoundedDouble)gridConfiguration.XRight.Value : RoundedDouble.NaN; try { grid.XLeft = xLeft; grid.XRight = xRight; } catch (ArgumentException e) { Log.LogCalculationConversionError(string.Format(Resources.MacroStabilityInwardsCalculationConfigurationImporter_TrySetGridXLeftXRight_Combination_of_XLeft_0_and_XRight_1_invalid_Reason_2, xLeft.ToPrecision(grid.XLeft.NumberOfDecimalPlaces), xRight.ToPrecision(grid.XRight.NumberOfDecimalPlaces), e.Message), calculationName); return(false); } return(true); }
/// <summary> /// Tries to assign the grid Z top and Z bottom parameters to the <paramref name="grid"/>. /// </summary> /// <param name="gridConfiguration">The grid configuration read from the imported file.</param> /// <param name="grid">The calculation grid to configure.</param> /// <param name="calculationName">The name of the read calculation.</param> /// <returns><c>true</c> if no z top and z bottom was given, or when z top and z bottom /// are set to the <paramref name="grid"/>, <c>false</c> otherwise.</returns> private bool TrySetGridZTopZBottom(MacroStabilityInwardsGridConfiguration gridConfiguration, MacroStabilityInwardsGrid grid, string calculationName) { bool hasZTopValue = gridConfiguration.ZTop.HasValue; bool hasZBottomValue = gridConfiguration.ZBottom.HasValue; if (!hasZTopValue && !hasZBottomValue) { return(true); } RoundedDouble zTop = hasZTopValue ? (RoundedDouble)gridConfiguration.ZTop.Value : RoundedDouble.NaN; RoundedDouble zBottom = hasZBottomValue ? (RoundedDouble)gridConfiguration.ZBottom.Value : RoundedDouble.NaN; try { grid.ZTop = zTop; grid.ZBottom = zBottom; } catch (ArgumentException e) { Log.LogCalculationConversionError(string.Format(Resources.MacroStabilityInwardsCalculationConfigurationImporter_TrySetGridZTopZBottom_Combination_of_ZTop_0_and_ZBottom_1_invalid_Reason_2, zTop.ToPrecision(grid.ZTop.NumberOfDecimalPlaces), zBottom.ToPrecision(grid.ZBottom.NumberOfDecimalPlaces), e.Message), calculationName); return(false); } return(true); }