Author Topic: Import and Export Reference Data within Add-in  (Read 19077 times)

avantol13-2

  • EA Novice
  • *
  • Posts: 11
  • Karma: +0/-0
    • View Profile
Import and Export Reference Data within Add-in
« on: October 24, 2014, 01:52:55 am »
Hello all,

I'd like to export the current code generation template for the C language, import a custom template (do some other unrelated stuff), then re-import the original C language template.

I've been digging into the API and have found methods to import files and directories to populate the model, but nothing for this reference data. :( Anyone know where I should be looking in the API?

Thanks,
Alex

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Import and Export Reference Data within Add-in
« Reply #1 on: October 24, 2014, 05:57:29 am »
Try
Code: [Select]
Repository.CustomCommand ("Repository", "ImportRefData", <xml>);
q.

avantol13-2

  • EA Novice
  • *
  • Posts: 11
  • Karma: +0/-0
    • View Profile
Re: Import and Export Reference Data within Add-in
« Reply #2 on: October 24, 2014, 07:04:33 am »
Repository.CustomCommand("Repository", "ImportRefData", "C:\\originalCodeGenTemplate.xml");

Does not seem to work, EA gives me an error that looks like this:

Error:
Code = 0xc00cs556
Source = Line:1; Char:1
Error Description = Invalid at the top level of the document.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Import and Export Reference Data within Add-in
« Reply #3 on: October 24, 2014, 08:29:56 am »
Not the path to the file. The XML itself as string.

q.

avantol13-2

  • EA Novice
  • *
  • Posts: 11
  • Karma: +0/-0
    • View Profile
Re: Import and Export Reference Data within Add-in
« Reply #4 on: October 24, 2014, 11:47:34 pm »
Awesome, that works, but export does not.

What parameters do I pass in to tell it to export the c code template? Or can I get force the export ref data window to appear to choose what to export?

Is this not possible? How can I work around this, I want to preserve the templates that are there before I import the new ones.

Thanks for all your help, I'm swimming in uncharted waters so I apologize for my ignorance.

Regards,
Alex

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Import and Export Reference Data within Add-in
« Reply #5 on: October 25, 2014, 12:47:39 am »
Unfortunately this is an unofficial API function. It has been investigated by a couple of people but just the export of ref-data and opening a hand full of dialogs were discovered so far. In order to get on with the ref-data export you could simply read the underlying table and write time simply formatted as XML to a file. I did so in the past and it's quite easy.

q.
« Last Edit: October 25, 2014, 12:48:10 am by qwerty »

avantol13-2

  • EA Novice
  • *
  • Posts: 11
  • Karma: +0/-0
    • View Profile
Re: Import and Export Reference Data within Add-in
« Reply #6 on: October 25, 2014, 01:01:34 am »
"read the underlying table and write time simply formatted as XML to a file"

I'm confused as to what you mean. What underlying table?

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Import and Export Reference Data within Add-in
« Reply #7 on: October 25, 2014, 08:21:41 am »
All reference data are stored in according tables of EA's database. I can't recall which table holds the code gen scripts. Maybe someone else? If not, I'll try to find it out Monday.

q.

[edit:] It looks like the default code templates are hard coded in EA and custom code templates go to t_template. The table structure is quite simple and you can probably figure out yourself.
« Last Edit: October 25, 2014, 08:47:28 am by qwerty »

avantol13-2

  • EA Novice
  • *
  • Posts: 11
  • Karma: +0/-0
    • View Profile
Re: Import and Export Reference Data within Add-in
« Reply #8 on: October 28, 2014, 01:10:46 am »
I am able to view the database table within EA by doing what you've said, and I'm looking into how to access that table using C# (attempting to establish a connection to the EA database and whatnot) but I'm having no luck so far. I'm a total newbie with databases (and everything else).

Question q: Does your book detail how to connect to the database using anything other than EA itself? I've looked over the sample, but didn't see anything.

Thanks again for all your help,
Alex

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Import and Export Reference Data within Add-in
« Reply #9 on: October 28, 2014, 01:48:16 am »
To access the contents of a table use Repository.SQLQuery ("SELECT <columns> FROM <table>...". The result is a XML formatted string containing the result set.

My Inside book details quite some of EA's internal tables. It's not complete (e.g. t_xref keeps quite some secrets, some tables are rather exotic, ...) but it contains really a lot of useful details. Also my Scripting book does not give a detailed example for above SQLQuery, but it provides a lot of basics in a concise form. Sure, you can find that in the online help, but then you need to be quite pain-free.

q.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13387
  • Karma: +564/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Import and Export Reference Data within Add-in
« Reply #10 on: September 09, 2021, 07:34:26 pm »
Just in case someone stumbles on this topic in the future... (like I just did)

Things have evolved since 2014. Now you can there are methods on the Project Interface to import and export reference data:

ExportReferenceData (string FileName, string Tables)
ImportReferenceData (string FileName, string DataSets)

Geert

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Import and Export Reference Data within Add-in
« Reply #11 on: September 09, 2021, 11:21:06 pm »
And does it work?

q.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13387
  • Karma: +564/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Import and Export Reference Data within Add-in
« Reply #12 on: September 09, 2021, 11:57:48 pm »
And does it work?

q.

Yes it does, but contrary to what the documentation says, you have to use the dataset names, and not the table names.
So use "Automation Scripts;" and not "t_script;"

This little test script copies my scripts from my DEV to my TEST repository

Code: [Select]
sub main
dim projectInterface as EA.Project
set projectInterface = Repository.GetProjectInterface
projectInterface.ExportReferenceData "H:\Temp\export\refdata.xml", "Automation Scripts;"
dim testRepository as EA.Repository
set testRepository = CreateObject("EA.Repository")
testRepository.OpenFile "DBType=1;Connect=Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=EA_TEST;Data Source=MyServer;LazyLoad=1;"
dim testProjectInterface as EA.Project
set testProjectInterface = testRepository.GetProjectInterface
testProjectInterface.ImportReferenceData "H:\Temp\export\refdata.xml", "Automation Scripts;"
testRepository.Exit
msgbox "finished"
end sub

main

I'm thinking of integrating that into my development tools.

Geert

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Import and Export Reference Data within Add-in
« Reply #13 on: September 10, 2021, 02:11:56 am »
The docs say
Quote
ables: String - the list of reference data tables to be output; the data table delimeter is ";"
If the string is empty, Enterprise Architect will prompt with a dialog to select the tables to output
It does not say database table names. But actually it even does not tell the name you can supply at all. A wonder you figured it out.

q.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13387
  • Karma: +564/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Import and Export Reference Data within Add-in
« Reply #14 on: September 10, 2021, 03:49:51 am »
The docs say
Quote
ables: String - the list of reference data tables to be output; the data table delimeter is ";"
If the string is empty, Enterprise Architect will prompt with a dialog to select the tables to output
It does not say database table names. But actually it even does not tell the name you can supply at all. A wonder you figured it out.

q.
Trial and error. Took me 5 or 6 tries I think.
Not that unusual when developing EA tooling ;)

Geert