Compare commits
2 Commits
f664bd79a4
...
3e4ab60366
| Author | SHA1 | Date | |
|---|---|---|---|
| 3e4ab60366 | |||
| 2b30498147 |
@@ -6,7 +6,7 @@ using System.Text.RegularExpressions;
|
|||||||
|
|
||||||
namespace EtchBendLines
|
namespace EtchBendLines
|
||||||
{
|
{
|
||||||
class BendLineExtractor
|
public class BendLineExtractor
|
||||||
{
|
{
|
||||||
public BendLineExtractor(string dxfFile)
|
public BendLineExtractor(string dxfFile)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -3,38 +3,77 @@ using System.Collections.Generic;
|
|||||||
using System.Configuration;
|
using System.Configuration;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
|
|
||||||
namespace EtchBendLines
|
namespace EtchBendLines
|
||||||
{
|
{
|
||||||
public class Program
|
public class Program
|
||||||
{
|
{
|
||||||
static Etcher etcher = new Etcher();
|
|
||||||
|
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
var path = AppDomain.CurrentDomain.BaseDirectory;
|
try
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
Console.WriteLine($"No DXF files founds. Place DXF files in \"{AppDomain.CurrentDomain.BaseDirectory}\" and run this program again.");
|
var etcher = new Etcher();
|
||||||
PressAnyKeyToExit();
|
etcher.EtchLength = GetAppSettingAsDouble("EtchLength");
|
||||||
return;
|
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)
|
foreach (var file in files)
|
||||||
{
|
{
|
||||||
etcher.AddEtchLines(file);
|
etcher.AddEtchLines(file);
|
||||||
Console.WriteLine();
|
Console.WriteLine();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.ForegroundColor = ConsoleColor.Red;
|
||||||
|
Console.WriteLine($"An error occured: {ex.Message}");
|
||||||
|
Console.ResetColor();
|
||||||
|
}
|
||||||
|
|
||||||
PressAnyKeyToExit();
|
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()
|
static void PressAnyKeyToExit()
|
||||||
{
|
{
|
||||||
Console.WriteLine("Press any key to exit.");
|
Console.WriteLine("Press any key to exit.");
|
||||||
|
|||||||
Reference in New Issue
Block a user