예제 #1
0
        /// <summary>
        /// Creates a new <see cref="MacroStabilityInwardsSoilProfileUnderSurfaceLine"/>.
        /// </summary>
        /// <param name="soilProfile">The soil profile containing layers under the <paramref name="surfaceLine"/>.</param>
        /// <param name="surfaceLine">The surface line which determines the top of the <paramref name="soilProfile"/>.</param>
        /// <returns>A new <see cref="MacroStabilityInwardsSoilProfileUnderSurfaceLine"/> containing geometries from the
        /// <paramref name="soilProfile"/> under the <paramref name="surfaceLine"/>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when any parameter is <c>null</c>.</exception>
        /// <exception cref="NotSupportedException">Thrown when the given <paramref name="soilProfile"/> type
        /// is not supported.</exception>
        public static MacroStabilityInwardsSoilProfileUnderSurfaceLine Create(IMacroStabilityInwardsSoilProfile <IMacroStabilityInwardsSoilLayer> soilProfile,
                                                                              MacroStabilityInwardsSurfaceLine surfaceLine)
        {
            if (soilProfile == null)
            {
                throw new ArgumentNullException(nameof(soilProfile));
            }

            if (surfaceLine == null)
            {
                throw new ArgumentNullException(nameof(surfaceLine));
            }

            var profile1D = soilProfile as MacroStabilityInwardsSoilProfile1D;

            if (profile1D != null)
            {
                return(Create(profile1D, surfaceLine));
            }

            var profile2D = soilProfile as MacroStabilityInwardsSoilProfile2D;

            if (profile2D != null)
            {
                return(Create(profile2D));
            }

            throw new NotSupportedException($"{soilProfile.GetType().Name} is not supported. " +
                                            $"Supported types are: {nameof(MacroStabilityInwardsSoilProfile1D)} " +
                                            $"and {nameof(MacroStabilityInwardsSoilProfile2D)}.");
        }
        /// <summary>
        /// Adds the entity representation of <paramref name="soilProfile"/> to the <paramref name="entity"/>.
        /// </summary>
        /// <param name="soilProfile">The soil profile to store.</param>
        /// <param name="entity">The entity to update.</param>
        /// <param name="registry">The registry to use for persisting entities.</param>
        /// <exception cref="NotSupportedException">Thrown when <paramref name="soilProfile"/> is
        /// not of type <see cref="MacroStabilityInwardsSoilProfile1D"/> or <see cref="MacroStabilityInwardsSoilProfile2D"/>.</exception>
        private static void AddEntityForProfile(IMacroStabilityInwardsSoilProfile <IMacroStabilityInwardsSoilLayer> soilProfile,
                                                MacroStabilityInwardsStochasticSoilProfileEntity entity,
                                                PersistenceRegistry registry)
        {
            var soilProfile1D = soilProfile as MacroStabilityInwardsSoilProfile1D;

            if (soilProfile1D != null)
            {
                entity.MacroStabilityInwardsSoilProfileOneDEntity = soilProfile1D.Create(registry);
                return;
            }

            var soilProfile2D = soilProfile as MacroStabilityInwardsSoilProfile2D;

            if (soilProfile2D != null)
            {
                entity.MacroStabilityInwardsSoilProfileTwoDEntity = soilProfile2D.Create(registry);
                return;
            }

            string exceptionMessage = $"{soilProfile.GetType().Name} is not supported. " +
                                      $"Supported types are: {nameof(MacroStabilityInwardsSoilProfile1D)} and {nameof(MacroStabilityInwardsSoilProfile2D)}.";

            throw new NotSupportedException(exceptionMessage);
        }
        private static bool IsSame(IMacroStabilityInwardsSoilProfile <IMacroStabilityInwardsSoilLayer> soilProfile,
                                   IMacroStabilityInwardsSoilProfile <IMacroStabilityInwardsSoilLayer> otherSoilProfile)
        {
            bool equalNames = soilProfile.Name.Equals(otherSoilProfile.Name);
            bool equalTypes = soilProfile.GetType() == otherSoilProfile.GetType();

            return(equalNames && equalTypes);
        }