예제 #1
0
        private string readUtterance()
        {
            ConsoleServices.PrintPrompt();

            string utterance;

            if (_simulatedUtterances.Count > 0)
            {
                utterance = _simulatedUtterances.Dequeue();
                ConsoleServices.PrintLine(utterance, ConsoleServices.ActiveColor);
            }
            else
            {
                utterance = ConsoleServices.ReadLine(ConsoleServices.ActiveColor);
            }

            return(utterance);
        }
예제 #2
0
        /// <summary>
        /// Run dialog service (is blocking)
        /// </summary>
        public void Run(bool useDirectInput = false)
        {
            if (_inputManager != null)
            {
                var initializationResponse = _inputManager.Initialize();
                ConsoleServices.PrintOutput(initializationResponse);
            }

            for (; ;)
            {
                var utterance = readUtterance();

                ResponseBase response;
                if (_manager == null)
                {
                    var parsedSentence = Dialog.UtteranceParser.Parse(utterance);
                    response = _inputManager.Input(parsedSentence);
                }
                else
                {
                    var parsedUtterance = parseUtterance(utterance);
                    if (parsedUtterance == null)
                    {
                        return;
                    }

                    if (useDirectInput)
                    {
                        response = _manager.Ask(utterance);
                    }
                    else
                    {
                        response = parsedUtterance.HandleManager(_manager);
                    }
                }
                ConsoleServices.PrintOutput(response);
            }
        }