Skip to content

Commit

Permalink
0.9.2-alpha (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikolaj-milewski authored Feb 15, 2024
1 parent f2982b1 commit f477d2b
Show file tree
Hide file tree
Showing 106 changed files with 470 additions and 449 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,9 @@ $RECYCLE.BIN/

# Angular
.angular
Transport/@stateflows/common/dist/
Transport/@stateflows/signalr-client/dist/
Transport/@stateflows/http-client/dist/
Examples/SignalR/SignalR.Client/ClientApp/.angular/
*.txt
Publish.ps1
2 changes: 1 addition & 1 deletion Core/Stateflows/Activities/Classes/ElseFlow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public override sealed Task<bool> GuardAsync()
=> Task.FromResult(true);
}

public abstract class ElseTokenFlow<TToken> : BaseTokenFlow<TToken>
public abstract class ElseFlow<TToken> : BaseFlow<TToken>
where TToken : Token, new()
{
public override sealed Task<bool> GuardAsync()
Expand Down
6 changes: 3 additions & 3 deletions Core/Stateflows/Activities/Classes/Flow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ public virtual Task<bool> GuardAsync()
public abstract class ControlFlow : BaseControlFlow
{ }

public abstract class BaseTokenFlow<TToken> : BaseControlFlow
public abstract class BaseFlow<TToken> : BaseControlFlow
where TToken : Token, new()
{
public virtual int Weight => 1;

new public IFlowContext<TToken> Context { get; internal set; }
}

public abstract class TokenFlow<TToken> : BaseTokenFlow<TToken>
public abstract class Flow<TToken> : BaseFlow<TToken>
where TToken : Token, new()
{ }

public abstract class DataFlow<TTokenPayload> : TokenFlow<Token<TTokenPayload>>
public abstract class DataFlow<TTokenPayload> : Flow<Token<TTokenPayload>>
{ }

public abstract class BaseTokenTransformationFlow<TToken, TTransformedToken> : BaseControlFlow
Expand Down
2 changes: 1 addition & 1 deletion Core/Stateflows/Activities/Engine/NodeScope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public TControlFlow GetControlFlow<TControlFlow>(IFlowContext context)
=> GetFlow<TControlFlow>(context);

public TFlow GetObjectFlow<TFlow, TToken>(IFlowContext<TToken> context)
where TFlow : TokenFlow<TToken>
where TFlow : Flow<TToken>
where TToken : Token, new()
=> GetFlow<TFlow>(context);

Expand Down
6 changes: 3 additions & 3 deletions Core/Stateflows/Activities/Extensions/BuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static void AddActivityEvents(this IActivityBuilder builder, Type activit
var methodInfo = interfaceType.GetMethods().First(m => m.Name == "OnInitializeAsync");
var requestType = interfaceType.GenericTypeArguments[0];
var requestName = Stateflows.Common.EventInfo.GetName(requestType);
(builder as ActivityBuilder).AddInitializer(requestName, c =>
(builder as ActivityBuilder).AddInitializer(requestType, requestName, c =>
{
var activity = c.Context.Executor.GetActivity(activityType, c.Context);
return methodInfo.Invoke(activity, new object[] { c.Context.Event }) as Task<bool>;
Expand Down Expand Up @@ -89,10 +89,10 @@ public static void AddObjectTransformationFlowEvents<TObjectTransformationFlow,
}

public static void AddObjectFlowEvents<TObjectFlow, TToken>(this IObjectFlowBuilder<TToken> builder)
where TObjectFlow : TokenFlow<TToken>
where TObjectFlow : Flow<TToken>
where TToken : Token, new()
{
if (typeof(BaseTokenFlow<TToken>).GetProperty(nameof(BaseTokenFlow<TToken>.Weight)).IsOverridenIn<TObjectFlow>())
if (typeof(BaseFlow<TToken>).GetProperty(nameof(BaseFlow<TToken>.Weight)).IsOverridenIn<TObjectFlow>())
{
var objectFlow = FormatterServices.GetUninitializedObject(typeof(TObjectFlow)) as TObjectFlow;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ public static IServiceCollection RegisterExceptionHandlerAction<TException, TExc
=> services?.AddServiceType<TExceptionHandler>();

public static IServiceCollection RegisterObjectFlow<TObjectFlow, TToken>(this IServiceCollection services)
where TObjectFlow : TokenFlow<TToken>
where TObjectFlow : Flow<TToken>
where TToken : Token, new()
=> services?.AddServiceType<TObjectFlow>();

public static IServiceCollection RegisterElseObjectFlow<TObjectFlow, TToken>(this IServiceCollection services)
where TObjectFlow : ElseTokenFlow<TToken>
where TObjectFlow : ElseFlow<TToken>
where TToken : Token, new()
=> services?.AddServiceType<TObjectFlow>();

Expand Down
25 changes: 10 additions & 15 deletions Core/Stateflows/Activities/Models/Graph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,16 @@ public Graph(string name, int version)

public int Version { get; }
public Type ActivityType { get; set; }
public Dictionary<string, Node> AllNodes { get; set; } = new Dictionary<string, Node>();
public Dictionary<string, Node> AllNamedNodes { get; set; } = new Dictionary<string, Node>();
public List<Edge> AllEdgesList { get; set; } = new List<Edge>();
public Dictionary<string, Edge> AllEdges { get; set; } = new Dictionary<string, Edge>();


private Dictionary<string, Logic<ActivityPredicateAsync>> initializers = null;
public Dictionary<string, Logic<ActivityPredicateAsync>> Initializers
=> initializers ??= new Dictionary<string, Logic<ActivityPredicateAsync>>();

public List<ActivityExceptionHandlerFactory> ExceptionHandlerFactories { get; set; } = new List<ActivityExceptionHandlerFactory>();

public List<ActivityInterceptorFactory> InterceptorFactories { get; set; } = new List<ActivityInterceptorFactory>();

public List<ActivityObserverFactory> ObserverFactories { get; set; } = new List<ActivityObserverFactory>();
public readonly Dictionary<string, Node> AllNodes = new Dictionary<string, Node>();
public readonly Dictionary<string, Node> AllNamedNodes = new Dictionary<string, Node>();
public readonly List<Edge> AllEdgesList = new List<Edge>();
public readonly Dictionary<string, Edge> AllEdges = new Dictionary<string, Edge>();

public readonly Dictionary<string, Logic<ActivityPredicateAsync>> Initializers = new Dictionary<string, Logic<ActivityPredicateAsync>>();
public readonly List<Type> InitializerTypes = new List<Type>();
public readonly List<ActivityExceptionHandlerFactory> ExceptionHandlerFactories = new List<ActivityExceptionHandlerFactory>();
public readonly List<ActivityInterceptorFactory> InterceptorFactories = new List<ActivityInterceptorFactory>();
public readonly List<ActivityObserverFactory> ObserverFactories = new List<ActivityObserverFactory>();

[DebuggerHidden]
public void Build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public ActivityBuilder(string name, int version, Node parentNode, IServiceCollec
Result = new Graph(name, version);
}

public IActivityBuilder AddInitializer(string initializerName, ActivityPredicateAsync initializerAction)
public IActivityBuilder AddInitializer(Type initializerType, string initializerName, ActivityPredicateAsync initializerAction)
{
if (!Result.Initializers.TryGetValue(initializerName, out var initializer))
{
Expand Down Expand Up @@ -64,7 +64,7 @@ public IActivityBuilder AddOnInitialize<TInitializationRequest>(Func<IActivityIn

var initializerName = EventInfo<TInitializationRequest>.Name;

return AddInitializer(initializerName, async c =>
return AddInitializer(typeof(TInitializationRequest), initializerName, async c =>
{
var result = false;
var context = new ActivityInitializationContext<TInitializationRequest>(c, c.Context.Event as TInitializationRequest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ public DecisionBuilder(NodeBuilder builder)
{ }

public IDecisionBuilder<TToken> AddFlow(string targetNodeName, ObjectFlowBuildAction<TToken> buildAction = null)
=> AddTokenFlow<TToken>(targetNodeName, buildAction) as IDecisionBuilder<TToken>;
=> AddFlow<TToken>(targetNodeName, buildAction) as IDecisionBuilder<TToken>;

public IDecisionBuilder<TToken> AddElseFlow(string targetNodeName, ElseObjectFlowBuildAction<TToken> buildAction = null)
=> AddElseTokenFlow<TToken>(targetNodeName, buildAction) as IDecisionBuilder<TToken>;
=> AddElseFlow<TToken>(targetNodeName, buildAction) as IDecisionBuilder<TToken>;
}
}
34 changes: 17 additions & 17 deletions Core/Stateflows/Activities/Registration/Builders/NodeBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ public IActionBuilder AddControlFlow(string targetNodeName, ControlFlowBuildActi
public IActionBuilder AddElseControlFlow(string targetNodeName, ElseControlFlowBuildAction buildAction = null)
=> AddDataFlowInternal<ControlToken>(targetNodeName, true, b => buildAction?.Invoke(b as IElseControlFlowBuilder));

public IActionBuilder AddTokenFlow<TToken>(string targetNodeName, ObjectFlowBuildAction<TToken> buildAction = null)
public IActionBuilder AddFlow<TToken>(string targetNodeName, ObjectFlowBuildAction<TToken> buildAction = null)
where TToken : Token, new()
=> AddDataFlowInternal<TToken>(targetNodeName, false, buildAction);

public IActionBuilder AddElseTokenFlow<TToken>(string targetNodeName, ElseObjectFlowBuildAction<TToken> buildAction = null)
public IActionBuilder AddElseFlow<TToken>(string targetNodeName, ElseObjectFlowBuildAction<TToken> buildAction = null)
where TToken : Token, new()
=> AddDataFlowInternal<TToken>(targetNodeName, true, b => buildAction?.Invoke(b as IElseObjectFlowBuilder<TToken>));

Expand Down Expand Up @@ -92,14 +92,14 @@ public IActionBuilderWithOptions SetOptions(NodeOptions nodeOptions)
IActionBuilderWithOptions IControlFlow<IActionBuilderWithOptions>.AddControlFlow(string targetNodeName, ControlFlowBuildAction buildAction)
=> AddControlFlow(targetNodeName, buildAction) as IActionBuilderWithOptions;

IActionBuilderWithOptions IObjectFlow<IActionBuilderWithOptions>.AddTokenFlow<TToken>(string targetNodeName, ObjectFlowBuildAction<TToken> buildAction)
=> AddTokenFlow(targetNodeName, buildAction) as IActionBuilderWithOptions;
IActionBuilderWithOptions IObjectFlow<IActionBuilderWithOptions>.AddFlow<TToken>(string targetNodeName, ObjectFlowBuildAction<TToken> buildAction)
=> AddFlow<TToken>(targetNodeName, buildAction) as IActionBuilderWithOptions;

IInitialBuilder IControlFlow<IInitialBuilder>.AddControlFlow(string targetNodeName, ControlFlowBuildAction buildAction)
=> AddControlFlow(targetNodeName, buildAction) as IInitialBuilder;

ITypedActionBuilder IObjectFlow<ITypedActionBuilder>.AddTokenFlow<TToken>(string targetNodeName, ObjectFlowBuildAction<TToken> buildAction)
=> AddTokenFlow<TToken>(targetNodeName, buildAction) as ITypedActionBuilder;
ITypedActionBuilder IObjectFlow<ITypedActionBuilder>.AddFlow<TToken>(string targetNodeName, ObjectFlowBuildAction<TToken> buildAction)
=> AddFlow<TToken>(targetNodeName, buildAction) as ITypedActionBuilder;

ITypedActionBuilder IControlFlow<ITypedActionBuilder>.AddControlFlow(string targetNodeName, ControlFlowBuildAction buildAction)
=> AddControlFlow(targetNodeName, buildAction) as ITypedActionBuilder;
Expand All @@ -109,7 +109,7 @@ public IActionBuilderWithOptions AddExceptionHandler<TException>(ExceptionHandle
{
var targetNodeName = $"{Node.Name}.{typeof(TException).FullName}.ExceptionHandler";

AddTokenFlow<ExceptionToken<TException>>(targetNodeName);
AddFlow<ExceptionToken<TException>>(targetNodeName);
ActivityBuilder.AddNode(
NodeType.ExceptionHandler,
targetNodeName,
Expand Down Expand Up @@ -137,23 +137,23 @@ ITypedActionBuilder IExceptionHandler<ITypedActionBuilder>.AddExceptionHandler<T
IActionBuilder IExceptionHandler<IActionBuilder>.AddExceptionHandler<TException>(ExceptionHandlerDelegateAsync<TException> exceptionHandler)
=> AddExceptionHandler<TException>(exceptionHandler) as IActionBuilder;

IInputBuilder IObjectFlow<IInputBuilder>.AddTokenFlow<TToken>(string targetNodeName, ObjectFlowBuildAction<TToken> buildAction)
=> AddTokenFlow<TToken>(targetNodeName, buildAction) as IInputBuilder;
IInputBuilder IObjectFlow<IInputBuilder>.AddFlow<TToken>(string targetNodeName, ObjectFlowBuildAction<TToken> buildAction)
=> AddFlow<TToken>(targetNodeName, buildAction) as IInputBuilder;

void IObjectFlow.AddTokenFlow<TToken>(string targetNodeName, ObjectFlowBuildAction<TToken> buildAction)
=> AddTokenFlow<TToken>(targetNodeName, buildAction);
void IObjectFlow.AddFlow<TToken>(string targetNodeName, ObjectFlowBuildAction<TToken> buildAction)
=> AddFlow<TToken>(targetNodeName, buildAction);

void IControlFlow.AddControlFlow(string targetNodeName, ControlFlowBuildAction buildAction)
=> AddControlFlow(targetNodeName, buildAction);

IForkBuilder IObjectFlow<IForkBuilder>.AddTokenFlow<TToken>(string targetNodeName, ObjectFlowBuildAction<TToken> buildAction)
=> AddTokenFlow<TToken>(targetNodeName, buildAction) as IForkBuilder;
IForkBuilder IObjectFlow<IForkBuilder>.AddFlow<TToken>(string targetNodeName, ObjectFlowBuildAction<TToken> buildAction)
=> AddFlow<TToken>(targetNodeName, buildAction) as IForkBuilder;

IForkBuilder IControlFlow<IForkBuilder>.AddControlFlow(string targetNodeName, ControlFlowBuildAction buildAction)
=> AddControlFlow(targetNodeName, buildAction) as IForkBuilder;

IAcceptEventActionBuilder IObjectFlow<IAcceptEventActionBuilder>.AddTokenFlow<TToken>(string targetNodeName, ObjectFlowBuildAction<TToken> buildAction)
=> AddTokenFlow<TToken>(targetNodeName, buildAction) as IAcceptEventActionBuilder;
IAcceptEventActionBuilder IObjectFlow<IAcceptEventActionBuilder>.AddFlow<TToken>(string targetNodeName, ObjectFlowBuildAction<TToken> buildAction)
=> AddFlow<TToken>(targetNodeName, buildAction) as IAcceptEventActionBuilder;

IAcceptEventActionBuilder IControlFlow<IAcceptEventActionBuilder>.AddControlFlow(string targetNodeName, ControlFlowBuildAction buildAction)
=> AddControlFlow(targetNodeName, buildAction) as IAcceptEventActionBuilder;
Expand All @@ -170,7 +170,7 @@ IDecisionBuilder IDecisionFlow<IDecisionBuilder>.AddFlow(string targetNodeName,
IDecisionBuilder IElseDecisionFlow<IDecisionBuilder>.AddElseFlow(string targetNodeName, ElseControlFlowBuildAction buildAction)
=> AddElseControlFlow(targetNodeName, buildAction) as IDecisionBuilder;

IDataStoreBuilder IObjectFlow<IDataStoreBuilder>.AddTokenFlow<TToken>(string targetNodeName, ObjectFlowBuildAction<TToken> buildAction)
=> AddTokenFlow<TToken>(targetNodeName, buildAction) as IDataStoreBuilder;
IDataStoreBuilder IObjectFlow<IDataStoreBuilder>.AddFlow<TToken>(string targetNodeName, ObjectFlowBuildAction<TToken> buildAction)
=> AddFlow<TToken>(targetNodeName, buildAction) as IDataStoreBuilder;
}
}
Loading

0 comments on commit f477d2b

Please sign in to comment.