Пример #1
0
        public Tuple <Command, IAliceRequestHandler> FindOrDefault(string userMessage)
        {
            Command command = null;
            IAliceRequestHandler handler = null;

            for (int index = 0; index < AliceContext.Current.Handlers.Count; index++)
            {
                IAliceRequestHandler currentHandler = AliceContext.Current.Handlers[index];
                command = Find(userMessage, currentHandler);

                if (command != null)
                {
                    handler = currentHandler;
                    break;
                }
            }

            if (command == null)
            {
                handler = AliceContext.Current.Handlers[0];
                command = CommandFinder.GetDefault();
            }

            Tuple <Command, IAliceRequestHandler> result = new Tuple <Command, IAliceRequestHandler>(command, handler);

            return(result);
        }
Пример #2
0
        private IAliceResponse ProcessMessage(string userMessage)
        {
            userMessage = CleanupRequestMessage(userMessage);

            CommandFinder finder = new CommandFinder();
            Tuple <Command, IAliceRequestHandler> tuple;

            tuple = finder.FindOrDefault(userMessage);

            Command command = tuple.Item1;
            IAliceRequestHandler handler   = tuple.Item2;
            CommandProcessor     processor = new CommandProcessor(handler, command, userMessage);
            IAliceResponse       response  = processor.Process();

            return(response);
        }