Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
156 lines (138 sloc) 5.65 KB
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);
}
}