#region --------------- Copyright Dresser Wayne Pignone -------------
/*
* $Log: /Wrk/WayneLibraries/Wrk/StateEngine/Transition.cs $
*
* 4 08-02-26 14:11 Mattias.larsson
* Removed Obsolete method.
*/
#endregion
#region Old file header
/*===============================================================================
* Transition
*
* Change history
* When Who Comment
* ---------- ------ ------------------------------------
* 2006-02-03 RMa FXCop updates: BasicTransitionType renamed to BasicTransitionTypes.
* 2006-01-27 RMa Removed interface Event. Use Event class instead.
* 2005-06-05 RMa Added Basic transition type 'Error'.
* 2005-12-09 RMa Added static method GetTransitionName for internal use.
* 2005-12-05 RMa This header added.
*
---------------------------------------------------------------------------------*/
#endregion
using System;
namespace Wayne.Lib.StateEngine
{
///
/// The transition class is used by state objects to signal that a change has occured.
/// The transition is interpreted by the statemachine's State-transition lookup table. it
/// determines which the next state should be.
///
/// The transition type identifies the transition and is supplied by the application. It is recommended
/// that enums are used as transition types, but any type can be used.
///
public class Transition
{
#region Fields
private State sender;
private StateEngineEvent sourceEvent;
private object type;
#endregion
#region Properties
///
/// Type of the transistion.
///
public object Type
{
get
{
return type;
}
set
{
type = value;
}
}
///
/// Represents the type name. It returns the Type.ToString(). This is
/// used by the statemachine to find the transition in the lookup table.
///
public string Name
{
get
{
return GetTransitionName(this.type);
}
}
///
/// The state that issued the transition.
///
public State Sender
{
get
{
return sender;
}
}
///
/// If the transition is generated when a state has received an event, it can be
/// supplied in this property.
///
public StateEngineEvent SourceEvent
{
get
{
return sourceEvent;
}
}
///
/// Internal writable source event. Assigned statemachine connects the event to the transition.
///
internal StateEngineEvent WritableSourceEvent
{
get { return sourceEvent; }
set { sourceEvent = value; }
}
#endregion
#region Construction
///
/// Transition constructor. assumes that the Source Event is null.
///
/// State that issued the transition
/// Type of the transition
public Transition(State sender, object type)
{
this.sender = sender;
this.type = type;
}
#endregion
#region Static Methods
///
/// Returns the name of the transition to use when persisting configuration etc.
///
///
///
public static string GetTransitionName(object transitionType)
{
if (transitionType == null)
return "-";
else if (transitionType is Enum)
return transitionType.GetType().FullName + "." + transitionType.ToString();
else if (transitionType.GetType() == typeof(string))
return transitionType.ToString();
else
return transitionType.GetType().FullName;
}
#endregion
}
}