-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathIProcessContext.cs
156 lines (138 loc) · 5.65 KB
/
IProcessContext.cs
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
using System;
using System.Collections.Generic;
using System.Runtime.Caching;
using Inversion.Collections;
using Inversion.Data;
using Inversion.Process.Behaviour;
namespace Inversion.Process {
/// <summary>
/// Provides a processing context as a self-contained and sufficient
/// channel of application execution. The context manages a set of
/// behaviours and mediates between them and the outside world.
/// </summary>
/// <remarks>
/// The process context along with the `IBehaviour` objects registered
/// on its bus *are* Inversion. Everything else is chosen convention about
/// how those behaviours interact with each other via the context.
/// </remarks>
public interface IProcessContext : IDisposable {
/// <summary>
/// Exposes the processes service container.
/// </summary>
IServiceContainer Services { get; }
/// <summary>
/// Exposes resources available to the context.
/// </summary>
IResourceAdapter Resources { get; }
/// <summary>
/// Provsion of a simple object cache for the context.
/// </summary>
/// <remarks>
/// This really needs replaced with our own interface
/// that we control. This isn't portable.
/// </remarks>
ObjectCache ObjectCache { get; }
/// <summary>
/// Messages intended for user feedback.
/// </summary>
/// <remarks>
/// This is a poor mechanism for localisation,
/// and may need to be treated as tokens
/// by the front end to localise.
/// </remarks>
IDataCollection<string> Messages { get; }
/// <summary>
/// Error messages intended for user feedback.
/// </summary>
/// <remarks>
/// This is a poor mechanism for localisation,
/// and may need to be treated as tokens
/// by the front end to localise.
/// </remarks>
IDataCollection<ErrorMessage> Errors { get; }
/// <summary>
/// A dictionary of named timers.
/// </summary>
/// <remarks>
/// `ProcessTimer` is only intended
/// for informal timings, and it not intended
/// for proper metrics.
/// </remarks>
ProcessTimerDictionary Timers { get; }
/// <summary>
/// Gives access to a collection of view steps
/// that will be used to control the render
/// pipeline for this context.
/// </summary>
ViewSteps ViewSteps { get; }
/// <summary>
/// Gives access to the current control state of the context.
/// This is the common state that behaviours share and that
/// provides the end state or result of a contexts running process.
/// </summary>
IDataDictionary<object> ControlState { get; }
/// <summary>
/// Flags for the context available to behaviours as shared state.
/// </summary>
IDataCollection<string> Flags { get; }
/// <summary>
/// The parameters of the contexts execution available
/// to behaviours as shared state.
/// </summary>
IDataDictionary<string> Params { get; }
/// <summary>
/// Registers a behaviour with the context ensuring
/// it is consulted for each event fired on this context.
/// </summary>
/// <param name="behaviour">The behaviour to register with this context.</param>
void Register(IProcessBehaviour behaviour);
/// <summary>
/// Registers a whole bunch of behaviours with this context ensuring
/// each one is consulted when an event is fired on this context.
/// </summary>
/// <param name="behaviours">The behaviours to register with this context.</param>
void Register(IEnumerable<IProcessBehaviour> behaviours);
/// <summary>
/// Creates and registers a runtime behaviour with this context constructed
/// from a predicate representing the behaviours condition, and an action
/// representing the behaviours action. This behaviour will be consulted for
/// any event fired on this context.
/// </summary>
/// <param name="condition">The predicate to use as the behaviours condition.</param>
/// <param name="action">The action to use as the behaviours action.</param>
void Register(Predicate<IEvent> condition, Action<IEvent, IProcessContext> action);
/// <summary>
/// Fires an event on the context. Each behaviour registered with context
/// is consulted in no particular order, and for each behaviour that has a condition
/// that returns true when applied to the event, that behaviours action is executed.
/// </summary>
/// <param name="ev">The event to fire on this context.</param>
/// <returns></returns>
IEvent Fire(IEvent ev);
/// <summary>
/// Constructs a simple event, with a simple string message
/// and fires it on this context.
/// </summary>
/// <param name="message">The message to assign to the event.</param>
/// <returns>Returns the event that was constructed and fired on this context.</returns>
IEvent Fire(string message);
/// <summary>
/// Constructs an event using the message specified, and using the dictionary
/// provided to populate the parameters of the event. This event is then
/// fired on this context.
/// </summary>
/// <param name="message">The message to assign to the event.</param>
/// <param name="parms">The parameters to populate the event with.</param>
/// <returns>Returns the event that was constructed and fired on this context.</returns>
IEvent Fire(string message, IDictionary<string, string> parms);
/// <summary>
/// Contructs an event with the message specified, using the supplied
/// parameter keys to copy parameters from the context to the constructed event.
/// This event is then fired on this context.
/// </summary>
/// <param name="message">The message to assign to the event.</param>
/// <param name="parms">The parameters to copy from the context.</param>
/// <returns>Returns the event that was constructed and fired on this context.</returns>
IEvent FireWith(string message, params string[] parms);
}
}