feat: add IDrawingInfoExtractor with equipment and default implementations
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,28 @@
|
|||||||
|
using System.Configuration;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
|
namespace ExportDXF.Services
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Fallback extractor that uses the document name as prefix
|
||||||
|
/// and appends the configured default suffix.
|
||||||
|
/// Always returns true — this is the catch-all.
|
||||||
|
/// </summary>
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
using System.IO;
|
||||||
|
|
||||||
|
namespace ExportDXF.Services
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 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.
|
||||||
|
/// </summary>
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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; }
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user