|
今天加班,终于把Teamcenter 2007自定义错误消息的问题解决了,部分信息来自顾问公司的指导,部分是通过研究帮助文档做出来的。
7 ~! ? a- @5 J; Z* E0 ^, [9 }) W x' f0 |
首先在Teamcenter 2007的ITK帮助文档里有用户定义message的大概步骤描述:
6 [4 a: ?- h+ o0 k
" E. Q' z/ G* O6 z* x: { rCreate a custom error message
0 F/ c) r D# z5 |1 k( {--------------------------------------------------------------------------------
0 j; |7 C; o$ l! [0 K
& q$ K$ j4 u8 g9 MUpdate your code to include the tc/emh_const.h file.
2 X) K$ L: |5 L! }: ?! Z( l: x, O$ H- ~- K
Add the #define statement for your error message in your code using the following syntax:" Z, u2 Z3 [( D7 j2 G9 W' ^
( {/ l) s: M# h# H9 M8 \
#define USER_ERROR_NAME (EMH_USER_error_base + nnn); x$ l. j; Z; B; v$ g
" W3 z, r) L; R5 J' u. ], ?where nnn is your error number. For example, you can define a connection failure error with a number of 10 as follows:! s6 R8 Y: g7 ?2 k; k& n% v
) z0 y6 c4 M6 `
#define CONNECT_FAILURE (EMH_USER_error_base + 10)% q' \' ^3 x) s1 r! y/ @! A: L
- F4 \5 G* ~$ `- B1 t. NCompile your code.
& M' G5 V! ~3 S
* x) {) A8 m% SCreate the local shared library file.3 v' W, o( g# N4 G
# T2 U2 M. n8 vCopy 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.
0 E/ k2 x( Y0 A$ b2 d0 P8 F5 s) K1 U. v! Q, x U7 W
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 i: k, h) r3 |; r& S7 h7 O& S. M& K
<error id = "10">Unable to connect %1$</error>
* ?& q+ u* S. B) c4 L
3 l0 m8 A: J3 e% N, t6 z" FSet 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.
% s8 K6 d! C& E- F) r7 }
( w8 u: N3 `0 [5 O在流程定义的rule handler中,当遇到需要返回错误消息的时候,利用Teamcenter 2007提供的emh.h的系列方法来保存错误消息,如EMH_store_error(),这个不传参数到错误消息中,也可以利用后面的EMH_store_error_s1() 一直到EMH_store_error_s5() ,也就是说最多可以一次向错误消息中返回5个参数,最大限度地给用户更多的提示。
$ Z6 {# E! a& G% F* [1 Z7 z0 O1 _( \* k' l& y H
具体步骤如下:
3 W/ W2 z- o$ I. M, `/ W
8 O2 e% a. ?7 @4 U9 n- ^. z6 S' T步骤1 修改%TC_DATA%\lang\textserver\en 下的ue_errors.xml文件,添加自定义的错误消息,如果消息中有中文的话,需修改配置文件引用的字符集为GB2312,错误消息如下定义:8 w9 L8 @# ~5 ~( m( `
<?xml version="1.0" encoding="GB2312" standalone="yes"?>% K: |( ]* L' }# M6 p0 @5 ]
<!--3 e5 \3 }9 x6 z& O
===============================================================================, Q6 r: @, q2 U- K+ G' R
Copyright (c) 2003-2005 ugS Corporation
! P/ v+ z! }1 r Unpublished - All Rights Reserved
, }) ^! T8 i f: l, Y; d3 d) L U/ x===============================================================================
9 x) b0 k/ |8 QFile description:- I4 x) @5 a0 ?0 Z" s: Q4 u
2 G, W5 b9 j) \( o/ s3 X1 A; f0 R Filename:
5 }) t/ J2 @: \3 [ Module:
! ~% Q2 j( J$ c$ _2 y: _$ |& Q
9 W! U" d b: B* M6 |9 |+ B1 B. u$ e XML File defining ___ module text/error messages.
+ b1 v; m. ~" n This was previously done in UIH/UIL/VIL format.3 I, P- j- g& d |4 s: C8 R7 m
-->
& j1 x" o, r N<textsrv filename="ue_errors.xml">$ N! X% G+ H% u7 l' }
<errors module="ue" error_base="919000">$ D/ ^. Y8 T! x) \
<error id="1">USER_EXIT: User Exit %1$ failed</error>3 Q: G3 x c) x, q7 a) L
<error id="300">错误: 流程目标不能为Item,必须为Item版本类型!</error>
& w" ~# h: N% d# p4 H4 [/ v4 @<error id="301">错误: 此流程必须有立项Item版本的附件才能启动!</error>' d% r: f# a4 ~+ p% L7 e$ ~
<error id="302">错误: 流程附件类型不能为零组件下的view类型,只能为零组件版本下的view类型!</error>+ n0 g$ s; S2 c; \
<error id="303">错误: 此流程目标某附件的所有者为%1$,必须由%2$本人才能发起此流程!</error>
6 L. Q$ k" y, P8 O, ~+ F</errors>
3 X9 t5 `1 q1 Z' A B</textsrv>
. |+ o2 {$ o- c8 j' v0 I5 L I6 w! y4 ?0 |
这里的%1$代表传入的第1个参数,同理,%2$代表传入的第2个参数。& ?/ b- T: }' [. j! p {$ m
) `# y/ N) C# e9 z8 e9 }步骤2:在rule handler的代码中定义错误代码:. E* L. y! P' t7 Z: l/ d! `
6 }+ t2 _; \( l# G' t! n
#define WORKFLOW_ERROR1 ( EMH_USER_error_base + 300 )
9 {* l2 X, z7 ~: v, k#define WORKFLOW_ERROR2 ( EMH_USER_error_base + 301 )
; `, b9 m& V& B! c3 u6 K4 k#define WORKFLOW_ERROR3 ( EMH_USER_error_base + 302 ): h# ^& N _5 q' n/ G
0 H7 d. T7 b* p% c m#define WORKFLOW_ERROR4 ( EMH_USER_error_base + 303 )
6 @$ @. S4 V3 h0 }. C" P* x! \: q# T+ _6 B' o4 V: B
使ID和配置文件中的错误消息ID号一致。
: j# p( D/ p" I$ E+ ?5 G& D A1 q
8 \! `- L% a- L, w- T. {/ Z步骤3:在rule handler的代码中,当不满足条件时,调用EMH_store_error的相关方法如(需要传递参数的话参照帮助文档):- V1 I, H; [7 D$ m- k% D% Q: O6 v( j
EMH_store_error (EMH_severity_user_error,WORKFLOW_ERROR2) ;
: v4 c* `+ m' n8 {) B/ h" q' istatus=WORKFLOW_ERROR2;1 I; Y" o! M% N1 k3 s
EMH_ask_error_text(status, &message);
a0 ~0 v5 H. y, a! a$ Z; ~printf("error is [%s]", message);
$ u' b; |5 k0 k5 R不满足条件仍然返回EPM_nogo即可。# T+ G$ [& R* L" h+ k( e, k* X
2 M$ N+ E5 t) P9 Z- K- p- Z
步骤4:按照帮助文档Create a custom error message的最后部分提示,先设置服务器端的环境变量& a4 S: {3 G% v! W! [
set TC_USER_MSG_DIR=%TC_DATA%\lang\textserver\en 使TC_USER_MSG_DIR指向ue_errors.xml所在的目录,并修改tcdata目录下的tc_profilevars.bat文件内容,内容如下:
' S* |3 z7 Q/ l+ _if not defined TC_USER_MSG_DIR set TC_USER_MSG_DIR=%TC_ROOT%\lang\textserver\en
3 q) l3 a. l J+ ~; H a
0 |8 A. M! e! n0 C3 g' U这样自定义消息就算完成了。编译文件,将dll和pdb文件放置到服务器端的bin目录下,如果是两层客户端,需要更新客户端的TC2007下bin目录下的相应的dll和pdb文件。! r6 v; T1 M7 M8 ~: Q; S- Y9 |
! m( \0 A7 t* l" p1 m" E
实际测试中,Teamcenter 2007两层胖客户端只需要重新登录就可以看到想要的结果,而四层的客户端需要重启服务器才能生效。 |
|