Book a Demo

Author Topic: Export XMI with unsaved Diagrams  (Read 5326 times)

Julian O

  • EA Novice
  • *
  • Posts: 10
  • Karma: +1/-0
    • View Profile
Export XMI with unsaved Diagrams
« on: June 17, 2016, 11:07:33 pm »
Good day everyone

In my C# Add-in i'm calling the EA.IDualPackage.ExportPackageXMI() method with all its arguments. This method has a string return value but after my testing the string is always empty.

Now to the real problem. The method mentioned above pops-up a dialog if the current package has some unsaved elements inside and asks if it should proceed with this unsaved elements or abort the import. Usally the export should be aborted. And since i'm calling an external application after it has exported i would also not execute if it wasn't exported.

I tried getting information about Diagrams and if they have unsaved changes, but i'm out of luck with the EA-API as far as i see it. But maybe one of you has already had a similar case and managed to find a solution. Maybe by directly executing a SQL-Query?
Is there a way to find if a package or it's diagrams are in a unsaved state?

Thank you very much for your help :)

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Export XMI with unsaved Diagrams
« Reply #1 on: June 17, 2016, 11:37:09 pm »
I don't think you can figure out if there are unsaved changes, but you should be able to save all diagrams.

I'm doing that in some of my scripts too and it might solve your problem too.

Geert

Uffe

  • EA Practitioner
  • ***
  • Posts: 1859
  • Karma: +133/-14
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Re: Export XMI with unsaved Diagrams
« Reply #2 on: June 17, 2016, 11:48:03 pm »
Hello,


"Unsaved" is a state in the EA client, and it applies only to diagrams, not packages. What it means is that changes have been made to the layout of a diagram which have not yet been written to the database. Saving the diagram writes the changes.

So a SQL query isn't going to help, because that returns only what's in the database. There is no way in the documented API to get at the internal client state.

All non-layout properties, such as element names, attributes, tagged values, etc etc, are written to the database immediately upon clicking OK in the dialog. Therefore, a package can not itself be in an unsaved state, but one or more of its diagrams might.

It's slightly different if you're using the API to modify things. Then your changes remain unwritten until you call the .Update() method on the appropriate Package, Element, Attribute, etc, object. But it would make no sense for you to omit that and then go calling Project.ExportPackageXMI(), and I'm not sure EA would even pick up on that situation: it is a fault state that you can only force the client into by not following the prescribed procedure.

The simplest way to deal with this situation is to call Repository.SaveAllDiagrams() before doing the export. It's probably a good idea to inform the user that this side effect will occur.

Which is essentially what Geert is saying. :)

HTH,


/Uffe
My theories are always correct, just apply them to the right reality.

Julian O

  • EA Novice
  • *
  • Posts: 10
  • Karma: +1/-0
    • View Profile
Re: Export XMI with unsaved Diagrams
« Reply #3 on: June 17, 2016, 11:54:57 pm »
Thank you both very much for your responses (and Uffe for the further explanation).
I will check that option to just save all diagrams but i think that would be an appropriate workaround.

Thanks. :)

Julian O

  • EA Novice
  • *
  • Posts: 10
  • Karma: +1/-0
    • View Profile
Re: Export XMI with unsaved Diagrams
« Reply #4 on: June 18, 2016, 12:27:54 am »
Okay, because I don't like just storing all Diagrams upon exporting one package i have implement a method to just save all diagrams in the specified package. Here is what it looks like:

Code: [Select]
    /// <summary>
    /// Saves all Diagrams inside the given Package
    /// </summary>
    /// <param name="i_oPackage">The Package to search for Diagrams</param>
    /// <param name="Repository">The EA Repository</param>
    public static void SaveAllDiagrams(this EA.IDualPackage i_oPackage, EA.Repository Repository)
    {
      // Save all Diagrams in the current Package
      foreach (EA.IDualDiagram oDiagram in i_oPackage.Diagrams)
      {
        Repository.SaveDiagram(oDiagram.DiagramID);
      }

      // Diagrams can also be in Elements
      foreach (EA.IDualElement oElement in i_oPackage.Elements)
      {
        oElement.SaveAllDiagrams(Repository);
      }

      // Go recursively through all Packages
      foreach (EA.IDualPackage oPackage in i_oPackage.Packages)
      {
        oPackage.SaveAllDiagrams(Repository);
      }
    }

    /// <summary>
    /// Saves all Diagrams inside the given Element
    /// </summary>
    /// <param name="i_oElement">The Element to search for Diagrams</param>
    /// <param name="Repository">The EA Repository</param>
    public static void SaveAllDiagrams(this EA.IDualElement i_oElement, EA.Repository Repository)
    {
      // Save all Diagrams in the current Element
      foreach (EA.IDualDiagram oDiagram in i_oElement.Diagrams)
      {
        Repository.SaveDiagram(oDiagram.DiagramID);
      }
    }