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;
  25. using System.Text;
  26. namespace Wayne.Lib.StateEngine
  27. {
  28. /// <summary>
  29. /// StateEntry contains information about the entry of a state.
  30. /// It is produced by the state transition lookup. The application
  31. /// receives it as an in parameter to the State.Enter() method.
  32. /// What is of intrest to the application might be the sourceTransition, and the
  33. /// attached source Event object.
  34. /// </summary>
  35. public class StateEntry
  36. {
  37. #region Fields
  38. private Transition sourceTransition;
  39. private string targetStateFactoryName;
  40. private HistoryType historyType;
  41. #endregion
  42. #region Construction
  43. /// <summary>
  44. /// Constructor for StateEntry
  45. /// </summary>
  46. /// <param name="sourceTransition">The transition that resulted in the state change.</param>
  47. /// <param name="targetStateFactoryName">The new state that is entered.</param>
  48. /// <param name="historyType">History type that should be used when entering a composite state.</param>
  49. public StateEntry(Transition sourceTransition, string targetStateFactoryName, HistoryType historyType)
  50. {
  51. this.sourceTransition = sourceTransition;
  52. this.targetStateFactoryName = targetStateFactoryName;
  53. this.historyType = historyType;
  54. }
  55. #endregion
  56. #region Properties
  57. /// <summary>
  58. /// The transition that resulted in the state change.
  59. /// </summary>
  60. public Transition SourceTransition
  61. {
  62. get { return sourceTransition; }
  63. }
  64. /// <summary>
  65. /// The new state that is entered.
  66. /// </summary>
  67. public string TargetStateFactoryName
  68. {
  69. get { return targetStateFactoryName; }
  70. }
  71. /// <summary>
  72. /// History type that should be used when entering a composite state.
  73. /// </summary>
  74. public HistoryType HistoryType
  75. {
  76. get { return historyType; }
  77. }
  78. #endregion
  79. /// <summary>
  80. /// Returns state information from the State entry.
  81. /// </summary>
  82. /// <returns></returns>
  83. public string GetStateInformation()
  84. {
  85. var stringBuilder = new StringBuilder();
  86. if (SourceTransition != null)
  87. {
  88. if (SourceTransition.Sender != null)
  89. stringBuilder.Append(string.Format("Came from: {0}.", SourceTransition.Sender.FactoryName));
  90. if (SourceTransition.SourceEvent != null)
  91. stringBuilder.Append(string.Format("Triggered by: {0}.", SourceTransition.Sender));
  92. ExceptionTransition exceptionTransition = SourceTransition as ExceptionTransition;
  93. if (exceptionTransition != null)
  94. {
  95. stringBuilder.Append(string.Format("Exception thrown: {0}.", exceptionTransition.Exception));
  96. }
  97. }
  98. return stringBuilder.ToString();
  99. }
  100. }
  101. }