ITK开发入门hello,world

ITK开发入门
1、ITK-Handler开发介绍

在Teamcenter EPM企业流程管理模块中,添加开发入口作为触发点。按照OOTB的流程,流程中Handler分为rule Hander和actiion Handler,程序中可以接收配置的参数名称和参数值作为入参。
2、ITK-Handler开发所需工具和开发环境配置
2.1vs中新建空项目

在这里插入图片描述

2.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, &paraFlag, &paraValue);
		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类似,在此省略。
在这里插入图片描述

  • 4
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值