Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
15 changes: 15 additions & 0 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,21 @@ jobs:
node_version: ${{ needs.EnvVar.outputs.node_version }}
REPOSITORY_NAME: ${{ needs.EnvVar.outputs.REPOSITORY_NAME }}

FormatCheck:
name: Format check
needs: [EnvVar]
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7

- uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ needs.EnvVar.outputs.dotnet_sdk_version }}

- name: Verify formatting
run: dotnet format "${{ github.workspace }}/MORYX-Framework.slnx" --verify-no-changes --verbosity minimal

UnitTests:
name: Unit Tests
needs: [EnvVar, Build]
Expand Down
5 changes: 4 additions & 1 deletion MORYX-Framework.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@
<Folder Name="/Solution Items/">
<File Path=".build/Common.props" />
<File Path=".editorconfig" />
<File Path=".github/dependabot.yml" />
<File Path=".github/workflows/build-and-test.yml" />
<File Path=".github/workflows/sbom-generation.yml" />
<File Path="CodeCoverage.runsettings" />
<File Path="Directory.Build.props" />
<File Path="Directory.Build.targets" />
Expand Down Expand Up @@ -186,5 +189,5 @@
<Project Path="src/Moryx.Container/Moryx.Container.csproj" />
<Project Path="src/Moryx.Launcher/Moryx.Launcher.csproj" />
<Project Path="src/Moryx/Moryx.csproj" />
<Project Path="src/StartProject.Asp/StartProject.Asp.csproj" DefaultStartup="true"/>
<Project Path="src/StartProject.Asp/StartProject.Asp.csproj" DefaultStartup="true" />
</Solution>
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ public class PartConnector

[DataMember]
public Entry PropertyTemplates { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ public class PartModel

[DataMember]
public ProductModel Product { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ public class ProductCustomization

[DataMember]
public ProductImporter[] Importers { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ public class ProductDefinitionModel

[DataMember]
public Entry Properties { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ public class ProductImporter

[DataMember]
public Entry Parameters { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ public class ProductInstanceModel

[DataMember]
public Entry Properties { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ public class ProductModel

[DataMember]
public RecipeModel[] Recipes { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ public enum RecipeClassificationModel
Intermediate,

Part
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ public class RecipeDefinitionModel

[DataMember]
public bool HasWorkplans { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@ public class RecipeModel
/// </summary>
[DataMember]
public bool IsClone { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ public class WorkplanModel

[DataMember]
public WorkplanState State { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,15 @@ protected bool SimpleProp(PropertyInfo prop)
if (typeof(ProductType).IsAssignableFrom(type) ||
typeof(ProductPartLink).IsAssignableFrom(type) ||
typeof(IEnumerable<ProductPartLink>).IsAssignableFrom(type))
{
return false;
}

// Filter default properties
if (FilteredProperties.Contains(prop.Name))
{
return false;
}

return true;
}
Expand All @@ -73,4 +77,4 @@ public void FillEmpty(object obj)
ValueProviderExecutor.Execute(obj, new ValueProviderExecutorSettings().AddDefaultValueProvider());
}
}
}
}
38 changes: 35 additions & 3 deletions src/Moryx.AbstractionLayer.Products.Endpoints/ProductConverter.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Copyright (c) 2026 Phoenix Contact GmbH & Co. KG
// Licensed under the Apache License, Version 2.0

using System.Collections;
using System.Reflection;
using Moryx.AbstractionLayer.Products.Endpoints.Models;
using Moryx.AbstractionLayer.Recipes;
using Moryx.Container;
using Moryx.Serialization;
using Moryx.Tools;
using Moryx.Workplans;
using System.Collections;
using System.Reflection;
using Moryx.AbstractionLayer.Products.Endpoints.Models;

namespace Moryx.AbstractionLayer.Products.Endpoints;

Expand Down Expand Up @@ -74,7 +74,9 @@ public async Task<ProductModel> ConvertProduct(ProductType productType, bool fla
};

if (flat)
{
return converted;
}

// Properties
var typeWrapper = _productManagement.GetTypeWrapper(productType.GetType().FullName);
Expand Down Expand Up @@ -155,7 +157,9 @@ private static Type FindGenericBaseDefinition(Type type, Type genericDefinition)
while (current != null && current != typeof(object))
{
if (current.IsGenericType && current.GetGenericTypeDefinition() == genericDefinition)
{
return current;
}

current = current.BaseType;
}
Expand All @@ -167,7 +171,9 @@ private async Task<PartModel> ConvertPart(ProductPartLink link)
{
// No link, no DTO!
if (link is null || link.Product is null)
{
return null;
}

var part = new PartModel
{
Expand Down Expand Up @@ -196,26 +202,38 @@ public async Task<ProductType> ConvertProductBack(ProductModel source, ProductTy
productRecipe = (IProductRecipe)Activator.CreateInstance(type);
}
else
{
productRecipe = (IProductRecipe)await _productManagement.LoadRecipeAsync(recipeModel.Id);
}

ConvertRecipeBack(recipeModel, productRecipe, converted);
recipes.Add(productRecipe);
}
if (recipes.Any())
{
foreach (var recipe in recipes)
{
await _productManagement.SaveRecipeAsync(recipe);
}
}

// Product is flat
if (source.Properties is null)
{
return converted;
}

// Delete recipes
if (converted.Id != 0)
{
var recipesOfProduct = await _productManagement.LoadRecipesAsync(converted, RecipeClassification.CloneFilter);
foreach (var recipe in recipesOfProduct)
{
if (recipes.FirstOrDefault(r => r.Id == recipe.Id) == null)
{
await _productManagement.DeleteRecipeAsync(recipe.Id);
}
}
}

// Copy extended properties
Expand All @@ -227,7 +245,9 @@ public async Task<ProductType> ConvertProductBack(ProductModel source, ProductTy
foreach (var partConnector in source.Parts ?? Enumerable.Empty<PartConnector>())
{
if (partConnector.Parts is null)
{
continue;
}

var prop = properties.First(p => p.Name == partConnector.Name);
var value = prop.GetValue(converted);
Expand Down Expand Up @@ -271,7 +291,9 @@ private async Task UpdateCollection(IList value, IEnumerable<PartModel> parts)
foreach (var partModel in parts)
{
if (partModel is null)
{
continue;
}

var oldPartMatch = oldParts.Find(r => r.Id == partModel.Id);
// new partlink
Expand All @@ -283,17 +305,23 @@ private async Task UpdateCollection(IList value, IEnumerable<PartModel> parts)
}
//modified reference
else if (oldPartMatch.Product.Id != partModel.Product.Id)
{
oldPartMatch.Product = await _productManagement.LoadTypeAsync(partModel.Product.Id);
}
else
{
// existing unchanged partlink: do not delete at the end
oldParts.Remove(oldPartMatch);
}

EntryConvert.UpdateInstance(oldPartMatch, partModel.Properties);
}

// Clear all values no longer present in the model
foreach (var part in oldParts)
{
value.Remove(part);
}
}

private async Task UpdateReference(ProductPartLink value, PartModel part)
Expand Down Expand Up @@ -355,7 +383,9 @@ public async Task<IProductRecipe> ConvertRecipeBack(RecipeModel recipe, IProduct
// Only load workplan if it changed
var workplanRecipe = productRecipe as IWorkplanRecipe;
if (workplanRecipe != null && workplanRecipe.Workplan?.Id != recipe.WorkplanModel.Id)
{
workplanRecipe.Workplan = await _productManagement.LoadWorkplanAsync(recipe.WorkplanModel.Id);
}

if (productRecipe.Product == null)
{
Expand All @@ -366,7 +396,9 @@ public async Task<IProductRecipe> ConvertRecipeBack(RecipeModel recipe, IProduct

// Do not update a clones classification
if (productRecipe.Classification.HasFlag(RecipeClassification.Clone))
{
return productRecipe;
}

switch (recipe.Classification)
{
Expand Down
Loading
Loading