Skip to content

Commit

Permalink
Merge pull request #396 from PHOENIXCONTACT/fix/load-step-exception
Browse files Browse the repository at this point in the history
Port #395 to release 8
  • Loading branch information
Toxantron authored Mar 18, 2024
2 parents 1ef64b3 + 6e623a7 commit e5c3dc2
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/Moryx.Products.Management/Implementation/RecipeStorage.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.Eventing.Reader;
using System.Drawing;
using System.Linq;
using Moryx.AbstractionLayer;
Expand Down Expand Up @@ -137,7 +138,7 @@ private static List<IWorkplanStep> LoadSteps(WorkplanEntity workplan, IDictionar

// Restore parameters from JSON
if (step is ITaskStep<IParameters> taskStep)
JsonConvert.PopulateObject(stepEntity.Parameters, taskStep.Parameters);
PopulateStepParameters(stepEntity, taskStep);

// Restore Subworkplan if necessary
if (step is ISubworkplanStep subworkplanStep)
Expand All @@ -153,6 +154,16 @@ private static List<IWorkplanStep> LoadSteps(WorkplanEntity workplan, IDictionar
return steps;
}

private static void PopulateStepParameters(WorkplanStepEntity stepEntity, ITaskStep<IParameters> taskStep)
{
if (taskStep.Parameters is null)
throw new InvalidOperationException($"{nameof(taskStep.Parameters)} could not " +
$"be populated from the database. Make sure the property of {taskStep.GetType()} " +
$"is initilized on instance creation.");
else
JsonConvert.PopulateObject(stepEntity.Parameters, taskStep.Parameters);
}

/// <summary>
/// Restore either <see cref="IWorkplanStep.Inputs"/> or <see cref="IWorkplanStep.Outputs"/>.
/// </summary>
Expand Down

0 comments on commit e5c3dc2

Please sign in to comment.