using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using CommandLine;
using Deltares.Dam.Data;
using Deltares.Dam.Tests;
using Deltares.Standard;
using Deltares.Standard.EventPublisher;
namespace Deltares.Dam.KernelComparisonRunner
{
///
///
///
internal class Program
{
///
/// Main method
///
/// The arguments.
static void Main(string[] args)
{
var commandLineArguments = new CommandOptions();
ICommandLineParser parser = new CommandLineParser();
bool success = parser.ParseArguments(args, commandLineArguments);
if (success)
{
var program = new Program();
program.StartCalculations(
commandLineArguments.DamXFileName,
commandLineArguments.KernelSpecificationFileName,
commandLineArguments.LocationsFileName,
commandLineArguments.OutputPath);
}
else
{
Console.WriteLine();
Console.WriteLine(commandLineArguments.GetUsage());
}
}
///
/// Starts the calculations.
///
/// The damx filename.
/// The kernel specification filename.
/// The locations filename.
/// The output path.
private void StartCalculations(string damxFilename, string kernelSpecificationFilename, string locationsFilename, string outputPath)
{
List kernelsToCalculate = ReadKernels(kernelSpecificationFilename);
List locationsList = ReadLocations(locationsFilename);
TextWriter textWriter = CreateTextWriter(outputPath);
ComparisonTestRunner runner = new ComparisonTestRunner();
ComparisonTestRunner.Tolerances = new DamIntegrationTestTolerance();
ComparisonTestRunner.PropertiesToCheck = new[] { "SafetyFactor", "Zone1EntryPointX", "Zone1EntryPointZ", "Zone1ExitPointX", "Zone1ExitPointZ" };
ComparisonTestRunner.DamWtiTestReportsDir = outputPath;
try
{
DataEventPublisher.InvokeWithoutPublishingEvents(() =>
{
List testMessagesNotOk = runner.RunStabilityComparisonTest(damxFilename, locationsList,kernelsToCalculate, textWriter);
});
}
finally
{
textWriter.Flush();
textWriter.Dispose();
}
}
///
/// Reads the kernels.
///
/// The kernel specification filename.
///
private List ReadKernels(string kernelSpecificationFilename)
{
if (String.IsNullOrEmpty(kernelSpecificationFilename))
{
return new List()
{
StabilityKernelType.DamClassic,
StabilityKernelType.DamClassicWti
};
}
else
{
var lines = File.ReadAllLines(kernelSpecificationFilename);
var stabilityKernels = new List();
foreach (string line in lines)
{
StabilityKernelType type = (StabilityKernelType)Enum.Parse(typeof(StabilityKernelType), line);
stabilityKernels.Add(type);
}
return stabilityKernels;
}
}
///
/// Reads the locations.
///
/// The locations filename.
///
private List ReadLocations(string locationsFilename)
{
if (String.IsNullOrEmpty(locationsFilename))
{
return null;
}
else
{
return File.ReadAllLines(locationsFilename).ToList();
}
}
///
/// Creates the text writer.
///
/// The output path.
///
private TextWriter CreateTextWriter(string outputPath)
{
string wtiDamComparisonTxTFullPath = Path.Combine(outputPath, "comparison.txt");
if (!Directory.Exists(outputPath))
{
Directory.CreateDirectory(outputPath);
}
if (File.Exists(wtiDamComparisonTxTFullPath))
{
File.Delete(wtiDamComparisonTxTFullPath);
}
var textWriter = new StreamWriter(wtiDamComparisonTxTFullPath, true);
return textWriter;
}
}
}