|
今天加班,终于把Teamcenter 2007自定义错误消息的问题解决了,部分信息来自顾问公司的指导,部分是通过研究帮助文档做出来的。
1 {1 o/ `3 N& ]( ?9 R/ `+ u* i+ x: p9 q/ g* Z t, E) }% k
首先在Teamcenter 2007的ITK帮助文档里有用户定义message的大概步骤描述:
& b. s# E, {' f' e2 O" }. n. H% i; F# _ u
Create a custom error message
2 _( p1 a; N% J" D& l--------------------------------------------------------------------------------
! t3 W# f. d5 G& g
& n* h2 K8 D# i- f* u4 f! GUpdate your code to include the tc/emh_const.h file.* l n7 W1 C' J0 N5 N/ v4 i
( c/ t1 g8 G) K3 w. eAdd the #define statement for your error message in your code using the following syntax:
4 _( A. u2 q: n" m1 k+ q! Y* J; d' y% E- q1 G! d
#define USER_ERROR_NAME (EMH_USER_error_base + nnn)
( W) o/ D4 b/ t' R( K/ H3 o) A5 @5 A' F! _. ^0 }. v. T
where nnn is your error number. For example, you can define a connection failure error with a number of 10 as follows:( |( |0 O1 i ~' W# Q! z
# M$ X. }6 x/ r+ _8 |' {
#define CONNECT_FAILURE (EMH_USER_error_base + 10), P! Z5 W! G5 r, i% j3 t7 X4 b* j+ |
6 {3 F- X# A# i7 F& j; C& L v
Compile your code.% u: r/ ^6 ^: R/ X) R
" m* j; [9 Z# i) h; {) }- @" @
Create the local shared library file.3 {. U- M6 B$ R" J
3 U/ [5 ]& I- T) @
Copy 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.: Q/ V3 d8 X/ W
8 p+ y. K* M8 h3 |$ R
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:
n! n/ R; F; C0 }, q8 b/ d; S; z0 }) o
<error id = "10">Unable to connect %1$</error>) ?, n4 L" ?1 I6 R- w) Q
7 P; V' J+ L8 D- T# h
Set 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.
% t z, P9 E. c% p- d0 h
) }( N2 {7 L7 X% A2 A在流程定义的rule handler中,当遇到需要返回错误消息的时候,利用Teamcenter 2007提供的emh.h的系列方法来保存错误消息,如EMH_store_error(),这个不传参数到错误消息中,也可以利用后面的EMH_store_error_s1() 一直到EMH_store_error_s5() ,也就是说最多可以一次向错误消息中返回5个参数,最大限度地给用户更多的提示。
; R5 H7 |$ K& k0 G& M7 r* `3 e5 ?! u
具体步骤如下:5 i+ Q# @4 T( ]8 B. y; U
9 ^# X% L# p7 k2 K3 b: j7 t; G
步骤1 修改%TC_DATA%\lang\textserver\en 下的ue_errors.xml文件,添加自定义的错误消息,如果消息中有中文的话,需修改配置文件引用的字符集为GB2312,错误消息如下定义:
1 @+ E4 R; y& B' I% x+ I<?xml version="1.0" encoding="GB2312" standalone="yes"?>) |: g- A- ~& y, k
<!--
) S% f$ J# ~. ^8 w: W6 I# O2 ]$ g===============================================================================) q+ {$ U, M% x$ P
Copyright (c) 2003-2005 ugS Corporation5 d; Z1 D* y1 \4 h! V1 ~5 T
Unpublished - All Rights Reserved$ l" s& Q+ O) G
===============================================================================
/ W7 B, O5 k1 y& K+ ]: WFile description:0 ^$ \& \% w7 d1 X' k9 f
8 L3 C8 B* d9 P T5 r Filename:
* x; A0 ~$ w. z r2 {5 @ Module:2 ?5 x. K" p% v# V8 o
c) ^% A' z4 ^. B ]5 y
XML File defining ___ module text/error messages.7 B) D) `6 z& l. K; _
This was previously done in UIH/UIL/VIL format.
1 G8 a! Y/ l! S7 D; ?. S-->
8 b" ]5 N& Z& X! Y7 C<textsrv filename="ue_errors.xml">7 L% `2 ~( x& |0 e. E, a8 s3 |
<errors module="ue" error_base="919000">, Q, U& _' w7 N' g( g
<error id="1">USER_EXIT: User Exit %1$ failed</error>
( F, Q6 E0 x5 u8 H1 e f4 D, s. s<error id="300">错误: 流程目标不能为Item,必须为Item版本类型!</error>
* f* }4 N* I( J<error id="301">错误: 此流程必须有立项Item版本的附件才能启动!</error>
+ A! J1 H3 o3 o4 Z. q<error id="302">错误: 流程附件类型不能为零组件下的view类型,只能为零组件版本下的view类型!</error>
7 R/ y2 ^9 P: b/ o! ]<error id="303">错误: 此流程目标某附件的所有者为%1$,必须由%2$本人才能发起此流程!</error>. l' Z$ X5 C& }- s
</errors>
1 T, z# V/ _3 L6 Y W. X+ o% Z</textsrv>9 k- n5 M% O2 B* `/ Y
. r- T; l3 q" c$ M这里的%1$代表传入的第1个参数,同理,%2$代表传入的第2个参数。; D0 I H& F% b6 G
! q s4 a7 J6 ?, w0 \
步骤2:在rule handler的代码中定义错误代码:2 b0 M4 V5 v# S4 j, v2 b1 k7 f5 R& L
' x: ~, G4 J) c6 [ ^, k#define WORKFLOW_ERROR1 ( EMH_USER_error_base + 300 )
* P* j! {0 M4 M, Y# i% I#define WORKFLOW_ERROR2 ( EMH_USER_error_base + 301 )$ K, P: k6 x+ w' ]# p9 @* M0 ?
#define WORKFLOW_ERROR3 ( EMH_USER_error_base + 302 )
: G1 T4 R. Z0 Y* n+ L
; f# h% P* o/ x9 ~ v% ~- G f. L#define WORKFLOW_ERROR4 ( EMH_USER_error_base + 303 )! a6 W0 b1 z a* O$ a6 u
, h- _7 |7 J, x Q1 y. {使ID和配置文件中的错误消息ID号一致。% ^! f- o; l, k# ~1 j; A
& f, _- y! v2 _# |& m8 _/ Z. n) U
步骤3:在rule handler的代码中,当不满足条件时,调用EMH_store_error的相关方法如(需要传递参数的话参照帮助文档):* p. R5 [/ t. j7 C7 K, }' D! g
EMH_store_error (EMH_severity_user_error,WORKFLOW_ERROR2) ;- M q, ]; M6 |+ e* z' Y; |
status=WORKFLOW_ERROR2;
2 C0 z& l. I9 m5 ZEMH_ask_error_text(status, &message);
' H/ u% l! |( t1 I7 A* B" Aprintf("error is [%s]", message); 9 F6 K6 e6 y3 e5 D+ |# W. ?& Y
不满足条件仍然返回EPM_nogo即可。
* g) b5 \( N+ E7 P$ Y8 V
9 d; S! p- M- q. x7 t' U8 _步骤4:按照帮助文档Create a custom error message的最后部分提示,先设置服务器端的环境变量
7 F! ?4 `* f9 aset TC_USER_MSG_DIR=%TC_DATA%\lang\textserver\en 使TC_USER_MSG_DIR指向ue_errors.xml所在的目录,并修改tcdata目录下的tc_profilevars.bat文件内容,内容如下:+ O, p3 H8 q5 I0 D0 ?
if not defined TC_USER_MSG_DIR set TC_USER_MSG_DIR=%TC_ROOT%\lang\textserver\en
5 P' s: W2 I' G ?1 V
s% L( e; s" K这样自定义消息就算完成了。编译文件,将dll和pdb文件放置到服务器端的bin目录下,如果是两层客户端,需要更新客户端的TC2007下bin目录下的相应的dll和pdb文件。
6 Z! ~! b; `* b5 B5 t |5 `
: \; v4 i% u6 ^& e! _实际测试中,Teamcenter 2007两层胖客户端只需要重新登录就可以看到想要的结果,而四层的客户端需要重启服务器才能生效。 |
|