AddInModelSearch - Helmut-Ortmann/EnterpriseArchitect_hoTools GitHub Wiki
Add-In: Model Search
Sometimes it's useful to define complex searches with a so called Add-In Search. If you have an Add-In ready to insert a function and to deploy it's an easy task.
The AddIn Search works the same way as other EA Searches. A simple way is:
- Store Information in a DataTable
- Run LINQ for the DataTable Selects, Order, and Filter rows of the table
- Generate xml from LINQ result/enumeration (standard method: 'MakeXml')
With hoTools you can export the results to Excel.
LINQ
LINQ is a powerful query tool in .NET. Using LINQ you only have to write the found data in a data tables. With LINQ you can:
- Filter
- Order
- JOIN
- GROUP
- Aggregate
- and a lot more
After querying the data just write 'xmlResult = MakeXml(dt, rows);' and you are done.
The simple query make with EA Query or SQL. For the complex queries concider Add-In Model Search with LINQ.
pros
- Complex Model Searches
- You may combine SQL and Add-In Searches (performant and complex)
cons
- Often EA Standard Query or SQL is easier
- Might be slow is searching a lot in the model (you may mitigate this by additional using SQL)
Steps
-
Specify what you want to search for
It's a good idea to define the first two columns as guid with the name 'CLASSGUID' and object_type with the name 'CLASSTYPE' See The GUID and Type
-
Define the signature of your method
public object AddInSearchSample(EA.Repository repository, string searchText, out string xmlResults)
-
Write the code to xml output the *.xml file
-
Define the Search with
CTRL+F, New Search
-
Store your Search
-
You find the defined Search in the Category 'My Searches'
-
EA stores all your Searches in c:\Users\<user>\AppData\Roaming\Sparx Systems\EA\Search Data\EA_Search.xml
Example
// Add-In Search
// Define the Add-In Search in EA
// CTRL+F, new Search, Select Add-In Search
// Name: Your Name
// Reference to Add-In Method: AddinName.MethodName
// EA stores the Search in the category 'My Searches'
public object AddInSearchSample(EA.Repository repository, string searchText, out string xmlResults)
{
// 1. Collect data into a data table
DataTable dt = SetTable();
// 2. LINQ: Order, Filter, Join,
OrderedEnumerableRowCollection<DataRow> rows = from row in dt.AsEnumerable()
orderby row.Field<string>("Name") descending
select row;
// 3. Make xml (standard method provided by AddInSimple)
xmlResults = MakeXml(dt, rows );
return "ok";
}
Support
AddInSimple has a function:
- private string MakeXml(dt, rows ) {}
MakeXml makes an EA-xml from a LINQ Enumeration and a DataTable. Have a look in the example.
Books
I've found, bought, and appreciated the following books
- Fifty Enterprise Architect tricks, by Peter Doomen
- Scripting Enterprise Architect, by Thomas Kilian
- Inside Enterprise Architect, by Thomas Kilian
- Shape Script made easy, by Thomas Kilian
References
- Excel Export
- EA Forum entry to show the principles
- AddInSimple: C# Example Addin with Shape Script extension
- AddinSimpleSetup: C#/WIX Example Installation Project for AddinSimple
- Tip&Tricks
- SPARX Tricks and Traps Add-In Deployment
- EA Installation Inspector V2, by Adrian
- Non-admin installation of Add-Ins
- Tutorial: C# Add-In in 10 minutes, by Geert Bellekens
- Shape Script made easy, by Thomas Kilian
- Domain specific Profiles, by Thomas Kilian
- Implementation