public StateDialogManager(StateContext context) { _context = context; _context.CallStorage.ReadStorage(); S <Welcome>() .Default(S <HowCanIHelp>()); QuestionRouting = EmptyState(true); S <HowCanIHelp>() .Default(QuestionRouting); S <ApologizeState>() .Default(QuestionRouting); S <RequestContext>() .YesNoEdge(S <RequestAnswer>(), AcceptAdvice.IsBasedOnContextProperty) .Edge(RequestContext.HasContextAnswerEdge, S <RequestAnswer>()) .Default(S <ApologizeState>()); S <RequestAnswer>() .IsEdge(S <AcceptAdvice>(), AcceptAdvice.CorrectAnswerProperty) .Edge(RequestAnswer.HasCorrectAnswerEdge, S <AcceptAdvice>()) .Default(S <ApologizeState>()); S <AcceptAdvice>() //when info is missing, we have to go back to advice routing .Edge(AcceptAdvice.MissingInfoEdge, S <RequestContext>()) //when advice handling is completed go to QuestionRouting .Default(QuestionRouting); QuestionRouting //we know requested question .HasMatch(_context.QuestionAnsweringModule.Triggers, S <QuestionAnswering>(), RequestAnswer.QuestionProperty) .Edge(EquivalenceQuestion.EquivalenceEdge, S <EquivalenceQuestion>()) .IsEdge(S <AcceptAdvice>(), AcceptAdvice.CorrectAnswerProperty) //question is not recognized as advice .Default(S <RequestContext>(), RequestAnswer.QuestionProperty); S <QuestionAnswering>() .TakeEdgesFrom(S <RequestAnswer>()) .Default(QuestionRouting); S <RepairAnswer>() .Edge(RepairAnswer.NoQuestionForRepair, S <HowCanIHelp>()) .Edge(RepairAnswer.AdviceAccepted, S <HowCanIHelp>()); _equivalenceQuestionState = S <EquivalenceQuestion>() .YesNoEdge(S <EquivalenceAdvice>(), EquivalenceAdvice.IsEquivalent) .Default(S <ApologizeState>()) ; S <EquivalenceAdvice>() .Edge(EquivalenceAdvice.NoEquivalency, S <RequestContext>()) .Default(S <QuestionAnswering>()); }
private StateGraphBuilder EntryState <StateImplementation>() where StateImplementation : StateBase, new() { var builder = S <StateImplementation>(); _currentState = builder; return(builder); }
private ModifiableResponse fireTrigger(Trigger trigger) { trigger.Apply(_context); _currentState = trigger.TargetNode; ConsoleServices.PrintLine(_currentState.State, ConsoleServices.OperatorColor); var response = _currentState.ExecuteState(_context); return(response); }
private StateGraphBuilder EmptyState(bool isEntryState = false) { var builder = new StateGraphBuilder(new EmptyState(), _context.Graph); if (isEntryState) { _currentState = builder; } _createdBuilders.Add(builder); return(builder); }
private StateGraphBuilder S <StateImplementation>() where StateImplementation : StateBase, new() { var key = typeof(StateImplementation); StateGraphBuilder builder; if (!_buildersIndex.TryGetValue(key, out builder)) { _buildersIndex[key] = builder = new StateGraphBuilder(new StateImplementation(), _context.Graph); _createdBuilders.Add(builder); } return(builder); }