示例#1
0
        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>());
        }
示例#2
0
        private StateGraphBuilder EntryState <StateImplementation>()
            where StateImplementation : StateBase, new()
        {
            var builder = S <StateImplementation>();

            _currentState = builder;

            return(builder);
        }
示例#3
0
        private ModifiableResponse fireTrigger(Trigger trigger)
        {
            trigger.Apply(_context);

            _currentState = trigger.TargetNode;
            ConsoleServices.PrintLine(_currentState.State, ConsoleServices.OperatorColor);
            var response = _currentState.ExecuteState(_context);

            return(response);
        }
示例#4
0
        private StateGraphBuilder EmptyState(bool isEntryState = false)
        {
            var builder = new StateGraphBuilder(new EmptyState(), _context.Graph);

            if (isEntryState)
            {
                _currentState = builder;
            }
            _createdBuilders.Add(builder);

            return(builder);
        }
示例#5
0
        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);
        }