Fastest way to get a collection of all version controlled packages in Enterprise Architect

186 views Asked by At

I am trying to use a C# Script to recreate Enterprise Architects functionality get all latest. I have succeeded at scanning every package and looking if its version controlled with the following code:

Collection models = eaRepository.Models;

foreach (Package package in models) {
    resolveRecursivelyGetLatestOnPackage(package);
}

eaRepository.ScanXMIAndReconcile();

Console.WriteLine("GetLatestFinished.");

private void resolveRecursivelyGetLatestOnPackage(Package package)
{
    if (package.IsVersionControlled) {
        package.VersionControlGetLatest(false);
    }

    foreach (Package childPackage in package.Packages) {
            resolveRecursivelyGetLatestOnPackage(childPackage);
    }
}

However the EAP model I am using this on is quite big and the upper code takes a lot of time since it scans through all packages. Therefore I am trying to get all version Controlled packages by using the Select statement.

SELECT * 
FROM t_package 
WHERE IsControlled = True 

Sadly I have found no way to receive a collection of packages in the automation interface of EA.

What I have tried so far:

eArepository.GetElementSet ("SELECT * FROM t_package WHERE IsControlled = True", false);

eArepository.SQLQuery ("SELECT * FROM t_package WHERE IsControlled = True");

The getElementSet does returns an empty collection, since it is no elements I am searching for.

The SQL query seems to return what I want, but in the wrong format. I don't know how to get packages out of the XML it returns. Is there a way to do this?

How do I get a collection of all version controlled Packages Fast?

1

There are 1 answers

0
Geert Bellekens On BEST ANSWER

You should only query the package ID's using the query and then use Repository.GetPackageByID() to get the EA.Package object.

The query then becomes

"SELECT Package_ID FROM t_package WHERE IsControlled = True"

You can use an operation similar to this operation from the Enterprise Architect Addin Framework

/// <summary>
/// returns the elementwrappers that are identified by the Object_ID's returned by the given query
/// </summary>
/// <param name="sqlQuery">query returning the Object_ID's</param>
/// <returns>elementwrappers returned by the query</returns>
public List<ElementWrapper> getElementWrappersByQuery(string sqlQuery)
{
  // get the nodes with the name "ObjectID"
  XmlDocument xmlObjectIDs = this.SQLQuery(sqlQuery);
  XmlNodeList objectIDNodes = xmlObjectIDs.SelectNodes(formatXPath("//Object_ID"));
  List<ElementWrapper> elements = new List<ElementWrapper>();

  foreach( XmlNode objectIDNode in objectIDNodes ) 
  {
    ElementWrapper element = this.getElementWrapperByID(int.Parse(objectIDNode.InnerText));
    if (element != null)
    {
        elements.Add(element);
    }
  }
  return elements;
}