public void TestInterpretation() { var svc = new GenericInterpreterService <CCEnumTypeAttribute, CCEnumBindingAttribute, CCItemBindingAttribute>(Assembly.GetAssembly(typeof(CCEnumBindingAttribute))); svc.Start(); var ret = svc.Interpret("backup world mybackup"); foreach (var item in ret) { foreach (var cmd in item.Commands) { if (ReflectionHelpers.HasInterface(cmd, typeof(ICommandExecute))) { if (ReflectionHelpers.HasInterface(cmd, typeof(INeedBotEngineInstance <BotEngine>))) { ((INeedBotEngineInstance <BotEngine>)cmd).BotEngine = null; } ICommandExecutionResult result = ((ICommandExecute)cmd).ExecuteCommand(); } } } // var ret = svc.Interpret("activate envi res=512 type=1 upd=25 time=20 aspect=0.5 zoom=0.8, @key value=mykey"); //var ret = svc.Interpret("bump lock owners=4711:1174:333333"); //var ret = svc.Interpret("create matfx type=2 coef=1 tex=self"); // var ret = svc.Interpret("activate media set vol=100 osd=on name=foo"); }
public void ProcessCommandLine(string commandLine) { var ret = _commandInterpeter.Interpret(commandLine); bool isInterpreted = false; if (ret != null) // use the object oriented commandline interpreter. { foreach (var item in ret) { foreach (var cmd in item.Commands) { if (ReflectionHelpers.HasInterface(cmd, typeof(ICommandExecute))) { if (cmd.GetType() == typeof(Help)) { // special attention to this. Help commands are interpeted through reflecting other commands } else { if (ReflectionHelpers.HasInterface(cmd, typeof(INeedBotEngineInstance <BotEngine>))) { ((INeedBotEngineInstance <BotEngine>)cmd).BotEngine = this; } try { ICommandExecutionResult result = ((ICommandExecute)cmd).ExecuteCommand(); ConsoleHelpers.WriteLine(result.DisplayMessage); } catch (Exception ex) { ConsoleHelpers.WriteLine(ConsoleColor.Red, ex.Message); } isInterpreted = true; } } } } if (isInterpreted) { ConsoleHelpers.ReadLine(); return; } } switch (commandLine.ToLower()) { case "help": string text = string.Empty; ConsoleHelpers.WriteLine(ConsoleColor.DarkYellow, "Supported Command groups. Type command group <command name> to get specific information about a command."); foreach (var item in _commandInterpeter.Cache.TriggerInterpreters) { text += item.LiteralAction.PadRight(12); } ConsoleHelpers.WriteLine(ConsoleColor.Green, text); break; case "list plugins": foreach (var type in LocalBotPluginServicesManager.PluginDiscovery) { ConsoleHelpers.WriteLine(ConsoleColor.Green, string.Format("{0} :{1}", type.PluginInfo.TechnicalName.PadRight(24), type.PluginInfo.Description)); } break; case "list services": foreach (var item in base.ServicesManager.List()) { string status; status = item.IsRunning ? "Running" : "Stopped"; ConsoleHelpers.WriteLine(ConsoleColor.Green, string.Format("{0} [{1}]", item.TechnicalName.PadRight(50), status)); } break; case "down": Environment.Exit(0); break; case "vrt time": case "vt": _isVrtPrompt = true; break; case "local time": case "lt": _isVrtPrompt = false; break; case "chat mode": case "cm": ConsoleHelpers.ParseCommandLine = ProcessChatMessage; ConsoleHelpers.GetPromptTarget = ChatPrompt; _chatType = ChatType.Normal; base.ChatEvent += new ChatEventDelegate(ChatMode_ChatEvent); break; default: var oldColor = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Red; ConsoleHelpers.WriteLine("?Syntax Error"); Console.ForegroundColor = oldColor; break; } ConsoleHelpers.ReadLine(); }