Development

This part contains information on software development

Subsections of Development

Architecture

When designing a Windows Forms application, you have several architectural patterns to choose from. The common ones are:

Model-View-Controller (MVC):

  • Description: MVC separates the application into three components:
    • Model: Represents the data and business logic.
    • View: Handles the presentation and user interface.
    • Controller: Manages user input and communicates between the Model and View.
  • Pros:
    • Clear separation of concerns.
    • Reusable components.
    • Supports unit testing.
  • Cons:
    • Can become complex for small applications.
    • Requires careful design to avoid tight coupling.
  • Use Case: Suitable for medium to large applications with complex interactions.

Clean Architecture:

  • Description: Clean Architecture emphasizes separation of concerns and independence from external frameworks.
  • Entities: Represent core business logic.
  • Use Cases (Interactors): Application-specific business rules.
  • Interfaces (Gateways): Define external interfaces (e.g., database, UI).
    • Frameworks & Drivers: External frameworks and tools (e.g., Windows Forms, databases).
    • Pros:
      • Highly modular and testable.
      • Adaptable to changes in external frameworks.
      • Focuses on business logic.
    • Cons:
      • Initial setup complexity.
      • May be overkill for small projects.
    • Use Case: Suitable for large, long-lived applications with evolving requirements.

Subsections of Architecture

Migrations

In .NET 8, when a migration attempts to create a table that already exists in the database, the behavior depends on the state of the migration history and the existing database schema:

Initial Migration

When you apply the initial migration, Entity Framework Core (EF Core) creates the specified tables based on your model. If the table already exists in the database, EF Core will not re-create it. It only creates tables that are not present.

Subsequent Migrations

For subsequent migrations (e.g., adding columns, modifying schema), EF Core generates migration scripts based on the difference between the current model and the previous migration’s snapshot. If a table is already in the database and corresponds to the model, EF Core will not attempt to create it again. However, if the table structure differs from the model (e.g., missing columns), EF Core will generate migration scripts to update the schema.

Migration History

EF Core maintains a special table called __EFMigrationsHistory (or __migrations_History in some databases). This table tracks which migrations have been applied to the database. If a migration has already been applied (recorded in this table), EF Core will skip creating the corresponding tables.

Rollback (Down) Method

The Down method in a migration handles rolling back changes. If you need to undo a migration, the Down method drops the corresponding tables. For example, if you remove a column in a migration, the Down method will drop that column.

Manual Truncation or Deletion

Be cautious when manually truncating or deleting tables (including the __EFMigrationsHistory table). If the migration history is lost, EF Core may treat subsequent migrations as initial migrations, leading to re-creation of existing tables. In summary, EF Core is designed to be aware of the existing database schema and avoid unnecessary table creation. Ensure that the migration history is intact, and avoid manual truncation of the migration history table to prevent unexpected behavior during migrations

Synchronize

AMPLI-SYNC is a framework for synchronizing data between a SQLite database and an MS SQL/MySQL/Oracle/PostgreSQL database.

It allows your application to work offline (Airplane Mode) and then perform automated bidirectional synchronization when an internet connection becomes available.

Official site

Roadmap

Umbau auf .Net 8

AspNetCore + Webassembly

Der mobile Client wird als Testprojekt mit AspNetCore für REST und Webassembly für den Client aufgesetzt

Aspire / Webassembly / Blazor

Ein Video dazu. Werd DTN für IPM fertig machen und dann ein entsprechendes Projekt fuer die weitere Diskussion als Beispiel aufsetzen. Ist allerdings erst in preview … das sollte man evtl. abwarten

Avalonia

Zurückgestellt Mit dem Avalonia framework könnte man einfache Clients wie e.g. die Spreadsheets für die Module bereitstellen. Das waere vorallem für Desktop Apps. Ansonsten würde Blazor wohl die einfachere Herangehensweise sein weil es über den Browser alles abdeckt. Sollte auf jeden Fall in separatem Verzeichnis entwickelt werden weil es Einstellungen vornimmt die mit anderen Frameworks nicht kompatibel sind. Ist allerdings noch auf .Net 7. Wird wohl noch ein bisschen dauern bis das fuer .Net 8 nachgezogen ist.

  • Alternativen:
    • MAUI - das unterstützt aber kein Linux und ist was ich gesehen hab auch nicht so performant
    • UNO - hab ich noch nicht genauer angesehen. Wohl ähnlich zu Avalonia aber nicht so verbreitet etc.

Cocona

Für CLI Clients

Beispiele für Diagramme

Note

for demo only - dates are not valid

timeline
    title Diversity Workbench - timeline
    2023-11-15 : Einstieg in Version 8
    2023-12-15 : IPM 
                : WinForm Client 2023-11-15
                : WASM-Client 2023-12-15
    2023-12-20 : WASM-Client 
               : Preview 2024-01-20
               : Workshop 2014-03-22
    2024-02-15 : WASM-Client for DC
gantt
        dateFormat  YYYY-MM-DD
        title IPM
        section IPM Winforms Client
        Completed task            :done,    des1, 2024-01-06,2024-01-08
        Active task               :active,  des2, 2024-01-09, 3d
        Future task               :         des3, after des2, 5d
        Future task2              :         des4, after des3, 5d
        section IPM WASM Client
        Completed task in the critical line :crit, done, 2024-01-06,24h
        Implement parser and jison          :crit, done, after des1, 2d
        Create tests for parser             :crit, active, 3d
        Future task in critical line        :crit, 5d
        Create tests for renderer           :2d
        Add to Mermaid                      :1d
gitGraph
    commit
    commit
    branch develop
    checkout develop
    commit
    commit
    checkout main
    merge develop
    commit
    commit

Subsections of Roadmap

IPM

The DiversityWorkbench provides several applications addressing every IPM related task:

  • Taxonomy of IPM related taxa
  • Identification key for pests
  • Collecting sensor data
  • Editing, collecting, exporting data in a desktop application.
  • A web application for trap inspection (ongoing project)

IPMtaxa

(!!! Heisst des wiklich so?, ist das nicht DTN? Der Kurz-Name ist doch schon TaxRef_SNSB_NHC-Pests? Es ist nicht klug Synonyme zu erzeugen.) -> das sind alles Platzhalter fuer Projekte in C#. TaxRef_SNSB_NHC-Pests ist nix was man als Projektbezeichner verwenden würde. Das ist ein internes Kürzel.

Taxonomic backbone providing 3 lists of taxa related to IPM:

  • Pests
  • Bycatch
  • Beneficials

The data include the taxonomic hierarchy, synonoyms, common names, life stages, links to information and thumbnails of the taxa for inclusion in e.g. tabular lists used for monitoring. Data are provided via a JSON API. For details see IPM

IPMdescriptions or IPMkey

(Gibt es das schon?) -> nein - Platzhalter

Identification key for taxa provided by IPMtaxa

IPMobile

(ongoing project) -> klar - aber das sollte bis September fertig sein. Ongoing ist bei uns alles

Mobile application for collecting taxon observations in traps etc. You can import existing data to ensure continuity and build upon historical information. Data are stored in a local SQLite database and synchronized via an API with the main database to enable offline inspection of the traps, specimen etc.

Zwischengespeicherte Daten für offline Betrieb

  • Taxonliste incl. Vorschaubildern
  • Bilder von Fallen
  • Grundriss

Zugriffsarten

es können alte Daten eingelesen und neue Daten geschrieben werden. Ändern und Löschen nach dem Speichern ist nicht vorgesehen.

  • Lesen
    • Taxonliste
    • Grundrisse
    • Bar- und QR-Codes
  • Schreiben
    • Beobachtungen von Schädlingen (Art, Anzahl, Ort)
    • Eingeben von Anmerkungen
  • Ändern
    • x
  • Löschen
    • x

Einstellungen

Auswahl der Taxa die für die Erfassung berücksichtigt werden sollen

Bereiche

  • Fallen
  • Specimen
  • Sensoren

Funktionen

  • Verortung in Plänen
  • Bilder von Fallen etc.
  • Zuordnung von Detailbildern zu Übersichtsaufnahme und deren Verortung innerhalb der Übersichtsaufnahme
  • Scannen von Codes auf Objekten und automatisches Laden der zugehörigen Daten
  • Eintrag von Notizen

Szenarien

  • Der User will einen Schädling eintragen können den er gerade auf einem Specimen gefunden hat.
  • Der User will eintragen, dass er keinen Schädling gefunden hat auf einem Specimen, Falle, Raum, Sammlung, …
  • Der User hat eine Falle aufgestellt und möchte die Falle anhand des QR-Codes auf der Falle identifizieren und die Position der Falle im Plan vermerken sowie evtl. eine Beschreibung des Standorts eingeben.
  • Der User möchte alle Fallen anhand eines Plans der Aktuellen Etage abgehen und dabei prüfen ob in den Fallen Fänge sind.
  • Der User möchte den aktuellen Zustand der Falle anhand von Bildern mit vorherigen Zuständen vergleichen
  • Der User hat einen Schaden entdeckt und möchte das Objekt anhand des Codes identifizieren sowie den Schaden mit einem Bild dokumentieren und einen kurzen Text schreiben was genau kaputt ist.
  • Über Bestimmungsapp via DD
    • Der User will dem gefunden Schädling einen Namen zuweisen

Tabellen in SQLite

  • lesend

    • Collection
    • CollectionSpecimen
    • CollectionSpecimenPart
    • IdentificationUnit
    • Task
    • CollectionTask_old (oder Marker in Tabelle CollectionTask)
    • CollectionTaskImage_old (oder Marker in Tabelle CollectionTaskImage)
  • schreibend

    • CollectionTask
    • CollectionTaskImage

IPMsensor

Sensors collecting room temperature and moisture values communicate via Bluetooth LE with IPMhubs. IPMhubs communicate with IPMserver via LoRa IPMserver collects sensor data provided by the IPMhubs and stores these data in a Prometheus timeseries database. These data are then provided for import in the main database via LAN.

IPMcollection

  • Spatial: The software provides the option to include floor plans and accurately pinpoint the locations of sensors and traps including the hight within a room. To avoid interference with administrative aspects of a collection, the software includes the option for a second hierarchy according to the positions.
  • Recording: Next to sensor data all events, observations etc. can be recorded for later evaluation aiming at the prediction of the effect of IPM related actions.
  • Customization: You can define templates or create custom task definitions based on your specific IPM requirements. This includes e.g. the typification of traps and treatments. The list of taxa based on the backbone can be adapted based on those taxa that should be included in the recoding.
  • Reports: Generation of reports including charts, floorplans, treatments etc.
  • Actions: Documenation of IPM related treatments of collection specimen, application of beneficial organisms etc.

HUGO

Installation of HUGO

Update des Themes

um das Theme auf die letzte Version zu bringen kann man den Befehl git submodule update --remote --merge themes/relearn verwenden

Übersetzung des Bestands an html

  • Übersetzung der *.html Seiten mit pandoc in *.md
  • Aufbau einer Ordnerstruktur die dem Index der chm Datei entspricht
  • Das Basisdokument der Ordner wird in die Ordner verschoben und in _index.md umbenannt
    • Dort im Frontmatter steht der Titel der im Menü angezeigt wird, e.g.:
      --- 
      title: Installation 
      ---  

Überarbeitung der md Dateien

  • Korrektur der Bildverweise
    • Ordner mit den Bildern in den Ordner static kopieren
    • von e.g. ![](img/...) in ![](/manual/dwb/img/...)
    • ACHTUNG - Case sensitiv. Namen müssen stimmen
    • Icons gegebenenfalls freistellen für Darkmode
  • Entfernung aller störenden Formatierungsangaben
  • Entfernung der Kopfzeile (Überschrift wird von HUGO automatisch erzeugt)
  • Korrektur der internen Verweise
    • ändern von [![](/manual/dwb/img/VideoDE.svg?classes=inline)](http://media.snsb.info/Tutorials/dwb/Editing/OeffentlicheKontaktdaten.webm) zu [![Video starten](/manual/dwb/img/VideoDE.svg?height=20px&lightbox=false&classes=inline)](http://media.snsb.info/Tutorials/dwb/Editing/OeffentlicheKontaktdaten.webm)
      • ansonsten wird das Bild gezeigt statt das Video zu starten
    • ändern von
      [Contact](Contact.htm)
      zu e.g.
      [Contact](/manual/dwb/editingdata/contact)
    • Wenn als Basisadresse in hugo.toml etwas angegeben wurde, e.g. baseURL = "http://www.diversityworkbench.de/manual/dwb/" dann muss diese auch für Verweise innerhalb der Files verwendet werden.
      • e.g. Bildverweise ![](/manual/dwb/img/IcoFeedback.gif?classes=inline)
      • Dateiverweise [Anmelden](/manual/dwb/database)
      • HUGO relearn erzeugt für Überschriften Anker die man ansteuern kann, e.g. kann man ### Table **AgentResource** über die Adresse /manual/dwb/database/database/#table-agentresource erreichen. Ein Index Eintrag dafür wäre e.g. [AgentResource](/manual/dwb/database/database/#table-agentresource). ACHTUNG - Case sensitiv: ### Table **AgentResource** wird in #table-agentresource übersetzt
    • Kommentare starten mit # ohne folgendes Leerzeichen

Frontmatter

You can change the frontmatter to a default using the documentation tool

  • Steht am Anfang der Datei und ist bei yaml durch --- oben und unten abgegrenzt, e.g.
    ---
    title: Login administration
    linktitle: Logins
    weight: 5
    menuPre: <img src="/manual/dwb/img/Documentation.svg" height="20">&nbsp;
    alwaysopen: false
    ---
  • Seiten die noch in Entwicklung sind kann man mit draft: true im Frontmatter markieren. Diese werden dann nicht in die Ausgabe übernommen
  • Der Titel wird mit title: Login administration angegeben. Dieser erscheint dann auch in der Seite als Überschrift
  • Der Text im Menü kann abweichend definiert werden mit linktitle: Logins. Ansonsten erscheit der Titel im Menü
  • Die Reihenfolge im Menü kann mit weight: 5 angegeben werden. Ansonsten wird alphabetisch sortiert
  • Ein Logo kann man mit menuPre: <img src="/manual/dwb/img/LinkedServer.svg" height="20">&nbsp; hinzufügen. Das Bild sollte *.svg sein
  • Wenn das Untermenue erst beim Anwählen geöffnet werden soll: alwaysopen: false

Bilder

You can adapt the images to a default using the documentation tool

  • Icons die e.g. in den Text integriert werden sollen, müssen folgedermassen eingebaut werden:
    • ![](/manual/dwb/img/Database.svg?height=20px&lightbox=false&classes=inline)
  • Die Bilder am Anfang der Seite werde wie folgt eingebaut:
    • ![](/manual/dwb/img/LinkedServer.svg?height=10vw&lightbox=false)

mit px wird das Bild mitgezoomt, bei vw bleibt es gleich gross

  • noch nicht zu svg konvertierte Bilder die im Fliesstest erscheinen sollen werden wie folgt eingebunden:
    • ![](/manual/dwb/diversitycollection/IcoDelete.gif?classes=inline&lightbox=false)
  • sonstige Bilder mit
    • ![](/manual/dwb/diversitycollection/IcoDelete.gif)

mit der Angabe ...lightbox=false wird verhindert, dass ein Bild beim Anklicken mit der Maus geöffnet wird. Dies sollte bei Bildern die nicht nach svg konvertiert wurden und nicht im Fliesstext erscheinen nicht verwendet werden, damit der User bei kleinen Bildern diese in Originalauflösung betrachten kann. Unten 2 Beispiele

![](/manual/dwb/diversitycollection/IcoDelete.gif?classes=inline&lightbox=false)

![](/manual/dwb/diversitycollection/IcoDelete.gif?classes=inline)

Für Links innerhalb des Manuals kann man shortcodes verwenden. Dafür entweder auf den Namen der Datei oder auf Links von Überschriften (ab ##) verwenden. Diese müssen innerhalb des Manuals eindeutig sein. Für Header als erstes Zeichen # dann Überschrift und alles lower case und Leerzeichen werden durch - ersetzt. Beispiel:

## Main form of diversityexsiccatae

wird zu sofern es sich in der gleichen Datei befindet: {{ % relref "#main-form-of-diversityexsiccatae" % }}

Für Links ausserhalb der Datei werden Verweise unter Einschluss des Dateinamens verwendet:

Verweis auf ein Kapitel innerhalb einer Datei {{ < relref "diversityexsiccatae#main-form-of-diversityexsiccatae" > }}

bzw. nur auf die Datei {{ < relref "diversityexsiccatae" > }}

Leerzeichen zwischen {{ % und % }} entfernen

Von ausserhalb kann e.g. eine Überschrift mit https://www.diversityworkbench.de/manual/dwb/modules/diversityexsiccatae/index.html#main-form-of-diversityexsiccatae aufgerufen werden. Diese können direkt aus dem Manual kopiert werden.

  • hierfür das Logo in den Ordner static kopieren
  • im Ordner layouts einen Ordner partials anlegen
  • dort eine Datei logo.html anlegen
    • in dieser auf das Logo verweisen e.g.:
      <h4><b>DiversityAgents</b></h4>
      <img src="/DA_4D.svg">
  • in static - layouts - partials die Datei menu-footer.html anlegen und anpassen

favicon

Im Ordner static den Ordner images anlegen Datei favicon.ico in der Ordner static/images kopieren

Einschliessen von Dateien

Das Verzeichnis templates enthält Dateien die in andere Dateien über eine shortcode eingeschlossen werden können, e.g.:  {{% include file="templates/template_workbench.md" %}} Diese Dateien dürfen kein frontmatter enthalten. Shortcodes müssen überprüft werden, da diese in der Regel nicht ausgewertet werden.

ER-Diagramm

dieses kann als Mermaid eingebaut werden, e.g.

---
title: ER-Diagram
---
graph LR;
    A[Agent] --> B[AgentContact<br/>Kontaktdaten der Agents]
    A --> C[AgentReference]
    A --> D[AgentIdentifier]
    A --> E[AgentResource]
    A --> F[AgentExternalID]
    G[AgentExternalDatabase] --> F[AgentExternalID]

soll das Diagramm zoombar sein wird die Version 5.23 des Themes benoetigt. Ausserdem kann der Parameter nur für die Shortcode Version angegeben werden, nicht für die Codefences:

{{ < mermaid align="center" zoom="true" > }}
... 
(remove space between {{ and < resp > and }} in header and footer for correct code)
...
{{ < /mermaid > }}

Anpassung des Themes

  • es werden 2 eigene Themes bereitgestellt

    • im Verzeichnes
      • themes
        • relearn
          • static
            • css:
            • theme-dwb-dark.css
            • theme-dwb.css

    diese an DWB Anforderungen anpassen

    • in \themes\relearn\static\css\theme.css
      #body img.inline {
          display: inline !important;
          margin: 0 !important;
          vertical-align: middle;
          /* vertical-align: bottom; */
      }
    • in \themes\relearn\static\css\theme-dwb.css
      /*--MENU-HEADER-BG-color: rgba( 28, 144, 243, 1 );*/ /* Background color of menu header */
      --MENU-HEADER-BG-color: rgba( 220, 220, 220, 1 ); /* Background color of menu header */
      --MENU-HEADER-BORDER-color: rgba( 51, 161, 255, 1 ); /*Color of menu header border */
      
      --MENU-SEARCH-color: rgba( 255, 255, 255, 1 ); /* Color of search field text */
      /*--MENU-SEARCH-BG-color: rgba( 22, 122, 208, 1 );*/ /* Search field background color (by default borders + icons) */
      --MENU-SEARCH-BG-color: rgba( 90, 90, 90, 1 ); /* Search field background color (by default borders + icons) */
      /*--MENU-SEARCH-BORDER-color: rgba( 51, 161, 255, 1 );*/ /* Override search field border color */
      --MENU-SEARCH-BORDER-color: rgba( 0, 0, 0, 1 ); /* Override search field border color */

Konfiguration - in hugo.toml:

```native
baseURL = "http://www.diversityworkbench.de/manual/dwb/"
languageCode = "en-us"
title = "DiversityAgents"
theme = "relearn"

[outputs]
    home = ["HTML", "RSS", "SEARCH", "SEARCHPAGE"]
    section = ["HTML", "RSS", "PRINT"]
    page = ["HTML", "RSS", "PRINT"]

[params]
    themeVariant = [ "auto", "dwb", "dwb-dark" ]
```

Start des Testservers:

  • mit einem Terminal in das Verzeichnis des Projekts wechseln
  • dort hugo server eingeben.
    • bei Problem mit Sonderzeichen: den Inhalt der Datei config.toml in hugo.toml kopieren und config.toml löschen (beide sollten wenn vorhanden UTF8 sein - werden manchmal als UTF16 angelegt - dieses dann nach UTF8 ändern)
      • Error: “…\diversityworkbench\hugo.toml:1:1”: unmarshal failed: toml: invalid character at start of key: ÿ
  • Im Browser an die angegebene Adresse navigieren, e.g. localhost:1313
  • Wenn als Basisadresse in hugo.toml etwas angegeben wurde, e.g. baseURL = "http://www.diversityworkbench.de/manual/dwb/" dann muss die passende Adresse eingeben werden also e.g. localhost:1313/manual/dwb/

Subsections of HUGO

HUGO

In the HUGO / HTML tab you generate markdown files according to HUGO and the relearn theme.

The conversion and adaptions are explained in a short tutorial: Video starten

For enumeration tables the content can be exported as explained in a short tutorial: Video starten

HUGO links

In the tab you can fix links in markdown files according to HUGO shortcodes.

The fixes for broken links are explained in a short tutorial: Video starten

The adaptions for links for HUGO as related references are explained in a short tutorial: Video starten

To map the files in the original links to new files in the documentation follow the steps shown in a short tutorial: Video starten

github

ssh-key

To use this option you may have to install OpenSSH for Windows

To change the authentication mechanism to SSH keys in Visual Studio Code and GitHub, you need to follow these steps:

  • Open the command line and change in your homedirectory if not already done cd %USERPROFILE%
  • Generate an SSH key pair on your local machine using the command ssh-keygen -a3 -t ed25519 -C "your_email@example.com" -f .ssh/id_github.
    • In case you omit the -f option nameing the file where the key should be stored, you will be asked th enter the name of the file where the key should be stored e.g. id_github. Make shure not to overwrite existing keys.
  • Next enter a passphrase (twice)
    • When you generate an SSH key pair, you have the option to add a passphrase to the private key. A passphrase is an extra layer of security that helps protect your private key from unauthorized access. If someone gains access to your private key, they can use it to authenticate as you and perform actions on your behalf. By adding a passphrase, you make it more difficult for someone to use your private key without your permission.
    • When you use an SSH key with a passphrase, you will be prompted to enter the passphrase every time you use the key. This can be inconvenient, but it ensures that only you can use the key to authenticate with remote servers. You can also use an SSH agent to store your passphrase so that you don’t have to enter it every time you use your key .
    • The location of your keys will be shown (e.g. id_github for the private key and id_github.pub for the public key) next to a fingerprint and a randomart image like
      +--[ED25519 256]--+
      |     ..   .+=.o  |
      |      .+ . o+*   |
      |    . +.. ooo.o  |
      |     +.B.+= =.o  |
      |      =+S=o* = o |
      |     . oo*= o o  |
      |      .  .       |
      |        . . o E  |
      |           o .   |
      +----[SHA256]-----+
  • Add the public key to your GitHub account by navigating to your account settings, selecting “SSH and GPG keys”, and clicking “New SSH key”.
  • Copy the contents of the public key file (usually ~/.ssh/id_rsa.pub) and paste it into the “Key” field on the GitHub website.
  • In Visual Studio Code, open the Command Palette (press Ctrl+Shift+P on Windows) and search for Remote-SSH: Open SSH Configuration File.
    • You may need to install the extension Remote-SSH first
  • Select the configuration file you want to edit and add the following lines:
    Host github.com
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_rsa
  • Save the file and close it.
  • Open the Command Palette again and search for Remote-SSH: Connect to Host.
  • Select the configuration file you just edited and wait for the connection to be established.
  • You should now be able to use Git with SSH authentication in Visual Studio Code.