|
|
using Eplan.EplApi.ApplicationFramework;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
using KPlan.Forms;
|
|
|
using KPlan.Util;
|
|
|
using System.ComponentModel;
|
|
|
using System.Windows;
|
|
|
using Eplan.EplApi.Base;
|
|
|
using System.Threading;
|
|
|
using Teamcenter.Soa.Client.Model;
|
|
|
using System.IO;
|
|
|
|
|
|
namespace KPlan.Actions {
|
|
|
class KDownloadTCDataAction : Eplan.EplApi.ApplicationFramework.IEplAction {
|
|
|
|
|
|
public bool Execute(ActionCallingContext ctx) {
|
|
|
TCUtil.DO_NOTHING();
|
|
|
if (!Util.TCUtil.CheckLogin()) {
|
|
|
return true;
|
|
|
}
|
|
|
Progress progress = new Progress("SimpleProgress");
|
|
|
try {
|
|
|
Download(progress);
|
|
|
progress.EndPart(true);
|
|
|
}
|
|
|
catch(Exception ex) {
|
|
|
progress.EndPart(true);
|
|
|
KUtil.LogErr(ex);
|
|
|
MessageBox.Show("执行出错:" + ex.Message);
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
|
|
|
private void Download(Progress progress) {
|
|
|
progress.SetTitle("下载TC数据");
|
|
|
progress.SetAllowCancel(false);
|
|
|
progress.BeginPart(30.0, "查询数据");
|
|
|
progress.SetActionText("查询数据...");
|
|
|
progress.ShowImmediately();
|
|
|
string loadEplanEnvTime = KUtil.GetConfigValue(KConfigure.REF_SECTION, KConfigure.REF_DATABASE_LAST_UPDATE_TIME);
|
|
|
string eplanDataFolderPath = KUtil.GetConfigValue(KConfigure.EPLAN_DATA_SECTION, KConfigure.EPLAN_DATA_FOLDER);
|
|
|
string dsUid = KUtil.GetConfigValue(KConfigure.EPLAN_DATA_SECTION, KConfigure.EPLAN_DATASET_UID);
|
|
|
if (KUtil.IsEmpty(dsUid)) {
|
|
|
throw new Exception("未配置TC数据集UID");
|
|
|
}
|
|
|
if (!System.IO.Directory.Exists(eplanDataFolderPath)) {
|
|
|
throw new Exception("EPLAN数据文件夹不存在,请检查配置:" + eplanDataFolderPath);
|
|
|
}
|
|
|
KUtil.Log("准备下载EPLAN数据文件夹:" + eplanDataFolderPath);
|
|
|
ModelObject mo = TCUtil.StringToComponent(dsUid);
|
|
|
if (mo == null) {
|
|
|
throw new Exception("未查询到Zip数据集 uid = " + dsUid + ",请检查配置");
|
|
|
}
|
|
|
ModelObject[] mos = TCUtil.Refresh(mo);
|
|
|
TCUtil.GetProperties(false, mos, "object_string");
|
|
|
string dsName = mo.GetPropertyDisplayableValue("object_string");
|
|
|
KUtil.Log("找到数据集:" + dsName);
|
|
|
if (!TCUtil.IsType(mo.SoaType, "Zip")) {
|
|
|
throw new Exception("配置的数据集<" + dsName + ">不是Zip数据集,uid = " + dsUid);
|
|
|
}
|
|
|
Teamcenter.Soa.Client.Model.Strong.Dataset dataset_zip = mo as Teamcenter.Soa.Client.Model.Strong.Dataset;
|
|
|
if (dataset_zip == null) {
|
|
|
return;
|
|
|
}
|
|
|
TCUtil.GetProperties(false,mos, "last_mod_date");
|
|
|
string last_mod_date = dataset_zip.Last_mod_date.ToString("yyyyMMddHHmmss");
|
|
|
KUtil.Log("数据修改时间:" + last_mod_date);
|
|
|
KUtil.Log("当前数据版本:" + loadEplanEnvTime);
|
|
|
if (last_mod_date.Equals(loadEplanEnvTime)) {
|
|
|
MessageBox.Show("当前EPLAN部件库已经是最新的,无须更新!", "提示");
|
|
|
return;
|
|
|
}
|
|
|
progress.EndPart(false);
|
|
|
|
|
|
progress.BeginPart(30.0, "下载数据集");
|
|
|
progress.SetActionText("下载数据集...");
|
|
|
List<Teamcenter.Soa.Client.Model.Strong.ImanFile> zipFiles = TCUtil.GetDatasetFile(dataset_zip, "");
|
|
|
int len = zipFiles == null ? 0 : zipFiles.Count;
|
|
|
if (len == 0) {
|
|
|
KUtil.Log("数据集<" + dsName + ">不存在文件引用");
|
|
|
throw new Exception("缺少Eplan主数据,请确认是否已上传Eplan主数据");
|
|
|
//throw new Exception("数据集<"+dsName+">不存在文件引用");
|
|
|
}
|
|
|
if (len > 1) {
|
|
|
throw new Exception("数据集<" + dsName + ">存在多个文件引用:"+len);
|
|
|
}
|
|
|
FileInfo zipFile = TCUtil.GetFileInfo(zipFiles[0]);
|
|
|
if (zipFile == null || !File.Exists(zipFile.FullName)){
|
|
|
throw new Exception("从数据集<" + dsName + ">下载文件失败");
|
|
|
}
|
|
|
KUtil.Log("下载文件:"+zipFile.FullName);
|
|
|
progress.EndPart(false);
|
|
|
|
|
|
progress.BeginPart(40.0, "解压文件");
|
|
|
progress.SetActionText("解压文件...");
|
|
|
KUtil.ReplaceZipContentName(zipFile.FullName);
|
|
|
KUtil.UnZipDirectory(zipFile.FullName, eplanDataFolderPath);
|
|
|
KUtil.SetConfigValue(KConfigure.REF_SECTION, KConfigure.REF_DATABASE_LAST_UPDATE_TIME, last_mod_date);
|
|
|
progress.EndPart(true);
|
|
|
if (!"TRUE".Equals(KUtil.GetConfigValue(KConfigure.EPLAN_DATA_SECTION, KConfigure.EPLAN_KEEP_ZIP)?.ToUpper())) {
|
|
|
zipFile.Delete();
|
|
|
KUtil.Log("已清理临时文件");
|
|
|
}
|
|
|
MessageBox.Show("下载EPLAN部件库完毕!", "提示");
|
|
|
}
|
|
|
|
|
|
public bool OnRegister(ref string Name, ref int Ordinal) {
|
|
|
Name = "KDownloadTCDataAction";
|
|
|
Ordinal = 20;
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
public void GetActionProperties(ref ActionProperties actionProperties) {
|
|
|
//actionProperties.Description = "Action test with parameters.";
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|