using connor_zwcadm.util; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using ZwSoft.ZwCAD.ApplicationServices; namespace connor_zwcadm.commands { public abstract class AbstractCADCommand { protected KCADUtil KCADUtil { get; } protected string File_Path { get; } protected AbstractCADCommand(string file_path, bool checkFile = true) { File_Path = file_path; if (!string.IsNullOrWhiteSpace(file_path) && file_path.Contains(":")) { KCADUtil = new KCADUtil(file_path); } else if(checkFile) { throw new Exception("请先使用cad保存文件后再进行操作"); } } protected abstract void InitCommand(); protected abstract void ExecuteCommand(); protected void ClearCache() { if (KCADUtil != null) { KCADUtil.CloseDatabse(); } } public void Execute() { InitCommand(); try { ExecuteCommand(); } finally { ClearCache(); } } } }