Beispiel #1
0
        /// <returns>True if command processing is done; false otherwise.</returns>
        public bool Parse(string request, ref int start, out ICommandHandler commandHandler)
        {
            commandHandler = null;
            var pos = request.IndexOf("\r", start);

            if (pos == -1)
            {
                //_state = CommandParseState.WaitForCommand;
                _commandLine = request;
                start        = request.Length;
                return(false);
            }

            try
            {
                var commandLine = _commandLine + request.Substring(start, pos - start);
                start = pos + 1;

                var commandInfo = _commandTypeHelper.GetCommandInfo(commandLine);
                if (commandInfo == null)
                {
                    return(true);
                }

                commandHandler = _commandRegistry.GetCommand(commandInfo.CommandName);

                if (commandHandler == null)
                {
                    return(true);
                }

                return(commandHandler.HandleCommand(commandInfo));
            }
            finally
            {
                Cleanup();
            }
        }