Book a Demo

Author Topic: Call behaviours from sequence diagrams in separate package, .net C#  (Read 4725 times)

dambsst_gmail

  • EA Novice
  • *
  • Posts: 11
  • Karma: +0/-0
    • View Profile
    • dcgblimited
Hello Everyone,

I have created and modified the add-in from http://blog.sparxsystems.eu/2015/06/do-you-miss-something-in-ea's-code-generator/ in order to solve the problem when calling an operation of a class which is outside the current package.

The message from the code template is "Associated behavior not found within the package!!" , I am sure you have already seen it  ;)

If I move this package to the same package than my calling class, it works perfectly.



So basically, I have reversed engineer the mscorlib.dll from microsoft inside a package called "framework" , so that I can access the .net framework inside EA.

I have another package called "system" with a class and an operation defined by a behaviour which interact with the class system.console from .net framework.

I want to call the operation WriteLine("") , but it complains that it can not find it within the package. If I nest the "framework" package under "system", everything is perfect it ends up with Console.WriteLine("Hello");

So what I have done so far: I have modified the C# code template "Action Call" and replace the section:
Code: [Select]
%if $sBehName == ""%
/*Warning: $sActionName - Associated behavior not found within the package!!*/
%endTemplate%

with
Code: [Select]
%if $sBehName == ""%
$sBehName = %EXEC_ADD_IN("EA_DCGB_ADDIN", "MyEASL_GET", "element", $GUID, "Name")%
%endIf%

Using visual studio and the debugger, I succeeded to find a matching object with same GUID, it is an object of type "Connector". The problem is now that I can not find any way to reach its operation to return its name.... and I am not even sure I should do this.

By using Bellekens Enterprise Architect Toolpack at https://bellekens.com/product/bellekens-enterprise-architect-toolpack/ , when I perform a search by GUID it finds the connector and the matching operation. But I don't succeed.

If someone has found how to do it I would really appreciate to receive a hint or a solution because I am a bit confused with the SDK, how the EA objects are constructed and how the behaviours are interpreted by the code generator.

Many Thanks,
« Last Edit: March 26, 2017, 06:34:51 am by dambsst_gmail »

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Call behaviours from sequence diagrams in separate package, .net C#
« Reply #1 on: March 26, 2017, 05:53:11 pm »
If you use the EA Navigator, and you select the message on the sequence diagram you should be able to select the operation.
It is based on a tagged value on the message that holds the guid of the operation.

Geert

dambsst_gmail

  • EA Novice
  • *
  • Posts: 11
  • Karma: +0/-0
    • View Profile
    • dcgblimited
Re: Call behaviours from sequence diagrams in separate package, .net C#
« Reply #2 on: March 26, 2017, 09:43:08 pm »
Hello Geert,

Thanks a lot!! But like, a lots of lots  :D :D

You lead me to the good way with the taggedvalue, now I will always inspect them because they hold information and even if they are not displayed in Enterprise Architect we can see them using InteropEA.dll

Using EA navigator yes I could view and select the operation, but not more, I didn't know where this information is stored and yes it is a  tag value called "operation_guid" ! 

So I tried to access it using the code tempate only but without success:
Code: [Select]
%if connectorTag:"operation_guid" != ""%
...
%endIf

%if connectorDestTag:"operation_guid" != ""%
...
%endIf

%if connectorDestElemTag:"operation_guid" != ""%
...
%endIf

But without success.

So I finally modified your add-in:

Code: [Select]
switch (what)
                {
                    case "connector":
                        EA.Connector conn = rep.GetConnectorByGuid(owner);
                        if (conn != null)
                        {
                            foreach (EA.ConnectorTag tag in conn.TaggedValues)
                            {
                                if (tag.Name == "operation_guid")
                                {
                                    EA.Method method = rep.GetMethodByGuid(tag.Value);
                                    result = method != null ? method.Name : "";
                                    break;
                                }
                            }
                        }
                        break;

                    case "element":
                        Element ownerElement = rep.GetElementByGuid(owner);
                        result = ownerElement != null ? GetElementProperty(rep, ownerElement, name) : "";
                        break;
....

and the c# code template of "Action Call":
Code: [Select]
%if $sBehName == ""%
$COMMENT = "Maybe it is in another package, it's not reachable"
$COMMENT = "If the $GUID is a \"connector\", try to get its \"operation_guid\" taggedvalue"
$sBehName = %EXEC_ADD_IN("EA_DCGB_ADDIN", "MyEASL_GET", "connector", $GUID, "Name")%
%if $sBehName == ""%
%endTemplate%
%endIf%

Now everything's fine, not completly clear I will certainly faced other issues later but I hope I will learn from your source at
https://github.com/GeertBellekens/Enterprise-Architect-Toolpack

I have 15 days left on my trial, I will go forward and fill my custom MDG Technology with lots of C#.

Thanks again!
Best support ever! (especially since we are sunday morning  ;) )