Compare commits

..

2 Commits

Author SHA1 Message Date
AJ
3e4ab60366 Allow multiple paths passed through args 2021-04-07 22:00:11 -04:00
AJ
2b30498147 Wrap main in try catch 2021-04-07 21:06:22 -04:00
2 changed files with 57 additions and 18 deletions

View File

@@ -6,7 +6,7 @@ using System.Text.RegularExpressions;
namespace EtchBendLines
{
class BendLineExtractor
public class BendLineExtractor
{
public BendLineExtractor(string dxfFile)
{

View File

@@ -3,38 +3,77 @@ using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
namespace EtchBendLines
{
public class Program
{
static Etcher etcher = new Etcher();
static void Main(string[] args)
{
var path = AppDomain.CurrentDomain.BaseDirectory;
var files = Directory.GetFiles(path, "*.dxf", SearchOption.AllDirectories);
etcher.EtchLength = double.Parse(ConfigurationManager.AppSettings["EtchLength"]);
etcher.MaxBendRadius = double.Parse(ConfigurationManager.AppSettings["MaxBendRadius"]);
if (files == null || files.Length == 0)
try
{
Console.WriteLine($"No DXF files founds. Place DXF files in \"{AppDomain.CurrentDomain.BaseDirectory}\" and run this program again.");
PressAnyKeyToExit();
return;
var etcher = new Etcher();
etcher.EtchLength = GetAppSettingAsDouble("EtchLength");
etcher.MaxBendRadius = GetAppSettingAsDouble("MaxBendRadius");
var paths = new List<string>(args);
if (paths.Count == 0)
{
paths.Add(AppDomain.CurrentDomain.BaseDirectory);
}
var files = new List<string>();
foreach (var path in paths)
{
if (File.Exists(path))
{
files.Add(path);
}
else if (Directory.Exists(path))
{
files.AddRange(Directory.GetFiles(path, "*.dxf", SearchOption.AllDirectories));
}
}
if (files.Count == 0)
{
Console.WriteLine($"No DXF files founds. Place DXF files in \"{AppDomain.CurrentDomain.BaseDirectory}\" and run this program again.");
}
else
{
foreach (var file in files)
{
etcher.AddEtchLines(file);
Console.WriteLine();
}
}
}
catch (Exception ex)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine($"An error occured: {ex.Message}");
Console.ResetColor();
}
PressAnyKeyToExit();
}
static double GetAppSettingAsDouble(string name)
{
double v;
try
{
return double.Parse(ConfigurationManager.AppSettings[name]);
}
catch
{
throw new Exception($"Failed to convert the value of AppSetting[\"{name}\"] to double");
}
}
static void PressAnyKeyToExit()
{
Console.WriteLine("Press any key to exit.");