Author Topic: Enterprise Architect shows Pop-Up when using API through C#  (Read 2270 times)

ea0921

  • EA User
  • **
  • Posts: 99
  • Karma: +0/-1
    • View Profile
Enterprise Architect shows Pop-Up when using API through C#
« on: October 27, 2023, 05:09:03 am »
I am using enterprise architect version 15 and I have created one file based project with .eapx file Extension. I am trying to create and update new package via API(using C# language) in enterprise architect with following hierarchy: Root Model/Package/New Package and while Updating the package I am getting following pop of underlying model has been changed, which freezes my enterprise architect to respond to any further API calls

Following is the order of execution(Here every step is an separate function which passes the newPackage that is created):

1. First create a package with name 'Demo'

Code: [Select]
Package newPackage = package.Packages.AddNew(EAConstants.OH_CREATE_TEMPLATE, "Package");
newPackage.Update();

2. Set the system field values.
Code: [Select]
Package package = (Package)newPackage;
package.Element.Status = "Approved"
package.Element.Stereotype = <Some Stereotype Value>;
package.Element.Update();
package.Update();

3. Set tagged values
Code: [Select]
Package pc = (Package)newPackage;
Element element = pc.Element;
set tag values for element
element.TaggedValues.Refresh();
element.Update();

4. Update name of the new package
Code: [Select]
Package changePackage = (Package)newPackage
changePackage.Name = "NewName"
changePackage.Update();

5. Refresh package
Code: [Select]
Package package = (Package)newPackage
newPackage.Element.Refresh();
newPackage.Update();

Tried things:
  • Tried to refresh all the models after each update step.
  • Tried to refresh all the model before each update step.

Expectations: Avoid the pop-up displaying warning message, because it freezes my enterprise application for any further API calls(More suitable approach: avoid using suppress dialog box method for package).

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13283
  • Karma: +556/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Enterprise Architect shows Pop-Up when using API through C#
« Reply #1 on: October 27, 2023, 05:50:20 pm »
I'm pretty sure this is happening because all of the superfluous Update() and Refresh() calls.

You really shouldn't execute code unless you know for sure you need it.

Examples:
Code: [Select]
Package package = (Package)newPackage;
package.Element.Status = "Approved"
package.Element.Stereotype = <Some Stereotype Value>;
package.Element.Update();
package.Update();
There no need for the last pacakge.Update() since you didn't change anything to the package object, and you already save the package.Element

Code: [Select]
Package pc = (Package)newPackage;
Element element = pc.Element;
set tag values for element
element.TaggedValues.Refresh();
element.Update();
This code does nothing (functional) at all. No need for either Refresh() or element.Update()

Code: [Select]
Package package = (Package)newPackage
newPackage.Element.Refresh();
newPackage.Update();

Again, this code does nothing at all.

If you limit your code to only those things you actually need, you will have a better chance at avoiding these annoying popups.

There's also a method to delay GUI updates (enableUI<something>..), and one to tell EA something has changed (notify<something>...). Those might help as well if all else fails.

Geert