OmniSeller:PlugIn Entwicklung: Unterschied zwischen den Versionen

Aus HTK Wiki
Zur Navigation springen Zur Suche springen
Keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
Zeile 1: Zeile 1:
<br>= OmniSeller PlugIn Entwicklung =
&lt;h1&gt;OmniSeller PlugIn Entwicklung&lt;/h1&gt;<br>&lt;h2&gt;Überblick&lt;/h2&gt;<br>&lt;p&gt;<br>&nbsp; &nbsp; Der OmniSeller DataService bietet die Möglichkeit, externe Logik über PlugIns zu integrieren. PlugIns können entwickelt werden,<br>&nbsp; &nbsp; um spezifische Geschäftsanforderungen zu erfüllen, beispielsweise das Anpassen von Produktdaten vor dem Upload oder das<br>&nbsp; &nbsp; Modifizieren von Preisen basierend auf bestimmten Kriterien.<br>&lt;/p&gt;<br>&lt;p&gt;<br>&nbsp; &nbsp; OmniSeller PlugIns basieren auf &lt;b&gt;.NET Standard 2.0&lt;/b&gt;, um sowohl mit alten (.NET Framework 4.7.2) als auch mit neuen<br>&nbsp; &nbsp; (.NET 6.0) Service-Versionen kompatibel zu sein.<br>&lt;/p&gt;<br>&lt;h2&gt;Voraussetzungen&lt;/h2&gt;<br>&lt;ul&gt;<br>&nbsp; &nbsp; &lt;li&gt;&lt;b&gt;Entwicklungsumgebung:&lt;/b&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;ul&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;li&gt;Visual Studio 2019 oder höher&lt;/li&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;li&gt;.NET Standard 2.0 als Zielplattform für PlugIns&lt;/li&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;/ul&gt;<br>&nbsp; &nbsp; &lt;/li&gt;<br>&nbsp; &nbsp; &lt;li&gt;&lt;b&gt;Abhängigkeiten:&lt;/b&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;ul&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;li&gt;OmniSeller.Common und OmniSeller.Enums aus dem HTK NuGet Repository: &lt;code&gt;https://htkpackages/repository/&lt;/code&gt;&lt;/li&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;/ul&gt;<br>&nbsp; &nbsp; &lt;/li&gt;<br>&nbsp; &nbsp; &lt;li&gt;&lt;b&gt;Nützliche Schnittstellen und Modelle:&lt;/b&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;ul&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;li&gt;IEntryPointPlugin (aus OmniSeller.Common)&lt;/li&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;li&gt;Enums.EntryPoint und Enums.ShopTypes&lt;/li&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;/ul&gt;<br>&nbsp; &nbsp; &lt;/li&gt;<br>&nbsp; &nbsp; &lt;li&gt;&lt;b&gt;Zugriff auf ein bestehendes OmniSeller-System&lt;/b&gt;, um das PlugIn zu testen&lt;/li&gt;<br>&lt;/ul&gt;<br>&lt;h2&gt;Struktur eines OmniSeller PlugIns&lt;/h2&gt;<br>&lt;p&gt;<br>&nbsp; &nbsp; Ein OmniSeller PlugIn muss die Schnittstelle &lt;code&gt;IEntryPointPlugin&lt;/code&gt; implementieren, die folgende Eigenschaften und Methoden definiert:<br>&lt;/p&gt;<br>&lt;pre&gt;<br>public interface IEntryPointPlugin<br>{<br>&nbsp; &nbsp; string Name { get; }<br>&nbsp; &nbsp; EntryPoint SupportedEntryPoints { get; }<br>&nbsp; &nbsp; string Version { get; }<br>&nbsp; &nbsp; int SortOrder { get; }<br>&nbsp; &nbsp; string Author { get; }<br>&nbsp; &nbsp; string Publisher { get; }<br>&nbsp; &nbsp; ShopTypes SupportedShopTypes { get; }<br>&nbsp; &nbsp; string Notes { get; }<br>&nbsp; &nbsp; Product Call(ShopTypes shopType, int portalID, Product productObj, EntryPoint entryPoint);<br>}<br>&lt;/pre&gt;<br>&lt;h3&gt;Beispiel für ein PlugIn: ZeroPricePlugIn&lt;/h3&gt;<br>&lt;p&gt;<br>&nbsp; &nbsp; Dieses PlugIn setzt automatisch den niedrigsten Preis für Produkte, die den Preis &lt;code&gt;0&lt;/code&gt; haben, basierend auf den Preisen der Kind-Produkte.<br>&lt;/p&gt;<br>&lt;pre&gt;<br>using OmniSeller.Enums;<br>using OmniSellerPlugins.Interfaces;<br>using OmniSellerPlugins.Models;<br>using System;
 
== Überblick ==<br>Der OmniSeller DataService bietet die Möglichkeit, externe Logik über PlugIns zu integrieren. PlugIns können entwickelt werden, um spezifische Geschäftsanforderungen zu erfüllen, beispielsweise das Anpassen von Produktdaten vor dem Upload oder das Modifizieren von Preisen basierend auf bestimmten Kriterien.
 
OmniSeller PlugIns basieren auf '''.NET Standard 2.0''', um sowohl mit alten (.NET Framework 4.7.2) als auch mit neuen (.NET 6.0) Service-Versionen kompatibel zu sein.
 
== Voraussetzungen ==<br># '''Entwicklungsumgebung''':<br>#* Visual Studio 2019 oder höher.<br>#* .NET Standard 2.0 als Zielplattform für PlugIns.<br># '''Abhängigkeiten''':<br>#* `OmniSeller.Common` und `OmniSeller.Enums` aus dem **HTK NuGet Repository**:<br># ```plaintext<br># https://htkpackages/repository/<br># ```<br># '''Nützliche Schnittstellen und Modelle''':<br>#* `IEntryPointPlugin` (aus `OmniSeller.Common`).<br>#* `Enums.EntryPoint` und `Enums.ShopTypes`.<br># '''Zugriff auf ein bestehendes OmniSeller-System''', um das PlugIn zu testen.
 
== Struktur eines OmniSeller PlugIns ==<br>Ein OmniSeller PlugIn muss die Schnittstelle `IEntryPointPlugin` implementieren, die folgende Eigenschaften und Methoden definiert:
 
```csharp<br>public interface IEntryPointPlugin<br>{<br>&nbsp; &nbsp; string Name { get; } // Der Name des PlugIns<br>&nbsp; &nbsp; EntryPoint SupportedEntryPoints { get; } // Unterstützte EntryPoints<br>&nbsp; &nbsp; string Version { get; } // Version des PlugIns<br>&nbsp; &nbsp; int SortOrder { get; } // Reihenfolge des PlugIns<br>&nbsp; &nbsp; string Author { get; } // Entwicklername<br>&nbsp; &nbsp; string Publisher { get; } // Herausgebername<br>&nbsp; &nbsp; ShopTypes SupportedShopTypes { get; } // Unterstützte Shop-Typen<br>&nbsp; &nbsp; string Notes { get; } // Notizen/Hinweise
 
&nbsp; &nbsp; Product Call(ShopTypes shopType, int portalID, Product productObj, EntryPoint entryPoint); // Hauptlogik<br>}<br>```
 
=== Beispiel für ein PlugIn: ZeroPricePlugIn ===<br>Dieses PlugIn setzt automatisch den niedrigsten Preis für Produkte, die den Preis `0` haben, basierend auf den Preisen der Kind-Produkte.
 
```csharp<br>using OmniSeller.Enums;<br>using OmniSellerPlugins.Interfaces;<br>using OmniSellerPlugins.Models;<br>using System;


namespace OmniSeller.PlugIns<br>{<br>&nbsp; &nbsp; internal class ZeroPricePlugIn : IEntryPointPlugin<br>&nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; public string Name =&gt; "OmniSellerZeroPricePlugIn";<br>&nbsp; &nbsp; &nbsp; &nbsp; public EntryPoint SupportedEntryPoints =&gt; EntryPoint.PRICE_BEFORE_UPLOAD;<br>&nbsp; &nbsp; &nbsp; &nbsp; public string Version =&gt; "1.0.0.0";<br>&nbsp; &nbsp; &nbsp; &nbsp; public int SortOrder =&gt; 1000;<br>&nbsp; &nbsp; &nbsp; &nbsp; public string Author =&gt; "AS";<br>&nbsp; &nbsp; &nbsp; &nbsp; public string Publisher =&gt; "HTK GmbH & Co.KG";<br>&nbsp; &nbsp; &nbsp; &nbsp; public ShopTypes SupportedShopTypes =&gt; ShopTypes.Magento;<br>&nbsp; &nbsp; &nbsp; &nbsp; public string Notes =&gt; "Kein Hinweistext";
namespace OmniSeller.PlugIns<br>{<br>&nbsp; &nbsp; internal class ZeroPricePlugIn : IEntryPointPlugin<br>&nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; public string Name =&gt; "OmniSellerZeroPricePlugIn";<br>&nbsp; &nbsp; &nbsp; &nbsp; public EntryPoint SupportedEntryPoints =&gt; EntryPoint.PRICE_BEFORE_UPLOAD;<br>&nbsp; &nbsp; &nbsp; &nbsp; public string Version =&gt; "1.0.0.0";<br>&nbsp; &nbsp; &nbsp; &nbsp; public int SortOrder =&gt; 1000;<br>&nbsp; &nbsp; &nbsp; &nbsp; public string Author =&gt; "AS";<br>&nbsp; &nbsp; &nbsp; &nbsp; public string Publisher =&gt; "HTK GmbH & Co.KG";<br>&nbsp; &nbsp; &nbsp; &nbsp; public ShopTypes SupportedShopTypes =&gt; ShopTypes.Magento;<br>&nbsp; &nbsp; &nbsp; &nbsp; public string Notes =&gt; "Kein Hinweistext";
Zeile 21: Zeile 5:
&nbsp; &nbsp; &nbsp; &nbsp; public ZeroPricePlugIn()<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine($"Running PlugIn {Name}");<br>&nbsp; &nbsp; &nbsp; &nbsp; }
&nbsp; &nbsp; &nbsp; &nbsp; public ZeroPricePlugIn()<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine($"Running PlugIn {Name}");<br>&nbsp; &nbsp; &nbsp; &nbsp; }


&nbsp; &nbsp; &nbsp; &nbsp; public Product Call(ShopTypes shopType, int portalID, Product productObj, EntryPoint entryPoint)<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine($"Running PlugIn {Name} for {shopType} at {entryPoint}");<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (shopType == ShopTypes.Magento)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Logik zur Anpassung von Produktpreisen<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return productObj;<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; }<br>}<br>```
&nbsp; &nbsp; &nbsp; &nbsp; public Product Call(ShopTypes shopType, int portalID, Product productObj, EntryPoint entryPoint)<br>&nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Console.WriteLine($"Running PlugIn {Name} for {shopType} at {entryPoint}");<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (shopType == ShopTypes.Magento)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Logik zur Anpassung von Produktpreisen<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return productObj;<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; }<br>}<br>&lt;/pre&gt;<br>&lt;h2&gt;Schritt-für-Schritt-Anleitung zur Erstellung eines PlugIns&lt;/h2&gt;<br>&lt;h3&gt;1. Projekt einrichten&lt;/h3&gt;<br>&lt;ul&gt;<br>&nbsp; &nbsp; &lt;li&gt;Erstelle ein neues &lt;b&gt;.NET Standard 2.0&lt;/b&gt; Class Library-Projekt in Visual Studio&lt;/li&gt;<br>&nbsp; &nbsp; &lt;li&gt;Füge die folgenden Pakete über das HTK NuGet Repository hinzu:&lt;/li&gt;<br>&nbsp; &nbsp; &lt;pre&gt;<br>OmniSeller.Common<br>OmniSeller.Enums<br>&nbsp; &nbsp; &lt;/pre&gt;<br>&lt;/ul&gt;<br>&lt;h3&gt;2. PlugIn-Logik implementieren&lt;/h3&gt;<br>&lt;ul&gt;<br>&nbsp; &nbsp; &lt;li&gt;Implementiere die Schnittstelle &lt;code&gt;IEntryPointPlugin&lt;/code&gt;.&lt;/li&gt;<br>&nbsp; &nbsp; &lt;li&gt;Definiere die unterstützten &lt;code&gt;EntryPoints&lt;/code&gt; und &lt;code&gt;ShopTypes&lt;/code&gt;.&lt;/li&gt;<br>&nbsp; &nbsp; &lt;li&gt;Implementiere die Logik in der Methode &lt;code&gt;Call&lt;/code&gt;.&lt;/li&gt;<br>&lt;/ul&gt;<br>&lt;h3&gt;3. PlugIn erstellen und veröffentlichen&lt;/h3&gt;<br>&lt;ul&gt;<br>&nbsp; &nbsp; &lt;li&gt;Kompiliere das Projekt.&lt;/li&gt;<br>&nbsp; &nbsp; &lt;li&gt;Die resultierende &lt;code&gt;.dll&lt;/code&gt;-Datei (zusammen mit ihren Abhängigkeiten) wird in das OmniSeller PlugIn-Verzeichnis kopiert:&lt;/li&gt;<br>&nbsp; &nbsp; &lt;pre&gt;C:\OmniVersum\Apps\OmniSellerService2\PlugIns&lt;/pre&gt;<br>&lt;/ul&gt;<br>&lt;h3&gt;4. PlugIn testen&lt;/h3&gt;<br>&lt;ul&gt;<br>&nbsp; &nbsp; &lt;li&gt;Starte den OmniSeller DataService und beobachte die Logs.&lt;/li&gt;<br>&nbsp; &nbsp; &lt;li&gt;Das PlugIn wird automatisch geladen und ausgeführt, wenn der entsprechende &lt;code&gt;EntryPoint&lt;/code&gt; erreicht wird.&lt;/li&gt;<br>&lt;/ul&gt;<br>&lt;h2&gt;EntryPoints und deren Bedeutung&lt;/h2&gt;<br>&lt;table border="1"&gt;<br>&nbsp; &nbsp; &lt;tr&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;th&gt;EntryPoint&lt;/th&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;th&gt;Beschreibung&lt;/th&gt;<br>&nbsp; &nbsp; &lt;/tr&gt;<br>&nbsp; &nbsp; &lt;tr&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;td&gt;PORTAL_STARTUP&lt;/td&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;td&gt;Wird beim Start eines Portals ausgeführt.&lt;/td&gt;<br>&nbsp; &nbsp; &lt;/tr&gt;<br>&nbsp; &nbsp; &lt;tr&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;td&gt;PRODUCT_BEFORE_UPLOAD&lt;/td&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;td&gt;Vor dem Produkt-Upload.&lt;/td&gt;<br>&nbsp; &nbsp; &lt;/tr&gt;<br>&nbsp; &nbsp; &lt;tr&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;td&gt;PRODUCT_AFTER_UPLOAD&lt;/td&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;td&gt;Nach dem Produkt-Upload.&lt;/td&gt;<br>&nbsp; &nbsp; &lt;/tr&gt;<br>&nbsp; &nbsp; &lt;tr&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;td&gt;PRICE_BEFORE_UPLOAD&lt;/td&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;td&gt;Vor dem Preis-Upload.&lt;/td&gt;<br>&nbsp; &nbsp; &lt;/tr&gt;<br>&nbsp; &nbsp; &lt;tr&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;td&gt;PRICE_AFTER_UPLOAD&lt;/td&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;td&gt;Nach dem Preis-Upload.&lt;/td&gt;<br>&nbsp; &nbsp; &lt;/tr&gt;<br>&nbsp; &nbsp; &lt;tr&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;td&gt;ORDER_AFTER_DOWNLOAD&lt;/td&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;td&gt;Nach dem Herunterladen einer Bestellung.&lt;/td&gt;<br>&nbsp; &nbsp; &lt;/tr&gt;<br>&lt;/table&gt;<br>&lt;h2&gt;Best Practices für PlugIns&lt;/h2&gt;<br>&lt;ul&gt;<br>&nbsp; &nbsp; &lt;li&gt;&lt;b&gt;Vermeide lange Blockaden:&lt;/b&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;ul&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;li&gt;Die Methode &lt;code&gt;Call&lt;/code&gt; sollte möglichst schnell ausgeführt werden, um Verzögerungen im DataService zu vermeiden.&lt;/li&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;/ul&gt;<br>&nbsp; &nbsp; &lt;/li&gt;<br>&nbsp; &nbsp; &lt;li&gt;&lt;b&gt;Fehlerbehandlung:&lt;/b&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;ul&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;li&gt;Verwende &lt;code&gt;try-catch&lt;/code&gt;, um Laufzeitfehler zu verhindern, die den gesamten Service beeinflussen könnten.&lt;/li&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;/ul&gt;<br>&nbsp; &nbsp; &lt;/li&gt;<br>&nbsp; &nbsp; &lt;li&gt;&lt;b&gt;Testumgebung nutzen:&lt;/b&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;ul&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;li&gt;Teste das PlugIn in einer Entwicklungs- oder Staging-Umgebung, bevor es in die Produktion übernommen wird.&lt;/li&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;/ul&gt;<br>&nbsp; &nbsp; &lt;/li&gt;<br>&nbsp; &nbsp; &lt;li&gt;&lt;b&gt;Log-Ausgaben:&lt;/b&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;ul&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;li&gt;Nutze &lt;code&gt;Console.WriteLine&lt;/code&gt;, um wichtige Informationen und Debug-Daten während der PlugIn-Ausführung zu loggen.&lt;/li&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;/ul&gt;<br>&nbsp; &nbsp; &lt;/li&gt;<br>&lt;/ul&gt;<br>&lt;h2&gt;Beispielhafte Ordnerstruktur&lt;/h2&gt;<br>&lt;pre&gt;<br>C:\OmniVersum\Apps\OmniSellerService2\<br>├── PlugIns\<br>│ &nbsp; ├── OmniSellerZeroPricePlugIn.dll<br>│ &nbsp; ├── OmniSeller.Common.dll<br>│ &nbsp; ├── OmniSeller.Enums.dll<br>├── OmniSellerService.exe<br>&lt;/pre&gt;<br>&lt;h2&gt;Häufige Fehler und Lösungen&lt;/h2&gt;<br>&lt;ul&gt;<br>&nbsp; &nbsp; &lt;li&gt;&lt;b&gt;PlugIn wird nicht geladen:&lt;/b&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;ul&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;li&gt;Überprüfe, ob die &lt;code&gt;IEntryPointPlugin&lt;/code&gt;-Schnittstelle korrekt implementiert wurde.&lt;/li&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;li&gt;Stelle sicher, dass alle Abhängigkeiten (z. B. &lt;code&gt;OmniSeller.Common&lt;/code&gt;) verfügbar sind.&lt;/li&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;/ul&gt;<br>&nbsp; &nbsp; &lt;/li&gt;<br>&nbsp; &nbsp; &lt;li&gt;&lt;b&gt;Assembly-Version inkompatibel:&lt;/b&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;ul&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;li&gt;Stelle sicher, dass die Hauptanwendung und das PlugIn dieselben Versionen von &lt;code&gt;OmniSeller.Common&lt;/code&gt; verwenden.&lt;/li&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;/ul&gt;<br>&nbsp; &nbsp; &lt;/li&gt;<br>&nbsp; &nbsp; &lt;li&gt;&lt;b&gt;Kein &lt;code&gt;EntryPoint&lt;/code&gt; aktiviert:&lt;/b&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;ul&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;li&gt;Prüfe, ob der EntryPoint des PlugIns (&lt;code&gt;SupportedEntryPoints&lt;/code&gt;) mit dem vom Service ausgelösten EntryPoint übereinstimmt.&lt;/li&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &lt;/ul&gt;<br>&nbsp; &nbsp; &lt;/li&gt;<br>&lt;/ul&gt;<br>
 
== Schritt-für-Schritt-Anleitung zur Erstellung eines PlugIns ==<br>=== 1. Projekt einrichten ===<br>* Erstelle ein neues '''.NET Standard 2.0''' Class Library-Projekt in Visual Studio.<br>* Füge die folgenden Pakete über das HTK NuGet Repository hinzu:<br>```plaintext<br>OmniSeller.Common<br>OmniSeller.Enums<br>```
 
=== 2. PlugIn-Logik implementieren ===<br>* Implementiere die Schnittstelle `IEntryPointPlugin`.<br>* Definiere die unterstützten `EntryPoints` und `ShopTypes`.<br>* Implementiere die Logik in der Methode `Call`.
 
=== 3. PlugIn erstellen und veröffentlichen ===<br>* Kompiliere das Projekt.<br>* Die resultierende `.dll`-Datei (zusammen mit ihren Abhängigkeiten) wird in das OmniSeller PlugIn-Verzeichnis kopiert:<br>```plaintext<br>C:\OmniVersum\Apps\OmniSellerService2\PlugIns<br>```
 
=== 4. PlugIn testen ===<br>* Starte den OmniSeller DataService und beobachte die Logs.<br>* Das PlugIn wird automatisch geladen und ausgeführt, wenn der entsprechende `EntryPoint` erreicht wird.
 
== EntryPoints und deren Bedeutung ==<br>{| class="wikitable"<br>|-<br>! EntryPoint<br>! Beschreibung<br>|-<br>| `PORTAL_STARTUP`<br>| Wird beim Start eines Portals ausgeführt.<br>|-<br>| `PRODUCT_BEFORE_UPLOAD`<br>| Vor dem Produkt-Upload.<br>|-<br>| `PRODUCT_AFTER_UPLOAD`<br>| Nach dem Produkt-Upload.<br>|-<br>| `PRICE_BEFORE_UPLOAD`<br>| Vor dem Preis-Upload.<br>|-<br>| `PRICE_AFTER_UPLOAD`<br>| Nach dem Preis-Upload.<br>|-<br>| `ORDER_AFTER_DOWNLOAD`<br>| Nach dem Herunterladen einer Bestellung.<br>|}
 
== Best Practices für PlugIns ==<br># '''Vermeide lange Blockaden''':<br>#* Die Methode `Call` sollte möglichst schnell ausgeführt werden, um Verzögerungen im DataService zu vermeiden.<br># '''Fehlerbehandlung''':<br>#* Verwende `try-catch`, um Laufzeitfehler zu verhindern, die den gesamten Service beeinflussen könnten.<br># '''Testumgebung nutzen''':<br>#* Teste das PlugIn in einer Entwicklungs- oder Staging-Umgebung, bevor es in die Produktion übernommen wird.<br># '''Log-Ausgaben''':<br>#* Nutze `Console.WriteLine`, um wichtige Informationen und Debug-Daten während der PlugIn-Ausführung zu loggen.
 
== Beispielhafte Ordnerstruktur ==<br>```plaintext<br>C:\OmniVersum\Apps\OmniSellerService2\<br>├── PlugIns\<br>│ &nbsp; ├── OmniSellerZeroPricePlugIn.dll<br>│ &nbsp; ├── OmniSeller.Common.dll<br>│ &nbsp; ├── OmniSeller.Enums.dll<br>├── OmniSellerService.exe<br>```
 
== Häufige Fehler und Lösungen ==<br># '''PlugIn wird nicht geladen''':<br>#* Überprüfe, ob die `IEntryPointPlugin`-Schnittstelle korrekt implementiert wurde.<br>#* Stelle sicher, dass alle Abhängigkeiten (z. B. `OmniSeller.Common`) verfügbar sind.<br># '''Assembly-Version inkompatibel''':<br>#* Stelle sicher, dass die Hauptanwendung und das PlugIn dieselben Versionen von `OmniSeller.Common` und `OmniSeller.Enums` verwenden.<br># '''Kein `EntryPoint` aktiviert''':<br>#* Prüfe, ob der EntryPoint des PlugIns (`SupportedEntryPoints`) mit dem vom Service ausgelösten EntryPoint übereinstimmt.
 
Falls es weitere Fragen oder Probleme gibt, wende dich an das '''OmniSeller-Entwicklungsteam'''.<br>

Version vom 5. Dezember 2024, 10:23 Uhr

<h1>OmniSeller PlugIn Entwicklung</h1>
<h2>Überblick</h2>
<p>
    Der OmniSeller DataService bietet die Möglichkeit, externe Logik über PlugIns zu integrieren. PlugIns können entwickelt werden,
    um spezifische Geschäftsanforderungen zu erfüllen, beispielsweise das Anpassen von Produktdaten vor dem Upload oder das
    Modifizieren von Preisen basierend auf bestimmten Kriterien.
</p>
<p>
    OmniSeller PlugIns basieren auf <b>.NET Standard 2.0</b>, um sowohl mit alten (.NET Framework 4.7.2) als auch mit neuen
    (.NET 6.0) Service-Versionen kompatibel zu sein.
</p>
<h2>Voraussetzungen</h2>
<ul>
    <li><b>Entwicklungsumgebung:</b>
        <ul>
            <li>Visual Studio 2019 oder höher</li>
            <li>.NET Standard 2.0 als Zielplattform für PlugIns</li>
        </ul>
    </li>
    <li><b>Abhängigkeiten:</b>
        <ul>
            <li>OmniSeller.Common und OmniSeller.Enums aus dem HTK NuGet Repository: <code>https://htkpackages/repository/</code></li>
        </ul>
    </li>
    <li><b>Nützliche Schnittstellen und Modelle:</b>
        <ul>
            <li>IEntryPointPlugin (aus OmniSeller.Common)</li>
            <li>Enums.EntryPoint und Enums.ShopTypes</li>
        </ul>
    </li>
    <li><b>Zugriff auf ein bestehendes OmniSeller-System</b>, um das PlugIn zu testen</li>
</ul>
<h2>Struktur eines OmniSeller PlugIns</h2>
<p>
    Ein OmniSeller PlugIn muss die Schnittstelle <code>IEntryPointPlugin</code> implementieren, die folgende Eigenschaften und Methoden definiert:
</p>
<pre>
public interface IEntryPointPlugin
{
    string Name { get; }
    EntryPoint SupportedEntryPoints { get; }
    string Version { get; }
    int SortOrder { get; }
    string Author { get; }
    string Publisher { get; }
    ShopTypes SupportedShopTypes { get; }
    string Notes { get; }
    Product Call(ShopTypes shopType, int portalID, Product productObj, EntryPoint entryPoint);
}
</pre>
<h3>Beispiel für ein PlugIn: ZeroPricePlugIn</h3>
<p>
    Dieses PlugIn setzt automatisch den niedrigsten Preis für Produkte, die den Preis <code>0</code> haben, basierend auf den Preisen der Kind-Produkte.
</p>
<pre>
using OmniSeller.Enums;
using OmniSellerPlugins.Interfaces;
using OmniSellerPlugins.Models;
using System;

namespace OmniSeller.PlugIns
{
    internal class ZeroPricePlugIn : IEntryPointPlugin
    {
        public string Name => "OmniSellerZeroPricePlugIn";
        public EntryPoint SupportedEntryPoints => EntryPoint.PRICE_BEFORE_UPLOAD;
        public string Version => "1.0.0.0";
        public int SortOrder => 1000;
        public string Author => "AS";
        public string Publisher => "HTK GmbH & Co.KG";
        public ShopTypes SupportedShopTypes => ShopTypes.Magento;
        public string Notes => "Kein Hinweistext";

        public ZeroPricePlugIn()
        {
            Console.WriteLine($"Running PlugIn {Name}");
        }

        public Product Call(ShopTypes shopType, int portalID, Product productObj, EntryPoint entryPoint)
        {
            Console.WriteLine($"Running PlugIn {Name} for {shopType} at {entryPoint}");
            if (shopType == ShopTypes.Magento)
            {
                // Logik zur Anpassung von Produktpreisen
            }
            return productObj;
        }
    }
}
</pre>
<h2>Schritt-für-Schritt-Anleitung zur Erstellung eines PlugIns</h2>
<h3>1. Projekt einrichten</h3>
<ul>
    <li>Erstelle ein neues <b>.NET Standard 2.0</b> Class Library-Projekt in Visual Studio</li>
    <li>Füge die folgenden Pakete über das HTK NuGet Repository hinzu:</li>
    <pre>
OmniSeller.Common
OmniSeller.Enums
    </pre>
</ul>
<h3>2. PlugIn-Logik implementieren</h3>
<ul>
    <li>Implementiere die Schnittstelle <code>IEntryPointPlugin</code>.</li>
    <li>Definiere die unterstützten <code>EntryPoints</code> und <code>ShopTypes</code>.</li>
    <li>Implementiere die Logik in der Methode <code>Call</code>.</li>
</ul>
<h3>3. PlugIn erstellen und veröffentlichen</h3>
<ul>
    <li>Kompiliere das Projekt.</li>
    <li>Die resultierende <code>.dll</code>-Datei (zusammen mit ihren Abhängigkeiten) wird in das OmniSeller PlugIn-Verzeichnis kopiert:</li>
    <pre>C:\OmniVersum\Apps\OmniSellerService2\PlugIns</pre>
</ul>
<h3>4. PlugIn testen</h3>
<ul>
    <li>Starte den OmniSeller DataService und beobachte die Logs.</li>
    <li>Das PlugIn wird automatisch geladen und ausgeführt, wenn der entsprechende <code>EntryPoint</code> erreicht wird.</li>
</ul>
<h2>EntryPoints und deren Bedeutung</h2>
<table border="1">
    <tr>
        <th>EntryPoint</th>
        <th>Beschreibung</th>
    </tr>
    <tr>
        <td>PORTAL_STARTUP</td>
        <td>Wird beim Start eines Portals ausgeführt.</td>
    </tr>
    <tr>
        <td>PRODUCT_BEFORE_UPLOAD</td>
        <td>Vor dem Produkt-Upload.</td>
    </tr>
    <tr>
        <td>PRODUCT_AFTER_UPLOAD</td>
        <td>Nach dem Produkt-Upload.</td>
    </tr>
    <tr>
        <td>PRICE_BEFORE_UPLOAD</td>
        <td>Vor dem Preis-Upload.</td>
    </tr>
    <tr>
        <td>PRICE_AFTER_UPLOAD</td>
        <td>Nach dem Preis-Upload.</td>
    </tr>
    <tr>
        <td>ORDER_AFTER_DOWNLOAD</td>
        <td>Nach dem Herunterladen einer Bestellung.</td>
    </tr>
</table>
<h2>Best Practices für PlugIns</h2>
<ul>
    <li><b>Vermeide lange Blockaden:</b>
        <ul>
            <li>Die Methode <code>Call</code> sollte möglichst schnell ausgeführt werden, um Verzögerungen im DataService zu vermeiden.</li>
        </ul>
    </li>
    <li><b>Fehlerbehandlung:</b>
        <ul>
            <li>Verwende <code>try-catch</code>, um Laufzeitfehler zu verhindern, die den gesamten Service beeinflussen könnten.</li>
        </ul>
    </li>
    <li><b>Testumgebung nutzen:</b>
        <ul>
            <li>Teste das PlugIn in einer Entwicklungs- oder Staging-Umgebung, bevor es in die Produktion übernommen wird.</li>
        </ul>
    </li>
    <li><b>Log-Ausgaben:</b>
        <ul>
            <li>Nutze <code>Console.WriteLine</code>, um wichtige Informationen und Debug-Daten während der PlugIn-Ausführung zu loggen.</li>
        </ul>
    </li>
</ul>
<h2>Beispielhafte Ordnerstruktur</h2>
<pre>
C:\OmniVersum\Apps\OmniSellerService2\
├── PlugIns\
│   ├── OmniSellerZeroPricePlugIn.dll
│   ├── OmniSeller.Common.dll
│   ├── OmniSeller.Enums.dll
├── OmniSellerService.exe
</pre>
<h2>Häufige Fehler und Lösungen</h2>
<ul>
    <li><b>PlugIn wird nicht geladen:</b>
        <ul>
            <li>Überprüfe, ob die <code>IEntryPointPlugin</code>-Schnittstelle korrekt implementiert wurde.</li>
            <li>Stelle sicher, dass alle Abhängigkeiten (z. B. <code>OmniSeller.Common</code>) verfügbar sind.</li>
        </ul>
    </li>
    <li><b>Assembly-Version inkompatibel:</b>
        <ul>
            <li>Stelle sicher, dass die Hauptanwendung und das PlugIn dieselben Versionen von <code>OmniSeller.Common</code> verwenden.</li>
        </ul>
    </li>
    <li><b>Kein <code>EntryPoint</code> aktiviert:</b>
        <ul>
            <li>Prüfe, ob der EntryPoint des PlugIns (<code>SupportedEntryPoints</code>) mit dem vom Service ausgelösten EntryPoint übereinstimmt.</li>
        </ul>
    </li>
</ul>