本文整理汇总了C#中IState.GetTransition方法的典型用法代码示例。如果您正苦于以下问题:C# IState.GetTransition方法的具体用法?C# IState.GetTransition怎么用?C# IState.GetTransition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IState
的用法示例。
在下文中一共展示了IState.GetTransition方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoTransition
/// <summary>
/// Performs a transition from the given state to the start indicated by
/// the transition defined by the state map matching the given event.
/// </summary>
/// <param name="startState">The state being transitioned from.</param>
/// <param name="eventName">The event causing the transition.</param>
/// <param name="transContext">The context of the request the transition is being
/// performed for.</param>
/// <returns>A <c>string</c> containing the name of the target of the transition.
/// This may be a page name if the resulting state is a <c>PageState</c>,
/// or an action name if the resulting state is a <c>ActionState</c></returns>
public IState DoTransition(
IState startState,
string eventName,
TransitionContext transContext)
{
IState targetState = null;
StateManager sm = StateManager.GetInstance();
string evnt = eventName;
// get the settings from config file
StatesConfigHandler.StatesConfig statesConfig =
(StatesConfigHandler.StatesConfig)ConfigurationManager.GetSection(TritonConfigurationSection.SectionName + "/" + SECTION_NAME);
do {
try {
if (statesConfig.ManagerTrace) {
TransitionSessionManager.AddEvent(transContext.Request.IP, startState.Id, evnt);
}
// get the transition for the given state and event
Transition trans = startState.GetTransition(evnt);
// if we didn't find a transition for the real event and there is
// a default event defined, try for a transition for the default event
if ((trans == null) && (statesConfig.DefaultEventName != null)) {
LogManager.GetCurrentClassLogger().Info(msg => msg(string.Format(
"No transition found for '{0}' on state {1}. Attempting default ['{2}'].", evnt, startState.Id, statesConfig.DefaultEventName)));
trans = startState.GetTransition(statesConfig.DefaultEventName);
}
// make sure we found a transition matching the given event
if (trans == null) {
// TODO: this should be a custom Exception type
throw new ApplicationException(string.Format(
"No transition found: state= {0} event= {1} [{2}]",
startState.Id, evnt, TransitionSessionManager.GetTrace(transContext)));
}
// get the State that is the destination of the tranistion
targetState = sm.GetState(trans.ToState);
if (targetState == null) {
// TODO: this should be a custom Exception type
throw new ApplicationException(string.Format(
"State not found: state= {0} [{1}]",
trans.ToState, TransitionSessionManager.GetTrace(transContext)));
}
// log the transition if logging is on
if (statesConfig.LogTrace) {
LogManager.GetCurrentClassLogger().Debug(
traceMessage => traceMessage("Transition: {0} {1} -> {2} -> {3} {4}",
startState.Id,
string.IsNullOrEmpty(startState.Name) ? "" : "[" + startState.Name + "]",
evnt,
targetState.Id,
string.IsNullOrEmpty(targetState.Name) ? "" : "[" + targetState.Name + "]"));
}
// set the current state that is being processed
transContext.SetCurrentState(targetState);
// handle the state
try {
// if there is a prerequisite on the state, recursively call DoTransition
// for the prerequisite
if (targetState.HasPrerequisite) {
for (int p = 0; p < targetState.Prerequisite.Length; p++) {
LogManager.GetCurrentClassLogger().Debug(traceMessage => traceMessage(
"Begin prerequisite {0}", targetState.Prerequisite[p].Name));
DoTransition(sm.GetState(targetState.Prerequisite[p].StartStateId), targetState.Prerequisite[p].StartEvent, transContext);
LogManager.GetCurrentClassLogger().Debug(traceMessage => traceMessage(
"End prerequisite {0}", targetState.Prerequisite[p].Name));
}
// need to reset the current state here since it will be the end state of the prerequisite otherwise
transContext.SetCurrentState(targetState);
// ?? what if ended on page state
}
evnt = targetState.Execute(transContext);
} catch (Exception ex) {
throw new ApplicationException(string.Format("Error executing state {0}.",
targetState.Id), ex);
}
// the destination state becomes the start state for the next iteration
startState = targetState;
} catch (Exception e) {
//.........这里部分代码省略.........