Book a Demo

Author Topic: Get Project or File name of currently open project  (Read 6525 times)

kilroy54

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Get Project or File name of currently open project
« on: June 21, 2012, 12:50:10 am »
How do I get the Project Name or the Filename of the currently open project in EA through automation?

Shaggy Man

  • EA Novice
  • *
  • Posts: 13
  • Karma: +0/-0
    • View Profile

kilroy54

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: Get Project or File name of currently open pro
« Reply #2 on: June 21, 2012, 03:34:26 am »
Yeah, unfortunately that only works with a file-based EA project. When the project is in a DBMS (SQL Server, etc.) that doesn't work.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Get Project or File name of currently open pro
« Reply #3 on: June 21, 2012, 07:19:37 am »
It works, but delivers an ODBC connection string.

(see also in my scripting ebook)

q.

kilroy54

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: Get Project or File name of currently open pro
« Reply #4 on: June 21, 2012, 07:28:11 am »
Yes, an ODBC connection string which is different for every DBMS out there. My parsing code begins to look like the old Windows event handlers (a mile long...). Within those strings I must ferret out the string that corresponds to the database name for the DBMS. What I am trying to do is an Add-in that does not know where the project came from at all, so it has no way of knowing whether the DBMS is Oracle, SQL Server, PostgreSQL, or what.

It would be a lot easier if there was a property (Repository.ProjectName) that would be easily accessed.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Get Project or File name of currently open pro
« Reply #5 on: June 21, 2012, 09:01:33 am »
Yep, sure. Especially if you open a shortcut .eap leading you to "somewhere". I detailed that procedure. Maybe you should send a feature request.

q.

KP

  • EA Administrator
  • EA Expert
  • *****
  • Posts: 2919
  • Karma: +55/-3
    • View Profile
Re: Get Project or File name of currently open pro
« Reply #6 on: June 21, 2012, 09:51:02 am »
The connection string will contain "DBType=n;" where n is

0 - MYSQL
1 - SQLSVR
2 - ADOJET
3 - ORACLE
4 - POSTGRES
5 - ASA
7 - OPENEDGE
8 - ACCESS2007
The Sparx Team
[email protected]

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Get Project or File name of currently open pro
« Reply #7 on: June 21, 2012, 03:42:06 pm »
Please define "Project Name".
Do you mean
- the filename of the .eap file (does it change when I rename my file)
- The name of a root package in the model
- The name of the database
- The name used in the connection string to the database
- The name of the .eap shortcut file

In other words, what do you need it for?

I usually don't use "project" in relation to EA things.
I use "Model" to denominate a root package and I use "Repository" to denominate the database (or .eap file) that contains the models.

Names of shortcuts I don't really care about.

Geert

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Get Project or File name of currently open pro
« Reply #8 on: June 21, 2012, 09:01:34 pm »
Quote
The connection string will contain "DBType=n;"
Good to know. I'll put that into my book immediately.

q.

kilroy54

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: Get Project or File name of currently open pro
« Reply #9 on: June 22, 2012, 12:21:53 am »
Geert, with respect to the Code Generation features of EA, in .NET, code generation is almost always done for a Visual Studio "project", which usually ends up being the Namespace of the underlying classes that are generated (a simplification, but a useful one). If I am just modelling in EA, I don't need a project name, but if I want to generate .NET code from the model, I want to be able to put a default namespace in the generated classes. I reasoned that the best way to do this (without, of course, interrupting the user with a dialog that actually ASKS for the namespace) is to use the project name/file name of the .EAP project. This is easy if the .EAP is just a file (Access), but gets difficult when you go to storing your EA project in a DBMS. I hope this explains what I need this for a little better.

KP, that is good to know about the DBType, but then I still have to parse the myriad connection strings that can be used to connect to the different DBs to get the "Project Name".

Geert may be on to something when he mentions the root package name in the model. Perhaps it is better to just get the namespace from the package itself...

kilroy54

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: Get Project or File name of currently open pro
« Reply #10 on: June 22, 2012, 12:35:20 am »
Perhaps I should explain what my Add-In is all about. I want to write an EA add-in that will allow me to interface with Codesmith. Codesmith is a great tool, but it's main drawback for me has always been that it generates its code from a database. What I want to do is generate CSLA objects (code) directly from EA models. The code generation feature of EA is inadequate for this purpose, as I need to generate multiple files for a class (classxx.cs, classxx.generated.cs, classxx.dataccess.cs) and I am pretty sure EA can't do that. At any rate Codesmith templates are MUCH more powerful than the simple code templates of EA.

To that end I have created a "Csla" profile in EA which allows me to do modelling using the various CSLA stereotypes (EditableRoot, EditableChild, etc.). A user can then model his classes in EA using my profile, and use my add-in to generate code with Codesmith templates. Somewhat specialized, but for me, very useful.

g.makulik

  • EA User
  • **
  • Posts: 355
  • Karma: +0/-0
    • View Profile
Re: Get Project or File name of currently open pro
« Reply #11 on: June 22, 2012, 02:38:44 am »
I think for your purposes you should either consider to use a dialog to ask the user when you have no .eap file in the connection string or always use the model name as default namespace (since a single repository DB  may contain more than one model).

HTH
Günther
Using EA9.3, UML2.3, C++, linux, my brain, http://makulik.github.com/sttcl/