private async Task <ICommand> GetCommandAsync(CancellationToken token) { string line = await Connection.ReadLineAsync(Encoding.UTF8, token); if (line.Length < 4) { await SendReplyAsync(ReplyCode.SyntaxError, "No command found", token); return(null); } int spaceIndex = line.IndexOf(" ", StringComparison.Ordinal); string command; string arguments; if (spaceIndex == -1) { command = line; arguments = null; } else { command = line.Substring(0, spaceIndex); arguments = line.Substring(spaceIndex + 1); } ICommandFactory commandFactory = ImplementationFactory.Get(command); if (commandFactory == null) { await SendReplyAsync(ReplyCode.SyntaxError, "Command not implemented", token); return(null); } return(commandFactory.CreateCommand(arguments)); }