|
今天加班,终于把Teamcenter 2007自定义错误消息的问题解决了,部分信息来自顾问公司的指导,部分是通过研究帮助文档做出来的。5 a: P3 Z* ?4 N) Z' V4 h( {
. \7 t5 _; h3 Q6 ~) ~/ N1 _! j% z
首先在Teamcenter 2007的ITK帮助文档里有用户定义message的大概步骤描述:+ K( y$ J" R' r; G5 O
, U) W. J" v' o& T
Create a custom error message2 \$ k) ?" A. \3 V% c- X N" M
--------------------------------------------------------------------------------
. c9 B5 s- v2 C5 v9 C# Y \- }! Q; u# Q' Q$ t: L( e& L
Update your code to include the tc/emh_const.h file.
$ ]4 Y4 B: M# n/ x" N4 p
\$ | }; w6 \3 WAdd the #define statement for your error message in your code using the following syntax:6 _7 c8 @: g# l
4 M, E2 n: B, e
#define USER_ERROR_NAME (EMH_USER_error_base + nnn)* j% V" c- Z# k' c; n& I
. \" n. j& m; s
where nnn is your error number. For example, you can define a connection failure error with a number of 10 as follows:
^6 [; ?- L% W0 a7 f: |& X' R# T+ m( O$ N7 G2 }1 Q3 a2 h
#define CONNECT_FAILURE (EMH_USER_error_base + 10)
4 e0 I" E. o4 j4 h$ Y% j8 [- {8 Q0 B3 c) D
Compile your code.
7 i$ d: G! v- C$ Q$ p/ F: L' w( A) T! s9 t+ w" B0 I
Create the local shared library file.
2 s/ _. L, W. @* }- P5 o, s( T
' `. d n6 `4 oCopy the TC_MSG_ROOT\TC_LOCALIZATION_DIR\ue_errors.xml file to your TC_USER_MSG_DIR directory. To view XML structure and format, see any of the XML files in the TC_MSG_ROOT\TC_LOCALIZATION_DIR directory.
; z$ x8 Q& Q+ F, G0 h6 d* `; W0 r# e" x
In your copy of the ue_errors.xml file, add a line to define the error string corresponding to your custom message. Type the text within a pair of error tags in the file. If you want to use a substitution marker, use %n$. For example:
2 i0 w- R& ]4 z" h% x# L5 n1 T. _4 m) A4 ^7 s
<error id = "10">Unable to connect %1$</error>- A1 h w) t5 B2 G
! _/ y7 c& p( ]1 v1 HSet the TC_USER_MSG_DIR environment variable in the TC_DATA\tc_profilevars.bat file to point to the directory that contains your ue_errors.xml file.% I# k4 [6 c* x4 I! D/ a- j
/ k8 m% k: b( ? E- n
在流程定义的rule handler中,当遇到需要返回错误消息的时候,利用Teamcenter 2007提供的emh.h的系列方法来保存错误消息,如EMH_store_error(),这个不传参数到错误消息中,也可以利用后面的EMH_store_error_s1() 一直到EMH_store_error_s5() ,也就是说最多可以一次向错误消息中返回5个参数,最大限度地给用户更多的提示。
4 m; l# I/ O2 @5 S/ P6 w
1 A- i8 Z! V$ ?" H- @5 {1 E具体步骤如下:
9 {& h8 j0 p3 J" t6 @# q+ p O# o* a; d
步骤1 修改%TC_DATA%\lang\textserver\en 下的ue_errors.xml文件,添加自定义的错误消息,如果消息中有中文的话,需修改配置文件引用的字符集为GB2312,错误消息如下定义: K5 x3 o B. }" V
<?xml version="1.0" encoding="GB2312" standalone="yes"?>; @5 u1 f% d; M( b5 ?* E
<!--
( h0 U- c( M* W) u A1 ^3 l; o2 {===============================================================================
5 B: w) _/ `2 B' T. l& }& \; K6 { Copyright (c) 2003-2005 ugS Corporation
. _' {+ t9 V w# @; o& s Unpublished - All Rights Reserved! p/ V! }( d6 l/ r6 [
===============================================================================
7 d2 |) s) P, t) l |File description:
+ X+ D b) Y1 Z5 k$ \5 H5 c! Y0 ^/ T! q( e
Filename:& ? r. f. Y( M4 Q: r5 w+ d
Module:5 y9 v& M; K9 R) m
( {, G" P# [( |8 n3 b4 x) ~ XML File defining ___ module text/error messages.( w8 X2 N, Z" T) i
This was previously done in UIH/UIL/VIL format.% W) z3 W6 J$ @0 `7 W4 Z' r
-->
& ?/ v) r/ t, l) H7 w6 m<textsrv filename="ue_errors.xml">* I7 L8 y) v K
<errors module="ue" error_base="919000">1 Z& w3 `# L( O; {. [* }0 ^( [
<error id="1">USER_EXIT: User Exit %1$ failed</error>
^2 @& i5 v! B& a4 S! y<error id="300">错误: 流程目标不能为Item,必须为Item版本类型!</error># v! E0 Y3 j3 Z) n4 {6 ^7 K
<error id="301">错误: 此流程必须有立项Item版本的附件才能启动!</error>- p& W% [4 w# Z5 m. o3 \+ \
<error id="302">错误: 流程附件类型不能为零组件下的view类型,只能为零组件版本下的view类型!</error>
6 W' F* b+ O! @2 I; K5 _<error id="303">错误: 此流程目标某附件的所有者为%1$,必须由%2$本人才能发起此流程!</error>
5 u2 ~1 u' r* j</errors>- l& I. Z1 b1 J+ L1 D
</textsrv>
9 J$ E8 R; a1 g6 M7 X5 X3 ]$ H! K
这里的%1$代表传入的第1个参数,同理,%2$代表传入的第2个参数。
5 Q0 R. I8 e& M) U/ `, U1 z% H* {) H3 }% s$ \7 l
步骤2:在rule handler的代码中定义错误代码:) n5 k8 }8 x" I' _& ?% u
$ H* ? A- w2 N2 e#define WORKFLOW_ERROR1 ( EMH_USER_error_base + 300 )% v# J K# ?2 v$ z
#define WORKFLOW_ERROR2 ( EMH_USER_error_base + 301 )
6 @+ N4 o. g! c# T% Q- e#define WORKFLOW_ERROR3 ( EMH_USER_error_base + 302 )
" s# ^' \4 m* ]$ ]. x
* T1 P1 R: P o( ^4 }' W#define WORKFLOW_ERROR4 ( EMH_USER_error_base + 303 )) ?4 V! l+ o f# j8 }- {
, o1 t' c2 Y3 m8 c& S使ID和配置文件中的错误消息ID号一致。
3 R$ H+ O( K( Y. v% S
d; z! b2 N9 F! T. E步骤3:在rule handler的代码中,当不满足条件时,调用EMH_store_error的相关方法如(需要传递参数的话参照帮助文档):
! ^8 S4 e" `& |6 I: c5 H" yEMH_store_error (EMH_severity_user_error,WORKFLOW_ERROR2) ;4 [2 T8 L2 d. A/ f9 D) B
status=WORKFLOW_ERROR2;5 p; t/ B' e% D }' J6 T
EMH_ask_error_text(status, &message);8 l6 b, r, t4 W, x5 ]
printf("error is [%s]", message); & C }! |! e* }1 D8 S7 H
不满足条件仍然返回EPM_nogo即可。& z( |. c. T$ x1 q7 ]* S1 M
+ h9 V6 L3 `+ f# f" f
步骤4:按照帮助文档Create a custom error message的最后部分提示,先设置服务器端的环境变量7 \+ J' _, I' Y# f# j2 Y; q |/ r
set TC_USER_MSG_DIR=%TC_DATA%\lang\textserver\en 使TC_USER_MSG_DIR指向ue_errors.xml所在的目录,并修改tcdata目录下的tc_profilevars.bat文件内容,内容如下:8 |; a( X" M+ v! C9 ^9 R
if not defined TC_USER_MSG_DIR set TC_USER_MSG_DIR=%TC_ROOT%\lang\textserver\en0 L7 W* `2 x) G% V0 H+ {
" L( K( X6 D% j. M$ |! [
这样自定义消息就算完成了。编译文件,将dll和pdb文件放置到服务器端的bin目录下,如果是两层客户端,需要更新客户端的TC2007下bin目录下的相应的dll和pdb文件。
* Z6 o/ y3 w* |4 l4 j( f$ r
. X3 A0 d( N# L& }* y+ a实际测试中,Teamcenter 2007两层胖客户端只需要重新登录就可以看到想要的结果,而四层的客户端需要重启服务器才能生效。 |
|