Book a Demo

Author Topic: accessing EA object model from background thread  (Read 7165 times)

harvinder

  • EA User
  • **
  • Posts: 30
  • Karma: +0/-0
    • View Profile
accessing EA object model from background thread
« on: November 06, 2012, 01:58:31 pm »
I have a addin that when invoked access the EA object model to create some artefacts. The problem is that it takes 3-5 minutes for the addin to finish and during this time the EA UI is not responsive.

Is it possible to access the EA objects using a background thread like C#'s BackgroundWorker etc....

Also, I found that accessing EA object through Automation Object Model slows the things, Is there a way to speed up things here.

Thanks
Harvinder

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: accessing EA object model from background thre
« Reply #1 on: November 06, 2012, 06:11:51 pm »
Harvinder,

Yes it is possible.
I've recently done so in the EA Navigator. See https://github.com/GeertBellekens/Enterprise-Architect-Toolpack/blob/master/EANavigator/NavigatorControl.cs
It works most of the time, but sometimes it still throws an multithreading related error.
I'm still trying to find a solution for that.

Furthermore, to speed up your add-in you can:
- disable GUI updates (flag in EA.Respository)
- cache certain EA object you need more then once
- avoid iterating EA.Collections (such as Element.Attributes, Element.Methods)
- use Repository.SQLQuery() to search for the id's of object you need so you can use the Repository.Get...ByID() operations to access the object
- use the SQL based Repository implementation provided by stao http://code.google.com/p/ea-sqlapi/

Geert

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: accessing EA object model from background thre
« Reply #2 on: November 06, 2012, 08:28:36 pm »
You can also run that addin in a 2nd instance of EA.

q.

harvinder

  • EA User
  • **
  • Posts: 30
  • Karma: +0/-0
    • View Profile
Re: accessing EA object model from background thre
« Reply #3 on: November 06, 2012, 10:44:02 pm »
Thanks Geert,

[1] Thanks I will have a look at the EA navigator.

[2]
Furthermore, to speed up your add-in you can:
- disable GUI updates (flag in EA.Respository)
Will look into it, not sure if it important in my case as the only thing my addin does is traverse the graph of EA objects and creates C#, xml files. It does not at any point update the model.

- cache certain EA object you need more then once
I have already done this and achieved a 41% time saving by caching GetElementById.

- avoid iterating EA.Collections (such as Element.Attributes, Element.Methods)
I depend on these functions to traverse my graph. What would be the best way to avoid them? SQL query?

- use Repository.SQLQuery() to search for the id's of object you need so you can use the Repository.Get...ByID() operations to access the object
Not sure what you mean here, could you please elaborate. Generally if I have to get the parent object I do

Code: [Select]
repository.GetElementById(element.ParentID)

Are you suggesting the SQL query would help in the above case?

- use the SQL based Repository implementation provided by stao http://code.google.com/p/ea-sqlapi/
I will look into it

thanks

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: accessing EA object model from background thre
« Reply #4 on: November 06, 2012, 10:58:51 pm »
There's also a Repository.GetAttributeByID, GetConnectorByID,...
So if you get the ID of the attribute or operation using SQLQuery you can get the Attribute object (or Method object) directly i.s.o. having to iterate all Attributes until you find the one you need.

But those won't help of course if you need all attributes of an element.

In any case you should avoid iterating the EA.Collections more then once.
Unlike what you would expect the Element.Attributes collection does not work in memory. No, each time you iterate to the next element it will fire a couple of sql commands to the database in order to get the details of the attribute.

It is usually the sheer number of (small) SQL queries that slows things down.

So just make sure you case the EA.Element.Attrbutes in a regular (in memory) collection when you might need to iterate them more then once.

Geert

harvinder

  • EA User
  • **
  • Posts: 30
  • Karma: +0/-0
    • View Profile
Re: accessing EA object model from background thre
« Reply #5 on: November 07, 2012, 10:33:41 pm »
Code: [Select]
thanks thanks thanksToday I have changed my code to use http://code.google.com/p/ea-sqlapi/ and reduced the time taken by add-in from 5:48 min to 12 s. That is 29 times faster. Of which around 50% is taken by the initial load of the model.

I would now be working on loading appropriate tables whenever any element/attributes etc is modified. If I am able to achieve it, it would be ~ 60 times faster. ;-)

Code: [Select]
EA_OnContextItemChanged would be helpful I trust
Thanks
Harvinder

harvinder

  • EA User
  • **
  • Posts: 30
  • Karma: +0/-0
    • View Profile
Re: accessing EA object model from background thre
« Reply #6 on: November 07, 2012, 10:39:05 pm »
typo, I trust it should be EA_OnNotifyContextItemModified

stao

  • EA User
  • **
  • Posts: 137
  • Karma: +0/-0
    • View Profile
Re: accessing EA object model from background thre
« Reply #7 on: November 07, 2012, 11:03:52 pm »
if you have some ideas and / or want to contribute i
can add you to the project.

harvinder

  • EA User
  • **
  • Posts: 30
  • Karma: +0/-0
    • View Profile
Re: accessing EA object model from background thre
« Reply #8 on: November 07, 2012, 11:29:08 pm »
I have made some changes to the SQLRepository (Implements IRepository) and also added EADiagramObject to make it work for me.

I would be happy to contribute my changes to the project after somebody reviews them.

Cheers
Harvinder
PS: thanks stao for uploading the project, it would now make many things possible for our project.