263 lines
10 KiB
C#
263 lines
10 KiB
C#
using System.Collections.Generic;
|
|
using System.Text;
|
|
using DTS.Common.Utilities.Logging;
|
|
|
|
namespace DTS.Common.ISO
|
|
{
|
|
public abstract class TestTypesFile
|
|
{
|
|
private static readonly string[] DefaultTestTypes = {
|
|
"Bumper Test",
|
|
"Car to Car",
|
|
"Euro NCAP Oblique Pole Impact",
|
|
"FMVSS 280 50K MAMA 2B",
|
|
"Frontal",
|
|
"Frontal Offset",
|
|
"Frontal Perpendicular",
|
|
"Full Width Frontal Impact 50km/h",
|
|
"GROUP RATING 40% OFFSET",
|
|
"Hybrid III 5th percentile female dummy",
|
|
"Interior Head Impact",
|
|
"Low Speed Repairability",
|
|
"Pedestrian",
|
|
"Pedestrian Protection",
|
|
"Pole Side Impact",
|
|
"Rear Impact",
|
|
"Side",
|
|
"Seat Test",
|
|
"Side Impact",
|
|
"Static Roof Crush",
|
|
"Static Side Door Strength",
|
|
"Steering System",
|
|
"Whiplash",
|
|
};
|
|
private const string TEST_TYPES_KEY = "#test types#";
|
|
private const string SUB_TYPES_KEY = "#test subtypes#";
|
|
private static readonly string[] DEFAULT_SUBTYPES = {
|
|
"NOVALUE",
|
|
"ODB",
|
|
"FW",
|
|
"MDB",
|
|
"Pole",
|
|
"Low",
|
|
"Medium",
|
|
"High",
|
|
"Headform",
|
|
"Upper Legform",
|
|
"Lower Legform",
|
|
"Barrier Test",
|
|
"Pendulum Test",
|
|
"Centerline Europe",
|
|
"Centerline NA",
|
|
"Impact",
|
|
"Oblique pole 32km/h",
|
|
"FMVSS 280 50K MAMA 2B",
|
|
"30 Deg. ECE 94",
|
|
"30 Deg. FMVSS LHS",
|
|
"30 Deg. FMVSS RHS",
|
|
"50km/h",
|
|
"64km/h",
|
|
"Def. Barrier",
|
|
"Rigid Barrier",
|
|
"30mph Belted",
|
|
"30mph Chassis",
|
|
"30mph Unbelted",
|
|
"35mph Belted",
|
|
"35mph Belted NA",
|
|
"ECE 12",
|
|
"FMVSS 204",
|
|
"50km/h",
|
|
"FRONT",
|
|
"REAR",
|
|
"Hybrid III 5th percentile female dummy",
|
|
"FMVSS 201",
|
|
"Frontal Offset",
|
|
"Rear Offset",
|
|
"Headform to Hoodtop",
|
|
"Lower Leg to Bumper",
|
|
"Thigh to Hood Leading Edge",
|
|
"Euro NCAP 29 Km/h",
|
|
"35mph Europe",
|
|
"35mph NA",
|
|
"ECE 32",
|
|
"FMVSS 301",
|
|
"Anchorage Test",
|
|
"Seat Back Torque Test",
|
|
"Static Seat Belt Anchorage Test",
|
|
"38mph",
|
|
"AEMDB 50KM/H",
|
|
"EEVC Step 1",
|
|
"EEVC Step 2",
|
|
"EEVC Step 2 - 2EUSID",
|
|
"Euro NCAP 50 Km/h",
|
|
"FMVSS 214",
|
|
"FMVSS 301",
|
|
"FMVSS 216",
|
|
"Default",
|
|
"Impact-Headform",
|
|
"Impact-Torso",
|
|
"Linear Guided Sled",
|
|
"Euro Ncap/ SRA 24km/h",
|
|
"Euro Ncap/IIWPG 16 km/h",
|
|
"Euro Ncap/SRA 16 km/h",
|
|
"L6e",
|
|
"L7e"
|
|
};
|
|
|
|
private static readonly object FILE_LOCK = new object();
|
|
|
|
private const string FILENAME = @"ISOTypesAndSubTypes.txt";
|
|
public static string[] GetTestTypes()
|
|
{
|
|
var types = new List<string>();
|
|
lock (FILE_LOCK)
|
|
{
|
|
try
|
|
{
|
|
if (!System.IO.File.Exists(FILENAME))
|
|
{
|
|
CreateFile();
|
|
}
|
|
var lines = System.IO.File.ReadAllLines(FILENAME, Encoding.UTF8);
|
|
var bHaveSeenStart = false;
|
|
foreach (var line in lines)
|
|
{
|
|
var sTrimAndLower = line.Trim().ToLower();
|
|
switch (sTrimAndLower)
|
|
{
|
|
case TEST_TYPES_KEY: bHaveSeenStart = true; break;
|
|
case SUB_TYPES_KEY: bHaveSeenStart = false; break;
|
|
default:
|
|
if (bHaveSeenStart)
|
|
{
|
|
if (line.StartsWith("#")) { continue; }
|
|
types.Add(line);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (System.Exception ex)
|
|
{
|
|
APILogger.Log(ex);
|
|
return DefaultTestTypes;
|
|
}
|
|
}
|
|
return types.ToArray();
|
|
}
|
|
public static string[] GetTestSubtypes()
|
|
{
|
|
var subtypes = new List<string>();
|
|
lock (FILE_LOCK)
|
|
{
|
|
try
|
|
{
|
|
if (!System.IO.File.Exists(FILENAME))
|
|
{
|
|
CreateFile();
|
|
}
|
|
var lines = System.IO.File.ReadAllLines(FILENAME, Encoding.UTF8);
|
|
var bHaveSeenStart = false;
|
|
foreach (var line in lines)
|
|
{
|
|
var sTrimAndLower = line.Trim().ToLower();
|
|
switch (sTrimAndLower)
|
|
{
|
|
case TEST_TYPES_KEY: bHaveSeenStart = false; break;
|
|
case SUB_TYPES_KEY: bHaveSeenStart = true; break;
|
|
default:
|
|
if (bHaveSeenStart)
|
|
{
|
|
if (line.StartsWith("#")) { continue; }
|
|
subtypes.Add(line);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch (System.Exception ex)
|
|
{
|
|
APILogger.Log(ex);
|
|
return DefaultTestTypes;
|
|
}
|
|
}
|
|
return subtypes.ToArray();
|
|
}
|
|
private static void CreateFile()
|
|
{
|
|
var sb = new StringBuilder();
|
|
sb.AppendLine(TEST_TYPES_KEY);
|
|
foreach (var type in DefaultTestTypes)
|
|
{
|
|
sb.AppendLine(type);
|
|
}
|
|
sb.AppendLine(SUB_TYPES_KEY);
|
|
foreach (var subtype in DEFAULT_SUBTYPES)
|
|
{
|
|
sb.AppendLine(subtype);
|
|
}
|
|
System.IO.File.WriteAllText(FILENAME, sb.ToString(), Encoding.UTF8);
|
|
}
|
|
public static void AddType(string type)
|
|
{
|
|
lock (FILE_LOCK)
|
|
{
|
|
try
|
|
{
|
|
if (!System.IO.File.Exists(FILENAME))
|
|
{
|
|
CreateFile();
|
|
}
|
|
var lines = new List<string>(System.IO.File.ReadAllLines(FILENAME, Encoding.UTF8));
|
|
var bFound = false;
|
|
for (var i = 0; i < lines.Count; i++)
|
|
{
|
|
var line = lines[i].Trim().ToLower();
|
|
if (line != TEST_TYPES_KEY) continue;
|
|
lines.Insert(i + 1, type);
|
|
bFound = true;
|
|
break;
|
|
}
|
|
if (!bFound)
|
|
{
|
|
lines.Add(TEST_TYPES_KEY);
|
|
lines.Add(type);
|
|
}
|
|
System.IO.File.WriteAllLines(FILENAME, lines.ToArray(), Encoding.UTF8);
|
|
}
|
|
catch (System.Exception ex) { APILogger.Log(ex); }
|
|
}
|
|
}
|
|
public static void AddSubtype(string type)
|
|
{
|
|
lock (FILE_LOCK)
|
|
{
|
|
try
|
|
{
|
|
if (!System.IO.File.Exists(FILENAME))
|
|
{
|
|
CreateFile();
|
|
}
|
|
var lines = new List<string>(System.IO.File.ReadAllLines(FILENAME, Encoding.UTF8));
|
|
var bFound = false;
|
|
for (var i = 0; i < lines.Count; i++)
|
|
{
|
|
var line = lines[i].Trim().ToLower();
|
|
if (line != SUB_TYPES_KEY) continue;
|
|
lines.Insert(i + 1, type);
|
|
bFound = true;
|
|
break;
|
|
}
|
|
if (!bFound)
|
|
{
|
|
lines.Add(SUB_TYPES_KEY);
|
|
lines.Add(type);
|
|
}
|
|
System.IO.File.WriteAllLines(FILENAME, lines.ToArray(), Encoding.UTF8);
|
|
}
|
|
catch (System.Exception ex) { APILogger.Log(ex); }
|
|
}
|
|
}
|
|
}
|
|
}
|