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");
}
}
}
}