123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- #region --------------- Copyright Dresser Wayne Pignone -------------
- /*
- * $Log: /Wrk/WayneLibraries/Wrk/StateEngine/StateEntry.cs $
- *
- * 3 08-03-25 14:00 Mattias.larsson
- * Clean-up.
- *
- * 2 08-02-26 14:08 Mattias.larsson
- * Renamed TargetStateName to TargetStateFactoryName.
- */
- #endregion
- #region Old file header
- /*===============================================================================
- * StateEntry
- *
- * Change history
- * When Who Comment
- * ---------- ------ ------------------------------------
- * 2006-07-18 RMa Renamed TargetState -> TargetStateName.
- * 2005-12-05 RMa This header added.
- *
- ---------------------------------------------------------------------------------*/
- #endregion
- using System;
- using System.Text;
- namespace Wayne.Lib.StateEngine
- {
- /// <summary>
- /// StateEntry contains information about the entry of a state.
- /// It is produced by the state transition lookup. The application
- /// receives it as an in parameter to the State.Enter() method.
- /// What is of intrest to the application might be the sourceTransition, and the
- /// attached source Event object.
- /// </summary>
- public class StateEntry
- {
- #region Fields
- private Transition sourceTransition;
- private string targetStateFactoryName;
- private HistoryType historyType;
- #endregion
- #region Construction
- /// <summary>
- /// Constructor for StateEntry
- /// </summary>
- /// <param name="sourceTransition">The transition that resulted in the state change.</param>
- /// <param name="targetStateFactoryName">The new state that is entered.</param>
- /// <param name="historyType">History type that should be used when entering a composite state.</param>
- public StateEntry(Transition sourceTransition, string targetStateFactoryName, HistoryType historyType)
- {
- this.sourceTransition = sourceTransition;
- this.targetStateFactoryName = targetStateFactoryName;
- this.historyType = historyType;
- }
- #endregion
- #region Properties
- /// <summary>
- /// The transition that resulted in the state change.
- /// </summary>
- public Transition SourceTransition
- {
- get { return sourceTransition; }
- }
- /// <summary>
- /// The new state that is entered.
- /// </summary>
- public string TargetStateFactoryName
- {
- get { return targetStateFactoryName; }
- }
- /// <summary>
- /// History type that should be used when entering a composite state.
- /// </summary>
- public HistoryType HistoryType
- {
- get { return historyType; }
- }
- #endregion
- /// <summary>
- /// Returns state information from the State entry.
- /// </summary>
- /// <returns></returns>
- public string GetStateInformation()
- {
- var stringBuilder = new StringBuilder();
- if (SourceTransition != null)
- {
- if (SourceTransition.Sender != null)
- stringBuilder.Append(string.Format("Came from: {0}.", SourceTransition.Sender.FactoryName));
- if (SourceTransition.SourceEvent != null)
- stringBuilder.Append(string.Format("Triggered by: {0}.", SourceTransition.Sender));
- ExceptionTransition exceptionTransition = SourceTransition as ExceptionTransition;
- if (exceptionTransition != null)
- {
- stringBuilder.Append(string.Format("Exception thrown: {0}.", exceptionTransition.Exception));
- }
- }
- return stringBuilder.ToString();
- }
- }
- }
|