ExplicitTransition.cs 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. using System;
  22. using System.Collections.Generic;
  23. using System.Text;
  24. namespace Wayne.Lib.StateEngine
  25. {
  26. /// <summary>
  27. /// The Explicit transition is a way to go around the State Transition Lookup, and directly
  28. /// decide which state to go to.
  29. /// It can be used in a small state machine application when an soft-coded state-transition
  30. /// configuration not is neccecary.
  31. /// Another usage is when doing transitions to general states like an error state. When we
  32. /// want to return from that state, we want to return to the state where it came from.
  33. ///
  34. /// </summary>
  35. /// <example>
  36. /// <code>
  37. /// Example of how to use the Explicit state as a "back" transition.
  38. ///
  39. /// class ErrorState : Wayne.Lib.StateEngine.State
  40. /// {
  41. /// string cameFromState;
  42. ///
  43. /// public override void Enter(Wayne.Lib.StateEngine.StateEntry Entry)
  44. /// {
  45. /// cameFromState = Entry.SourceTransition.Sender.Name;
  46. ///
  47. /// //Do some error handling code
  48. /// }
  49. ///
  50. /// public override void HandleEvent(Wayne.Lib.StateEngine.Event EventToHandle)
  51. /// {
  52. /// if (EventToHandle is ErrorConfirmedEvent) //The appropriate event has arrived, so we can leave the state.
  53. /// {
  54. /// PostTransition(new Wayne.Lib.StateEngine.ExplicitTransition(this, Wayne.Lib.StateEngine.BasicTransitionTypes.Done, cameFromState));
  55. /// }
  56. /// }
  57. /// }
  58. /// </code>
  59. /// </example>
  60. public class ExplicitTransition : Transition
  61. {
  62. #region Fields
  63. private string targetStateFactoryName;
  64. #endregion
  65. /// <summary>
  66. /// Constructor for the explicit transaction
  67. /// </summary>
  68. /// <param name="sender">State object that issued the transition</param>
  69. /// <param name="transitionType">Object representing the type of the transition</param>
  70. /// <param name="targetStateFactoryName">FactoryName of the state that should be searched for and entered.</param>
  71. public ExplicitTransition(State sender, object transitionType, string targetStateFactoryName)
  72. : base(sender, transitionType)
  73. {
  74. this.targetStateFactoryName = targetStateFactoryName;
  75. }
  76. /// <summary>
  77. /// Name of the target state of the transition.
  78. /// </summary>
  79. public string TargetStateFactoryName
  80. {
  81. get { return targetStateFactoryName; }
  82. }
  83. }
  84. }