ExplicitTransition.cs 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #region --------------- Copyright Dresser Wayne Pignone -------------
  2. /*
  3. * $Log: /Wrk/WayneLibraries/Wrk/StateEngine/ExplicitTransition.cs $
  4. *
  5. * 2 08-02-26 14:07 Mattias.larsson
  6. * Renamed TargetStateName to TargetStateFactoryName.
  7. */
  8. #endregion
  9. #region Old file header
  10. /*===============================================================================
  11. * CompositeState
  12. *
  13. * Change history
  14. * When Who Comment
  15. * ---------- ------ ------------------------------------
  16. * 2006-01-09 RMa Added comments
  17. * 2006-01-05 RMa Created
  18. *
  19. ---------------------------------------------------------------------------------*/
  20. #endregion
  21. namespace Wayne.Lib.StateEngine
  22. {
  23. /// <summary>
  24. /// The Explicit transition is a way to go around the State Transition Lookup, and directly
  25. /// decide which state to go to.
  26. /// It can be used in a small state machine application when an soft-coded state-transition
  27. /// configuration not is neccecary.
  28. /// Another usage is when doing transitions to general states like an error state. When we
  29. /// want to return from that state, we want to return to the state where it came from.
  30. ///
  31. /// </summary>
  32. /// <example>
  33. /// <code>
  34. /// Example of how to use the Explicit state as a "back" transition.
  35. ///
  36. /// class ErrorState : Wayne.Lib.StateEngine.State
  37. /// {
  38. /// string cameFromState;
  39. ///
  40. /// public override void Enter(Wayne.Lib.StateEngine.StateEntry Entry)
  41. /// {
  42. /// cameFromState = Entry.SourceTransition.Sender.Name;
  43. ///
  44. /// //Do some error handling code
  45. /// }
  46. ///
  47. /// public override void HandleEvent(Wayne.Lib.StateEngine.Event EventToHandle)
  48. /// {
  49. /// if (EventToHandle is ErrorConfirmedEvent) //The appropriate event has arrived, so we can leave the state.
  50. /// {
  51. /// PostTransition(new Wayne.Lib.StateEngine.ExplicitTransition(this, Wayne.Lib.StateEngine.BasicTransitionTypes.Done, cameFromState));
  52. /// }
  53. /// }
  54. /// }
  55. /// </code>
  56. /// </example>
  57. public class ExplicitTransition : Transition
  58. {
  59. #region Fields
  60. private string targetStateFactoryName;
  61. #endregion
  62. /// <summary>
  63. /// Constructor for the explicit transaction
  64. /// </summary>
  65. /// <param name="sender">State object that issued the transition</param>
  66. /// <param name="transitionType">Object representing the type of the transition</param>
  67. /// <param name="targetStateFactoryName">FactoryName of the state that should be searched for and entered.</param>
  68. public ExplicitTransition(State sender, object transitionType, string targetStateFactoryName)
  69. : base(sender, transitionType)
  70. {
  71. this.targetStateFactoryName = targetStateFactoryName;
  72. }
  73. /// <summary>
  74. /// Name of the target state of the transition.
  75. /// </summary>
  76. public string TargetStateFactoryName
  77. {
  78. get { return targetStateFactoryName; }
  79. }
  80. }
  81. }