Book a Demo

Author Topic: automated xml export  (Read 4840 times)

erwinv

  • EA Novice
  • *
  • Posts: 1
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
automated xml export
« on: May 22, 2006, 02:04:34 am »
is it possible to automate the xml export?

We use the exported xml file in our custom code generator. However, since the export process and code generation can take quite a while on large models, I would like to create a nightly process for this. We have the model stored in SQL Server.

Also, can I call custom code (vb or c# or something) after the export is complete? Then I can notify the code generator that the export is complete, so it can start.

Thanks a lot
Erwin van der Valk

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: automated xml export
« Reply #1 on: May 22, 2006, 05:56:22 am »
Yes Erwin,

I fact, this might be ideal for your situation.

From an automation process, obtain the Project interface. You can do this by, for example, calling Repository.GetProjectInterface().

From the project interface call ExportPackageXMI(). There is also an ImpoortPackageXMI() function to make things complete. You'll want to read through the parameters to understand the options. They are in section 15.1.2.9.1 of the EA User Guide (as of build 790).

[There is - IMHO - a glaring hole in this solution: you can only export to a file, rather than capture the resultant XMI as a string. I can see the logic here, as XMI strings can be very long, and some systems, languages, processors, etc. prefer long XML (and thus XMI) strings to be streamed (which might have been a bit much to ask for during development of the EA API) . Still, I would have liked the option...]

Given the above limitation, grab the file once EA has finished (it is synchronous, so you can do it when the function returns). Then you can run it through your own XSLT (for example) filters and such. Remember to be very careful not to trash things if you are going to do a later import.

HTH,
David
No, you can't have it!

tbeckum

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: automated xml export
« Reply #2 on: September 06, 2006, 01:56:14 pm »
So I have been trying this, and my code executes with no errors, but no file is created. Also, the string result returned from ExportPackageXMI is an empty string. Not sure if that is a good indication or bad one.

So here is my method. Anyone see what I am doing wrong?
Code: [Select]

       public bool Export(string eapFilePath, string xmiFilePath, bool includeDiagrams)
       {
           try
           {
               EA.Repository r = new EA.RepositoryClass();
               r.OpenFile(eapFilePath);

               EA.Package topPackage = r.Models.GetAt(0) as EA.Package;
               EA.Package p = topPackage.Packages.GetAt(0) as EA.Package;
               string packageGUID = p.PackageGUID;
               System.Console.WriteLine("Trying to export package name [" + p.Name + "].");

               /*
               int diagramXML = 0;
               int diagramImage = -1;
               int formatXML = 1;
               int useDTD = 0;
               EA.EnumXMIType xmiType = EA.EnumXMIType.xmiMOF14;
               */
               EA.EnumXMIType xmiType = EA.EnumXMIType.xmiEA11;
               int diagramXML = 1;
               int diagramImage = 0;
               int formatXML = 1;
               int useDTD = 1;
               xmiFilePath = "C:/Temp/autoexported.xml";
               string result =
                   r.GetProjectInterface().ExportPackageXMI(packageGUID, xmiType,
                       diagramXML, diagramImage, formatXML, useDTD, xmiFilePath);
               r.CloseFile();

           }
           catch (Exception e)
           {
               System.Console.WriteLine(e.Message);
           }

           return true;
       }

Any tips would be appreciated.

tbeckum

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: automated xml export
« Reply #3 on: September 06, 2006, 03:59:45 pm »
The answer is, the output file string uses forward slashes instead of double back slashes.
change C:/TEMP/autoexported.xml to C:\\TEMP\autoexported.xml and I'm in business.

Would be much nicer had EA not failed silently in this case though.

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: automated xml export
« Reply #4 on: September 06, 2006, 04:41:20 pm »
Yes indeed. I looked at this, but think in VB.Net, so didn't catch it. [Methinks I should look closer...]

Perhaps you should report this as a bug - use the bug report page on the Sparx site, or check your EA Help menu - so that there is at least some kind of error signal. I doubt the silent failure was the intended behaviour.

David
No, you can't have it!