Пример #1
0
        internal RoomieCommandInterpreter(RoomieThread parentThread, HierarchicalVariableScope parentScope)
        {
            ParentThread = parentThread;
            Scope        = parentScope.CreateLowerScope();

            CommandQueue = new ScriptCommandList();
            IsBusy       = false;
        }
Пример #2
0
        internal RoomieCommandInterpreter(RoomieThread parentThread, HierarchicalVariableScope parentScope)
        {
            ParentThread = parentThread;
            Scope = parentScope.CreateLowerScope();

            CommandQueue = new ScriptCommandList();
            IsBusy = false;
        }
Пример #3
0
        private bool ExecuteCommand(IScriptCommand languageCommand)
        {
            //TODO: move this check's logic into IScriptCommand
            if (languageCommand.FullName.Equals("RoomieScript"))
            {
                //TODO: just make a "RoomieScript" command?
                CommandQueue.AddBeginning(languageCommand.InnerCommands);
                return(true);
            }


            RoomieCommand command;

            try
            {
                command = ChooseCommand(languageCommand.FullName);
            }
            catch (CommandNotFoundException e)
            {
                WriteEvent(e.Message);
                CommandQueue.Clear();
                return(false);
            }


            // create a lower scope and populate it with the command arguments
            var commandScope = Scope.CreateLowerScope();

            foreach (var parameter in languageCommand.Parameters)
            {
                commandScope.Local.DeclareVariable(parameter.Name, parameter.Value);
            }

            try
            {
                var context = new RoomieCommandContext
                              (
                    interpreter: this,
                    scope: commandScope,
                    originalCommand: languageCommand
                              );
                command.Execute(context);
            }
            catch (RoomieRuntimeException e)
            {
                WriteEvent(e.Message);
                CommandQueue.Clear();
                return(false);
            }
            catch (NotImplementedException)
            {
                WriteEvent("Command \"" + command.FullName + "\" not implemented.");
                CommandQueue.Clear();
                return(false);
            }
            catch (ThreadAbortException e4)
            {
                WriteEvent("Thread shut down.");
                CommandQueue.Clear();
                return(false);
            }
            catch (Exception e2)
            {
                WriteEvent("REALLY unexpected error!");
                WriteEvent(e2.ToString());
                CommandQueue.Clear();
                return(false);
            }

            return(true);
        }