/// <summary> /// Updates the <see cref="MacroStabilityInwardsStochasticSoilProfile"/> with the properties /// from <paramref name="fromProfile"/>. /// </summary> /// <param name="fromProfile">The <see cref="MacroStabilityInwardsStochasticSoilProfile"/> to /// obtain the property values from.</param> /// <exception cref="ArgumentNullException">Thrown when <paramref name="fromProfile"/> /// is <c>null</c>.</exception> /// <returns><c>true</c> if the profile has been updated; <c>false</c> otherwise.</returns> public void Update(MacroStabilityInwardsStochasticSoilProfile fromProfile) { if (fromProfile == null) { throw new ArgumentNullException(nameof(fromProfile)); } SoilProfile = fromProfile.SoilProfile; Probability = fromProfile.Probability; }
/// <summary> /// Updates the <see cref="MacroStabilityInwardsStochasticSoilModel"/> with the properties /// from <paramref name="fromModel"/>. /// </summary> /// <param name="fromModel">The <see cref="MacroStabilityInwardsStochasticSoilModel"/> to /// obtain the property values from.</param> /// <exception cref="ArgumentNullException">Thrown when <paramref name="fromModel"/> /// is <c>null</c>.</exception> /// <exception cref="InvalidOperationException">Thrown when <see cref="StochasticSoilProfiles"/> /// contains multiple profiles with the same name, and <paramref name="fromModel"/> also contains a /// profile with the same name. /// </exception> public MacroStabilityInwardsStochasticSoilModelProfileDifference Update(MacroStabilityInwardsStochasticSoilModel fromModel) { if (fromModel == null) { throw new ArgumentNullException(nameof(fromModel)); } Name = fromModel.Name; Geometry = fromModel.Geometry; var newSoilProfiles = new List <IMacroStabilityInwardsSoilProfile <IMacroStabilityInwardsSoilLayer> >(); var updatedProfiles = new List <MacroStabilityInwardsStochasticSoilProfile>(); var addedProfiles = new List <MacroStabilityInwardsStochasticSoilProfile>(); var removedProfiles = new List <MacroStabilityInwardsStochasticSoilProfile>(); foreach (MacroStabilityInwardsStochasticSoilProfile fromProfile in fromModel.StochasticSoilProfiles) { MacroStabilityInwardsStochasticSoilProfile sameProfile = StochasticSoilProfiles.SingleOrDefault( sp => IsSame(sp, fromProfile) ); if (sameProfile != null) { if (!sameProfile.Equals(fromProfile)) { sameProfile.Update(fromProfile); updatedProfiles.Add(sameProfile); } } else { stochasticSoilProfiles.Add(fromProfile); addedProfiles.Add(fromProfile); } newSoilProfiles.Add(fromProfile.SoilProfile); } foreach (MacroStabilityInwardsStochasticSoilProfile profileToRemove in StochasticSoilProfiles.Where( sp => !newSoilProfiles.Any(newSp => IsSame(newSp, sp.SoilProfile))).ToArray()) { stochasticSoilProfiles.Remove(profileToRemove); removedProfiles.Add(profileToRemove); } return(new MacroStabilityInwardsStochasticSoilModelProfileDifference(addedProfiles, updatedProfiles, removedProfiles)); }
private static bool IsSame(MacroStabilityInwardsStochasticSoilProfile stochasticSoilProfile, MacroStabilityInwardsStochasticSoilProfile otherStochasticSoilProfile) { return(IsSame(stochasticSoilProfile.SoilProfile, otherStochasticSoilProfile.SoilProfile)); }
private bool Equals(MacroStabilityInwardsStochasticSoilProfile other) { return(Probability.Equals(other.Probability) && Equals(SoilProfile, other.SoilProfile)); }