ITK开发入门
1、ITK-Handler开发介绍
在Teamcenter EPM企业流程管理模块中,添加开发入口作为触发点。按照OOTB的流程,流程中Handler分为rule Hander和actiion Handler,程序中可以接收配置的参数名称和参数值作为入参。
2、ITK-Handler开发所需工具和开发环境配置
2.1vs中新建空项目
2.编辑工程属性
3、hello,world实例程序
handlers_register_callbacks.cpp
#include "Header.h"
#include "Handler_register.h"
#include "CommonFunc.h"
#ifdef __cplusplus
extern "C" {
#endif
extern DLLAPI int handlerTest_register_callbacks()
{
int ifail = ITK_ok;
CommonFunc::WriteInfoLog("********TC成功加载handlerTest************");
ITKCALL(ifail = CUSTOM_register_exit("handlerTest", "USER_gs_shell_init_module", (CUSTOM_EXIT_ftn_t)Handler_Register));
return ifail;
}
#ifdef __cplusplus
}
#endif
Handler_register.cpp
#include "Handler_Register.h"
#include "CommonFunc.h"
#include "Header.h"
//============================================
// 说明: 此函数用来注册Handlers
//============================================
extern DLLAPI int Handler_Register(int *decision, va_list args)
{
int status = ITK_ok;
*decision = ALL_CUSTOMIZATIONS;
CommonFunc::WriteInfoLog("> > > 开始注册action_func_test_name ... \n");
#pragma region ================注册TC的 action 的Handler========================
ITKCALL(status = EPM_register_action_handler("action_func_test_name","描述",action_func_test));
if (status == ITK_ok)
{
CommonFunc::WriteInfoLog("成功: 注册action_func_test_name ... ");
}
else
{
CommonFunc::WriteInfoLog("失败:action_func_test_name... ");
}
#pragma endregion
CommonFunc::WriteInfoLog("> > > 开始注册rule_func_test_name ... \n");
#pragma region ================注册TC的 rule 的Handler========================
ITKCALL(status = EPM_register_rule_handler("rule_func_test_name","描述",rule_func_test));
if (status == ITK_ok)
{
CommonFunc::WriteInfoLog("成功: 注册rule_func_test_name ... ");
}
else
{
CommonFunc::WriteInfoLog("失败: 注册rule_func_test_name ... ");
}
#pragma endregion
return status;
}
action_func_test.cpp
#include "CommonFunc.h"
#include "Header.h"
#define DELIMITER "\\"
#define TMPDIR "temp"
#define TC_ROOT "FMS_HOME"
#include <windows.h>
#include<io.h>
#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
int action_func_test(EPM_action_message_t msg)
{
CommonFunc::WriteInfoLog("action_func_test入口");
string errorStr = "错误:action_func_test:>>";
int result=EPM_go;
int rcode = ITK_ok;
int argsCount = 0;
bool isDebug = true;//是为了在控制台写log,正式包改为false
string para_status="";
char* paraArgsValue = NULL;
argsCount = TC_number_of_arguments(msg.arguments);
TC_init_argument_list(msg.arguments);
string datasetCheckStr="";
string attachType;
bool datasetCheckFlag=false;
bool typeFlag=false;
bool hasTypeFlag=false;
bool hasdatasetCheckFlag=false;
if(argsCount!=2)
{
rcode=ERROR_PARAMETER_LACK;
string logStr ="流程模板配置错误(检查到action_func_test参数数量不为2),请联系管理员";
CommonFunc::WriteInfoLog(logStr.c_str());
logStr=CommonFunc::gbk2utf(logStr);
rcode=ERROR_PARAMETER_LACK;
EMH_store_error_s1(EMH_severity_user_error, rcode, logStr.c_str());
return EPM_nogo;
}
CommonFunc::WriteInfoLog("流程模板该节点的参数个数:",(CommonFunc::intToString(argsCount)).c_str());
for (int i = 0; i < argsCount; i++)
{
char* paraValue = NULL;
char* paraFlag = NULL;
paraArgsValue = TC_next_argument(msg.arguments);
ITK_ask_argument_named_value(paraArgsValue, ¶Flag, ¶Value);
CommonFunc::WriteInfoLog(paraFlag);
// 读取参数
if (CommonFunc::IsEqual(paraFlag, "Type"))
{
hasTypeFlag=true;
if (!CommonFunc::IsEmpty(paraValue))
{
attachType=paraValue;
typeFlag=true;
}
}
if (CommonFunc::IsEqual(paraFlag, "DatasetCheck"))
{
hasdatasetCheckFlag=true;
if (!CommonFunc::IsEmpty(paraValue))
{
datasetCheckStr=paraValue;
datasetCheckFlag=true;
}
}
Free(paraValue);
Free(paraFlag);
}
if(hasdatasetCheckFlag==false||hasTypeFlag==false)
{
CommonFunc::WriteInfoLog("");
string logStr = errorStr+"流程参数配置错误,请联系管理员";
CommonFunc::WriteInfoLog(logStr.c_str());
logStr=CommonFunc::gbk2utf(logStr);
rcode=ERROR_PARAMETER_LACK;
EMH_store_error_s1(EMH_severity_user_error, rcode, logStr.c_str());
return EPM_nogo;
}
return ITK_ok;
}
**
Header.h
#pragma once
#include "tcinit/tcinit.h"
#include <ae/datasettype.h>
#include <string>
#include <time.h>
#include <io.h>
#include "epm/epm.h"
#include "sa/sa.h"
#include "fclasses/tc_date.h"
#include "epm/signoff.h"
#include "tccore/grmtype.h"
#include "tccore/grm.h"
#include <iostream>
#include <fstream>
#include <sa/am.h>
#include <sa/tcfile_cache.h>
#include <tccore/aom.h>
#include <tccore/aom_prop.h>
#include <ae/dataset.h>
#include <tccore/tc_msg.h>
#include <tc/folder.h>
#include <tccore/grm.h>
#include <tccore/grmtype.h>
#include <tccore/item.h>
#include <tccore/item_msg.h>
#include <tccore/method.h>
#include <tc/preferences.h>
#include <sa/sa.h>
#include <tc/tc_macros.h>
#include <tc/tc_util.h>
#include <tc/tc_startup.h>
#include <tccore/workspaceobject.h>
#include <fclasses/tc_string.h>
#include <res/res_itk.h>
#include "tccore/idcxt.h"
#include "tccore/idfr.h"
#include "epm/epm_task_template_itk.h"
#include <user_exits/epm_toolkit_utils.h>
#include <tccore/custom.h>
#include <tccore/tctype.h>
#include <ict/ict_userservice.h>
#include "epm/signoff.h"
#include <string>
#include <sstream>
#include "ict/ict_userservice.h"
#include "fclasses/tc_date.h"
#include "ps/ps.h"
#include <lov\lov.h>
#include <bom\bom.h>
#include <vector>
#include <map>
using namespace std;
// 此常量用于变量的长度
const int Long16 = 16;
const int Long32 = 32;
const int Long64 = 64;
const int dLong81 = 81;
const int Long128 = 128;
const int Long512 = 512;
const int Long1000 = 1000;
const int Long1500 = 1500;
const int Long2000 = 2000;
const int Long3000 = 3000;
//错误代码
#define ERROR_NOT_FIND (EMH_USER_error_base + 100003)
#define ERROR_DATA (EMH_USER_error_base + 100005)
#define ERROR_RULE_NOT_PASS (EMH_USER_error_base + 100008)
#define ERROR_PARAMETER_LACK (EMH_USER_error_base + 100010)
#define ERROR_PREF_NOT_FIND (EMH_USER_error_base + 100011)
// TC 中默认的关系
#define RELATION_specification "IMAN_specification"
// TC中默认的属性名称
#define PROP_itemId "item_id"
#define PROP_itemRevId "item_revision_id"
#define PROP_objectString "object_string"
#define PARAM_USER "-u="
#define PARAM_PASSWORD "-p="
#define PARAM_GROUP "-g="
#define PARAM_SLEEP "-sleep="
#define PARAM_FOLDER "-folder="
#define TEXT_FORMAT "TEXT"
#define BINARY_FORMAT "BINARY"
#define Free(obj) \
{ \
if(obj!=NULL) \
{ \
MEM_free(obj); \
obj = NULL; \
} \
};
#define SAFECALL(x) \
{ \
if((rcode = (x)) != ITK_ok) \
{ \
goto CLEANUP; \
} \
}
#ifdef COMM_LIB_IMPORT
#define COMM_LIB __declspec(dllimport)
#else
#define COMM_LIB __declspec(dllexport)
#endif
class Header
{
public:
Header(void);
~Header(void);
};
int action_func_test(EPM_action_message_t msg);
EPM_decision_t rule_func_test(EPM_rule_message_t msg);
Handler_register.h
#include "Header.h"
#pragma once
class Handler_Register
{
public:
Handler_Register(void);
~Handler_Register(void);
};
//============================================
// 说明: 此函数用来注册Handlers
//============================================
extern DLLAPI int Handler_Register(int *decision, va_list args);
//============================================
// 说明: 此函数用来注册Methods
//============================================
extern DLLAPI int Method_Register(int *decision, va_list args);
//调用dispatcher
//extern DLLAPI int DispatcherRequest(EPM_action_message_t msg);
4、TC中的配置以及测试**
4.1参数数量不符合条件时
4.2参数名称不符合条件时
4.3 action和rule类似,在此省略。
免责声明:本文系网络转载或改编,未找到原创作者,版权归原作者所有。如涉及版权,请联系删