Пример #1
0
        public static void PrepareForCall(this HierarchicalVariableScope scope, ICommandSpecification command, RoomieCommandInterpreter interpreter)
        {
            var givenValues      = scope.Local.FindGivenValues();
            var missingArguments = scope.FindMissingArguments(command.Arguments);

            if (missingArguments.Length > 0)
            {
                throw new MissingArgumentsException(missingArguments);
            }

            var defaultedValues = scope.ApplyDefaults(command.Arguments);

            if (interpreter.Engine.PrintCommandCalls)
            {
                var call = BuilCommandCall(command.Group + "." + command.Name, givenValues, defaultedValues);
                interpreter.WriteEvent(call);
            }

            var mistypedArguments = scope.FindMistypedArguments(command.Arguments);

            if (mistypedArguments.Any())
            {
                foreach (var argument in mistypedArguments)
                {
                    interpreter.WriteEvent(argument.Type.ValidationMessage(argument.Name));
                }

                throw new MistypedArgumentException(mistypedArguments);
            }
        }
Пример #2
0
        internal RoomieCommandInterpreter(RoomieThread parentThread, HierarchicalVariableScope parentScope)
        {
            ParentThread = parentThread;
            Scope        = parentScope.CreateLowerScope();

            CommandQueue = new ScriptCommandList();
            IsBusy       = false;
        }
Пример #3
0
 public RoomieThread(RoomieEngine engine, string name, HierarchicalVariableScope parentScope)
 {
     Engine       = engine;
     Id           = Guid.NewGuid().ToString();
     Name         = name;
     _interpreter = new RoomieCommandInterpreter(this, parentScope ?? Engine.GlobalScope);
     _workQueue   = new ParallelWorkQueue();
 }
Пример #4
0
        internal RoomieCommandInterpreter(RoomieThread parentThread, HierarchicalVariableScope parentScope)
        {
            ParentThread = parentThread;
            Scope = parentScope.CreateLowerScope();

            CommandQueue = new ScriptCommandList();
            IsBusy = false;
        }
Пример #5
0
 public RoomieThread(RoomieEngine engine, string name, HierarchicalVariableScope parentScope)
 {
     Engine = engine;
     Id = Guid.NewGuid().ToString();
     Name = name;
     _interpreter = new RoomieCommandInterpreter(this, parentScope ?? Engine.GlobalScope);
     _workQueue = new ParallelWorkQueue();
 }
Пример #6
0
 public RoomieEngine()
 {
     _engineState = EngineState.New;
     GlobalScope = new HierarchicalVariableScope();
     DataStore = new DataStore();
     StreamStore = new SafeWritingStreamStore(new BasicStreamStore());
     ThreadPools = new List<ThreadPool>();
     Threads = CreateThreadPool("Root Threads");
     CommandLibrary = new RoomieCommandLibrary();
     CommandLibrary.Message += CommandLibrary_Message;
     PrintCommandCalls = false;
     DevelopmentEnvironment = Environment.CurrentDirectory.EndsWith(@"\bin\Debug");
     ArgumentTypes = new ArgumentTypeCollection();
 }
Пример #7
0
 public RoomieEngine()
 {
     _engineState            = EngineState.New;
     GlobalScope             = new HierarchicalVariableScope();
     DataStore               = new DataStore();
     StreamStore             = new SafeWritingStreamStore(new BasicStreamStore());
     ThreadPools             = new List <ThreadPool>();
     Threads                 = CreateThreadPool("Root Threads");
     CommandLibrary          = new RoomieCommandLibrary();
     CommandLibrary.Message += CommandLibrary_Message;
     PrintCommandCalls       = false;
     DevelopmentEnvironment  = Environment.CurrentDirectory.EndsWith(@"\bin\Debug");
     ArgumentTypes           = new ArgumentTypeCollection();
 }
Пример #8
0
        public static RoomieCommandArgument[] FindMissingArguments(this HierarchicalVariableScope scope, IEnumerable <RoomieCommandArgument> arguments)
        {
            var result = new List <RoomieCommandArgument>();

            foreach (var argument in arguments)
            {
                if (!argument.HasDefault & !scope.Local.ContainsVariable(argument.Name))
                {
                    result.Add(argument);
                }
            }

            return(result.ToArray());
        }
Пример #9
0
        public RoomieThread CreateNewThread(string name = null, HierarchicalVariableScope parentScope = null)
        {
            lock (_threads)
            {
                if (name == null)
                {
                    name = _name + " thread " + (_threads.Count + 1);
                }

                var result = new RoomieThread(_engine, name, parentScope);

                _threads.Add(result);

                return(result);
            }
        }
Пример #10
0
        public static KeyValuePair <string, string>[] ApplyDefaults(this HierarchicalVariableScope scope, IEnumerable <RoomieCommandArgument> arguments)
        {
            var result = new List <KeyValuePair <string, string> >();

            foreach (var argument in arguments)
            {
                if (!scope.Local.ContainsVariable(argument.Name))
                {
                    scope.Local.DeclareVariable(argument.Name, argument.DefaultValue);

                    result.Add(new KeyValuePair <string, string>(argument.Name, argument.DefaultValue));
                }
            }

            return(result.ToArray());
        }
Пример #11
0
        public static RoomieCommandArgument[] FindMistypedArguments(this HierarchicalVariableScope scope, IEnumerable <RoomieCommandArgument> arguments)
        {
            var result = new List <RoomieCommandArgument>();

            foreach (var argument in arguments)
            {
                var variable = scope.GetVariable(argument.Name);
                var value    = variable.Interpolate(scope);
                var type     = argument.Type;
                var isValid  = type.Validate(value);

                if (!isValid)
                {
                    result.Add(argument);
                }
            }

            return(result.ToArray());
        }
Пример #12
0
        public static ReadOnlyParameter Interpolate(this VariableParameter givenVariable, HierarchicalVariableScope scope)
        {
            var builder = new StringBuilder(givenVariable.Value);

            List<string> variables;
            do
            {
                variables = VariablesInString(builder.ToString()).ToList();
                foreach (string variable in variables)
                {
                    var variableName = variable.Replace("${", "").Replace("}", "");
                    string replacement;
                    if (variableName != givenVariable.Name)
                    {
                        var matchedVariable = scope.GetVariable(variableName);

                        replacement = matchedVariable.Interpolate(scope).Value;
                    }
                    else if (scope.Parent != null)
                    {
                        var parentScope = scope.Parent;
                        var matchedVariable = parentScope.GetVariable(variableName);

                        replacement = matchedVariable.Interpolate(parentScope).Value;
                    }
                    else
                    {
                        replacement = null;
                    }

                    if (replacement == null)
                    {
                        //TODO: make this an explicit exception type
                        throw new VariableException("Variable \"" + variable + "\" not defined");
                    }
                    builder.Replace(variable, replacement);//TODO
                }
            } while (variables.Count != 0);

            return new ReadOnlyParameter(givenVariable.Name, builder.ToString());
        }
Пример #13
0
 public HierarchicalVariableScope(HierarchicalVariableScope parent = null)
 {
     Parent = parent;
     Local  = new LocalVariableScope();
 }
Пример #14
0
        public static ReadOnlyParameter Interpolate(this VariableParameter givenVariable, HierarchicalVariableScope scope)
        {
            var builder = new StringBuilder(givenVariable.Value);

            List <string> variables;

            do
            {
                variables = VariablesInString(builder.ToString()).ToList();
                foreach (string variable in variables)
                {
                    var    variableName = variable.Replace("${", "").Replace("}", "");
                    string replacement;
                    if (variableName != givenVariable.Name)
                    {
                        var matchedVariable = scope.GetVariable(variableName);

                        replacement = matchedVariable.Interpolate(scope).Value;
                    }
                    else if (scope.Parent != null)
                    {
                        var parentScope     = scope.Parent;
                        var matchedVariable = parentScope.GetVariable(variableName);

                        replacement = matchedVariable.Interpolate(parentScope).Value;
                    }
                    else
                    {
                        replacement = null;
                    }

                    if (replacement == null)
                    {
                        //TODO: make this an explicit exception type
                        throw new VariableException("Variable \"" + variable + "\" not defined");
                    }
                    builder.Replace(variable, replacement);//TODO
                }
            } while (variables.Count != 0);

            return(new ReadOnlyParameter(givenVariable.Name, builder.ToString()));
        }
Пример #15
0
 public HierarchicalVariableScope(HierarchicalVariableScope parent = null)
 {
     Parent = parent;
     Local = new LocalVariableScope();
 }
Пример #16
0
 internal RoomieCommandContext(RoomieCommandInterpreter interpreter, HierarchicalVariableScope scope, IScriptCommand originalCommand)
 {
     Interpreter = interpreter;
     Scope = scope;
     OriginalCommand = originalCommand;
 }
Пример #17
0
 internal RoomieCommandContext(RoomieCommandInterpreter interpreter, HierarchicalVariableScope scope, IScriptCommand originalCommand)
 {
     Interpreter     = interpreter;
     Scope           = scope;
     OriginalCommand = originalCommand;
 }