Book a Demo

Author Topic: link operations and behaviors using API  (Read 4861 times)

dambsst_gmail

  • EA Novice
  • *
  • Posts: 11
  • Karma: +0/-0
    • View Profile
    • dcgblimited
link operations and behaviors using API
« on: March 30, 2017, 07:25:56 pm »
Hello,

I am trying to automatically generate an "interaction with sequence diagram" for an operation by using and ADD_IN.

Everything is fine but in the "behavior tab" of the interaction the "specification" field is always empty, I can't figure out how to link it to the operation.

For the operation it's fine, the behavior tab displays the correct element.

Here is my code:
Code: [Select]
EA.Method theMethod = Repository.GetTreeSelectedObject() as EA.Method;

                if (theMethod != null)
                {
                    EA.Element oClass = Repository.GetElementByID(theMethod.ParentID);// class
                    //EA.Package oClass = Repository.GetPackageByID(oClasss.PackageID);// class
                    if (oClass != null)
                    {

                        EA.Element elt;
                        try
                        {
                            elt = oClass.Elements.GetByName(theMethod.Name);
                        }
                        catch
                        {
                            elt = oClass.Elements.AddNew(theMethod.Name, "Interaction");
                            if (elt.Update() == false)
                            {
                                Debug.WriteLine(elt.GetLastError());
                            }
                            oClass.Elements.Refresh();
                        }   


                        EA.Diagram diagram = elt.Diagrams.GetByName(theMethod.Name);                       
                        if(diagram == null)
                        {
                            diagram = elt.Diagrams.AddNew(theMethod.Name, "Sequence");
                            if (diagram.Update() == false)
                            {
                                Debug.WriteLine(diagram.GetLastError());
                            }
                            elt.Diagrams.Refresh();
                        }                                           
                       


                        theMethod.Behavior = elt.ElementGUID;
                        if (theMethod.Update() == false)
                        {
                            Debug.WriteLine(theMethod.GetLastError());
                        }

                        if (oClass.Update() == false)
                        {
                            Debug.WriteLine(oClass.GetLastError());
                        }                       
                    }
                   
                }

Also, I would like to generate the parameters automatically, but here too I can't find anywhere (taggedvalues, methods, methodsex, etc.....) where to put a reference or create these parameters!

Maybe someone knows how to handle this....

Thanks you,

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: link operations and behaviors using API
« Reply #1 on: March 30, 2017, 09:22:54 pm »
There's normally only a link from the operation to the interaction, not the other way around.
So it would be normal for the behavior tab of the interaction to be empty.

Geert

dambsst_gmail

  • EA Novice
  • *
  • Posts: 11
  • Karma: +0/-0
    • View Profile
    • dcgblimited
Re: link operations and behaviors using API
« Reply #2 on: March 30, 2017, 10:05:52 pm »
Thanks for your reply!

But if I used the behavior tab of the operation to assign a behavior to it, the behavior tab of the interaction is not empty it is also automatically filled with the reference of the operation. So there must be a kind of backward link which is created or sth like that, because TaggedValues and Methods/MethodsEx properties are always empty.

Later I will try to do a "database compare" before and after creating a link between operation and interaction using the UI, so I guess I will see which column/tables are affected. I will do the same for the interaction parameters because I can't find where they are stored.

Thanks again,

Damien

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: link operations and behaviors using API
« Reply #3 on: March 31, 2017, 05:19:26 pm »
Thanks for your reply!

But if I used the behavior tab of the operation to assign a behavior to it, the behavior tab of the interaction is not empty it is also automatically filled with the reference of the operation. So there must be a kind of backward link which is created or sth like that, because TaggedValues and Methods/MethodsEx properties are always empty.

Later I will try to do a "database compare" before and after creating a link between operation and interaction using the UI, so I guess I will see which column/tables are affected. I will do the same for the interaction parameters because I can't find where they are stored.

Thanks again,

Damien
Is it? I hadn't noticed that before.
I'll do some testing when I get around to it....

Geert

dambsst_gmail

  • EA Novice
  • *
  • Posts: 11
  • Karma: +0/-0
    • View Profile
    • dcgblimited
Re: link operations and behaviors using API
« Reply #4 on: April 01, 2017, 05:17:48 am »
Quote
Is it? I hadn't noticed that before.
I'll do some testing when I get around to it....

There is a row in the t_xref table which holds the link  :)

This C# function perform the database update:

Code: [Select]
private bool op_gen_add_t_xref(EA.Repository Rep, string operation_guid, string interaction_guid)
        {
            string xrefmysqlquery =
                "INSERT INTO t_xref (XrefID, Name, Type, Visibility, Behavior, Description,Client) "
                + "VALUES('@XrefID', '@Name', '@Type', '@Visibility', '@Behavior', '@Description', '@Client')";

            string xrefmysqlcmd = xrefmysqlquery;
            xrefmysqlcmd = xrefmysqlcmd.Replace("@XrefID", "{" + Guid.NewGuid().ToString() + "}");
            xrefmysqlcmd = xrefmysqlcmd.Replace("@Name", "MOFProps");
            xrefmysqlcmd = xrefmysqlcmd.Replace("@Type", "element property");
            xrefmysqlcmd = xrefmysqlcmd.Replace("@Visibility", "Public");
            xrefmysqlcmd = xrefmysqlcmd.Replace("@Behavior", "specification");
            xrefmysqlcmd = xrefmysqlcmd.Replace("@Description", operation_guid);
            xrefmysqlcmd = xrefmysqlcmd.Replace("@Client", interaction_guid);

            Debug.WriteLine(xrefmysqlcmd);
            try
            {
                Rep.Execute(xrefmysqlcmd);
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
                return false;
            }
            return true;
        }

Thanks for your help,

Damien

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: link operations and behaviors using API
« Reply #5 on: April 01, 2017, 05:06:53 pm »
Nice, thanks Damien :)

Geert