// Copyright (C) Stichting Deltares 2016. All rights reserved.
//
// This file is part of Ringtoets.
//
// Ringtoets is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
//
// All names, logos, and references to "Deltares" are registered trademarks of
// Stichting Deltares and remain full property of Stichting Deltares at all times.
// All rights reserved.
using System;
using System.Collections.Generic;
using System.Linq;
using Core.Common.Base;
using Ringtoets.Common.Data;
using Ringtoets.Common.Data.AssessmentSection;
using Ringtoets.HydraRing.Data;
using Ringtoets.Piping.Data;
using Ringtoets.Piping.Forms.Properties;
using Ringtoets.Piping.Primitives;
namespace Ringtoets.Piping.Forms.PresentationObjects
{
///
/// Presentation object representing all required piping knowledge to configure and create
/// piping related objects. It'll delegate observable behavior to the wrapped data object.
///
public abstract class PipingContext : IObservable where T : IObservable
{
///
/// Initializes a new instance of the class.
///
/// The concrete data instance wrapped by this context object.
/// The surface lines available within the piping context.
/// The stochastic soil models available within the piping context.
/// The assessment section which the piping context belongs to.
/// When any input parameter is null.
protected PipingContext(
T wrappedData,
IEnumerable surfaceLines,
IEnumerable stochasticSoilModels,
IAssessmentSection assessmentSection)
{
AssertInputsAreNotNull(wrappedData, surfaceLines, stochasticSoilModels, assessmentSection);
WrappedData = wrappedData;
AvailablePipingSurfaceLines = surfaceLines;
AvailableStochasticSoilModels = stochasticSoilModels;
AssessmentSection = assessmentSection;
}
///
/// Gets the available piping surface lines in order for the user to select one to
/// set .
///
public IEnumerable AvailablePipingSurfaceLines { get; private set; }
///
/// Gets the available stochastic soil models in order for the user to select a and
/// to set and .
///
public IEnumerable AvailableStochasticSoilModels { get; private set; }
///
/// Gets the available hydraulic boundary locations in order for the user to select one to
/// set .
///
public IEnumerable AvailableHydraulicBoundaryLocations
{
get
{
if (AssessmentSection.HydraulicBoundaryDatabase == null)
{
return Enumerable.Empty();
}
return AssessmentSection.HydraulicBoundaryDatabase.Locations;
}
}
///
/// Gets the concrete data instance wrapped by this context object.
///
public T WrappedData { get; private set; }
///
/// Gets the assessment section which the piping context belongs to.
///
public IAssessmentSection AssessmentSection { get; private set; }
public override bool Equals(object obj)
{
var context = obj as PipingContext;
if (context != null)
{
return WrappedData.Equals(context.WrappedData);
}
return base.Equals(obj);
}
public override int GetHashCode()
{
return WrappedData.GetHashCode();
}
///
/// Asserts the inputs are not null.
///
/// The wrapped data.
/// The surface lines.
/// The soil profiles.
/// The assessment section.
/// When any input parameter is null.
private static void AssertInputsAreNotNull(object wrappedData, object surfaceLines, object soilProfiles, object assessmentSection)
{
if (wrappedData == null)
{
var message = String.Format(Resources.PipingContext_AssertInputsAreNotNull_DataDescription_0_cannot_be_null,
Resources.PipingContext_DataDescription_WrappedData);
throw new ArgumentNullException("wrappedData", message);
}
if (surfaceLines == null)
{
var message = String.Format(Resources.PipingContext_AssertInputsAreNotNull_DataDescription_0_cannot_be_null,
Resources.PipingContext_DataDescription_Surfacelines);
throw new ArgumentNullException("surfaceLines", message);
}
if (soilProfiles == null)
{
var message = String.Format(Resources.PipingContext_AssertInputsAreNotNull_DataDescription_0_cannot_be_null,
Resources.PipingContext_DataDescription_Soilprofiles);
throw new ArgumentNullException("soilProfiles", message);
}
if (assessmentSection == null)
{
var message = String.Format(Resources.PipingContext_AssertInputsAreNotNull_DataDescription_0_cannot_be_null,
Resources.PipingContext_DataDescription_AssessmentSection);
throw new ArgumentNullException("assessmentSection", message);
}
}
#region IObservable
public void Attach(IObserver observer)
{
WrappedData.Attach(observer);
}
public void Detach(IObserver observer)
{
WrappedData.Detach(observer);
}
public void NotifyObservers()
{
WrappedData.NotifyObservers();
}
#endregion
}
}