Book a Demo

Author Topic: Issues with Add-Ins  (Read 4902 times)

Tom.Hopper

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Issues with Add-Ins
« on: April 21, 2016, 11:55:18 pm »
I have created an Add-In to go into Sparx to change the colours of a ShapeScript box depending on an inputted Tagged Value date.
When I install the Add-in and need to use a diagram with the elements included, it tends to seriously slow Sparx EA down to the point it is unsuable.

Could there be something I am meant to be including into the Add-In code that prevents this?

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Issues with Add-Ins
« Reply #1 on: April 22, 2016, 01:55:46 am »
If you show us the code we might be able to give tips on how to improve performance.

Geert

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Issues with Add-Ins
« Reply #2 on: April 22, 2016, 08:43:06 am »
Most likely the problem is that inside your broadcast you are loading the element to check values.  This would mean multiple calls to the database with every draw.

Tom.Hopper

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: Issues with Add-Ins
« Reply #3 on: July 14, 2016, 09:02:08 pm »
Hey guys,

Extremely long delay on this. Ok so I have 3 of the following functions within my c# add-in along with a EA_Connect() and EA_Disconnect() functions:
 
public string Shapescript_EndOfSupportDate(EA.Repository repository, string eaGuid, object theParams)
        {
            string return_value = "";
            EA.Element element = repository.GetElementByGuid(eaGuid);

            EA.TaggedValue EndOfSupportDate = (EA.TaggedValue)element.TaggedValues.GetByName("EndOfSupportDate");
            if (EndOfSupportDate != null)
            {
                try
                {
                    DateTime dt = DateTime.Parse(EndOfSupportDate.Value);
                    DateTime today = DateTime.Today;

                    if (dt.CompareTo(today.AddYears(1)) <= 0)
                        return_value = "red";
                    else if (dt.CompareTo(today.AddYears(2)) <= 0)
                        return_value = "amber";
                    else
                        return_value = "green";
                }
                catch (Exception e)
                {
                    return_value = "exception";
                }
            }
            return return_value;
        }

As I mentioned, we have 3 of these (including the one above). The issue we have is apparent, the addin (or internal shapescript code) continues to fill the colour in on the shapes to the point it makes the diagrams unusable.

I cant see it being the Shapescript code having the issue, but the below is a snippet of the code to call the add in

decoration endofSupport
{
   orientation="N";
   if(hasProperty("Type","Class")){
            if (HasProperty("#ADDIN:RAG_Stereotypes, Shapescript_EndOfSupportDate#", "red"))
              {
                     setpencolor (0,0,0);  //the border colour
                     SetFillColor(225,0,0);
              }
              else if (HasProperty("#ADDIN:RAG_Stereotypes, Shapescript_EndOfSupportDate#", "green"))
              {
                     setpencolor (0,0,0);  //the border colour
                     SetFillColor(0,255,0);
              }
              else if (HasProperty("#ADDIN:RAG_Stereotypes, Shapescript_EndOfSupportDate#", "amber"))
              {
                     setpencolor (0,0,0);  //the border colour
                     SetFillColor(255,215,0);
              }
              else
              {
                     setpencolor (0,0,0);  //the border colour
                     SetFillColor(0,0,255);
           }
          rectangle(65,45,130,125); //left, top, right,bottom
      }
   else{
      
   }
}

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Issues with Add-Ins
« Reply #4 on: July 14, 2016, 09:33:57 pm »
You are doing a few things that are slow in EA:

- Getting an instance of the element (GetElementByGuid)
- looping the tagged values ( element.TaggedValues.GetByName)

but as far as I can you you don't need the element object, nor the tagged value object, you just need the value of a certain tagged value.

If I were you I would use Repository.SQLQuery() to directly get the information you need.

So that would become something like:

Code: [Select]
string sqlGetTVValue = @"select tv.Value from t_objectproperties tv
inner join t_object o on tv.Object_ID = o.Object_ID
where tv.Property = 'EndOfSupportDate'
and o.ea_guid = '" + eaGuid + "'";

string queryResult = repository.SQLQuery(sqlGetTVValue );

This will get you an xml string with the results of the query.
I'm pretty sure this will be a lot faster then your original code.

Geert