You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.1 KiB

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();
}
}
}
}