-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathPrototypedBehaviour.cs
61 lines (55 loc) · 2.24 KB
/
PrototypedBehaviour.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
using System.Collections.Generic;
using System.Linq;
namespace Inversion.Process.Behaviour {
/// <summary>
/// A behaviour that can be configured with a prototype specification
/// of selection criteria used to drive the behaviours condition.
/// </summary>
public abstract class PrototypedBehaviour: ProcessBehaviour, IPrototypedBehaviour {
private readonly IPrototype _prototype;
/// <summary>
/// Provides access to a prototype specification.
/// </summary>
public IPrototype Prototype {
get { return _prototype; }
}
/// <summary>
/// Provices access to component configuration stuiable for querying.
/// </summary>
public IConfiguration Configuration {
get { return _prototype; }
}
/// <summary>
/// Creates a new instance of the behaviour.
/// </summary>
/// <param name="respondsTo">The message the behaviour responds to.</param>
protected PrototypedBehaviour(string respondsTo) : this(respondsTo, new Prototype()) {}
/// <summary>
/// Creates a new instance of the behaviour.
/// </summary>
/// <param name="respondsTo">The message the behaviour responds to.</param>
/// <param name="prototype">The prototype to use in configuring this behaviour.</param>
protected PrototypedBehaviour(string respondsTo, IPrototype prototype): base(respondsTo) {
_prototype = prototype;
}
/// <summary>
/// Creates a new instance of the behaviour.
/// </summary>
/// <param name="respondsTo">The message the behaviour responds to.</param>
/// <param name="config">The configuration elements to use in configuring this behaviour.</param>
protected PrototypedBehaviour(string respondsTo, IEnumerable<IConfigurationElement> config): base(respondsTo) {
_prototype = new Prototype(config);
}
/// <summary>
/// Determines if each of the behaviours selection criteria match.
/// </summary>
/// <param name="ev">The event to consult.</param>
/// <param name="context">The context to consult.</param>
/// <returns>
/// Returns true if the selection criteria for this behaviour each return true.
/// </returns>
public override bool Condition(IEvent ev, IProcessContext context) {
return base.Condition(ev, context) && this.Prototype.Criteria.All(criteria => criteria(this.Configuration, ev));
}
}
}