|
今天加班,终于把Teamcenter 2007自定义错误消息的问题解决了,部分信息来自顾问公司的指导,部分是通过研究帮助文档做出来的。/ }5 V2 ^4 H! H) ~+ }3 K2 \ x! k
4 |' c- ^* F+ L4 [ 首先在Teamcenter 2007的ITK帮助文档里有用户定义message的大概步骤描述:
2 z% U% b" D+ O) C$ ~6 H& k2 t7 M, y
) I5 o1 R8 q' I, hCreate a custom error message, I2 W' o! o3 q
--------------------------------------------------------------------------------( T! [& W3 _: |' o" o9 H/ s
2 {& K) g S0 [# B/ DUpdate your code to include the tc/emh_const.h file.
+ P+ g7 o' z! \4 I i" @0 c a: p+ ]" M/ T6 _
Add the #define statement for your error message in your code using the following syntax:1 d/ x+ ?1 D; X$ R- s0 w, x
@+ T9 Q' p' Y# }( w
#define USER_ERROR_NAME (EMH_USER_error_base + nnn)
4 B& @. [, a* s. ~# s$ h8 I( I" g3 E6 s2 S
where nnn is your error number. For example, you can define a connection failure error with a number of 10 as follows:2 s8 M) h2 h- c9 z- J8 ?
8 @" n% y" Z7 U, e' N#define CONNECT_FAILURE (EMH_USER_error_base + 10)( W' R* q* {1 Y) F( _7 U% C
. H, P4 W. P, B0 d7 x. j S+ A- s
Compile your code.
5 o! M2 i! b j2 J+ a$ b1 o, l
Create the local shared library file.2 T" ?7 \! W1 I, g! L$ L8 W
4 c# E H% h8 @, M
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.
6 U) ?1 r/ s/ ^0 {
2 b) o2 I. n1 jIn 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:0 e+ P4 U, E# B
$ h E3 I: K1 O2 J! U$ e
<error id = "10">Unable to connect %1$</error>* G' G4 T& a/ ]/ D7 v" A
2 z) u7 Y6 X p0 T! \$ ?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.
; j+ P) u/ X" G2 C" @% [* @4 Z- \3 A8 M! z) r- k
在流程定义的rule handler中,当遇到需要返回错误消息的时候,利用Teamcenter 2007提供的emh.h的系列方法来保存错误消息,如EMH_store_error(),这个不传参数到错误消息中,也可以利用后面的EMH_store_error_s1() 一直到EMH_store_error_s5() ,也就是说最多可以一次向错误消息中返回5个参数,最大限度地给用户更多的提示。
% W, Z, F T) v U# l6 `* k3 |: s: }% D4 L( [
具体步骤如下: Z! ~+ `0 Z2 ?4 T) q+ N1 ~7 Q
1 `7 S9 {+ ^3 \, ?步骤1 修改%TC_DATA%\lang\textserver\en 下的ue_errors.xml文件,添加自定义的错误消息,如果消息中有中文的话,需修改配置文件引用的字符集为GB2312,错误消息如下定义:
+ l0 ]7 c% @0 Q" ]. f" _# O<?xml version="1.0" encoding="GB2312" standalone="yes"?>
: r q! [' |9 \) Z, W<!--& N* E* n/ E; \+ n
===============================================================================' _: Q8 J9 L, d& f: J0 R6 T
Copyright (c) 2003-2005 ugS Corporation
* `4 X0 p; j' Y. K% D Unpublished - All Rights Reserved b! ^) `0 [0 ]
===============================================================================7 j- q8 |/ \$ `" \: C# R% M( C8 K! v
File description:( N7 i3 e4 R; n$ h2 K
+ s4 {. J1 s6 T* x& [6 W Filename:
; O& [; E; H* `9 T$ X3 V# U Module:# U5 O$ A/ @% F- C) h2 q
5 w. Z% D6 i5 b$ P2 D9 ?
XML File defining ___ module text/error messages.! O% O0 O9 g* D' T, Y m' @
This was previously done in UIH/UIL/VIL format.
$ g1 o2 ~6 g7 H* e-->* n' A1 F8 M* \
<textsrv filename="ue_errors.xml">
& L5 b$ L, j4 z<errors module="ue" error_base="919000">
$ d. k9 I# \: m; A. N, w<error id="1">USER_EXIT: User Exit %1$ failed</error>6 Q9 ~0 ?& Z! z
<error id="300">错误: 流程目标不能为Item,必须为Item版本类型!</error>
" C: [# I4 ^4 }0 I! c- I<error id="301">错误: 此流程必须有立项Item版本的附件才能启动!</error>
, O7 T w: z( C0 H; ~0 m, A<error id="302">错误: 流程附件类型不能为零组件下的view类型,只能为零组件版本下的view类型!</error>9 [. s/ L# h; p# i& R
<error id="303">错误: 此流程目标某附件的所有者为%1$,必须由%2$本人才能发起此流程!</error>2 w$ I c7 g) U. P
</errors>" F2 t. f+ j3 ^, A. l4 R1 L, K
</textsrv>
5 V9 f2 n0 t8 H' |2 }8 Z
' c/ Q4 B6 w, Q7 x' [, V- H这里的%1$代表传入的第1个参数,同理,%2$代表传入的第2个参数。
" Y# l, c' l4 L+ ]( B+ L
; H7 ?0 X V0 A6 w5 r, ^/ Q步骤2:在rule handler的代码中定义错误代码:+ q7 W3 ]( X. z) s6 W
- Q/ `- ]8 |6 R1 b
#define WORKFLOW_ERROR1 ( EMH_USER_error_base + 300 )
( T' k5 E( x2 v, k7 z#define WORKFLOW_ERROR2 ( EMH_USER_error_base + 301 )* w0 t/ w! H. Q
#define WORKFLOW_ERROR3 ( EMH_USER_error_base + 302 )6 e0 t6 R" A0 y* b4 ?
! Y& _5 J* H- `
#define WORKFLOW_ERROR4 ( EMH_USER_error_base + 303 )8 }6 E( b. N `& n/ O
6 n: n. ~8 U* ^6 @1 j* Y, O. ^
使ID和配置文件中的错误消息ID号一致。+ W4 G9 c+ p2 U
5 k8 k% P; ?# y9 q, M0 Y7 n4 l% R1 Q
步骤3:在rule handler的代码中,当不满足条件时,调用EMH_store_error的相关方法如(需要传递参数的话参照帮助文档):% I( ^8 P# H, K( \$ Z% l
EMH_store_error (EMH_severity_user_error,WORKFLOW_ERROR2) ;
6 E( O. V- @: g6 e" `. Gstatus=WORKFLOW_ERROR2;( {0 r' |0 m0 m
EMH_ask_error_text(status, &message);
' ~+ g/ d; T- n+ S0 o9 E1 U4 k+ x7 x) _printf("error is [%s]", message); 2 r z) `! n# D3 s; O' a" n
不满足条件仍然返回EPM_nogo即可。
7 `) r& m, j7 M& f0 Z7 @; [3 p# j- z8 x5 O
步骤4:按照帮助文档Create a custom error message的最后部分提示,先设置服务器端的环境变量
4 O. P: C* n3 M$ Eset TC_USER_MSG_DIR=%TC_DATA%\lang\textserver\en 使TC_USER_MSG_DIR指向ue_errors.xml所在的目录,并修改tcdata目录下的tc_profilevars.bat文件内容,内容如下:$ Y! C5 i& P$ {8 _6 v p
if not defined TC_USER_MSG_DIR set TC_USER_MSG_DIR=%TC_ROOT%\lang\textserver\en& q) T( D5 N& a: [5 i) N/ D
" x0 y5 p4 J( D9 L
这样自定义消息就算完成了。编译文件,将dll和pdb文件放置到服务器端的bin目录下,如果是两层客户端,需要更新客户端的TC2007下bin目录下的相应的dll和pdb文件。2 W) Z$ G8 T; h: o) b
$ {0 Z. h! J( c
实际测试中,Teamcenter 2007两层胖客户端只需要重新登录就可以看到想要的结果,而四层的客户端需要重启服务器才能生效。 |
|