예제 #1
0
        public TextScriptCommand(string line)
        {
            if (_lineRegex == null)
            {
                _lineRegex = new Regex(LinePattern);
                _parametersRegex = new Regex(ParametersPattern);
                _parameterRegex = new Regex(ParameterPattern);
            }

            Parameters = new ScriptCommandParameters();
            InnerCommands = new ScriptCommandList();
            OriginalText = line;

            var matches = _lineRegex.Match(line);

            if (!matches.Groups["FullName"].Success)
            {
                throw new RoomieScriptSyntaxErrorException("No command name specified");
            }

            FullName = matches.Groups["FullName"].Value;

            //TODO: make this less awful
            var parametersPart = matches.Groups["Parameters"];
            if (parametersPart.Success && parametersPart.Length > 0)
            {
                foreach (var parameter in ParseParameters(parametersPart.Value))
                {
                    Parameters.Add(parameter);
                }
            }
        }
예제 #2
0
 public void RegisterSpeechRecognizedAction(ScriptCommandList commands)
 {
     lock (this)
     {
         _speechRecognizedAction = new ScriptCommandList();
         _speechRecognizedAction.Add(commands);
     }
 }
예제 #3
0
        internal RoomieCommandInterpreter(RoomieThread parentThread, HierarchicalVariableScope parentScope)
        {
            ParentThread = parentThread;
            Scope        = parentScope.CreateLowerScope();

            CommandQueue = new ScriptCommandList();
            IsBusy       = false;
        }
예제 #4
0
        internal RoomieCommandInterpreter(RoomieThread parentThread, HierarchicalVariableScope parentScope)
        {
            ParentThread = parentThread;
            Scope = parentScope.CreateLowerScope();

            CommandQueue = new ScriptCommandList();
            IsBusy = false;
        }
예제 #5
0
 public RoomieDynamicCommand(string group, string name, List<RoomieCommandArgument> arguments, ScriptCommandList subcommands, string description)
     : base(new ReadOnlyCommandSpecification(
         name: name,
         group: group,
         description: description,
         source: "(dynamic command)",
         arguments: arguments
     ))
 {
     this.subcommands = subcommands;
 }
예제 #6
0
 public RoomieDynamicCommand(string group, string name, List <RoomieCommandArgument> arguments, ScriptCommandList subcommands, string description)
     : base(new ReadOnlyCommandSpecification(
                name: name,
                group: group,
                description: description,
                source: "(dynamic command)",
                arguments: arguments
                ))
 {
     this.subcommands = subcommands;
 }
예제 #7
0
파일: Program.cs 프로젝트: Mavtak/roomie
        static void Main(string[] args)
        {
            var engine = new RoomieEngine();

            setOutput(engine);
            //engine.TerminalMessageSent += new TerminalOutputEventHandler(controller_TerminalMessageSent);
            engine.Start();

            var line     = "";
            var input    = "";
            var xmlInput = new XmlDocument();

            //TODO: improve this.  Make the while loop directly depend on the engine's internal state.
            while (!input.Contains("Core.ShutDown"))
            {
                //TODO: pull reading from a text stream into Roomie.Desktop.Engine.RoomieEngine
                line = Console.ReadLine().Trim();
                if (!String.IsNullOrEmpty(line))
                {
                    if (input.Length > 0)
                    {
                        input += "\n";
                    }
                    input += line.TrimEnd('_');
                    //TODO: read multiple lines
                    if (!line.EndsWith("_"))
                    {
                        try
                        {
                            var script = ScriptCommandList.FromText(input);
                            engine.Threads.AddCommands(script);
                            Console.WriteLine("Command accepted.");
                            input = "";
                        }
                        catch (Exception exception)
                        {
                            Console.WriteLine("Error. " + exception.Message);
                        }
                    }
                }
                else
                {
                    if (input != "")
                    {
                        input = "";
                        Console.WriteLine("Input cleared.");
                    }
                }
            }
        }
예제 #8
0
        private void Run()
        {
            running = true;
            print("Webhook reading tasks...");


            foreach (RoomieCommand command in roomieController.CommandLibrary)
            {
                if (command.Name.Equals("WebHookConnectTasks"))
                {
                    AddCommand(command.BlankCommandCall());
                }
            }

            while (true)
            {
                try
                {
                    var response = Send <Task[]>("task", new Request
                    {
                        Action     = "GetForComputer",
                        Parameters = new Dictionary <string, object>
                        {
                            { "computerName", computerName }
                        },
                    });

                    if (response.Data.Length == 0)
                    {
                        print("no tasks");
                    }
                    else
                    {
                        foreach (var task in response.Data)
                        {
                            var commands = ScriptCommandList.FromText(task.Script.Text);
                            AddCommands(commands);
                        }
                    }
                }
                catch (RoomieRuntimeException exception)
                {
                    print(exception.Message);
                    print("sleeping for 10 seconds because of error...");
                    System.Threading.Thread.Sleep(new TimeSpan(0, 0, 10));
                }
            }
        }
예제 #9
0
        private void RunInput(bool clearInput = true)
        {
            ScriptCommandList script;

            try
            {
                script = ScriptCommandList.FromText(Input.Text);
            }
            catch (RoomieScriptSyntaxErrorException exception)
            {
                MessageBox.Show(exception.Message);

                return;
            }

            if (clearInput)
            {
                Input.Clear();
            }
            _engine.Threads.AddCommands(script);
        }
예제 #10
0
 public void RegisterSpeechRecognizedAction(ScriptCommandList commands)
 {
     lock (this)
     {
         _speechRecognizedAction = new ScriptCommandList();
         _speechRecognizedAction.Add(commands);
     }
 }
예제 #11
0
 public DeviceEventAction(DeviceEventType eventType, ScriptCommandList commands)
     : this(new[] { eventType }, commands)
 {
 }
예제 #12
0
 public DeviceEventAction(IEnumerable <DeviceEventType> eventTypes, ScriptCommandList commands)
 {
     EventTypes = eventTypes.ToList();
     Commands   = commands;
 }
예제 #13
0
        public void LoadContent()
        {
            string filepath = Environment.CurrentDirectory + @"/data/ScriptContentCommands.xml";

            if (File.Exists(filepath) == false)
            {
                MessageBox.Show("Failed to find \"ScriptContentCommands.xml\"!", "Script content error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            using (Stream fs = File.OpenRead(filepath)) {
                XmlSerializer     xml      = new XmlSerializer(typeof(ScriptCommandList));
                ScriptCommandList commands = (ScriptCommandList)xml.Deserialize(fs);
                if (commands != null)
                {
                    foreach (ScriptCommand cmd in commands)
                    {
                        string newIndex = "";

                        newIndex = cmd.Name.ToLower();
                        Commands.Add(newIndex, cmd);
                        PushContentToFlatList(CommandsFlat, newIndex);

                        if (cmd.NameOptional.Length > 0)
                        {
                            newIndex = cmd.NameOptional.ToLower();
                            Commands.Add(newIndex, cmd);
                            PushContentToFlatList(CommandsFlat, newIndex);
                        }
                    }
                }
            }


            filepath = Environment.CurrentDirectory + @"/data/ScriptContentMaps.txt";
            if (File.Exists(filepath) == false)
            {
                MessageBox.Show("Failed to find \"ScriptContentMaps.xml\"!", "Script content error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            using (Stream fs = File.OpenRead(filepath)) {
                using (StreamReader reader = new StreamReader(fs)) {
                    string map = "";
                    while ((map = reader.ReadLine()) != null && map.Length > 0)
                    {
                        map = map.Trim();
                        PushContentToFlatList(Maps, map);
                    }
                }
            }



            filepath = Environment.CurrentDirectory + @"/data/ScriptContentConstants.xml";
            if (File.Exists(filepath) == false)
            {
                MessageBox.Show("Failed to find \"ScriptContentConstants.xml\"!", "Script content error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            using (Stream fs = File.OpenRead(filepath)) {
                XmlSerializer      xml       = new XmlSerializer(typeof(ScriptConstantList));
                ScriptConstantList constants = (ScriptConstantList)xml.Deserialize(fs);
                if (constants != null)
                {
                    foreach (ScriptConstant constant in constants)
                    {
                        string name = constant.Name.ToLower();

                        Constants.Add(name, constant);
                        PushContentToFlatList(ConstantsFlat, name);
                    }
                }
            }
        }
예제 #14
0
 public void RegisterPhrase(string phrase, ScriptCommandList command)
 {
     RegisteredCommands.Add(phrase, command);
     _speechRecognizer.RegisterPhrase(phrase);
 }
예제 #15
0
 public DeviceEventAction(IEnumerable<DeviceEventType> eventTypes, ScriptCommandList commands)
 {
     EventTypes = eventTypes.ToList();
     Commands = commands;
 }
예제 #16
0
 public void RegisterPhrase(string phrase, ScriptCommandList command)
 {
     RegisteredCommands.Add(phrase, command);
     _speechRecognizer.RegisterPhrase(phrase);
 }
예제 #17
0
 public DeviceEventAction(DeviceEventType eventType, ScriptCommandList commands)
     : this(new[] {eventType}, commands)
 {
 }