【问题标题】:how to keep track of object and object history information in a loop如何在循环中跟踪对象和对象历史信息
【发布时间】:2017-01-12 16:22:33
【问题描述】:

我正在编写一个 DXL 脚本来从所有对象中提取历史信息,并将一些历史参数写入 DOORS 模块中的其他属性(列)。我从 DXL 参考手册(修订版 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

【问题讨论】:

    标签: ibm-doors


    【解决方案1】:

    我想您不仅要为一个对象设置 _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

    【讨论】:

      猜你喜欢
      • 2015-09-08
      • 2014-02-22
      • 1970-01-01
      • 1970-01-01
      • 2013-02-15
      • 1970-01-01
      • 1970-01-01
      • 2020-06-09
      • 1970-01-01
      相关资源
      最近更新 更多