diff --git a/ExportDXF/Services/DefaultDrawingInfoExtractor.cs b/ExportDXF/Services/DefaultDrawingInfoExtractor.cs new file mode 100644 index 0000000..f0263aa --- /dev/null +++ b/ExportDXF/Services/DefaultDrawingInfoExtractor.cs @@ -0,0 +1,28 @@ +using System.Configuration; +using System.IO; + +namespace ExportDXF.Services +{ + /// + /// Fallback extractor that uses the document name as prefix + /// and appends the configured default suffix. + /// Always returns true — this is the catch-all. + /// + public class DefaultDrawingInfoExtractor : IDrawingInfoExtractor + { + public bool TryExtract(string documentName, out DrawingInfoResult info) + { + var name = Path.GetFileNameWithoutExtension(documentName); + var suffix = ConfigurationManager.AppSettings["DefaultSuffix"] ?? "PT{item_no:2}"; + + info = new DrawingInfoResult + { + EquipmentNumber = null, + DrawingNumber = null, + DefaultTemplate = $"{name} {suffix}" + }; + + return true; + } + } +} diff --git a/ExportDXF/Services/EquipmentDrawingInfoExtractor.cs b/ExportDXF/Services/EquipmentDrawingInfoExtractor.cs new file mode 100644 index 0000000..400fb9f --- /dev/null +++ b/ExportDXF/Services/EquipmentDrawingInfoExtractor.cs @@ -0,0 +1,36 @@ +using System.IO; + +namespace ExportDXF.Services +{ + /// + /// Extracts equipment/drawing numbers from document names matching the + /// workplace format (e.g., "4321 A01.SLDDRW" → equipment "4321", drawing "A01"). + /// Uses the existing DrawingInfo.Parse() logic. + /// + public class EquipmentDrawingInfoExtractor : IDrawingInfoExtractor + { + public bool TryExtract(string documentName, out DrawingInfoResult info) + { + info = null; + + var name = Path.GetFileNameWithoutExtension(documentName); + var parsed = DrawingInfo.Parse(name); + + if (parsed == null || string.IsNullOrEmpty(parsed.EquipmentNo)) + return false; + + var template = !string.IsNullOrEmpty(parsed.DrawingNo) + ? $"{parsed.EquipmentNo} {parsed.DrawingNo} PT{{item_no:2}}" + : $"{parsed.EquipmentNo} PT{{item_no:2}}"; + + info = new DrawingInfoResult + { + EquipmentNumber = parsed.EquipmentNo, + DrawingNumber = parsed.DrawingNo, + DefaultTemplate = template + }; + + return true; + } + } +} diff --git a/ExportDXF/Services/IDrawingInfoExtractor.cs b/ExportDXF/Services/IDrawingInfoExtractor.cs new file mode 100644 index 0000000..e7b5440 --- /dev/null +++ b/ExportDXF/Services/IDrawingInfoExtractor.cs @@ -0,0 +1,14 @@ +namespace ExportDXF.Services +{ + public interface IDrawingInfoExtractor + { + bool TryExtract(string documentName, out DrawingInfoResult info); + } + + public class DrawingInfoResult + { + public string EquipmentNumber { get; set; } + public string DrawingNumber { get; set; } + public string DefaultTemplate { get; set; } + } +}