-
Notifications
You must be signed in to change notification settings - Fork 129
Expand file tree
/
Copy pathStandardFactory.cs
More file actions
120 lines (103 loc) · 4.49 KB
/
StandardFactory.cs
File metadata and controls
120 lines (103 loc) · 4.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
//-------------------------------------------------------------------------------
// <copyright file="StandardFactory.cs" company="Appccelerate">
// Copyright (c) 2008-2019 Appccelerate
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
//-------------------------------------------------------------------------------
namespace Appccelerate.StateMachine.AsyncMachine
{
using System;
using System.Threading.Tasks;
using ActionHolders;
using Contexts;
using Events;
using GuardHolders;
using States;
/// <summary>
/// Standard implementation of the state machine factory.
/// </summary>
/// <typeparam name="TState">The type of the state.</typeparam>
/// <typeparam name="TEvent">The type of the event.</typeparam>
//// ReSharper disable ClassWithVirtualMembersNeverInherited.Global
public class StandardFactory<TState, TEvent> : IFactory<TState, TEvent>
//// ReSharper restore ClassWithVirtualMembersNeverInherited.Global
where TState : IComparable
where TEvent : IComparable
{
public virtual IActionHolder CreateActionHolder(Action action)
{
return new ArgumentLessActionHolder(action);
}
public virtual IActionHolder CreateActionHolder<T>(Action<T> action)
{
return new ArgumentActionHolder<T>(action);
}
public virtual IActionHolder CreateActionHolder<T>(Action<T> action, T parameter)
{
return new ParametrizedActionHolder<T>(action, parameter);
}
public virtual IActionHolder CreateTransitionActionHolder(Action action)
{
return new ArgumentLessActionHolder(action);
}
public virtual IActionHolder CreateTransitionActionHolder<T>(Action<T> action)
{
return new ArgumentActionHolder<T>(action);
}
public virtual IActionHolder CreateActionHolder(Func<Task> action)
{
return new ArgumentLessActionHolder(action);
}
public virtual IActionHolder CreateActionHolder<T>(Func<T, Task> action)
{
return new ArgumentActionHolder<T>(action);
}
public virtual IActionHolder CreateActionHolder<T>(Func<T, Task> action, T parameter)
{
return new ParametrizedActionHolder<T>(action, parameter);
}
public virtual IActionHolder CreateTransitionActionHolder(Func<Task> action)
{
return new ArgumentLessActionHolder(action);
}
public virtual IActionHolder CreateTransitionActionHolder<T>(Func<T, Task> action)
{
return new ArgumentActionHolder<T>(action);
}
public virtual IGuardHolder CreateGuardHolder(Func<bool> guard)
{
return new ArgumentLessGuardHolder(guard);
}
public virtual IGuardHolder CreateGuardHolder(Func<Task<bool>> guard)
{
return new ArgumentLessGuardHolder(guard);
}
public virtual IGuardHolder CreateGuardHolder<T>(Func<T, bool> guard)
{
return new ArgumentGuardHolder<T>(guard);
}
public virtual IGuardHolder CreateGuardHolder<T>(Func<T, Task<bool>> guard)
{
return new ArgumentGuardHolder<T>(guard);
}
public virtual ITransitionContext<TState, TEvent> CreateTransitionContext(IStateDefinition<TState, TEvent> state, Missable<TEvent> eventId, object? eventArgument, INotifier<TState, TEvent> notifier)
{
return new TransitionContext<TState, TEvent>(state, eventId, eventArgument, notifier);
}
public virtual StateMachineInitializer<TState, TEvent> CreateStateMachineInitializer(IStateDefinition<TState, TEvent> initialState, ITransitionContext<TState, TEvent> context)
{
return new StateMachineInitializer<TState, TEvent>(initialState, context);
}
}
}