StateEntry.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #region --------------- Copyright Dresser Wayne Pignone -------------
  2. /*
  3. * $Log: /Wrk/WayneLibraries/Wrk/StateEngine/StateEntry.cs $
  4. *
  5. * 3 08-03-25 14:00 Mattias.larsson
  6. * Clean-up.
  7. *
  8. * 2 08-02-26 14:08 Mattias.larsson
  9. * Renamed TargetStateName to TargetStateFactoryName.
  10. */
  11. #endregion
  12. #region Old file header
  13. /*===============================================================================
  14. * StateEntry
  15. *
  16. * Change history
  17. * When Who Comment
  18. * ---------- ------ ------------------------------------
  19. * 2006-07-18 RMa Renamed TargetState -> TargetStateName.
  20. * 2005-12-05 RMa This header added.
  21. *
  22. ---------------------------------------------------------------------------------*/
  23. #endregion
  24. using System.Text;
  25. namespace Wayne.Lib.StateEngine
  26. {
  27. /// <summary>
  28. /// StateEntry contains information about the entry of a state.
  29. /// It is produced by the state transition lookup. The application
  30. /// receives it as an in parameter to the State.Enter() method.
  31. /// What is of intrest to the application might be the sourceTransition, and the
  32. /// attached source Event object.
  33. /// </summary>
  34. public class StateEntry
  35. {
  36. #region Fields
  37. private Transition sourceTransition;
  38. private string targetStateFactoryName;
  39. private HistoryType historyType;
  40. #endregion
  41. #region Construction
  42. /// <summary>
  43. /// Constructor for StateEntry
  44. /// </summary>
  45. /// <param name="sourceTransition">The transition that resulted in the state change.</param>
  46. /// <param name="targetStateFactoryName">The new state that is entered.</param>
  47. /// <param name="historyType">History type that should be used when entering a composite state.</param>
  48. public StateEntry(Transition sourceTransition, string targetStateFactoryName, HistoryType historyType)
  49. {
  50. this.sourceTransition = sourceTransition;
  51. this.targetStateFactoryName = targetStateFactoryName;
  52. this.historyType = historyType;
  53. }
  54. #endregion
  55. #region Properties
  56. /// <summary>
  57. /// The transition that resulted in the state change.
  58. /// </summary>
  59. public Transition SourceTransition
  60. {
  61. get { return sourceTransition; }
  62. }
  63. /// <summary>
  64. /// The new state that is entered.
  65. /// </summary>
  66. public string TargetStateFactoryName
  67. {
  68. get { return targetStateFactoryName; }
  69. }
  70. /// <summary>
  71. /// History type that should be used when entering a composite state.
  72. /// </summary>
  73. public HistoryType HistoryType
  74. {
  75. get { return historyType; }
  76. }
  77. #endregion
  78. /// <summary>
  79. /// Returns state information from the State entry.
  80. /// </summary>
  81. /// <returns></returns>
  82. public string GetStateInformation()
  83. {
  84. var stringBuilder = new StringBuilder();
  85. if (SourceTransition != null)
  86. {
  87. if (SourceTransition.Sender != null)
  88. stringBuilder.Append(string.Format("Came from: {0}.", SourceTransition.Sender.FactoryName));
  89. if (SourceTransition.SourceEvent != null)
  90. stringBuilder.Append(string.Format("Triggered by: {0}.", SourceTransition.Sender));
  91. ExceptionTransition exceptionTransition = SourceTransition as ExceptionTransition;
  92. if (exceptionTransition != null)
  93. {
  94. stringBuilder.Append(string.Format("Exception thrown: {0}.", exceptionTransition.Exception));
  95. }
  96. }
  97. return stringBuilder.ToString();
  98. }
  99. }
  100. }