#region --------------- Copyright Dresser Wayne Pignone -------------
/*
* $Log: /Wrk/WayneLibraries/Wrk/StateEngine/StateEntry.cs $
*
* 3 08-03-25 14:00 Mattias.larsson
* Clean-up.
*
* 2 08-02-26 14:08 Mattias.larsson
* Renamed TargetStateName to TargetStateFactoryName.
*/
#endregion
#region Old file header
/*===============================================================================
* StateEntry
*
* Change history
* When Who Comment
* ---------- ------ ------------------------------------
* 2006-07-18 RMa Renamed TargetState -> TargetStateName.
* 2005-12-05 RMa This header added.
*
---------------------------------------------------------------------------------*/
#endregion
using System;
using System.Text;
namespace Wayne.Lib.StateEngine
{
///
/// StateEntry contains information about the entry of a state.
/// It is produced by the state transition lookup. The application
/// receives it as an in parameter to the State.Enter() method.
/// What is of intrest to the application might be the sourceTransition, and the
/// attached source Event object.
///
public class StateEntry
{
#region Fields
private Transition sourceTransition;
private string targetStateFactoryName;
private HistoryType historyType;
#endregion
#region Construction
///
/// Constructor for StateEntry
///
/// The transition that resulted in the state change.
/// The new state that is entered.
/// History type that should be used when entering a composite state.
public StateEntry(Transition sourceTransition, string targetStateFactoryName, HistoryType historyType)
{
this.sourceTransition = sourceTransition;
this.targetStateFactoryName = targetStateFactoryName;
this.historyType = historyType;
}
#endregion
#region Properties
///
/// The transition that resulted in the state change.
///
public Transition SourceTransition
{
get { return sourceTransition; }
}
///
/// The new state that is entered.
///
public string TargetStateFactoryName
{
get { return targetStateFactoryName; }
}
///
/// History type that should be used when entering a composite state.
///
public HistoryType HistoryType
{
get { return historyType; }
}
#endregion
///
/// Returns state information from the State entry.
///
///
public string GetStateInformation()
{
var stringBuilder = new StringBuilder();
if (SourceTransition != null)
{
if (SourceTransition.Sender != null)
stringBuilder.Append(string.Format("Came from: {0}.", SourceTransition.Sender.FactoryName));
if (SourceTransition.SourceEvent != null)
stringBuilder.Append(string.Format("Triggered by: {0}.", SourceTransition.Sender));
ExceptionTransition exceptionTransition = SourceTransition as ExceptionTransition;
if (exceptionTransition != null)
{
stringBuilder.Append(string.Format("Exception thrown: {0}.", exceptionTransition.Exception));
}
}
return stringBuilder.ToString();
}
}
}