// Copyright (C) Stichting Deltares 2020. 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.Runtime.InteropServices;
using System.Text;
namespace Deltares.LayerOnSlopeTool.StiFileCreator
{
public class DGSMStabDAMInterface : DgsStandardDllInterface
{
private const string DllFileName = @"DGSMStabDAM.dll";
[DllImport(DllFileName)]
static extern int GetDamLicenseType();
[DllImport(DllFileName)]
static extern int GetDamLiveLicenseType();
[DllImport(DllFileName)]
static extern int DllGetVersion(out DllVersionInfoStructure dllVersionInfoStructure);
[DllImport(DllFileName)]
static extern string GetDescription(StringBuilder errorMessage, ref int bufferSize);
[DllImport(DllFileName)]
static extern int GetErrorMessage(StringBuilder errorMessage, ref int bufferSize);
[DllImport(DllFileName)]
static extern int CreateMStabProject(string inputXmlString);
[DllImport(DllFileName)]
static extern int ConvertGeometry2DTo1D(string inputXML, StringBuilder outputXML, ref int bufferSize);
[DllImport(DllFileName)]
static extern int CreateGeometry2DData(string inputXML, StringBuilder outputXML, ref int bufferSize);
///
/// Gets DllVersion
///
/// version as string
public new string GetDllVersion()
{
DllVersionInfoStructure dllInfo;
DllGetVersion(out dllInfo);
return dllInfo.DwBuildNumber.ToString();
}
///
/// Create ProjectFile for MStab
///
/// Error number
public int CreateProjectFile(string inputXmlString)
{
return (CreateMStabProject(inputXmlString));
}
///
/// returns ErrorMessage
///
/// Error as string
public new string ErrorMessage()
{
const int maxErrorMessageLength = 50;
int errorMessageLength = maxErrorMessageLength;
var errorMessage = new StringBuilder(maxErrorMessageLength);
int returnCode = GetErrorMessage(errorMessage, ref errorMessageLength);
if (returnCode == DllErrorOutputBufferTooSmall)
{
errorMessage = new StringBuilder(errorMessageLength);
returnCode = GetErrorMessage(errorMessage, ref errorMessageLength);
}
if (returnCode == DllErrorNone)
{
return errorMessage.ToString();
}
else
{
return "Unknow error";
}
}
/// converts 2D geometry to 1D
///
///
///
/// Error as integer
public int Geometry2DTo1DConversion(string inputXml, StringBuilder outputXml, ref int bufferSize)
{
return (ConvertGeometry2DTo1D(inputXml, outputXml, ref bufferSize));
}
/// Creates the geometry2 d data from geometry2 d.
/// The input XML.
/// The output XML.
/// Size of the buffer.
///
public int CreateGeometry2DDataFromGeometry2D(string inputXml, StringBuilder outputXml, ref int bufferSize)
{
return (CreateGeometry2DData(inputXml, outputXml, ref bufferSize));
}
}
}