OmniSeller:PlugIn Entwicklung: Unterschied zwischen den Versionen

Aus HTK Wiki
Zur Navigation springen Zur Suche springen
Keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
Zeile 1: Zeile 1:
&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;
<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<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
{
    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";


&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; }
        public ZeroPricePlugIn()
        {
            Console.WriteLine($"Running PlugIn {Name}");
        }


&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>
        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>
 
{| border="1"  
|-
! | EntryPoint
! | Beschreibung
|-
| | PORTAL_STARTUP
| | Wird beim Start eines Portals ausgeführt.
|-
| | PRODUCT_BEFORE_UPLOAD
| | Vor dem Produkt-Upload.
|-
| | PRODUCT_AFTER_UPLOAD
| | Nach dem Produkt-Upload.
|-
| | PRICE_BEFORE_UPLOAD
| | Vor dem Preis-Upload.
|-
| | PRICE_AFTER_UPLOAD
| | Nach dem Preis-Upload.
|-
| | ORDER_AFTER_DOWNLOAD
| | Nach dem Herunterladen einer Bestellung.
|}
 
<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>

Version vom 5. Dezember 2024, 10:24 Uhr

OmniSeller PlugIn Entwicklung

Überblick

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

  • Entwicklungsumgebung:
    • Visual Studio 2019 oder höher
    • .NET Standard 2.0 als Zielplattform für PlugIns
  • Abhängigkeiten:
  • Nützliche Schnittstellen und Modelle:
    • IEntryPointPlugin (aus OmniSeller.Common)
    • Enums.EntryPoint und Enums.ShopTypes
  • Zugriff auf ein bestehendes OmniSeller-System, um das PlugIn zu testen

Struktur eines OmniSeller PlugIns

Ein OmniSeller PlugIn muss die Schnittstelle IEntryPointPlugin implementieren, die folgende Eigenschaften und Methoden definiert:

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

Beispiel für ein PlugIn: ZeroPricePlugIn

Dieses PlugIn setzt automatisch den niedrigsten Preis für Produkte, die den Preis 0 haben, basierend auf den Preisen der Kind-Produkte.

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

Schritt-für-Schritt-Anleitung zur Erstellung eines PlugIns

1. Projekt einrichten

  • Erstelle ein neues .NET Standard 2.0 Class Library-Projekt in Visual Studio
  • Füge die folgenden Pakete über das HTK NuGet Repository hinzu:
  • OmniSeller.Common
    OmniSeller.Enums
        

2. PlugIn-Logik implementieren

  • Implementiere die Schnittstelle IEntryPointPlugin.
  • Definiere die unterstützten EntryPoints und ShopTypes.
  • Implementiere die Logik in der Methode Call.

3. PlugIn erstellen und veröffentlichen

  • Kompiliere das Projekt.
  • Die resultierende .dll-Datei (zusammen mit ihren Abhängigkeiten) wird in das OmniSeller PlugIn-Verzeichnis kopiert:
  • C:\OmniVersum\Apps\OmniSellerService2\PlugIns

4. PlugIn testen

  • Starte den OmniSeller DataService und beobachte die Logs.
  • Das PlugIn wird automatisch geladen und ausgeführt, wenn der entsprechende EntryPoint erreicht wird.

EntryPoints und deren Bedeutung

EntryPoint Beschreibung
PORTAL_STARTUP Wird beim Start eines Portals ausgeführt.
PRODUCT_BEFORE_UPLOAD Vor dem Produkt-Upload.
PRODUCT_AFTER_UPLOAD Nach dem Produkt-Upload.
PRICE_BEFORE_UPLOAD Vor dem Preis-Upload.
PRICE_AFTER_UPLOAD Nach dem Preis-Upload.
ORDER_AFTER_DOWNLOAD Nach dem Herunterladen einer Bestellung.

Best Practices für PlugIns

  • Vermeide lange Blockaden:
    • Die Methode Call sollte möglichst schnell ausgeführt werden, um Verzögerungen im DataService zu vermeiden.
  • Fehlerbehandlung:
    • Verwende try-catch, um Laufzeitfehler zu verhindern, die den gesamten Service beeinflussen könnten.
  • Testumgebung nutzen:
    • Teste das PlugIn in einer Entwicklungs- oder Staging-Umgebung, bevor es in die Produktion übernommen wird.
  • Log-Ausgaben:
    • Nutze Console.WriteLine, um wichtige Informationen und Debug-Daten während der PlugIn-Ausführung zu loggen.

Beispielhafte Ordnerstruktur

C:\OmniVersum\Apps\OmniSellerService2\
├── PlugIns\
│   ├── OmniSellerZeroPricePlugIn.dll
│   ├── OmniSeller.Common.dll
│   ├── OmniSeller.Enums.dll
├── OmniSellerService.exe

Häufige Fehler und Lösungen

  • PlugIn wird nicht geladen:
    • Überprüfe, ob die IEntryPointPlugin-Schnittstelle korrekt implementiert wurde.
    • Stelle sicher, dass alle Abhängigkeiten (z. B. OmniSeller.Common) verfügbar sind.
  • Assembly-Version inkompatibel:
    • Stelle sicher, dass die Hauptanwendung und das PlugIn dieselben Versionen von OmniSeller.Common verwenden.
  • Kein EntryPoint aktiviert:
    • Prüfe, ob der EntryPoint des PlugIns (SupportedEntryPoints) mit dem vom Service ausgelösten EntryPoint übereinstimmt.