|
|
#pragma warning (disable: 4996)
|
|
|
#pragma warning (disable: 4819)
|
|
|
|
|
|
#include "kutil.h"
|
|
|
|
|
|
FILE* logFile = NULL;
|
|
|
|
|
|
#define MAX_PATH_LENGTH 200
|
|
|
#define MAX_PRINTLINE_LENGTH 400000
|
|
|
|
|
|
|
|
|
//void sendGetRequest()
|
|
|
//{
|
|
|
// //开始进行socket初始化;
|
|
|
// WSADATA wData;
|
|
|
// ::WSAStartup(MAKEWORD(2, 2), &wData);
|
|
|
//
|
|
|
// SOCKET clientSocket = socket(AF_INET, 1, 0);
|
|
|
// struct sockaddr_in ServerAddr = { 0 };
|
|
|
// int Ret = 0;
|
|
|
// int AddrLen = 0;
|
|
|
// HANDLE hThread = 0;
|
|
|
//
|
|
|
// char *bufSend = "Get /check?+参数 HTTP/1.1\r\n"
|
|
|
// "Connection:Keep-Alive\r\n"
|
|
|
// "Accept-Encoding:gzip, deflate\r\n"
|
|
|
// "Accept-Language:zh-CN,en,*\r\n"
|
|
|
// "host:www.baidu.com\r\n"
|
|
|
// "User-Agent:Mozilla/5.0\r\n\r\n";
|
|
|
//
|
|
|
// char addIp[256] = { 0 };
|
|
|
// GetIpByDomainName("www.baidu.com", addIp);
|
|
|
// ServerAddr.sin_addr.s_addr = inet_addr(addIp);
|
|
|
// ServerAddr.sin_port = htons(80);;
|
|
|
// ServerAddr.sin_family = AF_INET;
|
|
|
// char bufData[3069] = { 0 };
|
|
|
// char bufRecv[3069] = { 0 };
|
|
|
// int errNo = 0;
|
|
|
// errNo = connect(clientSocket, (sockaddr*)&ServerAddr, sizeof(ServerAddr));
|
|
|
// if (errNo == 0)
|
|
|
// {
|
|
|
// //如果发送成功,则返回发送成功的字节数;
|
|
|
// if (send(clientSocket, bufSend, strlen(bufData), 0)>0)
|
|
|
// {
|
|
|
// cout << "发送成功\n";;
|
|
|
// }
|
|
|
// //如果接受成功,则返回接受的字节数;
|
|
|
// if (recv(clientSocket, bufRecv, 3069, 0)>0)
|
|
|
// {
|
|
|
// cout << "接受的数据:" << bufRecv << endl;
|
|
|
// }
|
|
|
// }
|
|
|
// else
|
|
|
// {
|
|
|
// errNo = WSAGetLastError();
|
|
|
// }
|
|
|
// //socket环境清理;
|
|
|
// ::WSACleanup();
|
|
|
//}
|
|
|
//
|
|
|
//BOOL GetIpByDomainName(char *szHost, char* szIp)
|
|
|
//{
|
|
|
// WSADATA wsaData;
|
|
|
//
|
|
|
// HOSTENT *pHostEnt;
|
|
|
// int nAdapter = 0;
|
|
|
// struct sockaddr_in sAddr;
|
|
|
// if (WSAStartup(0x0101, &wsaData))
|
|
|
// {
|
|
|
// printf(" gethostbyname error for host:\n");
|
|
|
// return FALSE;
|
|
|
// }
|
|
|
//
|
|
|
// pHostEnt = gethostbyname(szHost);
|
|
|
// if (pHostEnt)
|
|
|
// {
|
|
|
// if (pHostEnt->h_addr_list[nAdapter])
|
|
|
// {
|
|
|
// memcpy(&sAddr.sin_addr.s_addr, pHostEnt->h_addr_list[nAdapter], pHostEnt->h_length);
|
|
|
// sprintf(szIp, "%s", inet_ntoa(sAddr.sin_addr));
|
|
|
// }
|
|
|
// }
|
|
|
// else
|
|
|
// {
|
|
|
// // DWORD dwError = GetLastError();
|
|
|
// // CString csError;
|
|
|
// // csError.Format("%d", dwError);
|
|
|
// }
|
|
|
// WSACleanup();
|
|
|
// return TRUE;
|
|
|
//}
|
|
|
|
|
|
int write_string_to_file_append(const std::string & file_string, const std::string str)
|
|
|
{
|
|
|
std::ofstream OsWrite(file_string, std::ofstream::app);
|
|
|
OsWrite << str;
|
|
|
OsWrite << std::endl;
|
|
|
OsWrite.close();
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
|
|
|
void setProperty(tag_t formValue, char * propertyName, tag_t toValue, char * toPropertyName)
|
|
|
{
|
|
|
PROP_value_type_t propertyType;
|
|
|
char * valtype_n = NULL;
|
|
|
//获取属性类型
|
|
|
AOM_ask_value_type(formValue, propertyName, &propertyType, &valtype_n);
|
|
|
switch (propertyType)
|
|
|
{
|
|
|
case PROP_date:
|
|
|
date_t propertyValue;
|
|
|
AOM_ask_value_date(formValue, propertyName, &propertyValue);
|
|
|
//先lock
|
|
|
AOM_lock(toValue);
|
|
|
AOM_set_value_date(toValue, toPropertyName, propertyValue);
|
|
|
//再save
|
|
|
AOM_save(toValue);
|
|
|
//最后unlock
|
|
|
AOM_unlock(toValue);
|
|
|
AOM_refresh(toValue, FALSE);
|
|
|
break;
|
|
|
case PROP_double:
|
|
|
double propertyValue2;
|
|
|
AOM_ask_value_double(formValue, propertyName, &propertyValue2);
|
|
|
//先lock
|
|
|
AOM_lock(toValue);
|
|
|
AOM_set_value_double(toValue, toPropertyName, propertyValue2);
|
|
|
//再save
|
|
|
AOM_save(toValue);
|
|
|
//最后unlock
|
|
|
AOM_unlock(toValue);
|
|
|
AOM_refresh(toValue, FALSE);
|
|
|
break;
|
|
|
case PROP_int:
|
|
|
int propertyValue3;
|
|
|
AOM_ask_value_int(formValue, propertyName, &propertyValue3);
|
|
|
//先lock
|
|
|
AOM_lock(toValue);
|
|
|
AOM_set_value_int(toValue, toPropertyName, propertyValue3);
|
|
|
//再save
|
|
|
AOM_save(toValue);
|
|
|
//最后unlock
|
|
|
AOM_unlock(toValue);
|
|
|
AOM_refresh(toValue, FALSE);
|
|
|
break;
|
|
|
case PROP_string:
|
|
|
char * propertyValue4;
|
|
|
AOM_ask_value_string(formValue, propertyName, &propertyValue4);
|
|
|
//先lock
|
|
|
AOM_lock(toValue);
|
|
|
AOM_set_value_string(toValue, toPropertyName, propertyValue4);
|
|
|
//再save
|
|
|
AOM_save(toValue);
|
|
|
//最后unlock
|
|
|
AOM_unlock(toValue);
|
|
|
AOM_refresh(toValue, FALSE);
|
|
|
DOFREE(propertyValue4);
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
DOFREE(valtype_n);
|
|
|
}
|
|
|
|
|
|
bool is_str_utf8(const char* str)
|
|
|
{
|
|
|
unsigned int nBytes = 0;//UFT8可用1-6个字节编码,ASCII用一个字节
|
|
|
unsigned char chr = *str;
|
|
|
bool bAllAscii = true;
|
|
|
for (unsigned int i = 0; str[i] != '\0'; ++i) {
|
|
|
chr = *(str + i);
|
|
|
//判断是否ASCII编码,如果不是,说明有可能是UTF8,ASCII用7位编码,最高位标记为0,0xxxxxxx
|
|
|
if (nBytes == 0 && (chr & 0x80) != 0) {
|
|
|
bAllAscii = false;
|
|
|
}
|
|
|
if (nBytes == 0) {
|
|
|
//如果不是ASCII码,应该是多字节符,计算字节数
|
|
|
if (chr >= 0x80) {
|
|
|
if (chr >= 0xFC && chr <= 0xFD) {
|
|
|
nBytes = 6;
|
|
|
}
|
|
|
else if (chr >= 0xF8) {
|
|
|
nBytes = 5;
|
|
|
}
|
|
|
else if (chr >= 0xF0) {
|
|
|
nBytes = 4;
|
|
|
}
|
|
|
else if (chr >= 0xE0) {
|
|
|
nBytes = 3;
|
|
|
}
|
|
|
else if (chr >= 0xC0) {
|
|
|
nBytes = 2;
|
|
|
}
|
|
|
else {
|
|
|
return false;
|
|
|
}
|
|
|
nBytes--;
|
|
|
}
|
|
|
}
|
|
|
else {
|
|
|
//多字节符的非首字节,应为 10xxxxxx
|
|
|
if ((chr & 0xC0) != 0x80) {
|
|
|
return false;
|
|
|
}
|
|
|
//减到为零为止
|
|
|
nBytes--;
|
|
|
}
|
|
|
}
|
|
|
//违返UTF8编码规则
|
|
|
if (nBytes != 0) {
|
|
|
return false;
|
|
|
}
|
|
|
if (bAllAscii) { //如果全部都是ASCII, 也是UTF8
|
|
|
return true;
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
bool find_prop(int prop_cnt, char** props, const char* prop) {
|
|
|
for (int i = 0; i < prop_cnt; i++) {
|
|
|
if (tc_strcmp(props[i], prop) == 0) {
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
string itoa_self(int i)
|
|
|
{
|
|
|
stringstream ss;
|
|
|
ss << i;
|
|
|
return ss.str();
|
|
|
}
|
|
|
|
|
|
//从文件读入到string里
|
|
|
string readFileIntoString(char * filename)
|
|
|
{
|
|
|
//string line;
|
|
|
|
|
|
//ifstream infile(filename, ios::in);
|
|
|
|
|
|
//if (infile) // 有该文件
|
|
|
//{
|
|
|
// while (getline(infile, line, '\n')) // line中不包括每行的换行符
|
|
|
// {
|
|
|
// cout << line << endl;
|
|
|
// }
|
|
|
//}
|
|
|
|
|
|
//
|
|
|
////返回与流对象buf关联的字符串
|
|
|
//cout << line<<endl;
|
|
|
|
|
|
std::ifstream f{ filename, std::ios::binary };
|
|
|
std::stringstream ss;
|
|
|
ss << f.rdbuf();
|
|
|
return ss.str();
|
|
|
}
|
|
|
|
|
|
map<string, string> jsonstr2map(const string& json)
|
|
|
{
|
|
|
//cout << json << endl;
|
|
|
Json::Reader reader;
|
|
|
Json::Value value;
|
|
|
map<string, string> maps;
|
|
|
|
|
|
if (json.length() > 0)
|
|
|
{
|
|
|
if (reader.parse(json, value))
|
|
|
{
|
|
|
Json::Value::Members members = value.getMemberNames();
|
|
|
for (Json::Value::Members::iterator it = members.begin(); it != members.end(); it++)
|
|
|
{
|
|
|
Json::ValueType vt = value[*it].type();
|
|
|
switch (vt)
|
|
|
{
|
|
|
case Json::stringValue:
|
|
|
{
|
|
|
maps.insert(pair<string, string>(*it, value[*it].asString()));
|
|
|
break;
|
|
|
}
|
|
|
case Json::intValue:
|
|
|
{
|
|
|
int intTmp = value[*it].asInt();
|
|
|
maps.insert(pair<string, string>(*it, itoa_self(intTmp)));
|
|
|
break;
|
|
|
}
|
|
|
case Json::arrayValue:
|
|
|
{
|
|
|
std::string strid;
|
|
|
for (unsigned int i = 0; i < value[*it].size(); i++)
|
|
|
{
|
|
|
strid += value[*it][i].asString();
|
|
|
strid += ",";
|
|
|
}
|
|
|
if (!strid.empty())
|
|
|
{
|
|
|
strid = strid.substr(0, strid.size() - 1);
|
|
|
}
|
|
|
maps.insert(pair<string, string>(*it, strid));
|
|
|
break;
|
|
|
}
|
|
|
default:
|
|
|
{
|
|
|
break;
|
|
|
}
|
|
|
}//end switch
|
|
|
}//end for
|
|
|
}//end if
|
|
|
}
|
|
|
|
|
|
return maps;
|
|
|
}
|
|
|
|
|
|
|
|
|
//获取当前时间
|
|
|
void getCurrentTime(date_t * now)
|
|
|
{
|
|
|
time_t tim = time(NULL);
|
|
|
time(&tim);
|
|
|
struct tm * gmt = NULL;
|
|
|
gmt = localtime(&tim);
|
|
|
//char temp[MAX_PATH_LENGTH];
|
|
|
//sprintf(temp, "%d-%d-%d", gmt->tm_year, gmt->tm_mon, gmt->tm_mday);
|
|
|
cout << now->year << 1900 + gmt->tm_year; //02021
|
|
|
cout << now->month << 1 + gmt->tm_mon; //8
|
|
|
cout << now->day << gmt->tm_mday;
|
|
|
cout << now->hour << gmt->tm_hour;
|
|
|
cout << now->minute << gmt->tm_min;
|
|
|
}
|
|
|
|
|
|
//获取当前年的后两位
|
|
|
int getLast2Year(char* &year)
|
|
|
{
|
|
|
int ifail = ITK_ok;
|
|
|
time_t now = time(0);
|
|
|
tm* ltm = localtime(&now);
|
|
|
char temp[200] = "";
|
|
|
snprintf(temp, sizeof(temp), "%d", 1900 + ltm->tm_year);
|
|
|
string year2(temp);
|
|
|
year2 = year2.substr(2);
|
|
|
strcpy(temp, year2.c_str());
|
|
|
year = temp;
|
|
|
return ifail;
|
|
|
}
|
|
|
|
|
|
//设置只读属性的值
|
|
|
int connor_set_prop_value(char* propname, const char* propvalue, tag_t &tag_instance) {
|
|
|
int ifail = ITK_ok;
|
|
|
|
|
|
POM_AM__set_application_bypass(true);
|
|
|
char * class_id = NULL;
|
|
|
tag_t attr_id = NULLTAG, class_tag = NULLTAG;
|
|
|
|
|
|
ITKCALL(AOM_lock(tag_instance));
|
|
|
ITKCALL(ifail = POM_class_of_instance(tag_instance, &class_tag));
|
|
|
ITKCALL(ifail = POM_name_of_class(class_tag, &class_id));
|
|
|
ITKCALL(ifail = POM_attr_id_of_attr(propname, class_id, &attr_id));
|
|
|
ITKCALL(POM_refresh_instances_any_class(1, &tag_instance, POM_modify_lock));
|
|
|
ITKCALL(POM_set_attr_string(1, &tag_instance, attr_id, propvalue));
|
|
|
ITKCALL(POM_save_instances(1, &tag_instance, true));
|
|
|
ITKCALL(AOM_unlock(tag_instance));
|
|
|
DOFREE(class_id);
|
|
|
POM_AM__set_application_bypass(false);
|
|
|
return ITK_ok;
|
|
|
}
|
|
|
|
|
|
//设置只读属性的值
|
|
|
int connor_set_prop_value(void *returnValue)
|
|
|
{
|
|
|
int ifail = ITK_ok;
|
|
|
WriteLog(ifail, "> 开始执行 <设置不可修改的属性> ");
|
|
|
char *propname = NULL, *propvalue = NULL, *class_id = NULL;
|
|
|
tag_t tag_instance = NULLTAG, attr_id = NULLTAG, class_tag = NULLTAG;
|
|
|
ITKCALL(ifail = USERARG_get_string_argument(&propname));
|
|
|
ITKCALL(ifail = USERARG_get_string_argument(&propvalue));
|
|
|
ITKCALL(ifail = USERARG_get_tag_argument(&tag_instance));
|
|
|
WriteLog(ifail, ">>> propname = %s 、 propvalue = %s", propname, propvalue);
|
|
|
|
|
|
{
|
|
|
POM_AM__set_application_bypass(true);
|
|
|
ITKCALL(AOM_lock(tag_instance));
|
|
|
ITKCALL(ifail = POM_class_of_instance(tag_instance, &class_tag));
|
|
|
ITKCALL(ifail = POM_name_of_class(class_tag, &class_id));
|
|
|
ITKCALL(ifail = POM_attr_id_of_attr(propname, class_id, &attr_id));
|
|
|
ITKCALL(POM_refresh_instances_any_class(1, &tag_instance, POM_modify_lock));
|
|
|
ITKCALL(POM_set_attr_string(1, &tag_instance, attr_id, propvalue));
|
|
|
ITKCALL(POM_save_instances(1, &tag_instance, true));
|
|
|
ITKCALL(AOM_unlock(tag_instance));
|
|
|
DOFREE(class_id);
|
|
|
POM_AM__set_application_bypass(false);
|
|
|
}
|
|
|
//设置返回值
|
|
|
char server_string[10];
|
|
|
if (ifail == ITK_ok)
|
|
|
{
|
|
|
tc_strcpy(server_string, "true");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
tc_strcpy(server_string, "false");
|
|
|
}
|
|
|
|
|
|
*((char **)returnValue) = (char *)MEM_alloc((strlen(server_string) + 1) * sizeof(char));
|
|
|
tc_strcpy(*((char **)returnValue), server_string);
|
|
|
WriteLog(ifail, "> 执行结束 <设置不可修改的属性> ");
|
|
|
return ifail;
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
判断对象objtag是否属于type_name类型
|
|
|
*/
|
|
|
bool isTypeOf(tag_t objtag, const char * type_name) {
|
|
|
tag_t type = NULLTAG;
|
|
|
TCTYPE_ask_object_type(objtag, &type);
|
|
|
tag_t item_type = NULLTAG;
|
|
|
TCTYPE_find_type(type_name, "", &item_type);
|
|
|
bool is_type = false;
|
|
|
if (item_type != NULLTAG) {
|
|
|
logical isok = FALSE;
|
|
|
TCTYPE_is_type_of(type, item_type, &isok);
|
|
|
if (isok) {
|
|
|
is_type = true;
|
|
|
}
|
|
|
}
|
|
|
return is_type;
|
|
|
}
|
|
|
|
|
|
void initUserDir(char *userId) {
|
|
|
char logFileDir[MAX_PATH_LENGTH];
|
|
|
memset(logFileDir, 0, sizeof(logFileDir));
|
|
|
sprintf(logFileDir, "%s", getenv("TEMP"));
|
|
|
strcat(logFileDir, "\\tc_");
|
|
|
strcat(logFileDir, userId);
|
|
|
if (chdir(logFileDir) != ITK_ok) {
|
|
|
printf(">> 新建路径:%s\n", logFileDir);
|
|
|
mkdir(logFileDir);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
bool copyFile(const char *SRC, const char* DEST)
|
|
|
{
|
|
|
std::ifstream src(SRC, std::ios::binary);
|
|
|
std::ofstream dest(DEST, std::ios::binary);
|
|
|
dest << src.rdbuf();
|
|
|
return src && dest;
|
|
|
}
|
|
|
|
|
|
int WriteToFile(logical debug, FILE* file, const char* format, ...)
|
|
|
{
|
|
|
va_list arg;
|
|
|
char tmp[MAX_PRINTLINE_LENGTH];
|
|
|
|
|
|
//get the message
|
|
|
memset(tmp, 0, sizeof(tmp));
|
|
|
va_start(arg, format);
|
|
|
vsprintf(tmp, format, arg);
|
|
|
va_end(arg);
|
|
|
//print message to log file
|
|
|
WriteLog(debug, "写入内容:%s", tmp);
|
|
|
if (file)
|
|
|
{
|
|
|
fprintf(file, "%s", tmp);
|
|
|
fflush(file);
|
|
|
return ITK_ok;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
WriteLog(debug, "写入文件失败,文件不存在");
|
|
|
return -1;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void WriteLog(logical debug, const char* format, ...)
|
|
|
{
|
|
|
va_list arg;
|
|
|
char tmp[MAX_PRINTLINE_LENGTH];
|
|
|
char date_string[MAX_PATH_LENGTH];
|
|
|
time_t now;
|
|
|
struct tm *p;
|
|
|
|
|
|
//get the message
|
|
|
memset(tmp, 0, sizeof(tmp));
|
|
|
va_start(arg, format);
|
|
|
vsprintf(tmp, format, arg);
|
|
|
va_end(arg);
|
|
|
//----------print to command window for trace--------//
|
|
|
//printf("%s\n", tmp);
|
|
|
printf("%s\n", tmp);
|
|
|
//print message to log file
|
|
|
TC_write_syslog("%s\n", tmp);
|
|
|
}
|
|
|
|
|
|
void WriteLog2(logical debug, const char* format, ...)
|
|
|
{
|
|
|
va_list arg;
|
|
|
char tmp[MAX_PRINTLINE_LENGTH];
|
|
|
char date_string[MAX_PATH_LENGTH];
|
|
|
time_t now;
|
|
|
struct tm *p;
|
|
|
|
|
|
//get the message
|
|
|
memset(tmp, 0, sizeof(tmp));
|
|
|
va_start(arg, format);
|
|
|
vsprintf(tmp, format, arg);
|
|
|
va_end(arg);
|
|
|
//----------print to command window for trace--------//
|
|
|
//printf("%s\n", tmp);
|
|
|
printf("%s\n", tmp);
|
|
|
//print message to log file
|
|
|
if (!debug) {
|
|
|
return;
|
|
|
}
|
|
|
if (logFile)
|
|
|
{
|
|
|
time(&now);
|
|
|
//current_time(&status_now);
|
|
|
p = localtime(&now);
|
|
|
memset(date_string, 0, sizeof(date_string));
|
|
|
sprintf(date_string, "%02d:%02d:%02d", p->tm_hour, p->tm_min, p->tm_sec);
|
|
|
fprintf(logFile, "[%s] %s\n", date_string, tmp);
|
|
|
fflush(logFile);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
printf("*!Error!*: Log File Not Exist\n");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void CloseLog(void)
|
|
|
{
|
|
|
if (logFile)
|
|
|
{
|
|
|
fclose(logFile);
|
|
|
logFile = NULL;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
int CreateTempFile(logical debug, const char* temp_path, char *file_name, char* ext, char **fullname, FILE **file)
|
|
|
{
|
|
|
int ifail = ITK_ok;
|
|
|
char logFileName[MAX_PATH_LENGTH];
|
|
|
|
|
|
if (chdir(temp_path) != ITK_ok) {
|
|
|
printf(">> 新建路径:%s", temp_path);
|
|
|
mkdir(temp_path);
|
|
|
}
|
|
|
memset(logFileName, 0, sizeof(logFileName));
|
|
|
//get session_uid to make sure the log file name unique
|
|
|
//POM_ask_session(&session_tag);
|
|
|
//ITK__convert_tag_to_uid(session_tag, &session_uid);
|
|
|
//get logFileName
|
|
|
sprintf(logFileName, "%s.%s", file_name, ext);
|
|
|
//printf("log file name: %s\n", logFileName);
|
|
|
|
|
|
*fullname = (char *)MEM_alloc(sizeof(char) * 512);
|
|
|
sprintf(*fullname, "%s\\%s", temp_path, logFileName);
|
|
|
|
|
|
//for(i = 0; _access((char *)logFileName, 4) == 0; i++)
|
|
|
/*{
|
|
|
memset(logFileName, 0, sizeof(logFileName));
|
|
|
sprintf(logFileName, "%s_%s_%s_%d.log", FunctionName, session_uid, date_string, i);
|
|
|
}
|
|
|
printf("final log file name: %s\n", logFileName);*/
|
|
|
|
|
|
//create log file
|
|
|
*file = fopen(logFileName, "a");
|
|
|
return ITK_ok;
|
|
|
//CLEANUP:;
|
|
|
//DOFREE(date_string);
|
|
|
/*if(session_uid!=NULL){
|
|
|
MEM_free(session_uid);
|
|
|
session_uid=NULL;
|
|
|
}*/
|
|
|
}
|
|
|
|
|
|
|
|
|
int CreateTempFile(logical debug, const char* temp_path, char *file_name, char* user_id, char* ext, char **fullname, FILE **file)
|
|
|
{
|
|
|
int ifail = ITK_ok;
|
|
|
//date_t status_now;
|
|
|
//char* date_string = NULL;
|
|
|
char date_string[MAX_PATH_LENGTH];
|
|
|
char logFileName[MAX_PATH_LENGTH];
|
|
|
//char* session_uid = NULL;
|
|
|
//tag_t session_tag = NULLTAG;
|
|
|
|
|
|
time_t now;
|
|
|
struct tm *p;
|
|
|
|
|
|
time(&now);
|
|
|
|
|
|
//logFile = NULL;
|
|
|
//current_time(&status_now);
|
|
|
p = localtime(&now);
|
|
|
|
|
|
memset(date_string, 0, sizeof(date_string));
|
|
|
sprintf(date_string, "%4d%02d%02d%02d%02d%02d", 1900 + p->tm_year, p->tm_mon + 1, p->tm_mday, p->tm_hour, p->tm_min, p->tm_sec);
|
|
|
//sprintf(date_string, "%4d%02d%02d", 1900 + p->tm_year, p->tm_mon + 1, p->tm_mday);
|
|
|
//if( DATE_date_to_string( status_now, "%Y%m%d%H%M%S", &date_string) != ITK_ok )
|
|
|
//ifail = ITK_date_to_string (status_now, &date_string );
|
|
|
//if (ifail)
|
|
|
//{
|
|
|
// printf("!*ERROR*!: Failed to get current date time\n");
|
|
|
// goto CLEANUP;
|
|
|
//}
|
|
|
if (chdir(temp_path) != ITK_ok) {
|
|
|
printf(">> 新建路径:%s", temp_path);
|
|
|
mkdir(temp_path);
|
|
|
}
|
|
|
memset(logFileName, 0, sizeof(logFileName));
|
|
|
//get session_uid to make sure the log file name unique
|
|
|
//POM_ask_session(&session_tag);
|
|
|
//ITK__convert_tag_to_uid(session_tag, &session_uid);
|
|
|
//get logFileName
|
|
|
sprintf(logFileName, "%s_%s_%s.%s", file_name, user_id, date_string, ext);
|
|
|
//printf("log file name: %s\n", logFileName);
|
|
|
|
|
|
*fullname = (char *)MEM_alloc(sizeof(char) * 512);
|
|
|
sprintf(*fullname, "%s\\%s", temp_path, logFileName);
|
|
|
|
|
|
//for(i = 0; _access((char *)logFileName, 4) == 0; i++)
|
|
|
/*{
|
|
|
memset(logFileName, 0, sizeof(logFileName));
|
|
|
sprintf(logFileName, "%s_%s_%s_%d.log", FunctionName, session_uid, date_string, i);
|
|
|
}
|
|
|
printf("final log file name: %s\n", logFileName);*/
|
|
|
|
|
|
//create log file
|
|
|
*file = fopen(logFileName, "a");
|
|
|
return ITK_ok;
|
|
|
//CLEANUP:;
|
|
|
//DOFREE(date_string);
|
|
|
/*if(session_uid!=NULL){
|
|
|
MEM_free(session_uid);
|
|
|
session_uid=NULL;
|
|
|
}*/
|
|
|
}
|
|
|
|
|
|
|
|
|
int CreateUserFile(logical debug, char* FunctionName, char *userId, char **fullname, FILE **file)
|
|
|
{
|
|
|
int ifail = ITK_ok;
|
|
|
//date_t status_now;
|
|
|
//char* date_string = NULL;
|
|
|
char date_string[MAX_PATH_LENGTH];
|
|
|
char logFileDir[MAX_PATH_LENGTH];
|
|
|
char logFileName[MAX_PATH_LENGTH];
|
|
|
//char* session_uid = NULL;
|
|
|
//tag_t session_tag = NULLTAG;
|
|
|
|
|
|
time_t now;
|
|
|
struct tm *p;
|
|
|
|
|
|
time(&now);
|
|
|
|
|
|
//logFile = NULL;
|
|
|
//current_time(&status_now);
|
|
|
p = localtime(&now);
|
|
|
|
|
|
memset(date_string, 0, sizeof(date_string));
|
|
|
sprintf(date_string, "%4d%02d%02d%02d%02d%02d", 1900 + p->tm_year, p->tm_mon + 1, p->tm_mday, p->tm_hour, p->tm_min, p->tm_sec);
|
|
|
//sprintf(date_string, "%4d%02d%02d", 1900 + p->tm_year, p->tm_mon + 1, p->tm_mday);
|
|
|
//if( DATE_date_to_string( status_now, "%Y%m%d%H%M%S", &date_string) != ITK_ok )
|
|
|
//ifail = ITK_date_to_string (status_now, &date_string );
|
|
|
//if (ifail)
|
|
|
//{
|
|
|
// printf("!*ERROR*!: Failed to get current date time\n");
|
|
|
// goto CLEANUP;
|
|
|
//}
|
|
|
|
|
|
memset(logFileDir, 0, sizeof(logFileDir));
|
|
|
memset(logFileName, 0, sizeof(logFileName));
|
|
|
//get log dir
|
|
|
sprintf(logFileDir, "%s", getenv("TEMP"));
|
|
|
strcat(logFileDir, "\\tc_");
|
|
|
strcat(logFileDir, userId);
|
|
|
//printf("\n log file dir: %s\n", logFileDir);
|
|
|
//try to change dir to TC_USER_LOG_DIR
|
|
|
if (chdir(logFileDir) != ITK_ok)
|
|
|
{
|
|
|
//not set TC_USER_LOG_DIR
|
|
|
//log in to default TC_LOG
|
|
|
memset(logFileDir, 0, sizeof(logFileDir));
|
|
|
sprintf(logFileDir, "%s", getenv("TC_LOG"));
|
|
|
WriteLog(debug, "TC_USER_LOG_DIR invalide, log file dir: %s", logFileDir);
|
|
|
//printf("\n TC_USER_LOG_DIR invalide, log file dir: %s\n", logFileDir);
|
|
|
if (chdir(logFileDir) != ITK_ok)
|
|
|
{
|
|
|
//still can not change to log dir
|
|
|
WriteLog(debug, "!*ERROR*!: Failed to change dir to TC_USER_LOG_DIR");
|
|
|
//printf("!*ERROR*!: Failed to change dir to TC_USER_LOG_DIR\n");
|
|
|
return -1;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//get session_uid to make sure the log file name unique
|
|
|
//POM_ask_session(&session_tag);
|
|
|
//ITK__convert_tag_to_uid(session_tag, &session_uid);
|
|
|
//get logFileName
|
|
|
sprintf(logFileName, "%s_%s_%s.txt", FunctionName, userId, date_string);
|
|
|
//printf("log file name: %s\n", logFileName);
|
|
|
|
|
|
*fullname = (char *)MEM_alloc(sizeof(char) * 512);
|
|
|
sprintf(*fullname, "%s\\%s", logFileDir, logFileName);
|
|
|
|
|
|
//for(i = 0; _access((char *)logFileName, 4) == 0; i++)
|
|
|
/*{
|
|
|
memset(logFileName, 0, sizeof(logFileName));
|
|
|
sprintf(logFileName, "%s_%s_%s_%d.log", FunctionName, session_uid, date_string, i);
|
|
|
}
|
|
|
printf("final log file name: %s\n", logFileName);*/
|
|
|
|
|
|
//create log file
|
|
|
*file = fopen(logFileName, "a");
|
|
|
return ITK_ok;
|
|
|
//CLEANUP:;
|
|
|
//DOFREE(date_string);
|
|
|
/*if(session_uid!=NULL){
|
|
|
MEM_free(session_uid);
|
|
|
session_uid=NULL;
|
|
|
}*/
|
|
|
}
|
|
|
|
|
|
|
|
|
void CreateLogFile(char* FunctionName, char *userId, char **fullname)
|
|
|
{
|
|
|
int ifail = ITK_ok;
|
|
|
//date_t status_now;
|
|
|
//char* date_string = NULL;
|
|
|
char date_string[MAX_PATH_LENGTH];
|
|
|
char logFileDir[MAX_PATH_LENGTH];
|
|
|
char logFileName[MAX_PATH_LENGTH];
|
|
|
//char* session_uid = NULL;
|
|
|
//tag_t session_tag = NULLTAG;
|
|
|
|
|
|
time_t now;
|
|
|
struct tm *p;
|
|
|
|
|
|
time(&now);
|
|
|
|
|
|
logFile = NULL;
|
|
|
//current_time(&status_now);
|
|
|
p = localtime(&now);
|
|
|
|
|
|
memset(date_string, 0, sizeof(date_string));
|
|
|
//sprintf(date_string,"%4d%02d%02d%02d%02d%02d",1900+p->tm_year,p->tm_mon+1 ,p->tm_mday ,p->tm_hour,p->tm_min ,p->tm_sec );
|
|
|
sprintf(date_string, "%4d%02d%02d", 1900 + p->tm_year, p->tm_mon + 1, p->tm_mday);
|
|
|
//if( DATE_date_to_string( status_now, "%Y%m%d%H%M%S", &date_string) != ITK_ok )
|
|
|
//ifail = ITK_date_to_string (status_now, &date_string );
|
|
|
//if (ifail)
|
|
|
//{
|
|
|
// printf("!*ERROR*!: Failed to get current date time\n");
|
|
|
// goto CLEANUP;
|
|
|
//}
|
|
|
|
|
|
memset(logFileDir, 0, sizeof(logFileDir));
|
|
|
memset(logFileName, 0, sizeof(logFileName));
|
|
|
//get log dir
|
|
|
sprintf(logFileDir, "%s", getenv("TEMP"));
|
|
|
strcat(logFileDir, "\\tc_");
|
|
|
strcat(logFileDir, userId);
|
|
|
//printf("\n log file dir: %s\n", logFileDir);
|
|
|
//try to change dir to TC_USER_LOG_DIR
|
|
|
if (chdir(logFileDir) != ITK_ok)
|
|
|
{
|
|
|
//not set TC_USER_LOG_DIR
|
|
|
//log in to default TC_LOG
|
|
|
memset(logFileDir, 0, sizeof(logFileDir));
|
|
|
sprintf(logFileDir, "%s", getenv("TC_LOG"));
|
|
|
printf("\n TC_USER_LOG_DIR invalide, log file dir: %s\n", logFileDir);
|
|
|
if (chdir(logFileDir) != ITK_ok)
|
|
|
{
|
|
|
//still can not change to log dir
|
|
|
printf("!*ERROR*!: Failed to change dir to TC_USER_LOG_DIR\n");
|
|
|
goto CLEANUP;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//get session_uid to make sure the log file name unique
|
|
|
//POM_ask_session(&session_tag);
|
|
|
//ITK__convert_tag_to_uid(session_tag, &session_uid);
|
|
|
//get logFileName
|
|
|
sprintf(logFileName, "%s_%s_%s.log", FunctionName, userId, date_string);
|
|
|
//printf("log file name: %s\n", logFileName);
|
|
|
|
|
|
*fullname = (char *)MEM_alloc(sizeof(char) * 512);
|
|
|
sprintf(*fullname, "%s\\%s", logFileDir, logFileName);
|
|
|
|
|
|
//for(i = 0; _access((char *)logFileName, 4) == 0; i++)
|
|
|
/*{
|
|
|
memset(logFileName, 0, sizeof(logFileName));
|
|
|
sprintf(logFileName, "%s_%s_%s_%d.log", FunctionName, session_uid, date_string, i);
|
|
|
}
|
|
|
printf("final log file name: %s\n", logFileName);*/
|
|
|
|
|
|
//create log file
|
|
|
logFile = fopen(logFileName, "a");
|
|
|
|
|
|
CLEANUP:;
|
|
|
//DOFREE(date_string);
|
|
|
/*if(session_uid!=NULL){
|
|
|
MEM_free(session_uid);
|
|
|
session_uid=NULL;
|
|
|
}*/
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void set_bypass(logical bypass)
|
|
|
{
|
|
|
//AM__set_application_bypass(bypass);
|
|
|
POM_AM__set_application_bypass(bypass);
|
|
|
}
|
|
|
|
|
|
bool isClass(tag_t class_id, char *className) {
|
|
|
tag_t *pclass_ids = NULL;
|
|
|
char* class_name = NULL;
|
|
|
int pclass_count = 0, ifail = ITK_ok;
|
|
|
ITKCALL(POM_name_of_class(class_id, &class_name));
|
|
|
printf("class name = %s\n", class_name);
|
|
|
bool isType = false;
|
|
|
if (strcmp(class_name, className) == 0) {
|
|
|
isType = true;
|
|
|
}
|
|
|
DOFREE(class_name);
|
|
|
if (isType) {
|
|
|
return true;
|
|
|
}
|
|
|
ITKCALL(ifail = POM_superclasses_of_class(class_id, &pclass_count, &pclass_ids));
|
|
|
for (int i = 0; i < pclass_count; i++) {
|
|
|
isType = isClass(pclass_ids[i], className);
|
|
|
if (isType) {
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
bool isType(tag_t item, char* type) {
|
|
|
tag_t class_id = NULLTAG, *pclass_ids = NULL;
|
|
|
char* class_name = NULL;
|
|
|
int pclass_count = 0, ifail = ITK_ok;
|
|
|
|
|
|
ITKCALL(POM_class_of_instance(item, &class_id));
|
|
|
return isClass(class_id, type);
|
|
|
}
|
|
|
|
|
|
void deleteFile(bool debug, char *path) {
|
|
|
//删除文件
|
|
|
if (remove(path) == 0) {
|
|
|
WriteLog(debug, "删除文件成功:%s", path);
|
|
|
WriteLog2(debug, "删除文件成功:%s", path);
|
|
|
}
|
|
|
else {
|
|
|
WriteLog(debug, "删除文件失败:%s", path);
|
|
|
WriteLog2(debug, "删除文件失败:%s", path);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
int readError(bool debug, char *errFilePath, int errCode) {
|
|
|
fstream _file;
|
|
|
_file.open(errFilePath, ios::in);
|
|
|
if (_file) {
|
|
|
WriteLog(debug, "找到异常临时文件:%s", errFilePath);
|
|
|
ifstream fin(errFilePath);
|
|
|
string s;
|
|
|
while (getline(fin, s))
|
|
|
{
|
|
|
WriteLog(debug, s.c_str());
|
|
|
EMH_store_error_s1(EMH_severity_error, errCode, s.c_str());
|
|
|
}
|
|
|
_file.close();
|
|
|
return errCode;
|
|
|
}
|
|
|
return ITK_ok;
|
|
|
}
|
|
|
|
|
|
//导入数据集
|
|
|
int import_dataset_file(tag_t dataset, const char *ref_name, char *ext, char *fullfilename, char *original_name)
|
|
|
{
|
|
|
int ifail = ITK_ok;
|
|
|
tag_t new_file_tag = NULLTAG;
|
|
|
IMF_file_t file_descriptor = NULL;
|
|
|
AOM_refresh(dataset, FALSE);
|
|
|
char *new_file_name = NULL;
|
|
|
char new_ds_name[WSO_name_size_c + 1] = "";
|
|
|
char *filename = NULL;
|
|
|
new_file_name = USER_new_file_name(new_ds_name, ref_name, ext, 0);
|
|
|
filename = strrchr(fullfilename, '\\') + 1;
|
|
|
if (filename == NULL)
|
|
|
return ITK_ok;
|
|
|
|
|
|
ITKCALL(ifail = IMF_import_file(fullfilename, new_file_name, SS_TEXT, &new_file_tag, &file_descriptor));
|
|
|
if (ifail != ITK_ok) {
|
|
|
ITKCALL(ifail = IMF_import_file(fullfilename, new_file_name, SS_BINARY, &new_file_tag, &file_descriptor));
|
|
|
}
|
|
|
ITKCALL(ifail = IMF_set_original_file_name2(new_file_tag, original_name));
|
|
|
|
|
|
ITKCALL(ifail = IMF_close_file(file_descriptor));
|
|
|
ITKCALL(ifail = AOM_save(new_file_tag));
|
|
|
AOM_unlock(new_file_tag);
|
|
|
ITKCALL(ifail = AOM_refresh(new_file_tag, FALSE));
|
|
|
|
|
|
ITKCALL(AOM_lock(dataset));
|
|
|
if (ifail != ITK_ok) { return ifail; }
|
|
|
ITKCALL(ifail = RES_checkout2(dataset, "import file", NULL, getenv("TEMP"), RES_EXCLUSIVE_RESERVE));
|
|
|
if (ifail != ITK_ok) { return ifail; }
|
|
|
ITKCALL(ifail = AE_remove_dataset_named_ref2(dataset, ref_name));
|
|
|
ITKCALL(ifail = AOM_save(dataset));
|
|
|
|
|
|
ITKCALL(ifail = AE_add_dataset_named_ref2(dataset, ref_name, AE_PART_OF, new_file_tag));
|
|
|
AOM_save(dataset);
|
|
|
ITKCALL(ifail = RES_checkin(dataset));
|
|
|
AOM_unlock(dataset);
|
|
|
|
|
|
//ITKCALL( AOM_refresh( dataset, FALSE ) );
|
|
|
return ifail;
|
|
|
}
|
|
|
|
|
|
//导入数据集
|
|
|
int import_dataset_file_binary(tag_t dataset, const char* temp_path, const char *ref_name, char *ext, char *fullfilename, char *original_name)
|
|
|
{
|
|
|
int ifail = ITK_ok;
|
|
|
tag_t new_file_tag = NULLTAG;
|
|
|
IMF_file_t file_descriptor = NULL;
|
|
|
AOM_refresh(dataset, FALSE);
|
|
|
char *new_file_name = NULL;
|
|
|
char new_ds_name[WSO_name_size_c + 1] = "";
|
|
|
char *filename = NULL;
|
|
|
new_file_name = USER_new_file_name(new_ds_name, ref_name, ext, 0);
|
|
|
filename = strrchr(fullfilename, '\\') + 1;
|
|
|
if (filename == NULL)
|
|
|
return ITK_ok;
|
|
|
ITKCALL(ifail = IMF_import_file(fullfilename, new_file_name, SS_BINARY, &new_file_tag, &file_descriptor));
|
|
|
ITKCALL(ifail = IMF_set_original_file_name2(new_file_tag, original_name));
|
|
|
|
|
|
ITKCALL(ifail = IMF_close_file(file_descriptor));
|
|
|
ITKCALL(ifail = AOM_save(new_file_tag));
|
|
|
AOM_unlock(new_file_tag);
|
|
|
ITKCALL(ifail = AOM_refresh(new_file_tag, FALSE));
|
|
|
//添加至命名引用
|
|
|
ITKCALL(ifail = AOM_lock(dataset));
|
|
|
if (ifail != ITK_ok) { return ifail; }
|
|
|
ITKCALL(ifail = RES_checkout2(dataset, "import file", NULL, temp_path, RES_EXCLUSIVE_RESERVE));
|
|
|
if (ifail != ITK_ok) { return ifail; }
|
|
|
ITKCALL(ifail = AE_remove_dataset_named_ref2(dataset, ref_name));
|
|
|
if (ifail != ITK_ok) { return ifail; }
|
|
|
ITKCALL(ifail = AOM_save(dataset));
|
|
|
ITKCALL(ifail = AE_add_dataset_named_ref2(dataset, ref_name, AE_PART_OF, new_file_tag));
|
|
|
AOM_save(dataset);
|
|
|
ITKCALL(ifail = RES_checkin(dataset));
|
|
|
AOM_unlock(dataset);
|
|
|
//ITKCALL( AOM_refresh( dataset, FALSE ) );
|
|
|
return ifail;
|
|
|
}
|
|
|
|
|
|
|
|
|
void Split(string strArg, char spliter, vector<string> &ans)
|
|
|
{
|
|
|
ans.clear();
|
|
|
size_t index0 = 0;
|
|
|
string one_arg;
|
|
|
if (strArg.find_first_not_of(' ') == string::npos)
|
|
|
strArg = "";
|
|
|
while (strArg.size() > 0)
|
|
|
{
|
|
|
index0 = strArg.find_first_of(spliter);
|
|
|
if (index0 != string::npos)
|
|
|
{
|
|
|
one_arg = strArg.substr(0, index0);
|
|
|
strArg = strArg.substr(index0 + 1);
|
|
|
ans.push_back(one_arg);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
ans.push_back(strArg);
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void Split(string strArg, string spliter, vector<string> &ans)
|
|
|
{
|
|
|
ans.clear();
|
|
|
size_t index0 = 0;
|
|
|
string one_arg;
|
|
|
if (strArg.find_first_not_of(' ') == string::npos)
|
|
|
strArg = "";
|
|
|
while (strArg.size() > 0)
|
|
|
{
|
|
|
index0 = strArg.find_first_of(spliter);
|
|
|
if (index0 != string::npos)
|
|
|
{
|
|
|
one_arg = strArg.substr(0, index0);
|
|
|
strArg = strArg.substr(index0 + 1);
|
|
|
ans.push_back(one_arg);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
ans.push_back(strArg);
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
bool inArray(vector<string> types, string type) {
|
|
|
int len = types.size();
|
|
|
for (int i = 0; i < len; i++) {
|
|
|
if (strcmp(types[i].c_str(), type.c_str()) == 0) {
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
int getIndexInArray(vector<string> types, string type) {
|
|
|
int len = types.size();
|
|
|
for (int i = 0; i < len; i++) {
|
|
|
if (strcmp(types[i].c_str(), type.c_str()) == 0) {
|
|
|
return i;
|
|
|
}
|
|
|
}
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
bool CheckType(string config, char* type, char spliter) {
|
|
|
vector<string> types;
|
|
|
Split(config, spliter, types);
|
|
|
int len = types.size();
|
|
|
for (int i = 0; i < len; i++) {
|
|
|
if (strcmp(types[i].c_str(), type) == 0) {
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
int GetProcessTargets(bool debug, int att_cnt, tag_t *attachments, vector<tag_t> &targets, char* formType, char splitter) {
|
|
|
char *object_name = NULL, *object_type = NULL;
|
|
|
int ifail = ITK_ok;
|
|
|
WriteLog(debug, "开始检索流程目标对象:%d", att_cnt);
|
|
|
for (int i = 0; i < att_cnt; i++) {
|
|
|
ITKCALL(ifail = WSOM_ask_name2(attachments[i], &object_name));
|
|
|
ITKCALL(ifail = WSOM_ask_object_type2(attachments[i], &object_type));
|
|
|
WriteLog(debug, "%d. 流程对象<%s>,类型:%s", i + 1, object_name, object_type);
|
|
|
//if (strcmp(object_type, TYPE_ITEM_PZJ.c_str()) == 0) {
|
|
|
if (CheckType(formType, object_type, splitter)) {
|
|
|
targets.push_back(attachments[i]);
|
|
|
}
|
|
|
DOFREE(object_name);
|
|
|
DOFREE(object_type);
|
|
|
}
|
|
|
return ITK_ok;
|
|
|
}
|
|
|
|
|
|
int findUser(bool debug, string userStr, tag_t *user_tag) {
|
|
|
int ind1 = userStr.find_first_of('(');
|
|
|
int ind2 = userStr.find_first_of(')');
|
|
|
WriteLog(debug, "查询用户:%s", userStr.c_str());
|
|
|
if (ind1 != string::npos&&ind2 != string::npos&&ind1 < ind2) {
|
|
|
userStr = userStr.substr(ind1 + 1, ind2 - ind1 - 1);
|
|
|
WriteLog(debug, ">> 用户id: %s", userStr.c_str());
|
|
|
}
|
|
|
int ifail = ITK_ok;
|
|
|
ITKCALL(ifail = SA_find_user2(userStr.c_str(), user_tag));
|
|
|
return ifail;
|
|
|
}
|
|
|
|
|
|
int GetBomLinePropString(bool debug, tag_t line, char* propName, int errCode, char** attr_val) {
|
|
|
int attribute_id = 0, ifail = ITK_ok;
|
|
|
ITKCALL(ifail = BOM_line_look_up_attribute(propName, &attribute_id));
|
|
|
if (attribute_id == 0) {
|
|
|
WriteLog(debug, "BOM行属性不存在:%s", propName);
|
|
|
EMH_store_error_s2(EMH_severity_error, errCode, "BOM行属性不存在", propName);
|
|
|
return errCode;
|
|
|
}
|
|
|
else {
|
|
|
ITKCALL(ifail = BOM_line_ask_attribute_string(line, attribute_id, &*attr_val));
|
|
|
return ifail;
|
|
|
}
|
|
|
return ITK_ok;
|
|
|
}
|
|
|
|
|
|
int GetStringProp(tag_t obj, char* propName, char** attr_val) {
|
|
|
return AOM_ask_value_string(obj, propName, &*attr_val);
|
|
|
}
|
|
|
|
|
|
void CreateDirectoryAndFile(const char* directory_path, const char* file_path) {
|
|
|
// 将目录路径转换为宽字符串
|
|
|
wchar_t w_directory_path[MAX_PATH];
|
|
|
MultiByteToWideChar(CP_UTF8, 0, directory_path, -1, w_directory_path, MAX_PATH);
|
|
|
|
|
|
// 检查文件夹是否存在,如果不存在则创建
|
|
|
DWORD dwAttrib = GetFileAttributes(w_directory_path);
|
|
|
if (dwAttrib == INVALID_FILE_ATTRIBUTES || !(dwAttrib & FILE_ATTRIBUTE_DIRECTORY)) {
|
|
|
// 文件夹不存在,尝试创建
|
|
|
if (_wmkdir(w_directory_path) != 0) {
|
|
|
perror("Failed to create directory.");
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 将文件路径转换为宽字符串
|
|
|
wchar_t w_file_path[MAX_PATH];
|
|
|
MultiByteToWideChar(CP_UTF8, 0, file_path, -1, w_file_path, MAX_PATH);
|
|
|
|
|
|
// 检查文件是否存在,如果不存在则创建
|
|
|
FILE* file = fopen(file_path, "r");
|
|
|
if (file == NULL) {
|
|
|
// 文件不存在,尝试创建并打开(这里以追加模式打开)
|
|
|
file = fopen(file_path, "a+");
|
|
|
if (file == NULL) {
|
|
|
perror("Failed to create and open file.");
|
|
|
return;
|
|
|
}
|
|
|
fclose(file); // 关闭刚创建的文件
|
|
|
}
|
|
|
else {
|
|
|
fclose(file); // 如果文件已存在,则关闭打开的文件句柄
|
|
|
}
|
|
|
}
|
|
|
|
|
|
bool isRev(char* object_type) {
|
|
|
if (((strstr(object_type, "Revision") != NULL) || (strstr(object_type, "revision") != NULL))
|
|
|
&& (strstr(object_type, "Master") == NULL) && (strstr(object_type, "master") == NULL)
|
|
|
&& (strstr(object_type, "BOM") == NULL) && (strstr(object_type, "bom") == NULL) && (strstr(object_type, "Bom") == NULL)) {
|
|
|
return true;
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
int GetBomView(tag_t rev_tag, char* viewtype, tag_t *bomView, tag_t *bomBVR, bool debug)
|
|
|
{
|
|
|
WriteLog(debug, "开始获取BOM视图:%s", viewtype);
|
|
|
int ifail = ITK_ok, bvr_count = 0;
|
|
|
tag_t *bvr_list = NULL, bom_view = NULLTAG, view_type = NULLTAG;
|
|
|
*bomBVR = NULLTAG;
|
|
|
*bomView = NULLTAG;
|
|
|
ITKCALL(ITEM_rev_list_bom_view_revs(rev_tag, &bvr_count, &bvr_list));
|
|
|
if (bvr_count > 0)
|
|
|
{
|
|
|
for (int i = 0; i < bvr_count; i++)
|
|
|
{
|
|
|
ITKCALL(PS_ask_bom_view_of_bvr(bvr_list[i], &bom_view));
|
|
|
|
|
|
ITKCALL(PS_ask_bom_view_type(bom_view, &view_type));
|
|
|
//ITKCALL( PS_find_view_type(bom_view, &view_type));
|
|
|
char *view_type_name = NULL;
|
|
|
ITKCALL(PS_ask_view_type_name(view_type, &view_type_name));
|
|
|
WriteLog(debug, "找到视图 类型:%s", view_type_name);
|
|
|
if (tc_strcmp(view_type_name, viewtype) == 0)
|
|
|
{
|
|
|
*bomBVR = bvr_list[i];
|
|
|
*bomView = bom_view;
|
|
|
}
|
|
|
DOFREE(view_type_name);
|
|
|
}
|
|
|
}
|
|
|
//else {
|
|
|
// WriteLog(debug, "没有找到bvr开始进行创建");
|
|
|
// tag_t bv = NULLTAG, bvr = NULLTAG, item_tag = NULLTAG;
|
|
|
// int bvCnt = 0;
|
|
|
// tag_t* bvTags = NULL;
|
|
|
|
|
|
|
|
|
// ITKCALL(ifail = ITEM_ask_item_of_rev(rev_tag, &item_tag));
|
|
|
|
|
|
|
|
|
// tag_t tWindow = NULLTAG;
|
|
|
// ITKCALL(BOM_create_window(&tWindow));
|
|
|
|
|
|
// tag_t tTopLine = NULLTAG;
|
|
|
// ITKCALL(BOM_set_window_top_line(tWindow, item_tag, NULLTAG, NULLTAG, &tTopLine));
|
|
|
|
|
|
// //查找原BOM视图
|
|
|
// ITKCALL(ifail=ITEM_list_bom_views(item_tag, &bvCnt, &bvTags));
|
|
|
// if (bvCnt > 0) {
|
|
|
// WriteLog(debug, "对象已存在BOM视图:%d", bvCnt);
|
|
|
// bv = bvTags[0];
|
|
|
// }
|
|
|
// ITKCALL(AOM_lock(item_tag));
|
|
|
// if (bv == NULLTAG) {
|
|
|
// ITKCALL(ifail=PS_create_bom_view(NULLTAG, "", "", item_tag, &bv));
|
|
|
// if (ifail != ITK_ok) {
|
|
|
// ITKCALL(AOM_unlock(item_tag));
|
|
|
// return ifail;
|
|
|
// }
|
|
|
// ITKCALL(AOM_save(bv));
|
|
|
// }
|
|
|
// ITKCALL(ifail=PS_create_bvr(bv, "", "", false, rev_tag, &bvr));
|
|
|
// if (ifail != ITK_ok) {
|
|
|
// ITKCALL(AOM_unlock(item_tag));
|
|
|
// return ifail;
|
|
|
// }
|
|
|
// ITKCALL(AOM_save(bvr));
|
|
|
// ITKCALL(AOM_save(bv));
|
|
|
// ITKCALL(AOM_save(item_tag));
|
|
|
|
|
|
// tag_t tChildLine = NULLTAG;
|
|
|
|
|
|
// ITKCALL(BOM_save_window(tWindow));
|
|
|
// ITKCALL(BOM_close_window(tWindow));
|
|
|
|
|
|
// ITKCALL(AOM_unlock(item_tag));
|
|
|
// *bomBVR = bvr;
|
|
|
// *bomView = bv;
|
|
|
// WriteLog(debug, "bvr新建完成");
|
|
|
// DOFREE(bvTags);
|
|
|
|
|
|
//}
|
|
|
DOFREE(bvr_list);
|
|
|
return ifail;
|
|
|
}
|
|
|
|
|
|
bool propExist(bool debug, tag_t obj, const char *propName) {
|
|
|
tag_t clTag = NULLTAG, *superClass = NULL;
|
|
|
char *clName = NULL;
|
|
|
int ifail = ITK_ok, cnt = 0;
|
|
|
logical exists = false;
|
|
|
ITKCALL(ifail = POM_class_of_instance(obj, &clTag));
|
|
|
if (ifail != ITK_ok) { return false; }
|
|
|
ITKCALL(ifail = POM_name_of_class(clTag, &clName));
|
|
|
if (ifail != ITK_ok) { return false; }
|
|
|
WriteLog(debug, ">> 检查%s属性: %s", clName, propName);
|
|
|
ITKCALL(ifail = POM_attr_exists(propName, clName, &exists));
|
|
|
if (ifail != ITK_ok) { return false; }
|
|
|
DOFREE(clName);
|
|
|
if (exists) {
|
|
|
//WriteLog(debug,"属性存在");
|
|
|
return exists;
|
|
|
}
|
|
|
ITKCALL(ifail = POM_superclasses_of_class(clTag, &cnt, &superClass));
|
|
|
for (int i = 0; i < cnt; i++) {
|
|
|
ITKCALL(ifail = POM_name_of_class(superClass[i], &clName));
|
|
|
if (ifail != ITK_ok) { return false; }
|
|
|
WriteLog(debug, ">> 检查%s属性: %s", clName, propName);
|
|
|
ITKCALL(ifail = POM_attr_exists(propName, clName, &exists));
|
|
|
DOFREE(clName);
|
|
|
if (exists) {
|
|
|
//WriteLog(debug, "属性存在");
|
|
|
return exists;
|
|
|
}
|
|
|
}
|
|
|
WriteLog(debug, "属性不存在");
|
|
|
return exists;
|
|
|
}
|
|
|
|
|
|
char* U2G(const char* utf8)
|
|
|
{
|
|
|
int len = MultiByteToWideChar(CP_UTF8, 0, utf8, -1, NULL, 0);
|
|
|
wchar_t* wstr = new wchar_t[len + 1];
|
|
|
memset(wstr, 0, len + 1);
|
|
|
MultiByteToWideChar(CP_UTF8, 0, utf8, -1, wstr, len);
|
|
|
len = WideCharToMultiByte(CP_ACP, 0, wstr, -1, NULL, 0, NULL, NULL);
|
|
|
char* str = new char[len + 1];
|
|
|
memset(str, 0, len + 1);
|
|
|
WideCharToMultiByte(CP_ACP, 0, wstr, -1, str, len, NULL, NULL);
|
|
|
if (wstr) delete[] wstr;
|
|
|
return str;
|
|
|
}
|
|
|
|
|
|
|
|
|
char* G2U(const char* gb2312)
|
|
|
{
|
|
|
int len = MultiByteToWideChar(CP_ACP, 0, gb2312, -1, NULL, 0);
|
|
|
wchar_t* wstr = new wchar_t[len + 1];
|
|
|
memset(wstr, 0, len + 1);
|
|
|
MultiByteToWideChar(CP_ACP, 0, gb2312, -1, wstr, len);
|
|
|
len = WideCharToMultiByte(CP_UTF8, 0, wstr, -1, NULL, 0, NULL, NULL);
|
|
|
char* str = new char[len + 1];
|
|
|
memset(str, 0, len + 1);
|
|
|
WideCharToMultiByte(CP_UTF8, 0, wstr, -1, str, len, NULL, NULL);
|
|
|
if (wstr) delete[] wstr;
|
|
|
return str;
|
|
|
}
|
|
|
|
|
|
int getPrefStrings(const char *preference, TC_preference_search_scope_t scope, vector<string> &pref_vec)
|
|
|
{
|
|
|
int ifail = ITK_ok, i = 0, j = 0, k = 0, num = 0;
|
|
|
char **values;
|
|
|
TC_preference_search_scope_t old_scope;
|
|
|
//ITKCALL(ifail = PREF_ask_search_scope(&old_scope));
|
|
|
//ITKCALL(ifail = PREF_set_search_scope(scope));
|
|
|
//ITKCALL(ifail = PREF_ask_char_values(preference, &num, &values));
|
|
|
ITKCALL(ifail = PREF_ask_char_values_at_location(preference, scope, &num, &values));
|
|
|
if (ifail != ITK_ok) {
|
|
|
return ifail;
|
|
|
}
|
|
|
for (i = 0; i < num; i++)
|
|
|
{
|
|
|
pref_vec.push_back(values[i]);
|
|
|
}
|
|
|
DOFREE(values);
|
|
|
//ITKCALL(ifail = PREF_set_search_scope(old_scope));
|
|
|
return ifail;
|
|
|
}
|
|
|
|
|
|
int getPrefStrings2(const char *preference, TC_preference_search_scope_t scope, char splitter, vector<string> &pref_vec)
|
|
|
{
|
|
|
int ifail = ITK_ok, i = 0, j = 0, k = 0, num = 0;
|
|
|
char **values;
|
|
|
TC_preference_search_scope_t old_scope;
|
|
|
//ITKCALL(ifail = PREF_ask_search_scope(&old_scope));
|
|
|
//ITKCALL(ifail = PREF_set_search_scope(scope));
|
|
|
//ITKCALL(ifail = PREF_ask_char_values(preference, &num, &values));
|
|
|
ITKCALL(ifail = PREF_ask_char_values_at_location(preference, scope, &num, &values));
|
|
|
if (ifail != ITK_ok) {
|
|
|
return ifail;
|
|
|
}
|
|
|
for (i = 0; i < num; i++)
|
|
|
{
|
|
|
vector<string> split;
|
|
|
Split(values[i], splitter, split);
|
|
|
for each (string val in split)
|
|
|
{
|
|
|
pref_vec.push_back(val);
|
|
|
}
|
|
|
}
|
|
|
DOFREE(values);
|
|
|
//ITKCALL(ifail = PREF_set_search_scope(old_scope));
|
|
|
return ifail;
|
|
|
}
|
|
|
|
|
|
|
|
|
//导出数据集文件
|
|
|
int export_dataset_file_to_dir(bool debug, tag_t dataset, const char *ref_name, const char* temp_path, char *ext, char **filename, char **original_name)
|
|
|
{
|
|
|
int ifail = ITK_ok;
|
|
|
tag_t ref_object = NULLTAG,
|
|
|
datasettype = NULLTAG,
|
|
|
new_ds = NULLTAG,
|
|
|
tool = NULLTAG,
|
|
|
folder_tag = NULLTAG,
|
|
|
spec_dataset_rev = NULLTAG;
|
|
|
AE_reference_type_t reference_type;
|
|
|
tag_t new_file_tag = NULLTAG;
|
|
|
IMF_file_t file_descriptor;
|
|
|
char *target_ds_name = NULL;
|
|
|
char *new_file_name;
|
|
|
WSOM_ask_name2(dataset, &target_ds_name);
|
|
|
WriteLog(debug, "开始从数据集<%s>下载文件", target_ds_name);
|
|
|
DOFREE(target_ds_name);
|
|
|
*filename = (char *)MEM_alloc(sizeof(char) * 512);
|
|
|
*original_name = (char *)MEM_alloc(sizeof(char) * 512);
|
|
|
strcpy(*filename, "");
|
|
|
AE_ask_dataset_latest_rev(dataset, &spec_dataset_rev);
|
|
|
AE_ask_dataset_named_ref2(dataset, ref_name, &reference_type, &ref_object);
|
|
|
if (ref_object == NULLTAG)
|
|
|
{
|
|
|
WriteLog(debug, "文件引用为空");
|
|
|
return 1;
|
|
|
}
|
|
|
if (reference_type == AE_PART_OF)
|
|
|
{
|
|
|
char *pathname2 = NULL;
|
|
|
IMF_ask_file_pathname2(ref_object, SS_WNT_MACHINE, &pathname2);
|
|
|
DOFREE(pathname2);
|
|
|
char *origin_file_name2 = NULL;
|
|
|
IMF_ask_original_file_name2(ref_object, &origin_file_name2);
|
|
|
strcpy(*original_name, origin_file_name2);
|
|
|
DOFREE(origin_file_name2);
|
|
|
char new_ds_name[WSO_name_size_c + 1] = "";
|
|
|
char *new_file_name = USER_new_file_name(new_ds_name, ref_name, ext, 0);
|
|
|
char temp_file[SS_MAXPATHLEN] = "";
|
|
|
strcpy(temp_file, temp_path);
|
|
|
strcat(temp_file, "\\");
|
|
|
strcat(temp_file, new_file_name);
|
|
|
WriteLog(debug, "临时文件路径:%s", temp_file);
|
|
|
if ((_access(temp_file, 0)) != -1) {
|
|
|
if (!remove(temp_file)) {
|
|
|
remove(temp_file);
|
|
|
}
|
|
|
}
|
|
|
ITKCALL(ifail = IMF_export_file(ref_object, temp_file));
|
|
|
strcpy(*filename, temp_file);
|
|
|
return ifail;
|
|
|
}
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
bool exists_test0(const std::string& name) {
|
|
|
ifstream f(name.c_str());
|
|
|
return f.good();
|
|
|
}
|
|
|
|
|
|
//导出数据集文件
|
|
|
int export_dataset_file(tag_t dataset, char *ref_name, char *ext, char **filename, char **original_name)
|
|
|
{
|
|
|
int ifail = ITK_ok;
|
|
|
tag_t ref_object = NULLTAG,
|
|
|
datasettype = NULLTAG,
|
|
|
new_ds = NULLTAG,
|
|
|
tool = NULLTAG,
|
|
|
folder_tag = NULLTAG,
|
|
|
spec_dataset_rev = NULLTAG;
|
|
|
AE_reference_type_t reference_type;
|
|
|
tag_t new_file_tag = NULLTAG;
|
|
|
IMF_file_t file_descriptor;
|
|
|
char new_ds_name[WSO_name_size_c + 1] = "";
|
|
|
char *new_file_name;
|
|
|
|
|
|
*filename = (char *)MEM_alloc(sizeof(char) * 5120);
|
|
|
*original_name = (char *)MEM_alloc(sizeof(char) * 5120);
|
|
|
strcpy(*filename, "");
|
|
|
AE_ask_dataset_latest_rev(dataset, &spec_dataset_rev);
|
|
|
AE_ask_dataset_named_ref2(dataset, ref_name, &reference_type, &ref_object);
|
|
|
if (ref_object == NULLTAG)
|
|
|
{
|
|
|
//ECHO("ref_object is NULLTAG\n");
|
|
|
return 1;
|
|
|
}
|
|
|
//WriteLog("\reference_type=%d\n",reference_type);
|
|
|
if (reference_type == AE_PART_OF)
|
|
|
{
|
|
|
char *pathname = NULL;
|
|
|
IMF_ask_file_pathname2(ref_object, SS_WNT_MACHINE, &pathname);
|
|
|
char *origin_file_name = NULL;
|
|
|
IMF_ask_original_file_name2(ref_object, &origin_file_name);
|
|
|
strcpy(*original_name, origin_file_name);
|
|
|
char new_ds_name[WSO_name_size_c + 1] = "";
|
|
|
char *new_file_name = USER_new_file_name(new_ds_name, ref_name, ext, 0);
|
|
|
char *temp_dir = getenv("TEMP");
|
|
|
char temp_file[SS_MAXPATHLEN] = "";
|
|
|
strcpy(temp_file, temp_dir);
|
|
|
strcat(temp_file, "\\");
|
|
|
strcat(temp_file, new_file_name);
|
|
|
//ECHO("temp_file=%s\n", temp_file);
|
|
|
|
|
|
IMF_export_file(ref_object, temp_file);
|
|
|
strcpy(*filename, temp_file);
|
|
|
}
|
|
|
return ITK_ok;
|
|
|
}
|
|
|
|
|
|
|
|
|
//导出数据集文件
|
|
|
int export_dataset_file(bool debug, tag_t dataset, const char *ref_name, char* userId, char *ext, char **filename, char **original_name)
|
|
|
{
|
|
|
int ifail = ITK_ok;
|
|
|
tag_t ref_object = NULLTAG,
|
|
|
datasettype = NULLTAG,
|
|
|
new_ds = NULLTAG,
|
|
|
tool = NULLTAG,
|
|
|
folder_tag = NULLTAG,
|
|
|
spec_dataset_rev = NULLTAG;
|
|
|
AE_reference_type_t reference_type;
|
|
|
tag_t new_file_tag = NULLTAG;
|
|
|
IMF_file_t file_descriptor;
|
|
|
char *target_ds_name = NULL;
|
|
|
char *new_file_name;
|
|
|
WSOM_ask_name2(dataset, &target_ds_name);
|
|
|
WriteLog(debug, "开始从数据集<%s>下载文件", target_ds_name);
|
|
|
DOFREE(target_ds_name);
|
|
|
*filename = (char *)MEM_alloc(sizeof(char) * 512);
|
|
|
*original_name = (char *)MEM_alloc(sizeof(char) * 512);
|
|
|
strcpy(*filename, "");
|
|
|
AE_ask_dataset_latest_rev(dataset, &spec_dataset_rev);
|
|
|
AE_ask_dataset_named_ref2(dataset, ref_name, &reference_type, &ref_object);
|
|
|
if (ref_object == NULLTAG)
|
|
|
{
|
|
|
WriteLog(debug, "文件引用为空");
|
|
|
return 1;
|
|
|
}
|
|
|
if (reference_type == AE_PART_OF)
|
|
|
{
|
|
|
char *pathname2 = NULL;
|
|
|
IMF_ask_file_pathname2(ref_object, SS_WNT_MACHINE, &pathname2);
|
|
|
DOFREE(pathname2);
|
|
|
char *origin_file_name2 = NULL;
|
|
|
IMF_ask_original_file_name2(ref_object, &origin_file_name2);
|
|
|
strcpy(*original_name, origin_file_name2);
|
|
|
DOFREE(origin_file_name2);
|
|
|
char new_ds_name[WSO_name_size_c + 1] = "";
|
|
|
char *new_file_name = USER_new_file_name(new_ds_name, ref_name, ext, 0);
|
|
|
char *temp_dir = getenv("TEMP");
|
|
|
char temp_file[SS_MAXPATHLEN] = "";
|
|
|
strcpy(temp_file, temp_dir);
|
|
|
strcat(temp_file, "\\tc_");
|
|
|
strcat(temp_file, userId);
|
|
|
strcat(temp_file, "\\");
|
|
|
strcat(temp_file, new_file_name);
|
|
|
WriteLog(debug, "临时文件路径:%s", temp_file);
|
|
|
|
|
|
if ((_access(temp_file, 0)) != -1) {
|
|
|
if (!remove(temp_file)) {
|
|
|
remove(temp_file);
|
|
|
}
|
|
|
}
|
|
|
IMF_export_file(ref_object, temp_file);
|
|
|
strcpy(*filename, temp_file);
|
|
|
return ITK_ok;
|
|
|
}
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
//得到文件中的所有内容
|
|
|
char* getfileall(const char* fname)
|
|
|
{
|
|
|
FILE* fp;
|
|
|
char* str;
|
|
|
char txt[1000];
|
|
|
int filesize;
|
|
|
//打开一个文件
|
|
|
if ((fp = fopen(fname, "r")) == NULL) {
|
|
|
printf("打开文件%s错误\n", fname);
|
|
|
return NULL;
|
|
|
}
|
|
|
//将文件指针移到末尾
|
|
|
fseek(fp, 0, SEEK_END);
|
|
|
filesize = ftell(fp);//通过ftell函数获得指针到文件头的偏移字节数。
|
|
|
|
|
|
str = (char*)malloc(filesize);//动态分配str内存
|
|
|
// str=malloc(filesize);//动态分配str内存
|
|
|
str[0] = 0;//字符串置空
|
|
|
// memset(str,filesize*sizeof(char),0);//清空数组,字符串置空第二种用法
|
|
|
rewind(fp);
|
|
|
|
|
|
while ((fgets(txt, 1000, fp)) != NULL) {//循环读取1000字节,如果没有数据则退出循环
|
|
|
strcat(str, txt);//拼接字符串
|
|
|
}
|
|
|
fclose(fp);
|
|
|
return str;
|
|
|
} |