如何以编程方式向场景添加上下文引用

时间:2021-04-30 07:31:17

I'm currently modifying the importer script Simple VBA Excel to EA importer v4 from bellekens.

我目前正在从bellekens将importer脚本Simple VBA Excel修改为EA importer v4。

I have succesfully imported a usecase containing scenarios and scenario steps. I'm looking for a way to add the context references programmatically.

我成功地导入了一个包含场景和场景步骤的usecase。我正在寻找一种以编程方式添加上下文引用的方法。

I'm currently adding them manualy with the use case Properties > Rules > Scenarios > Context References.

我目前正在使用用例属性>规则>场景>上下文引用来添加它们。

Is there a way to add theses context references from the API?

有办法从API中添加这些上下文引用吗?

2 个解决方案

#1


3  

I found the answer on http://sparxsystems.com/forums/smf/index.php?topic=4735.0

我在http://sparxsystems.com/forums/smf/index.php? topic?

Basicly if you associate an actor with the use case it shows up in the context reference table.

如果您将一个参与者与一个用例关联起来,它会出现在上下文引用表中。

to create the entry programmaticaly just add links between your Use case and actor programmatically.

要创建entry programmaticaly,只需以编程方式在您的用例和actor之间添加链接。

#2


1  

I actually wrote a VBScript that does that. It looks into the logical class model and adds a context reference to it if that class name is used by the use case scenario step.

实际上我写了一个VBScript来实现这一点。如果用例场景步骤使用了类名,它将查看逻辑类模型并向其添加上下文引用。

Here's that part that does the actual linking:

这是做实际链接的部分:

function linkDomainClassesWithUseCases(dictionary,regExp,usecases)
    Session.Output usecases.Count & " use cases found"
    dim usecase as EA.Element

    'loop de use cases
    for each usecase in usecases
        Repository.WriteOutput "Link to Logical Data Model", "Processing use case: " & usecase.Name, 0
        'first remove all automatic traces
        removeAllAutomaticTraces usecase
        'get all dependencies left
        dim dependencies
        set dependencies = getDependencies(usecase)
        dim scenario as EA.Scenario
        'loop scenarios
        for each scenario in usecase.Scenarios
            dim scenarioStep as EA.ScenarioStep
            for each scenarioStep in scenario.Steps
                'first remove any additional terms in the uses field
                scenarioStep.Uses = removeAddionalUses(dependencies, scenarioStep.Uses)
                dim matches
                set matches = regExp.Execute(scenarioStep.Name)
                dim classesToMatch 
                set classesToMatch = getClassesToMatchDictionary(matches, dictionary)
                dim classToMatch as EA.Element
                for each classToMatch in classesToMatch.Items
                    Session.Output "scenarioStep.Uses before " & scenarioStep.Uses
                    if not instr(scenarioStep.Uses,"LDM-" & classToMatch.Name) > 0 then
                        if len(scenarioStep.Uses) > 0 then 
                            'add a space if needed
                            scenarioStep.Uses = scenarioStep.Uses & " "
                        end if
                        'add the name of the class
                        scenarioStep.Uses = scenarioStep.Uses & "LDM-" & classToMatch.Name
                    end if
                    'create the dependency between the use case and the Logical Data Model class
                    linkElementsWithAutomaticTrace usecase, classToMatch
                    Session.Output "adding link between " & usecase.Name & " and Logical Data Model class " & classToMatch.Name & " because of step " & scenario.Name & "." & scenarioStep.Name
                next
                'save scenario step
                scenarioStep.Update
                scenario.Update
            next
        next
    next
end function

function linkElementsWithAutomaticTrace(sourceElement, TargetElement)
    dim trace as EA.Connector
    set trace = sourceElement.Connectors.AddNew("","trace")
    trace.Alias = "automatic"
    trace.SupplierID = TargetElement.ElementID
    trace.Update
end function

#1


3  

I found the answer on http://sparxsystems.com/forums/smf/index.php?topic=4735.0

我在http://sparxsystems.com/forums/smf/index.php? topic?

Basicly if you associate an actor with the use case it shows up in the context reference table.

如果您将一个参与者与一个用例关联起来,它会出现在上下文引用表中。

to create the entry programmaticaly just add links between your Use case and actor programmatically.

要创建entry programmaticaly,只需以编程方式在您的用例和actor之间添加链接。

#2


1  

I actually wrote a VBScript that does that. It looks into the logical class model and adds a context reference to it if that class name is used by the use case scenario step.

实际上我写了一个VBScript来实现这一点。如果用例场景步骤使用了类名,它将查看逻辑类模型并向其添加上下文引用。

Here's that part that does the actual linking:

这是做实际链接的部分:

function linkDomainClassesWithUseCases(dictionary,regExp,usecases)
    Session.Output usecases.Count & " use cases found"
    dim usecase as EA.Element

    'loop de use cases
    for each usecase in usecases
        Repository.WriteOutput "Link to Logical Data Model", "Processing use case: " & usecase.Name, 0
        'first remove all automatic traces
        removeAllAutomaticTraces usecase
        'get all dependencies left
        dim dependencies
        set dependencies = getDependencies(usecase)
        dim scenario as EA.Scenario
        'loop scenarios
        for each scenario in usecase.Scenarios
            dim scenarioStep as EA.ScenarioStep
            for each scenarioStep in scenario.Steps
                'first remove any additional terms in the uses field
                scenarioStep.Uses = removeAddionalUses(dependencies, scenarioStep.Uses)
                dim matches
                set matches = regExp.Execute(scenarioStep.Name)
                dim classesToMatch 
                set classesToMatch = getClassesToMatchDictionary(matches, dictionary)
                dim classToMatch as EA.Element
                for each classToMatch in classesToMatch.Items
                    Session.Output "scenarioStep.Uses before " & scenarioStep.Uses
                    if not instr(scenarioStep.Uses,"LDM-" & classToMatch.Name) > 0 then
                        if len(scenarioStep.Uses) > 0 then 
                            'add a space if needed
                            scenarioStep.Uses = scenarioStep.Uses & " "
                        end if
                        'add the name of the class
                        scenarioStep.Uses = scenarioStep.Uses & "LDM-" & classToMatch.Name
                    end if
                    'create the dependency between the use case and the Logical Data Model class
                    linkElementsWithAutomaticTrace usecase, classToMatch
                    Session.Output "adding link between " & usecase.Name & " and Logical Data Model class " & classToMatch.Name & " because of step " & scenario.Name & "." & scenarioStep.Name
                next
                'save scenario step
                scenarioStep.Update
                scenario.Update
            next
        next
    next
end function

function linkElementsWithAutomaticTrace(sourceElement, TargetElement)
    dim trace as EA.Connector
    set trace = sourceElement.Connectors.AddNew("","trace")
    trace.Alias = "automatic"
    trace.SupplierID = TargetElement.ElementID
    trace.Update
end function