Skip to content

Commit

Permalink
Updating local process to respect initial state.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Thomas committed Oct 15, 2024
1 parent ca50172 commit b743ebd
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions dotnet/src/Experimental/Process.LocalRuntime/LocalStep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ protected virtual async ValueTask InitializeStepAsync()
this._inputs = this._initialInputs.ToDictionary(kvp => kvp.Key, kvp => kvp.Value?.ToDictionary(kvp => kvp.Key, kvp => kvp.Value));

// Activate the step with user-defined state if needed
KernelProcessStepState? stateObject = null;
KernelProcessStepState stateObject = this._stepInfo.State;
Type? stateType = null;

if (TryGetSubtypeOfStatefulStep(this._stepInfo.InnerStepType, out Type? genericStepType) && genericStepType is not null)
Expand All @@ -254,14 +254,17 @@ protected virtual async ValueTask InitializeStepAsync()
throw new KernelException(errorMessage);
}

stateObject = (KernelProcessStepState?)Activator.CreateInstance(stateType, this.Name, this.Id);
stateType.GetProperty(nameof(KernelProcessStepState<object>.State))?.SetValue(stateObject, Activator.CreateInstance(userStateType));
var userState = stateType.GetProperty(nameof(KernelProcessStepState<object>.State))?.GetValue(stateObject);
if (userState is null)
{
stateType.GetProperty(nameof(KernelProcessStepState<object>.State))?.SetValue(stateObject, Activator.CreateInstance(userStateType));
}
}
else
{
// The step is a KernelProcessStep with no user-defined state, so we can use the base KernelProcessStepState.
stateType = typeof(KernelProcessStepState);
stateObject = new KernelProcessStepState(this.Name, this.Id);
//stateObject = new KernelProcessStepState(this.Name, this.Id);
}

if (stateObject is null)
Expand Down

0 comments on commit b743ebd

Please sign in to comment.