/// <summary> /// 状態遷移する /// </summary> private void DoTransitionState(string nextStateId) { //遷移先状態を取得 FormState nextState = GetState(nextStateId); if (nextState == null) { logger.Error("遷移先状態が見つかりません。" + "class " + currState.GetType().FullName + " " + "状態パス:\"" + currState.GetCanonicalPath() + "\" から、\"" + currState.NextStateId + "\""); } //遷移元と先の状態でルート状態から共通の祖先状態の数を取得。 List <FormState> nextStateParents = nextState.GetCanonicalPathList(); List <FormState> currStateParents = currState.GetCanonicalPathList(); int commonCount = GetCommonPathCount(nextStateParents, currStateParents); //現在状態から互いに共通の祖先の状態まで、すべての親状態のStateOutの処理を実行 ExitState(currStateParents, commonCount); currState = nextState;//現在状態の書き換え //互いに共通の祖先の状態から遷移先状態まで順に降りながらStateInを実行する。 transitionInProcess = false; EnterState(nextStateParents, commonCount); }
/// <summary> /// 指定された状態パスに相当する状態のインスタンスを取得する。 /// </summary> /// <param name="statePathString"></param> /// <returns></returns> private FormState GetState(String statePathString) { FormState state = null; if (statePathString == FormState.NEXT_STATE_ID) { FormState tempState = currState; while (state == null) { //現在の状態の次の状態を取得 if (tempState.ParentState == null) { //親状態がない場合は状態遷移しない。 state = currState; } else { //親オブジェクトの中で現在状態の次の状態を取得 state = tempState.ParentState.GetChildStateByIndex(tempState.Index + 1); if (state == null) { //次の状態がない場合、親状態へ移動。 tempState = tempState.ParentState; } } } } else { statePathString += "/"; char[] chars = statePathString.ToCharArray(); int startIndex = 0; if (chars[startIndex] == '/') { state = this; startIndex++; } else { state = currState; } int length = statePathString.Length; String pathElement = ""; for (int i = startIndex; i < length; i++) { if (chars[i] == '/') { if (pathElement == "") { state = null; break; } else if (pathElement != ".") { if (pathElement == "..") { state = state.ParentState; } else { state = state.GetChildStateById(pathElement); } } pathElement = ""; if (state == null) { break; } } else { pathElement += chars[i]; } } } if (state != null) { //この時点での状態に子状態がある場合は最初の子状態を遷移先とする。 state = GetFirstState(state); logger.Debug("GetState(\"" + statePathString + "\") 遷移先: " + state.GetCanonicalPath()); } else { logger.Debug("GetState(\"" + statePathString + "\") 遷移先: null"); } return(state); }