Sparx Systems Enterprise Architect + SQL Queries : SQL Abfragen innerhalb von Enterprise Architect absetzen

Problem

Wer schon einmal versucht hat, eine lokale .EAP Datei in Microsoft Access zu öffnen, erlebt sein blaues Wunder, denn im Prinzip ist eine .EAP Datei nichts anderes als eine MS Access Datenbank (also ein .mdb-File), auf welches man SQL Queries absetzen kann. Bei der Migration eines lokalen .EAP Files in einen normalen SQL-Server, muss man zunächst die Datenstruktur anlegen und anschließend den Import starten. Eine großartige Transformation der Daten zwischen den Formaten findet also gar nicht statt. Was passiert aber wenn man kein MS Access / SQL Studio zur Verfügung hat?

Ansatz – Approach

Nutzung des kostenlosen Tools MDB Plus von Alex Nolan (das ist eine Windows Delphi Anwendung, die einfach gestartet werden kann).

Lösung – Solution

Das Tool lässt sich hier downloaden: http://www.alexnolan.net/ .
Anschließend geht man auf „Open“ und stellt die Datei-Extensionsuche von .mdb auf *.* um – danach kann man .eap Dateien öffnen.

Sparx Systems Enterprise Architect + C#: Get all EA Elements of a package

Problem

All Elements of a package should be retrieved.

Approach – Ansatz

The method getElementsOfElement, which has been defined in the previous article is used to add all subelements of a package.

Lösung – Solution

public List<EA.Element> getElementsOfPackage(EA.Package package, string packageName)
{
    List<EA.Element> elementsOfPackage = new List<EA.Element>();
    // Only list the elements if the actual package is connected to a DOORS module
    if (package.Name == packageName)
    {
        foreach (EA.Element element in package.Elements)
        {
            elementsOfPackage.Add(element);
            elementsOfPackage.AddRange(getElementsOfElement(element));
        }
    }

    foreach (EA.Package subPackage in package.Packages)
    {
        elementsOfPackage.AddRange(getElementsOfPackage(subPackage, packageName));
    }
    return elementsOfPackage;
}

private List<EA.Element> getElementsOfElement(EA.Element actualElement)
{
    List<EA.Element> elementsOfElement = new List<EA.Element>();
    EA.Collection elements;
    elements = actualElement.Elements;

    foreach (EA.Element element in elements)
    {
        elementsOfElement.Add(element);
        elementsOfElement.AddRange(getElementsOfElement(element));
    }
    return elementsOfElement;
}

Sparx Systems Enterprise Architect + C#: Recursively get all elements and sub elements of an EA Element

Problem

All elements of an subelement should be catched

Approach – Solution

Recursively iterate through all subelements and AddRange (already a list) to the List.
The interuption of the recursion is, when an empty List is used as parameter for AddRange, because the loop will not be called where the AddRange-Method is in on next iteration.

Solution – Approach

private List<EA.Element> getElementsOfElement(EA.Element actualElement)
{
    List<EA.Element> elementsOfElement = new List<EA.Element>();
    EA.Collection elements;
    elements = actualElement.Elements;

    foreach (EA.Element element in elements)
    {
        elementsOfElement.Add(element);
        elementsOfElement.AddRange(getElementsOfElement(element));
    }
    return elementsOfElement;
}

Sparx Systems Enterprise Architect + C#: Get Top Package from selected Package

Problem

The top package of an Enterprise Architect Project EAP should be retrieved

Approach

Navigate to the Parent ID until the package return null.

Solution – Lösung

public EA.Package getTopPackage(EA.Package selectedPackage)
{
    EA.Package package = null;
    try
    {
        // If it has a parent it won't throw an error
        package = repository.GetPackageByID(selectedPackage.ParentID);
    }
    catch (System.Runtime.InteropServices.COMException)
    {
        // The selectedPackage is the top package
        package = selectedPackage;
    }
    // If this is not the top package, recall this function
    if (package != selectedPackage)
    {
        package = getTopPackage(package);
    }
    return package;
}

IBM Doors DXL: Recursively load formal module by name without knowing the path / Modul nach Name Laden (Folder bekannt)

Problem

A module should be loaded by name independend from the position in the Doors Project Structure.
Ein Modul soll nur anhand seines Namens geladen werden, ohne die genaue Position im Doors Projekt zu wissen.

Premise – Prerequirement – Voraussetzung

Start Folder is known. The doors module name is unique in the project, otherwise only the first found module with that name will be loaded.
Der Startordner ist bekannt. Der Doors Modulname ist im Projekt eindeutig. Ist dies nicht der Fall, wird nur das erste Modul mit diesem Namen geladen.

Lösung -Solution

Module getModule(Folder selectedFolder, string moduleNameToCompare)
{
 Item itm;
 Module moduleToReturn = null

 for itm in selectedFolder do 
 { 
  if(type(itm) "" == "Folder") 
  { 
   moduleToReturn = getModule(folder(itm), moduleNameToCompare);	
   if(moduleToReturn != null)
   {
    break
   } 
  } 
  else if(type(itm) "" == "Formal")
  {
   Module mod;		
   mod = edit(fullName(itm), false);
   if(!null mod)
   {
     if(name(mod) "" == moduleNameToCompare) 
     {  
      moduleToReturn = mod;
      objectFound = true
      break;
     }
   }
  }
  else if(type(itm) "" == "Link")
  {
  }
 }

 return moduleToReturn;
}

IBM Doors DXL: Error Handling / Exceptions: try/catch / On Error Goto … missing? Fehlerbehandlung in Doors / DXL Fehler unterdrücken

Problem

DXL windows are opening every time a DXL error occurs and the users are sick of it :-).
Es werden jedesmal DXL-Fenster angezeigt, wenn eine DXL Funktion nicht richtig ausgeführt wird.

Ansatz

Über die Funktionen
void noError()
string lastError()

lassen sich Fehlerbehandlungsroutinen erzeugen, die Ähnlich den JAVA-Exceptions und .NET-Errors sind.

Lösung-Solution

// Try-Block start
noError(); // Alle Fehler werden deaktiviert und die Ausgabe im DXL Fenster unterdrückt

// hier den Code hin, der Fehler werfen kann

string catchMsg=lastError(); // Beinhaltet den letzten Fehler zur Ausgabe

// catchMsg ist null wenn kein Fehler existierte
if(!null catchMsg)
{
   infoBox catchMsg;
   halt;
}