private static void Main(string[] args) { Console.Title = "Platform Racing 3 Server"; try { XmlConfigurator.Configure(LogManager.GetRepository(Assembly.GetEntryAssembly()), new FileInfo("log4net.config")); //Setup log4net logging } catch (Exception ex) { Console.WriteLine($"Failed to setup logging! {ex.ToString()}"); } Program.Logger.Info("Starting up server..."); Program.Instance.Init(); Program.Logger.Info("Server is ready!"); ConsoleCommandExecutor consoleExecutor = new ConsoleCommandExecutor(); while (true) { string line = Console.ReadLine(); string[] commmandArgs = line.Split(' '); if (!PlatformRacing3Server.CommandManager.Execte(consoleExecutor, commmandArgs[0], commmandArgs.AsSpan().Slice(1, commmandArgs.Length - 1))) { Console.WriteLine($"Unknown command!"); } } }
private static void RunWithArgString(ConsoleCommandExecutor executor, string args) { Console.WriteLine("----------------------------------------------------------"); Console.WriteLine("Running with args: " + args); var argArray = args == null ? new string[0] : args.Split(); executor.Execute(argArray); }
void ExecuteCommands() { var executor = new ConsoleCommandExecutor( ServiceLocator.GetService <IEnumerable <ICommandLocator> >(), ServiceLocator.GetService <IEventHub>(), ServiceLocator.GetService <ICommandOutputFormatter>()); foreach (var command in _commands) { executor.Execute(command, Enumerable.Empty <string>()); } }
private static ConsoleCommandExecutor GetConsoleExecutor() { var executor = new ConsoleCommandExecutor(); executor.RegisterEmptyCommand((args) => Console.WriteLine("No args!")); executor.RegisterCommand("help-default", new HelpCommand(executor)); var customHelp = new CustomHelp(executor); executor.RegisterCommand("help-custom", customHelp); executor.RegisterCommand("help", customHelp); executor.RegisterCommand("hello", new HelloWorldCommand()); return(executor); }
public CustomHelp(ConsoleCommandExecutor executor) : base(executor) { }