如何循环跟踪对象和对象历史信息 [英] how to keep track of object and object history information in a loop

查看:101
本文介绍了如何循环跟踪对象和对象历史信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写DXL脚本以从所有对象中提取历史记录信息,并将一些历史记录参数写入DOORS模块中的其他属性(列)中.我从DXL参考手册(rev 9.6,第333页附近)中的示例脚本开始,该脚本仅将信息打印到DXL编辑器窗口中.我试图添加一些代码以写入属性_Reviewer -参见下文.编写的代码着眼于当前选择的对象,而不是当前h历史记录所属的对象.传递给函数print的最安全的变量是什么,以便我可以访问所需的对象并写入其_Reviewer属性?

// history DXL Example
/*   from doors  manual  
Example history DXL program.
Generate a report of the current Module's
history.
*/
// print a brief report of the history record
// hs     is a variable of type HistorySession
// module      is a variable of type Module

void print(History h) {
HistoryType ht = h.type
print h.author "\t" h.date "\t" ht "\t"
//next 3 lines are the code I added to the manual's example 
Buffer authortmp = create;
authortmp =  h.author "\t" h.date "\t" ht "\t"
 (current Object)."_Reviewer" = authortmp; 

// other code from original deleted
}

// Main program
History h
print "All history\n\n"
for h in current Module do print h
print "\nHistory for current Object\n\n"
for h in current Object do print h
print "\nNon object history\n\n"
for h in top current Module do print h

我设想您不仅要为模块的一个对象而且要为模块的所有对象设置_Reviewer属性.因此,您将在所有对象上循环,对于每个对象,将在其每个历史记录条目上循环.

所以,主循环就像

Module m = current
string sHistoryAttributeName = "_Reviewer"
if (null m) then {infoBox "Open this script from a module";halt)
// […]add more code to check whether the attribute "_Reviewer" already exists in the current module and whether the module is open in edit mode
Object o
for o in entire m do {
  if isDeleted(o) then continue // deleted objects are not of interest
  // perhaps there are more objects that are not of interest. add relevant code here
  if (!canModify o.sHistoryAttributeName) then {warn "cannot modify history entry for object " (identifier o) "\n"; continue}
  Buffer bContentOfReview = create
  History h
  for h in o do {
    bContentOfReview += getHistoryContent(h) "\n"
  }
  o.sHistoryAttributeName = sContentOfReview
  delete bContentOfReview
}
save m

和函数getHistoryContent与函数void print (History h)类似,只不过您将返回一个字符串而不是打印历史记录条目.像

string getHistoryContent (History h) {
  HistoryType ht = h.type
  string sReturnValue = h.author "\t" h.date "\t" ht ""
  return sReturnValue
}

另一个提示:您写了其他属性(列)".上面的解决方案是针对持久属性的.取而代之的是,您可能希望在视图中将信息显示为DXL布局列或DXL属性-两种可能性都具有以下优点:信息或多或少始终是最新的,但具有持久属性信息仅在您运行脚本后才是最新的.还要注意,这种方法只会给您自上次基准以来的更改.如果您需要更多,问题将会更加复杂.请参阅Rational DXL论坛或google,以获取显示历史记录条目的更复杂的解决方案

//删除了字符串连接中的错字,请使用Buffer insted

I'm writing a DXL script to extract history information from all objects and write some of the history parameters into other attributes (columns) in the DOORS module. I started out with the example script in the DXL Reference Manual (rev 9.6, near page 333), which just prints the information into the DXL editor window. I tried to add some code to write to the attribute _Reviewer -- see below. The code as written looks at the currently selected object rather than the one to which the current h history belongs to. What's the safest variable to pass into the function print so I can access the desired object and write to its _Reviewer attribute?

// history DXL Example
/*   from doors  manual  
Example history DXL program.
Generate a report of the current Module's
history.
*/
// print a brief report of the history record
// hs     is a variable of type HistorySession
// module      is a variable of type Module

void print(History h) {
HistoryType ht = h.type
print h.author "\t" h.date "\t" ht "\t"
//next 3 lines are the code I added to the manual's example 
Buffer authortmp = create;
authortmp =  h.author "\t" h.date "\t" ht "\t"
 (current Object)."_Reviewer" = authortmp; 

// other code from original deleted
}

// Main program
History h
print "All history\n\n"
for h in current Module do print h
print "\nHistory for current Object\n\n"
for h in current Object do print h
print "\nNon object history\n\n"
for h in top current Module do print h

解决方案

I imagine that you want to set the _Reviewer attribute not only for one object but rather for all objects of the module. So you will have a loop over all objects and for each object you will have a loop over each of its history entries.

So, the main loop would be like

Module m = current
string sHistoryAttributeName = "_Reviewer"
if (null m) then {infoBox "Open this script from a module";halt)
// […]add more code to check whether the attribute "_Reviewer" already exists in the current module and whether the module is open in edit mode
Object o
for o in entire m do {
  if isDeleted(o) then continue // deleted objects are not of interest
  // perhaps there are more objects that are not of interest. add relevant code here
  if (!canModify o.sHistoryAttributeName) then {warn "cannot modify history entry for object " (identifier o) "\n"; continue}
  Buffer bContentOfReview = create
  History h
  for h in o do {
    bContentOfReview += getHistoryContent(h) "\n"
  }
  o.sHistoryAttributeName = sContentOfReview
  delete bContentOfReview
}
save m

and your function getHistoryContent would be similar to your function void print (History h), only that you will return a string instead of printing the history entry. Something like

string getHistoryContent (History h) {
  HistoryType ht = h.type
  string sReturnValue = h.author "\t" h.date "\t" ht ""
  return sReturnValue
}

One additional hint: you wrote "into other attributes (columns)". The above solution is for persistent attributes. Instead of this, you might want to show the information in a view as a DXL Layout column or or as a DXL attribute -- both possibilities have the advantage that the information is more or less always up to date, but with a persistent attribute the information will only be current after you run the script. Also note that this approach will only give you the changes since the last baseline. If you need more, the problem will be more complex. See the Rational DXL forum or google for more complex solutions of showing history entries

//Edit: removed typo in string concatenation, use Buffer insted

这篇关于如何循环跟踪对象和对象历史信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆