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

  1. 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

  2. Define the signature of your method

    public object AddInSearchSample(EA.Repository repository, string searchText, out string xmlResults)

  3. Write the code to xml output the *.xml file

  4. Define the Search with

    CTRL+F, New Search

  5. Store your Search

  6. You find the defined Search in the Category 'My Searches'

  7. 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&lt;DataRow> rows = from row in dt.AsEnumerable()
            orderby row.Field&lt;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

References