Kategoriearchiv: Programmierung

Sparx Systems Enterprise Architect: SQL to get the start / end coordinates of the link connector routing with customized lines

Problem

A SQL-Statement is needed (here Access / .eap) that gets all Coordinate-, Routing- and Position information of links in a diagram of the Sparx Systems Enterprise Architect.

Approach

Data Mining and the Usage of MDB Plus

Solution

The link routing is diagram dependent. In the following diagram the diagram „PLM Framework“ has been used. Further more the stereotype „BusinessProcess“ is requested (you have to replace these String according to your needs.

SELECT bp.[Object_ID] as [start_object_id],
       bp.[Name] as [start_object_name],
       tconn.[Connector_ID] as [conn_id],
       tconn.[Start_Edge] as [conn_start_edge],
       tconn.[End_Edge] as [conn_end_edge],
       tconn.[PtStartX] as [conn_pt_start_x],
       tconn.[PtStartY] as [conn_pt_start_y],
       tconn.[PtEndX] as [conn_pt_end_x],
       tconn.[PtEndY] as [conn_pt_end_y],
       tconn.[RouteStyle] as [conn_route_style],
       linkpath.[Path] as [conn_path],
       bpdest.[Object_ID] as [end_object_id],
       bpdest.[Name] as [end_object_name],
       bp.[Alias] as [start_key],
       bpdest.[Alias] as [end_key],
       startobjcoord.x as [start_obj_x],
       startobjcoord.y as [start_obj_y],
       endobjcoord.x as [end_obj_x],
       endobjcoord.y as [end_obj_y],
       linkpath.Geometry as [geometry] 
FROM
((((( 
   SELECT Object_ID, [Alias], Name 
   FROM t_object
   WHERE Stereotype='BusinessProcess'
)bp
INNER JOIN 
(  SELECT [Connector_ID],[Start_Object_ID], [End_Object_ID], [Start_Edge], [End_Edge], [PtStartX], [PtStartY], [PtEndX], [PtEndY], [RouteStyle] 
   FROM [t_connector] 
)tconn
ON tconn.[Start_Object_ID]=bp.[Object_ID])
INNER JOIN 
( 
   SELECT Object_ID, [Alias],Name 
   FROM  [t_object] 
)bpdest ON tconn.[End_Object_ID]=bpdest.Object_ID)
INNER JOIN
(
  SELECT ConnectorID, Path, Geometry
  FROM t_diagramlinks WHERE DiagramID IN (SELECT Diagram_ID FROM t_diagram WHERE Name='PLM Framework')
) linkpath ON linkpath.[ConnectorID]=tconn.[Connector_ID])
INNER JOIN
(
  SELECT objstart.Object_ID,
         objstart.Alias,
         diaobj.RectLeft As x,
         diaobj.RectTop As y
  FROM
  ((
      [t_diagram] dia LEFT JOIN (Select Diagram_ID, Object_ID, RectLeft, RectTop from [t_diagramobjects]) diaobj ON dia.[Diagram_ID]=diaobj.[Diagram_ID])
                                  LEFT JOIN [t_object] objstart ON objstart.[Object_ID]=diaobj.[Object_ID])
  WHERE dia.Name='PLM Framework'
  AND objstart.stereotype='BusinessProcess'
) startobjcoord ON startobjcoord.[Object_ID]=bp.[Object_ID])
INNER JOIN
(
  SELECT objstart.Object_ID,
         objstart.Alias,
         diaobj.RectLeft As x,
         diaobj.RectTop As y
  FROM
  ((
      [t_diagram] dia LEFT JOIN (Select Diagram_ID, Object_ID, RectLeft, RectTop from [t_diagramobjects]) diaobj ON dia.[Diagram_ID]=diaobj.[Diagram_ID])
                                  LEFT JOIN [t_object] objstart ON objstart.[Object_ID]=diaobj.[Object_ID])
  WHERE dia.Name='PLM Framework'
  AND objstart.stereotype='BusinessProcess'
) endobjcoord ON endobjcoord.[Object_ID]=bpdest.[Object_ID]

Sparx Systems Enterprise Architect: Get Composite Diagram by SQL

Problem

The menu point „Set Composite Diagram“ allows to create a clickable link to another diagram from objects. Unfortunetly to get the references in SQL (with start and end GUID) is a little bit tricky…

Approach

Open the .eap (MDB Plus) file or der SQL Server structure (MS SQL Server Studio Express) in a tool that allows you to test SQL Statements

Solution

Composite Diagrams of Activities

i.e. for the .eap-File (Access):
To get the activities Composite diagrams, you need to join the t_object.PData1 Columne with the t_diagram.Diagram_ID Column. This can be done in the following way:

SELECT compobjects.ea_guid As src_guid,
       compobjects.name As src_name,
       b.ea_guid As dest_guid,
       b.name As dest_name 
FROM 
(
      SELECT ea_guid, 
             Name, 
             Object_Type, 
             Stereotype, 
             PData1 
      FROM t_object 
      WHERE NType=8 AND PData1 IS NOT null AND isnumeric(PData1)) compobjects
INNER JOIN t_diagram b ON b.Diagram_ID=CInt(compobjects.PData1)

Composite Diagrams of Classes

SELECT Client As src_guid, 
       obj.name As src_name, 
       Supplier As dest_guid, 
       obj2.name As dest_name   
FROM ( t_xref xr
LEFT JOIN t_object obj ON xr.Client=obj.ea_guid)
LEFT JOIN t_diagram obj2 ON xr.Supplier=obj2.ea_guid 
WHERE Supplier<>'<none>'

All Composites by source guid

SELECT src_guid,
       src_name,
       dest_guid,
       dest_name
FROM       
(
	SELECT compobjects.ea_guid As src_guid,
		   compobjects.name As src_name,
		   b.ea_guid As dest_guid,
		   b.name As dest_name 
	FROM
	(
		  SELECT ea_guid, 
				 Name, 
				 Object_Type, 
				 Stereotype, 
				 PData1 
		  FROM t_object 
		  WHERE NType=8 AND PData1 IS NOT null AND isnumeric(PData1)) compobjects
	INNER JOIN t_diagram b ON b.Diagram_ID=CInt(compobjects.PData1)
	UNION ALL 
	SELECT Client As src_guid, 
		   obj.name As src_name, 
		   Supplier As dest_guid, 
		   obj2.name As dest_name   
	FROM ( t_xref xr
	LEFT JOIN t_object obj ON xr.Client=obj.ea_guid)
	LEFT JOIN t_diagram obj2 ON xr.Supplier=obj2.ea_guid 
	WHERE Supplier<>'<none>'
)
WHERE src_guid='Put your GUID here'

C#.NET + MS SQL Server : Nach INSERT direkt die Auto-Increment ID erhalten ohne zweite Abfrage

Problem

Um die Auto-Increment ID zu erhalten werden desöfteren 2 Statements abgesetzt, obwohl das INSERT-Statement direkt die Auto-Increment ID zurückgeben kann

Ansatz – Approach

Anstelle von comm.ExecuteNonQuery() sollte man lieber comm.ExecuteScalar() mit SELECT SCOPE_IDENTITY() kombinieren.

Lösung – Solution

public string insertMainTherapyData(string serial_no
                    ,string therapy_start
                    ,string machine_type
                    ,string file_source
                    ,string dialog_version
                    ,string tlc_version
                    ,string versions
                    ,DateTime uploaded_on
                    ,string uploaded_by
                    ,bool processed
                    ,string user_original_file
                    ,string user_country
                    ,string user_comment
                    ,string user_upload_reason
                    ,string user_location)
{
    string sqlStatement=@"
        INSERT INTO [dbo].[therapy]
                    ([serial_no]
                    ,[therapy_start]
                    ,[machine_type]
                    ,[file_source]
                    ,[dialog_version]
                    ,[tlc_version]
                    ,[versions]
                    ,[uploaded_on]
                    ,[uploaded_by]
                    ,[processed]
                    ,[user_original_file]
                    ,[user_country]
                    ,[user_comment]
                    ,[user_upload_reason]
                    ,[user_location])
        VALUES
                    (@serial_no
                    ,@therapy_start
                    ,@machine_type
                    ,@file_source
                    ,@dialog_version
                    ,@tlc_version
                    ,@versions
                    ,@uploaded_on
                    ,@uploaded_by
                    ,@processed
                    ,@user_original_file
                    ,@user_country
                    ,@user_comment
                    ,@user_upload_reason
                    ,@user_location);
            SELECT SCOPE_IDENTITY()
            ";
    int myID = -1;
    SqlConnection conn = new SqlConnection(MyConfigurationManager.prdSqlServerString);
    try
    {
        conn.Open();
        SqlCommand comm = new SqlCommand();
        comm.Connection = conn;
        comm.CommandText = sqlStatement;
        comm.Parameters.AddWithValue("serial_no", serial_no);
        comm.Parameters.AddWithValue("therapy_start", therapy_start);
        comm.Parameters.AddWithValue("machine_type", machine_type);
        comm.Parameters.AddWithValue("file_source", file_source);
        comm.Parameters.AddWithValue("dialog_version", dialog_version);
        comm.Parameters.AddWithValue("tlc_version", tlc_version);
        comm.Parameters.AddWithValue("versions", versions);
        comm.Parameters.AddWithValue("uploaded_on", uploaded_on);
        comm.Parameters.AddWithValue("uploaded_by", uploaded_by);
        comm.Parameters.AddWithValue("processed", processed);
        comm.Parameters.AddWithValue("user_original_file", user_original_file);
        comm.Parameters.AddWithValue("user_country", user_country);
        comm.Parameters.AddWithValue("user_comment", user_comment);
        comm.Parameters.AddWithValue("user_upload_reason", user_upload_reason);
        comm.Parameters.AddWithValue("user_location", user_location);
        myID = Convert.ToInt32(comm.ExecuteScalar());
    }
    catch (Exception ex)
    {
        return "ERROR: "+ex.Message;
    }
    finally
    {
        conn.Close();
    }

    return myID.ToString();
}

Javascript: Read URL GET Parameter from the browsers address bar that have been passed / commited

Problem

A javascript should read the browsers address bar to get GET Üarameters that have been appended to the adress bar.

Approach – Ansatz

Usage of decodeURIComponent

Solution

var getUrlParameter = function getUrlParameter(sParam) {
	var sPageURL = decodeURIComponent(window.location.search.substring(1)),
		sURLVariables = sPageURL.split('&'),
		sParameterName,
		i;

	for (i = 0; i < sURLVariables.length; i++) {
		sParameterName = sURLVariables[i].split('=');

		if (sParameterName[0] === sParam) {
			return sParameterName[1] === undefined ? true : sParameterName[1];
		}
	}
};

var myMap = getUrlParameter("map");
if (myMap) {
	diagramType = myMap;
}

You can call now the script like this:
http://webseite.html?map=Test

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;
}

GIT: Die 3 wichtigsten Kommandofolgen für die Zusammenarbeit / The three most important command line sequences

Die 3 häufigsten Kommandofolgen, die man beim Zusammenarbeiten braucht

Updaten (Aktuellen Stand vom Server holen):

1.) git fetch
2.) git merge

Committen / (Eigene Änderungen auf den Server schieben):

1.) git add .
2.) git commit -m „meine Nachricht“
3.) git push origin

Bei Konflikten / (Wenn Update/Commit aufgrund zu vieler Änderungen nicht mehr funktioniert):

1.) git fetch
2.) git add .
3.) git commit -m „meine Nachricht“
4.) git merge
5.) git add .
6.) git commit -m „meine Nachricht“
7.) git push origin

Weitere hilfreiche Kommandos

Vorgängerversion einer Datei holen

git checkout HEAD^^ -- <filename>
git checkout HEAD^^ -- src\de\caprisoft\managedbeans\create\CreateWorkerBean.java

Unter Windows ist ein doppeltes ^^ notwendig

Microsoft Visual C++ : How to call WinMain() from a console apps main()-method / Wie man die WinMain-Methode von einer Konsolenanwendung aus aufruft

Problem

Eine C++ Anwendung hat als Konsolenanwendung den Einstiegspunkt

int main(void) {...}

aber als Win32-Anwendung den Einstiegspunkt

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)  {...}

Es wird nach einer Möglichkeit gesucht, die WinMain-Methode von einer Konsolen-Anwendung aus aufzurufen, um eine Hauptfenster in der Konsolenanwendung zu generieren.

Ansatz

MSDN definiert die WinMain()-Methode folgendermaßen:

  • hInstance ist ein Element, das als „Handle für eine Instanz“ oder „Handle für ein Modul“ bezeichnet wird. Das Betriebssystem identifiziert mithilfe dieses Werts die ausführbare Datei (EXE), wenn diese in den Arbeitsspeicher geladen wird. Das Instanzhandle wird für bestimmte Windows-Funktionen benötigt—z. B. um Symbole oder Bitmaps zu laden.
  • hPrevInstance hat keine Bedeutung. Es wurde in 16-Bit-Windows verwendet, es ist aber jetzt stets 0 (null).
  • pCmdLine enthält die Befehlszeilenargumente als Unicode-Zeichenfolge.
  • nCmdShow ist ein Flag, das angibt, ob das Hauptanwendungsfenster minimiert, maximiert oder in Normalgröße angezeigt wird.

Die WinMain()-Methode kann von der main()-Anwendung aufgerufen werden, wenn man ein hInstance Handle bekommt. Dies geht folgermaßen:

GetModuleHandle(NULL)

Lösung – Solution

// HelloWorld.cpp : Definiert den Einstiegspunkt für die Konsolenanwendung.
//

#include "stdafx.h"
#include <windows.h> 

// Das hier braucht man nur wenn man die test.wav abspielen will
//#pragma comment(lib,"winmm.lib")  //für MSV C++   

const char g_szClassName[] = "myWindowClass";

// Step 4: the Window Procedure
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch (msg)
	{
	case WM_CLOSE:
		DestroyWindow(hwnd);
		break;
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
	default:
		return DefWindowProc(hwnd, msg, wParam, lParam);
	}
	return 0;
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
	WNDCLASSEX wc;
	HWND hwnd;
	MSG Msg;

	//Step 1: Registering the Window Class
	wc.cbSize = sizeof(WNDCLASSEX);
	wc.style = 0;
	wc.lpfnWndProc = WndProc;
	wc.cbClsExtra = 0;
	wc.cbWndExtra = 0;
	wc.hInstance = hInstance;
	wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
	wc.hCursor = LoadCursor(NULL, IDC_ARROW);
	wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
	wc.lpszMenuName = NULL;
	wc.lpszClassName = (LPCWSTR) g_szClassName;
	wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);

	if (!RegisterClassEx(&wc))
	{
		MessageBox(NULL, L"Window Registration Failed!", L"Error!",
			MB_ICONEXCLAMATION | MB_OK);
		return 0;
	}

	// Step 2: Creating the Window
	hwnd = CreateWindowEx(
		WS_EX_CLIENTEDGE,
		(LPCWSTR) g_szClassName,
		L"Eine Mischung aus Console und Window App",
		WS_OVERLAPPEDWINDOW,
		CW_USEDEFAULT, CW_USEDEFAULT, 240, 120,
		NULL, NULL, hInstance, NULL);

	if (hwnd == NULL)
	{
		MessageBox(NULL, L"Window Creation Failed!", L"Error!",
			MB_ICONEXCLAMATION | MB_OK);
		return 0;
	}

	ShowWindow(hwnd, nCmdShow);
	UpdateWindow(hwnd);

	// Step 3: The Message Loop
	while (GetMessage(&Msg, NULL, 0, 0) > 0)
	{
		TranslateMessage(&Msg);
		DispatchMessage(&Msg);
	}
	return Msg.wParam;
}


int main()
{
	// Das hier spielt eine Datei test.wav im gleichen Verzeichnis
	//PlaySound(L"test.wav", NULL, SND_ASYNC);
	
	WinMain(GetModuleHandle(NULL), 0, 0, 1);

	printf("Se hams Fenster geschlossen!");
	getchar();

	return 0;
}