|
|
using Eplan.EplApi.ApplicationFramework;
|
|
|
using KPlan.RefActions;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
using KPlan.Util;
|
|
|
using System.Windows.Forms;
|
|
|
using System.IO;
|
|
|
using Teamcenter.ClientX;
|
|
|
using Teamcenter.Soa.Client;
|
|
|
using Eplan.EplApi.Base;
|
|
|
using KPlan.Forms;
|
|
|
using System.ComponentModel;
|
|
|
using System.Threading;
|
|
|
using Teamcenter.Soa.Client.Model;
|
|
|
|
|
|
namespace KPlan.Actions {
|
|
|
class DownloadTCDataAction : Eplan.EplApi.ApplicationFramework.IEplAction {
|
|
|
|
|
|
|
|
|
public bool Execute(ActionCallingContext ctx) {
|
|
|
TCUtil.DO_NOTHING();
|
|
|
if (!Util.TCUtil.CheckLogin()) {
|
|
|
return true;
|
|
|
}
|
|
|
Progress progress = new Progress("SimpleProgress");
|
|
|
try {
|
|
|
loadEplanEnv(progress);
|
|
|
progress.EndPart(true);
|
|
|
}
|
|
|
catch (System.Exception ex) {
|
|
|
progress.EndPart(true);
|
|
|
KUtil.LogErr(ex);
|
|
|
MessageBox.Show("执行出错:" + ex.Message);
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
|
|
|
public bool OnRegister(ref string Name, ref int Ordinal) {
|
|
|
Name = "DownloadTCDataAction";
|
|
|
Ordinal = 20;
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
public void GetActionProperties(ref ActionProperties actionProperties) {
|
|
|
//actionProperties.Description = "Action test with parameters.";
|
|
|
}
|
|
|
|
|
|
static private short loadEplanEnv(Progress progress) {
|
|
|
progress.SetTitle("下载TC数据");
|
|
|
progress.SetAllowCancel(false);
|
|
|
progress.BeginPart(30.0, "查询数据");
|
|
|
progress.ShowImmediately();
|
|
|
progress.SetActionText("查询数据...");
|
|
|
string loadEplanEnvTime = KUtil.GetConfigValue(KConfigure.REF_SECTION, KConfigure.REF_DATABASE_LAST_UPDATE_TIME);
|
|
|
bool load = false;
|
|
|
|
|
|
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("未查询到数据集 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 0;
|
|
|
}
|
|
|
/*string dbItemID = KUtil.GetConfigValue(KConfigure.REF_SECTION, KConfigure.REF_DATABSE_ITEMID);
|
|
|
Teamcenter.Soa.Client.Model.Strong.ItemRevision eplanEnvItemRevision = TCTool.getLastItemRev(dbItemID);
|
|
|
TCUtil.Refresh(eplanEnvItemRevision);
|
|
|
Teamcenter.Soa.Client.Model.Strong.Dataset dataset_zip = TCTool.getDataset(eplanEnvItemRevision, "Zip", "EPLAN_PARTS");
|
|
|
if (dataset_zip != null) {
|
|
|
TCUtil.Refresh(dataset_zip);
|
|
|
if (0 != TCTool.checkZipDatasetCheckout(dataset_zip)) {
|
|
|
return 1;
|
|
|
}
|
|
|
//if (0 != TCTool.deleteDataset(projItemRevision, dataset_zw1))
|
|
|
//{
|
|
|
// return 2;
|
|
|
//}
|
|
|
}
|
|
|
else {
|
|
|
dataset_zip = TCTool.createDataset(eplanEnvItemRevision, "Zip", "EPLAN_PARTS");
|
|
|
if (dataset_zip == null) {
|
|
|
return 3;
|
|
|
}
|
|
|
}*/
|
|
|
String[] attributes2 = { "last_mod_date" };
|
|
|
TCUtil.dmService.GetProperties(mos, attributes2);
|
|
|
string last_mod_date = dataset_zip.Last_mod_date.ToString("yyyyMMddHHmmss");
|
|
|
KUtil.Log("数据修改时间:" + last_mod_date);
|
|
|
KUtil.Log("当前数据版本:" + loadEplanEnvTime);
|
|
|
if (string.IsNullOrEmpty(loadEplanEnvTime)) {
|
|
|
load = true;
|
|
|
}
|
|
|
if (!load) {
|
|
|
if (-1 == string.Compare(loadEplanEnvTime, last_mod_date)) {
|
|
|
load = true;
|
|
|
}
|
|
|
}
|
|
|
if (!load) {
|
|
|
MessageBox.Show("当前EPLAN部件库已经是最新的,无须更新!", "提示");
|
|
|
return 0;
|
|
|
}
|
|
|
progress.EndPart();
|
|
|
progress.BeginPart(30.0, "下载数据集");
|
|
|
progress.SetActionText("下载数据集...");
|
|
|
string fmsHome = Environment.GetEnvironmentVariable("FMS_HOME");
|
|
|
string zipFile = fmsHome + "\\EPlan\\" + "EPLAN_PARTS.zip";
|
|
|
try {
|
|
|
// Console.WriteLine("0-------------------------");
|
|
|
List<String> orgFileNames = new List<string>();
|
|
|
List<String> orgFilePaths = new List<string>();
|
|
|
String cacheDir = KUtil.GetConfigValue(KConfigure.FMS_SECTION, KConfigure.FMS_PATH);
|
|
|
if (!Directory.Exists(cacheDir)) {
|
|
|
Directory.CreateDirectory(cacheDir);
|
|
|
}
|
|
|
String[] FMS_Bootstrap_Urls = new String[] { KUtil.GetConfigValue(KConfigure.FMS_SECTION, KConfigure.FMS_URL) };
|
|
|
FileManagementUtility fMSFileManagement = new FileManagementUtility(Session.getConnection(), null, null, FMS_Bootstrap_Urls, cacheDir);
|
|
|
TCUtil.dmService.GetProperties(new Teamcenter.Soa.Client.Model.ModelObject[] { dataset_zip }, new string[] { "ref_list" });
|
|
|
Teamcenter.Soa.Client.Model.ModelObject[] ref_list = dataset_zip.Ref_list;
|
|
|
//Console.WriteLine("1-------------------------");
|
|
|
foreach (Teamcenter.Soa.Client.Model.ModelObject refobj in ref_list) {
|
|
|
Teamcenter.Soa.Client.Model.ModelObject[] ref_list1 = new Teamcenter.Soa.Client.Model.ModelObject[1];
|
|
|
ref_list1[0] = refobj;
|
|
|
TCUtil.dmService.GetProperties(ref_list1, new string[] { "original_file_name" });
|
|
|
string original_file_name = ref_list1[0].GetProperty("original_file_name").StringValue;
|
|
|
//Console.WriteLine("1.1-------------------------");
|
|
|
Teamcenter.Soa.Client.GetFileResponse fileresp = fMSFileManagement.GetFiles(ref_list1);
|
|
|
//Console.WriteLine("1.2-------------------------");
|
|
|
if (fileresp != null && fileresp.SizeOfFiles() > 0) {
|
|
|
FileInfo[] fis = fileresp.GetFiles();
|
|
|
FileInfo fi = fis[0];
|
|
|
orgFileNames.Add(original_file_name);
|
|
|
orgFilePaths.Add(fi.FullName);
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
// Console.WriteLine("2-------------------------");
|
|
|
fMSFileManagement.Term();
|
|
|
// Console.WriteLine("2.1-------------------------");
|
|
|
if (orgFilePaths.Count > 0) {
|
|
|
if (File.Exists(zipFile)) {
|
|
|
FileInfo fi = new FileInfo(zipFile);
|
|
|
if (fi.Attributes.ToString().IndexOf("ReadOnly") != -1)
|
|
|
fi.Attributes = FileAttributes.Normal;
|
|
|
File.Delete(zipFile);
|
|
|
}
|
|
|
System.IO.File.Copy(orgFilePaths[0], zipFile, true);
|
|
|
{
|
|
|
FileInfo fi = new FileInfo(zipFile);
|
|
|
if (fi.Attributes.ToString().IndexOf("ReadOnly") != -1)
|
|
|
fi.Attributes = FileAttributes.Normal;
|
|
|
}
|
|
|
//Console.WriteLine("3-------------------------");
|
|
|
{
|
|
|
FileInfo fi = new FileInfo(orgFilePaths[0]);
|
|
|
if (fi.Attributes.ToString().IndexOf("ReadOnly") != -1)
|
|
|
fi.Attributes = FileAttributes.Normal;
|
|
|
File.Delete(orgFilePaths[0]);
|
|
|
}
|
|
|
//Console.WriteLine("4-------------------------");
|
|
|
}
|
|
|
}
|
|
|
catch (SystemException e) {
|
|
|
progress.EndPart(true);
|
|
|
MessageBox.Show("下载EPLAN部件库失败:\r\n" + e.ToString(), "提示");
|
|
|
return 11;
|
|
|
}
|
|
|
progress.EndPart();
|
|
|
progress.BeginPart(40.0, "解压文件");
|
|
|
progress.SetActionText("解压文件...");
|
|
|
//Console.WriteLine("待解压的文件-------------------------" + zipFile);
|
|
|
if (File.Exists(zipFile)) {
|
|
|
// Console.WriteLine("解压目录-------------------------" + TCTool.DatabaseInfo["ELECPartLib"]);
|
|
|
//Console.WriteLine("测试解压-------------------------" );
|
|
|
// if (!ZipHelper.UnZips(zipFile, TCTool.DatabaseInfo["ELECPartLib"]))
|
|
|
//string unzipPath = KUtil.GetConfigValue(KConfigure.REF_SECTION, KConfigure.REF_UNZIP_PATH);
|
|
|
KUtil.ReplaceZipContentName(zipFile);
|
|
|
if (!ZipHelper.UnZips(zipFile, eplanDataFolderPath)) {
|
|
|
progress.EndPart(true);
|
|
|
MessageBox.Show("解压缩EPLAN部件库失败!", "提示");
|
|
|
return 21;
|
|
|
}
|
|
|
/* if (!ZipHelper.UnZips(zipFile, "D:\\AS2"))
|
|
|
{
|
|
|
MessageBox.Show("解压缩D:\\AS失败", "提示");
|
|
|
return 21;
|
|
|
}*/
|
|
|
/* if (!ZipHelper.UnZip(zipFile, TCTool.DatabaseInfo["ELECPartLibUnzip"]))
|
|
|
{
|
|
|
MessageBox.Show("解压缩EPLAN部件库失败!", "提示");
|
|
|
return 21;
|
|
|
}*/
|
|
|
}
|
|
|
KUtil.SetConfigValue(KConfigure.REF_SECTION, KConfigure.REF_DATABASE_LAST_UPDATE_TIME, last_mod_date);
|
|
|
progress.EndPart(true);
|
|
|
//iniFile.WriteString("databaseinfo", "更新时间", last_mod_date);
|
|
|
MessageBox.Show("下载EPLAN部件库完毕!", "提示");
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|