I'm currently working on Moryx 8 and want to configure a custom importer that automatically creates workplans. For that I created a custom workplan importer. My Question is, how do I execute this importer so that the workplans get created?
Here is my current importer with a method to create a test workplan. The tasks exists and there are no issues with the parameters.
namespace Products.Importer
{
public class WorkplanImporter
{
public Workplan CreateWorkplan()
{
var workplan = new Workplan();
workplan.Name = "TestWorkplan";
var start = WorkplanInstance.CreateConnector("Start", NodeClassification.Start);
var end = WorkplanInstance.CreateConnector("Ende", NodeClassification.End);
var failed = WorkplanInstance.CreateConnector("Failed", NodeClassification.Failed);
workplan.Add(start, end, failed);
var input = start;
var output = WorkplanInstance.CreateConnector("Task 1 finished");
workplan.AddStep(new InsertHousingTask(), new AssembleParameters(), input, output, failed);
input = output;
output = WorkplanInstance.CreateConnector("Task 2 finished");
workplan.AddStep(new TestHousingTask(), new AssembleParameters(), input, output, failed);
input = output;
output = WorkplanInstance.CreateConnector("Task 3 finished");
workplan.AddStep(new InsertPowerbarTask(), new AssembleParameters(), input, output, failed);
return workplan;
}
}
}
I worked with Initializers already, so I tried to find an option to execute the importer in the appropiate module in the command center. But for me there was no option to execute something like an importer. The following picture shows where I tried to find an option to execute the importer.
I would appreciate if someone can tell me how to execute a workplan importer and check my provided importer for major mistakes. Thank you!
Workplans and Products are coupled in MORYX, since a workplan is usually used in a recipe for a product. The WorkplanEditing module you were looking at is currenlty only used to actually edit workplans in sessions managed by exactly that module.
In order to create a Workplan
we use an implementation of the ProductImporterBase
class.
Workplan Importer
using System.Threading.Tasks;
using Moryx.AbstractionLayer.Products;
using Moryx.Container;
using Moryx.Modules;
using Moryx.Workplans;
[ExpectedConfig(typeof(WorkplanImporterConfig))]
[Plugin(LifeCycle.Transient, typeof(IProductImporter), Name = nameof(WorkplanImporter))]
public class WorkplanImporter : ProductImporterBase<WorkplanImporterConfig, WorkplanImporterParameters>
{
public IWorkplans WorkplanStorage { get; set; }
protected override Task<ProductImporterResult> Import(ProductImportContext context, WorkplanImporterParameters parameters)
{
var workplan = CreateWorkplan();
WorkplanStorage.SaveWorkplan(workplan);
return Task.FromResult(new ProductImporterResult { Saved = true });
}
private Workplan CreateWorkplan()
{
// Your Code...
}
}
public class WorkplanImporterParameters {}
public class WorkplanImporterConfig : ProductImporterConfig {}
This implementation of ProductImporterBase
would create the workplan you designed in your method and save it using the injected WorkplanStorage
component.
The execution of the importer is done via the IProductManagement
facade, which you can find here.
If you don't want to execute your WorkplanImporter
from your code directly you can either use the Rest API on the facade in the Moryx.AbstractionLayer.Products.Endpoints
package (code can be found here) or the web interface.
From your screenshot I gather that you are using the Web interface. If you want to execute the workplan from there you can use the Moryx.Products.Web
nuget package. After you configured the WorkplanImporter
in the module config of the Product Management, it will be selectable in the web interface.
Module Config
{
"MaxImporterWait": 20,
"Importers": [
{
"PluginName": "DefaultImporter"
},
{
"$type": "Products.Importer.WorkplanImporterConfig, Products.Importer",
"PluginName": "WorkplanImporter"
}
],
...
}
Note:
From your code example it does not appeaer as if your importer would require any configuration or parameterization. Hence, the WorkplanImporterConfig
and the WorkplanImporterParameters
classes are left empty.
Generally you could use the config for your importer to provide values which are configured in the module config (e.g. a host url), while the parameters can be used to provide values with each execution of the importer (e.g. the name for the workplan).