// Copyright (C) Stichting Deltares 2018. All rights reserved.
//
// This file is part of the Dam Engine.
//
// The Dam Engine is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero 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 Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero 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.Text;
using Deltares.DamEngine.Calculators.Interfaces;
namespace Deltares.DamEngine.Calculators.Stability
{
///
/// Defines the service agent which is responsible for delegating calls
/// to the MStab calculation kernel or services
///
public class StabilityServiceAgent : IDisposable
{
private readonly DGSMStabDAMInterface mstabDamDll;
public StabilityServiceAgent()
{
mstabDamDll = new DGSMStabDAMInterface();
}
#region Wrapper Methods
///
/// Create Soilprofile for location X in geometry-2d
///
///
///
public void ConvertGeometry2DTo1D(string inputXml, out StringBuilder outputXml)
{
const int defaultBufferSize = 10000;
int bufferSize = defaultBufferSize;
outputXml = new StringBuilder(bufferSize);
int returnCode = mstabDamDll.Geometry2DTo1DConversion(inputXml, outputXml, ref bufferSize);
if (returnCode == DgsStandardDllInterface.DllErrorOutputBufferTooSmall)
{
outputXml = new StringBuilder(bufferSize);
returnCode = mstabDamDll.Geometry2DTo1DConversion(inputXml, outputXml, ref bufferSize);
}
if (returnCode != DgsStandardDllInterface.DllErrorNone)
throw new StabilityServiceAgentException(mstabDamDll.ErrorMessage());
}
#endregion
#region IDispose Members
public void Dispose()
{
Dispose(true);
}
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
// No need to call the finalizer since we've now cleaned
// up the unmanaged memory
GC.SuppressFinalize(this);
}
}
// This finalizer is called when Garbage collection occurs, but only if
// the IDisposable.Dispose method wasn't already called.
~StabilityServiceAgent()
{
Dispose(false);
}
#endregion
}
}