// Copyright (C) Stichting Deltares 2017. All rights reserved.
//
// This file is part of the application DAM - UI.
//
// DAM - UI 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.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
namespace Deltares.Dam.Data
{
public class DamHelperFunctions
{
///
/// Determine a filename based on the different inout parameters
///
/// Name of the location.
/// Name of the scenario.
/// Name of the soil geometry.
/// Index of the iteration.
///
public static string DetermineCalculationFilename(string locationName, string scenarioName,
string soilGeometryName, int iterationIndex)
{
string calculationName;
if (iterationIndex < 0)
{
calculationName = String.Format("Loc({0})_Sce({1})_Pro({2})", locationName, scenarioName,
soilGeometryName);
}
else
{
calculationName = String.Format("Loc({0})_Sce({1})_Pro({2})_Ite({3})", locationName, scenarioName,
soilGeometryName, iterationIndex);
}
return Regex.Replace(calculationName, @"[\\\/:\*\?""'<>|.]", "_");
}
///
/// Convert Date to time stamp as needed by TNO AnySense.
///
/// The date time.
///
public static string DateToTimeStamp(DateTime dateTime)
{
// Following 2 lines is an example how to handle customization of this format.
// TNO at the last moment decided they did not need this change so we change it back to
// the default format
// string customFormat = "yyyy-MM-dd_HH-mm-ss";
// return dateTime.ToString(customFormat);
return dateTime.ToString("s", DateTimeFormatInfo.InvariantInfo);
}
///
/// Determine name of Stability project file
///
internal static string GetProjectFileName(string dikeName, Location location, int? jobCount, MStabModelType? model, string stabilityWorkingPath, DateTime? dateTime)
{
string calculationName = String.Format("Dik({0})_Loc({1})", dikeName, location.Name);
if (jobCount != null)
{
calculationName = calculationName + String.Format("_Stp({0})", jobCount);
}
if (model != null)
{
calculationName = calculationName + String.Format("_Mdl({0})", model);
}
if (dateTime != null)
{
calculationName = calculationName + "_" + DateToTimeStamp(dateTime.Value);
}
calculationName = Regex.Replace(calculationName, @"[\\\/:\*\?""'<>|.]", "_");
// assemble the target project file name
return Path.Combine(stabilityWorkingPath, calculationName + ".sti");
}
///
/// Gets the D-GeoStability executable path.
///
///
/// The m stab executable path.
///
public static string MStabExePath
{
get
{
return Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
@"DGeoStability.exe");
}
}
}
}