|
今天加班,终于把Teamcenter 2007自定义错误消息的问题解决了,部分信息来自顾问公司的指导,部分是通过研究帮助文档做出来的。: _1 h. ~- `! R6 ]7 f A0 p$ _
3 h. l; y! z t9 d% i4 R 首先在Teamcenter 2007的ITK帮助文档里有用户定义message的大概步骤描述:# `6 y5 m- M' T* F5 E }5 W
4 ^- \! O! K/ J1 _* [1 cCreate a custom error message
3 d/ s# p4 |) x7 L--------------------------------------------------------------------------------; q& w0 s* S+ z6 k0 a( c% k- H
* |- O" ]- Q! z! b
Update your code to include the tc/emh_const.h file." t2 r1 E1 v$ K$ q$ N0 R
5 f( I) u# b: g# c OAdd the #define statement for your error message in your code using the following syntax:1 \/ E6 Z4 L5 |4 A, a; @1 G
# H: ~# @ ~. P6 O" T& ?
#define USER_ERROR_NAME (EMH_USER_error_base + nnn)2 V1 P1 O8 Y$ X* K
) M. y: c* A( P* `1 s g5 pwhere nnn is your error number. For example, you can define a connection failure error with a number of 10 as follows: ]4 U$ h5 I& B5 L) b4 O+ J% G
( h8 A2 w: ]+ H3 N. K6 X; [( K1 D
#define CONNECT_FAILURE (EMH_USER_error_base + 10)
* T6 R# o- T* b& q# T: J4 l3 V1 l# J% G+ p
Compile your code.
* d$ k/ s: M' r4 m! f) W
' a+ s1 O- u& h- P# xCreate the local shared library file.% x" f/ w$ ^. h9 }3 ^' V
6 U/ [9 ?9 I# o8 D/ ]
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./ p% a9 F% q5 x8 C$ n; O: g* }
; L' Q0 J8 M. q; Z
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:0 V ^" e. j2 b2 T0 T
) ^' j/ q9 l' a" D+ }- Z% X<error id = "10">Unable to connect %1$</error>% T* C9 t4 c' V+ T
9 B6 m4 K' Q. E6 l. [/ Z& E% ISet 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.; \3 W( x6 o$ {' F
7 O6 ^$ \# f) q& u7 `
在流程定义的rule handler中,当遇到需要返回错误消息的时候,利用Teamcenter 2007提供的emh.h的系列方法来保存错误消息,如EMH_store_error(),这个不传参数到错误消息中,也可以利用后面的EMH_store_error_s1() 一直到EMH_store_error_s5() ,也就是说最多可以一次向错误消息中返回5个参数,最大限度地给用户更多的提示。4 C7 q7 _! `! A/ _" p
+ n, S# m% Q) G2 `6 O' I P具体步骤如下:
% b8 {2 H1 |- `! b7 J( ? A2 r) f4 c% }) P7 D
步骤1 修改%TC_DATA%\lang\textserver\en 下的ue_errors.xml文件,添加自定义的错误消息,如果消息中有中文的话,需修改配置文件引用的字符集为GB2312,错误消息如下定义:. c7 Q" M7 U4 e: v
<?xml version="1.0" encoding="GB2312" standalone="yes"?>/ V& ~6 ?; R) A& n4 a5 ^
<!--
( \( p" D8 }1 u; a1 i6 h3 e. ^% O===============================================================================
5 w8 v9 B. h) {" `1 M) ~( ] Copyright (c) 2003-2005 ugS Corporation
& \) B# q7 b. a6 ^. ^ Unpublished - All Rights Reserved
) ]: j- s$ p) I/ f===============================================================================. `) h; o" w$ U+ l) y
File description:
1 B( k H# u6 r0 S! g: i% F9 G8 ?3 P* \
Filename:4 f+ J7 a. H ~3 D+ q/ R- v4 }+ F& Q
Module: M3 n! M" v' l) P
]) ^! v! C4 h7 H E) e$ V
XML File defining ___ module text/error messages.
$ o7 K+ x: m6 ^; q; Y+ T This was previously done in UIH/UIL/VIL format.9 L. Z4 @1 A8 q* K
-->% F: d+ R: A2 F' `8 _( u
<textsrv filename="ue_errors.xml">2 R, z) @$ E0 l& X' C" O% F
<errors module="ue" error_base="919000">! o7 k! d, t' [) ]! |; c; z
<error id="1">USER_EXIT: User Exit %1$ failed</error>
& Z. {5 l3 T' r: E, I<error id="300">错误: 流程目标不能为Item,必须为Item版本类型!</error>+ v0 C- s# s1 F6 s
<error id="301">错误: 此流程必须有立项Item版本的附件才能启动!</error>4 \4 N" p) }* t' k5 K
<error id="302">错误: 流程附件类型不能为零组件下的view类型,只能为零组件版本下的view类型!</error>3 _+ u& e" S/ y. ?: F: |0 O. R# g& i5 [
<error id="303">错误: 此流程目标某附件的所有者为%1$,必须由%2$本人才能发起此流程!</error>
, \6 I+ S0 S4 B</errors>
% u# K5 K8 o- x, G b6 @8 I |</textsrv> } K" {" w, g2 M
) A9 O6 @: c1 U7 }) _8 ]
这里的%1$代表传入的第1个参数,同理,%2$代表传入的第2个参数。
$ j9 u+ w" C" h, y8 B- X; s; {1 Y) h$ @2 g: F' u9 [+ c
步骤2:在rule handler的代码中定义错误代码:
! q3 N5 R6 l# M8 f3 E9 h8 [( a- f1 x" ] q) N
#define WORKFLOW_ERROR1 ( EMH_USER_error_base + 300 )
) O- @- Z+ L# D0 v0 T" ~+ D1 j9 A#define WORKFLOW_ERROR2 ( EMH_USER_error_base + 301 )8 b9 v3 |4 s: g
#define WORKFLOW_ERROR3 ( EMH_USER_error_base + 302 )+ {7 p4 B9 [0 T4 j
) W, @: Q h& Y
#define WORKFLOW_ERROR4 ( EMH_USER_error_base + 303 )
: o9 s( x0 y: O2 F1 D0 P' B' x* b) f: M( v' L$ j
使ID和配置文件中的错误消息ID号一致。7 \4 k( i A( I* k
% q! b+ b, e, P% m
步骤3:在rule handler的代码中,当不满足条件时,调用EMH_store_error的相关方法如(需要传递参数的话参照帮助文档):
0 U- t0 a& J0 }& n6 p7 Q4 @EMH_store_error (EMH_severity_user_error,WORKFLOW_ERROR2) ;* U" c) l6 l: |4 }* r
status=WORKFLOW_ERROR2;
+ N# p1 J7 ~! SEMH_ask_error_text(status, &message);+ q& g4 _ |4 j" G3 U
printf("error is [%s]", message);
2 l. |: @5 ~# ^5 e1 G5 q0 @/ ]1 v不满足条件仍然返回EPM_nogo即可。
* c+ Q0 o9 S1 v" o- {8 Z% t6 @' _( @, C: u6 v' [7 t
步骤4:按照帮助文档Create a custom error message的最后部分提示,先设置服务器端的环境变量6 _0 y- `( Z. [* L4 U& O$ k' D: L$ {
set TC_USER_MSG_DIR=%TC_DATA%\lang\textserver\en 使TC_USER_MSG_DIR指向ue_errors.xml所在的目录,并修改tcdata目录下的tc_profilevars.bat文件内容,内容如下:
( Y( Y( S; z0 _. u* |- J0 ~if not defined TC_USER_MSG_DIR set TC_USER_MSG_DIR=%TC_ROOT%\lang\textserver\en+ ]; n+ f5 ]; Q' M7 J; q
5 R! [/ D5 F9 g1 `这样自定义消息就算完成了。编译文件,将dll和pdb文件放置到服务器端的bin目录下,如果是两层客户端,需要更新客户端的TC2007下bin目录下的相应的dll和pdb文件。
/ J4 y, P+ v- [0 @* d
( L* Z- }- N+ b: [$ Q( @) y: h; t$ d实际测试中,Teamcenter 2007两层胖客户端只需要重新登录就可以看到想要的结果,而四层的客户端需要重启服务器才能生效。 |
|