Book a Demo

Author Topic: Adding Custom Property to EA project or database  (Read 7211 times)

Mithal

  • EA User
  • **
  • Posts: 27
  • Karma: +0/-0
    • View Profile
Adding Custom Property to EA project or database
« on: November 11, 2010, 09:28:43 pm »
Hi.

How can i add a custom property or user property to my EA project or database.

Here is the scenario.  Every time the EA_FileOpen event fires, i want to check the repository for this Custom Property or User Property that i added.

If i find this property or not then i can do something.

Thanks. :)

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Adding Custom Property to EA project or databa
« Reply #1 on: November 12, 2010, 05:15:22 pm »
Mithal,

Do you want one property for the whole repository, or one for each element?

Geert

Mithal

  • EA User
  • **
  • Posts: 27
  • Karma: +0/-0
    • View Profile
Re: Adding Custom Property to EA project or databa
« Reply #2 on: November 12, 2010, 05:18:36 pm »
One for the whole repository.

I am currently using this:
EA.PropertyType tagType = (EA.PropertyType)Repository.PropertyTypes.AddNew(property, "");

there is more code to this, though.

Is it the correct one or have i gone of in the wrong direction.

Thanks :)

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Adding Custom Property to EA project or databa
« Reply #3 on: November 12, 2010, 05:40:22 pm »
The property types are actually the predefined tagged values you can set using "Settings|UML|Tagged Value Types"
The downside of this is that users can start using this tagged value on their elements.
I don't really see an obvious better choice, you could use things like Repository.Terms

Another option is to (ab)use the notes field of the root model(s).
You can find them if you search for t_package where parentID = 0.
That notes field isn't displayed in EA and is also not editable by the users, so they can't mess up your solution.

Geert

Mithal

  • EA User
  • **
  • Posts: 27
  • Karma: +0/-0
    • View Profile
Re: Adding Custom Property to EA project or databa
« Reply #4 on: November 12, 2010, 06:16:59 pm »
Ok.

Can you help with some sample code ?

Thank you.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Adding Custom Property to EA project or databa
« Reply #5 on: November 12, 2010, 06:32:59 pm »
To set your property you could do something like
Code: [Select]
foreach (EA.Package rootModel in myRepository.Models)
{
   rootModel.Notes = "myProperty";
   rootModel.Update();
}

To read it you do something similar
Code: [Select]
boolean hasMyProperty;
foreach (EA.Package rootModel in myRepository.Models)
{
   if (!hasMyProperty)
   {
      hasMyProperty = rootModel.Notes.Equals("myProperty");
   }
}

Geert

Mithal

  • EA User
  • **
  • Posts: 27
  • Karma: +0/-0
    • View Profile
Re: Adding Custom Property to EA project or databa
« Reply #6 on: November 12, 2010, 06:39:49 pm »
That works Geert.  Thank you.