/// <summary> /// Updates the <see cref="PipingStochasticSoilProfile"/> with the properties /// from <paramref name="fromProfile"/>. /// </summary> /// <param name="fromProfile">The <see cref="PipingStochasticSoilProfile"/> to /// obtain the property values from.</param> /// <exception cref="ArgumentNullException">Thrown when <paramref name="fromProfile"/> /// is <c>null</c>.</exception> public void Update(PipingStochasticSoilProfile fromProfile) { if (fromProfile == null) { throw new ArgumentNullException(nameof(fromProfile)); } SoilProfile = fromProfile.SoilProfile; Probability = fromProfile.Probability; }
/// <summary> /// Updates the <see cref="PipingStochasticSoilModel"/> with the properties from <paramref name="fromModel"/>. /// </summary> /// <param name="fromModel">The <see cref="PipingStochasticSoilModel"/> to /// obtain the property values from.</param> /// <returns>The differences summed up in an instance of <see cref="PipingStochasticSoilModelProfileDifference"/>.</returns> /// <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 PipingStochasticSoilModelProfileDifference Update(PipingStochasticSoilModel fromModel) { if (fromModel == null) { throw new ArgumentNullException(nameof(fromModel)); } Name = fromModel.Name; Geometry = fromModel.Geometry; var newSoilProfiles = new List <PipingSoilProfile>(); var updatedProfiles = new List <PipingStochasticSoilProfile>(); var addedProfiles = new List <PipingStochasticSoilProfile>(); var removedProfiles = new List <PipingStochasticSoilProfile>(); foreach (PipingStochasticSoilProfile fromProfile in fromModel.StochasticSoilProfiles) { PipingStochasticSoilProfile 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); } PipingStochasticSoilProfile[] remainingProfiles = StochasticSoilProfiles.Where( sp => !newSoilProfiles.Any(newSp => IsSame(newSp, sp.SoilProfile))).ToArray(); foreach (PipingStochasticSoilProfile profileToRemove in remainingProfiles) { stochasticSoilProfiles.Remove(profileToRemove); removedProfiles.Add(profileToRemove); } return(new PipingStochasticSoilModelProfileDifference(addedProfiles, updatedProfiles, removedProfiles)); }
private bool Equals(PipingStochasticSoilProfile other) { return(Probability.Equals(other.Probability) && Equals(SoilProfile, other.SoilProfile)); }
private static bool IsSame(PipingStochasticSoilProfile stochasticSoilProfile, PipingStochasticSoilProfile otherStochasticSoilProfile) { return(IsSame(stochasticSoilProfile.SoilProfile, otherStochasticSoilProfile.SoilProfile)); }