コード例 #1
0
ファイル: Beep.cs プロジェクト: Mavtak/roomie
        protected override void Execute_Definition(RoomieCommandContext context)
        {
            int frequency = context.ReadParameter("Frequency").ToInteger();
            TimeSpan duration = context.ReadParameter("Duration").ToTimeSpan();

            double ms = duration.TotalMilliseconds;

            if (ms > int.MaxValue)
                throw new RoomieRuntimeException("Duration for beep too long.  Can be at most " + new TimeSpan(0, 0, 0, 0, int.MaxValue).TotalDays + " days.");

            Console.Beep(frequency, (int)ms);
        }
コード例 #2
0
ファイル: SubtractTimeSpan.cs プロジェクト: Mavtak/roomie
        protected override void Execute_Definition(RoomieCommandContext context)
        {
            var scope = context.Scope;

            DateTime dateTime = context.ReadParameter("DateTime").ToDateTime();
            TimeSpan timeSpan = context.ReadParameter("TimeSpan").ToTimeSpan();
            string resultName = context.ReadParameter("ResultName").Value;

            DateTime result = dateTime.Subtract(timeSpan);

            scope.Parent.Local.SetVariable(resultName, TimeUtils.DateTimeToString(result));
        }
コード例 #3
0
ファイル: Subtract.cs プロジェクト: Mavtak/roomie
        protected override void Execute_Definition(RoomieCommandContext context)
        {
            var scope = context.Scope;

            TimeSpan value1 = context.ReadParameter("Value1").ToTimeSpan();
            TimeSpan value2 = context.ReadParameter("Value2").ToTimeSpan();
            string resultName = context.ReadParameter("ResultName").Value;

            TimeSpan result = value1.Subtract(value2);

            scope.Parent.Local.SetVariable(resultName, result.ToString());
        }
コード例 #4
0
ファイル: Add.cs プロジェクト: Mavtak/roomie
        protected override void Execute_Definition(RoomieCommandContext context)
        {
            var scope = context.Scope;

            int value1 = context.ReadParameter("Value1").ToInteger();
            int value2 = context.ReadParameter("Value2").ToInteger();
            string resultName = context.ReadParameter("ResultName").Value;

            int result = value1 + value2;

            scope.Parent.Local.SetVariable(resultName, result.ToString());
        }
コード例 #5
0
ファイル: SetName.cs プロジェクト: Mavtak/roomie
        protected override void Execute_Definition(RoomieCommandContext context)
        {
            var interpreter = context.Interpreter;
            var threads = context.Threads;
            var currentThread = interpreter.ParentThread;

            var currentName = context.ReadParameter("CurrentName").Value;
            var newName = context.ReadParameter("NewName").Value;

            var thread = SelectThread(currentName, currentThread, threads);

            thread.Name = newName;
        }
コード例 #6
0
ファイル: DeclareVariable.cs プロジェクト: Mavtak/roomie
        protected override void Execute_Definition(RoomieCommandContext context)
        {
            var globalScope = context.GlobalScope;
            var scope = context.Scope;

            string name = context.ReadParameter("Name").Value;
            string value = context.ReadParameter("Value").Value;
            bool global = context.ReadParameter("Global").ToBoolean();

            if (global)
                globalScope.Local.DeclareVariable(name, value);
            else
                scope.Parent.Local.DeclareVariable(name, value);
        }
コード例 #7
0
ファイル: Speak.cs プロジェクト: Mavtak/roomie
        protected override void Execute_Definition(RoomieCommandContext context)
        {
            if (synthesizer == null)
            {
                synthesizer = new SpeechSynthesizer();
            }

            String text = context.ReadParameter("Text").Value;
            bool async = context.ReadParameter("Async").ToBoolean();

            if (async)
                synthesizer.SpeakAsync(text);
            else
                synthesizer.Speak(text);
        }
コード例 #8
0
ファイル: List.cs プロジェクト: Mavtak/roomie
        protected override void Execute_Definition(RoomieCommandContext context)
        {
            //TODO: make this more efficient
            var commands = context.CommandLibrary;
            var interpreter = context.Interpreter;

            var group = context.ReadParameter("Group").Value;

            IEnumerable<RoomieCommand> subset;

            if (string.IsNullOrEmpty(group))
            {
                subset = commands;
            }
            else
            {
                subset = from command in commands
                         where @group == ""
                            || command.Group == @group
                         select command;
            }
            foreach (var command in subset)
            {
                interpreter.WriteEvent(command.ToConsoleFriendlyString());
            }
        }
コード例 #9
0
ファイル: RandomInteger.cs プロジェクト: Mavtak/roomie
        protected override void Execute_Definition(RoomieCommandContext context)
        {
            var scope = context.Scope;

            int min = context.ReadParameter("Min").ToInteger();
            int max = context.ReadParameter("Max").ToInteger();
            string resultName = context.ReadParameter("ResultName").Value;

            if (min > max)
                throw new RoomieRuntimeException("Min > Max");

            if(random == null)
                random = new System.Random();

            int result = random.Next(min, max);

            scope.Parent.SetVariable(resultName, result.ToString());
        }
コード例 #10
0
ファイル: WaitUntil.cs プロジェクト: Mavtak/roomie
        protected override void Execute_Definition(RoomieCommandContext context)
        {
            var interpreter = context.Interpreter;

            DateTime target = context.ReadParameter("Time").ToDateTime();

            interpreter.WriteEvent("waiting for " + target);
            Common.WaitUntil(target);
        }
コード例 #11
0
ファイル: SetCommandPrinting.cs プロジェクト: Mavtak/roomie
        protected override void Execute_Definition(RoomieCommandContext context)
        {
            var engine = context.Engine;
            var interpreter = context.Interpreter;

            bool value = context.ReadParameter("Value").ToBoolean();

            engine.PrintCommandCalls = value;
        }
コード例 #12
0
ファイル: InsertScript.cs プロジェクト: Mavtak/roomie
        protected override void Execute_Definition(RoomieCommandContext context)
        {
            var threads = context.Threads;
            var interpreter = context.Interpreter;
            var scope = context.Scope;
            var originalCommand = context.OriginalCommand;
            var innerCommands = originalCommand.InnerCommands;

            string where = context.ReadParameter("Where").Value;
            string threadName = context.ReadParameter("NewThreadName").Value;
            string path = context.ReadParameter("Path").Value;

            IEnumerable<IScriptCommand> commandsToAdd;

            if (string.IsNullOrEmpty(path))
            {
                commandsToAdd = innerCommands;
            }
            else
            {
                commandsToAdd = RoomieScript.FromFile(path);
            }

            //TODO: detect when there are no commands?

            switch(where)
            {
                case "End":
                    interpreter.CommandQueue.Add(commandsToAdd);
                    return;
                case "Here":
                    interpreter.CommandQueue.AddBeginning(commandsToAdd);
                    return;
                case "New Thread":
                    if (string.IsNullOrEmpty(threadName))
                        throw new MissingArgumentsException("NewThreadName");
                    RoomieThread newThread = threads.CreateNewThread(threadName, scope);
                    newThread.AddCommands(commandsToAdd);
                    return;
                default:
                    throw new RoomieRuntimeException("Unexpected value for \"Where\" (" + where + ").  Must be set to \"End\", \"Here\", or \"New Thread\"");
            }
        }
コード例 #13
0
        protected override void Execute_Definition(RoomieCommandContext context)
        {
            var name = context.ReadParameter("Name");
            var expectedRunning = context.ReadParameter("Running").ToBoolean();
            var pollInterval = context.ReadParameter("PollInterval").ToTimeSpan();

            while (true)
            {
                var processes = Process.GetProcesses();
                var actualRunning = processes.Any(x => string.Equals(x.ProcessName, name));

                if (actualRunning == expectedRunning)
                {
                    return;
                }

                Thread.Sleep(pollInterval);
            }
        }
コード例 #14
0
ファイル: Wait.cs プロジェクト: Mavtak/roomie
        protected override void Execute_Definition(RoomieCommandContext context)
        {
            var interpreter = context.Interpreter;

            var duration = context.ReadParameter("Duration").ToTimeSpan();
            var target = DateTime.Now.Add(duration);

            interpreter.WriteEvent("waiting for " + target);
            Common.WaitUntil(target);
        }
コード例 #15
0
ファイル: OpenFile.cs プロジェクト: Mavtak/roomie
        protected override void Execute_Definition(RoomieCommandContext context)
        {
            string path = context.ReadParameter("Path").Value;
            bool abortOnError = context.ReadParameter("AbortOnError").ToBoolean();

            try
            {
                System.Diagnostics.Process.Start(path);
            }
            catch(Exception e)
            {
                if (abortOnError)
                {
                    throw new RoomieRuntimeException("Error opening file: " + e.Message);
                }
                else
                {
                    //TODO:
                }
            }
        }
コード例 #16
0
ファイル: ModifyVariable.cs プロジェクト: Mavtak/roomie
        protected override void Execute_Definition(RoomieCommandContext context)
        {
            var globalScope = context.GlobalScope;
            var interpreter = context.Interpreter;
            var scope = context.Scope;

            string name = context.ReadParameter("Name").Value;

            bool literal = context.ReadParameter("Literal").ToBoolean();
            string value;
            if(literal)
                value = scope.GetVariable("Value").Value;
            else
                value = context.ReadParameter("Value").Value;
            bool global = context.ReadParameter("Global").ToBoolean();

            if (global)
                globalScope.GetVariable(name).Update(value);
            else
                scope.Parent.GetVariable(name).Update(value);
        }
コード例 #17
0
ファイル: ListVariables.cs プロジェクト: Mavtak/roomie
        protected override void Execute_Definition(RoomieCommandContext context)
        {
            var interpreter = context.Interpreter;
            var scope = context.Scope;

            bool literalValues = context.ReadParameter("LiteralValues").ToBoolean();

            HierarchicalVariableScope currentScope = scope;
            interpreter.WriteEvent("---");
            while (currentScope != null)
            {
                foreach (string name in currentScope.Local.Names)
                {
                    if(literalValues)
                        interpreter.WriteEvent(name + ": " + scope.GetVariable(name).Value);
                    else
                        interpreter.WriteEvent(name + ": " + context.ReadParameter(name));
                }
                interpreter.WriteEvent("---");
                currentScope = currentScope.Parent;
            }
        }
コード例 #18
0
ファイル: WakeComputer.cs プロジェクト: Mavtak/roomie
        protected override void Execute_Definition(RoomieCommandContext context)
        {
            var macAddress = context.ReadParameter("MAC").Value;
            macAddress = macAddress.Replace("-", "");

            try
            {
                Common.WakeFunction(macAddress);
            }
            catch (Exception e)
            {
                throw new RoomieRuntimeException("Error sending Wake On LAN message: " + e.Message);
            }
        }
コード例 #19
0
ファイル: WriteDocumentation.cs プロジェクト: Mavtak/roomie
        //TODO: eliminate use of System.Xml
        protected override void Execute_Definition(RoomieCommandContext context)
        {
            var commands = context.CommandLibrary;
            var interpreter = context.Interpreter;

            var path = context.ReadParameter("Path").Value;

            interpreter.WriteEvent("Writing...");

            var writer = XmlWriter.Create(path);
            commands.WriteToXml(writer, false);
            writer.Close();

            interpreter.WriteEvent("Done.");
        }
コード例 #20
0
ファイル: TwitterCommand.cs プロジェクト: Mavtak/roomie
        protected override void Execute_Definition(RoomieCommandContext context)
        {
            var greaterContext = new TwitterCommandContext(context);
            var users = greaterContext.TwitterUsers;

            string username = context.ReadParameter("Username").Value;

            if (!users.ContainsKey(username) && this.Name != "SignIn") //TODO: decouple this
            {
                throw new RoomieRuntimeException("Twitter user @" + username + " is not signed in.");
            }

            Twitterizer.Framework.Twitter user = null;

            if (users.ContainsKey(username))
            {
                user = users[username];
            }

            Execute_TwitterDefinition(greaterContext);
        }
コード例 #21
0
ファイル: EmailCommand.cs プロジェクト: Mavtak/roomie
        protected override void Execute_Definition(RoomieCommandContext context)
        {
            var dataStore = context.DataStore;

            string senderAddress = context.ReadParameter("Address").Value;

            EmailCommandContext greaterContext = new EmailCommandContext(context);

            var mailers = greaterContext.Mailers;

            if (!mailers.ContainsKey(senderAddress) && !this.Name.Contains("Register"))
            {
                throw new RoomieRuntimeException("Sender address \"" + senderAddress + "\" not registered.");
            }
            else if(mailers.ContainsKey(senderAddress))
            {
                greaterContext.Sender = mailers[senderAddress];;
            }

            Execute_EmailDefinition(greaterContext);
        }
コード例 #22
0
ファイル: Loop.cs プロジェクト: Mavtak/roomie
        protected override void Execute_Definition(RoomieCommandContext context)
        {
            var interpreter = context.Interpreter;
            var originalCommand = context.OriginalCommand;
            var innerCommands = originalCommand.InnerCommands;

            int times = context.ReadParameter("Times").ToInteger();

            while (times != 0)
            {
                var subInterpreter = interpreter.GetSubinterpreter();
                subInterpreter.CommandQueue.Add(innerCommands);
                bool success = subInterpreter.ProcessQueue();

                if (!success)
                {
                    throw new RoomieRuntimeException("A command in the loop failed.");
                }

                if (times > 0)
                    times--;
            }
        }
コード例 #23
0
ファイル: WriteDocumentation.cs プロジェクト: Mavtak/roomie
        //TODO: eliminate use of System.Xml
        protected override void Execute_Definition(RoomieCommandContext context)
        {
            var commands = context.CommandLibrary;
            var interpreter = context.Interpreter;

            try
            {
                string filename = context.ReadParameter("Filename").Value;

                XmlWriterSettings settings = new XmlWriterSettings();
                settings.Encoding = Encoding.UTF8;
                settings.Indent = true;

                XmlWriter writer = XmlWriter.Create(filename, settings);
                writer.WriteStartDocument();
                commands.WriteToXml(writer, false);
                writer.WriteEndDocument();
                writer.Close();
            }
            catch (Exception exception)
            {
                throw new RoomieRuntimeException("Failed to write documentation: " + exception.Message, exception);
            }
        }
コード例 #24
0
ファイル: PlaySound.cs プロジェクト: Mavtak/roomie
 protected override void Execute_Definition(RoomieCommandContext context)
 {
     var path = context.ReadParameter("Path").Value;
     var player = new SoundPlayer(path);
     player.Play();
 }
コード例 #25
0
ファイル: Print.cs プロジェクト: Mavtak/roomie
        protected override void Execute_Definition(RoomieCommandContext context)
        {
            var interpreter = context.Interpreter;

            interpreter.WriteEvent(context.ReadParameter("Text").Value);
        }
コード例 #26
0
ファイル: Define.cs プロジェクト: Mavtak/roomie
        protected override void Execute_Definition(RoomieCommandContext context)
        {
            var commandLibrary = context.CommandLibrary;
            var interpreter = context.Interpreter;
            var parameterTypes = context.ArgumentTypes;
            var originalCommand = context.OriginalCommand;
            var innerCommands = originalCommand.InnerCommands;

            if (originalCommand == null)
            {
                throw new RoomieRuntimeException("No custom command definition");
            }

            if (innerCommands.Select("Subcommands") == null)
            {
                throw new RoomieRuntimeException("No subcommands specified");
            }

            string group = context.ReadParameter("Group").Value;
            string name = context.ReadParameter("Name").Value;
            string description = context.ReadParameter("Description").Value;
            if (String.IsNullOrWhiteSpace(description))
            {
                description = null;
            }

            List<RoomieCommandArgument> arguments = new List<RoomieCommandArgument>();

            var argumentsDefinition = innerCommands.Select("Arguments");

            if (argumentsDefinition != null)
            {
                foreach (var argumentDefinition in argumentsDefinition.InnerCommands)
                {
                    if (!argumentDefinition.Parameters.ContainsParameterName("Name"))
                    {
                        throw new RoomieRuntimeException("\"Name\" not specified in an argument listing for the " + group + "." + name + " custom command.");
                    }
                    string argumentName = argumentDefinition.Parameters["Name"].Value;

                    if (!argumentDefinition.Parameters.ContainsParameterName("Type"))
                    {
                        throw new RoomieRuntimeException("Type not specified for the \"" + argumentName + "\" argumet in an argument listing for the " + group + "." + name + " custom command.");
                    }
                    string typeString = argumentDefinition.Parameters["Type"].Value;
                    var type = parameterTypes[typeString];
                    //TODO: catch not found exception
                    if (!argumentDefinition.Parameters.ContainsParameterName("Default"))
                    {
                        var argument = new RoomieCommandArgument(
                            name: argumentName,
                            type: type
                            );
                        arguments.Add(argument);
                    }
                    else
                    {
                        string defaultValue = argumentDefinition.Parameters["Default"].Value;
                        var argument = new RoomieCommandArgument(
                            name: argumentName,
                            type: type,
                            defaultValue: defaultValue,
                            hasDefault: true
                            );
                        arguments.Add(argument);
                    }
                }
            }

            var subcommands = innerCommands.Select("Subcommands").InnerCommands;

            var dynamicCommand = new RoomieDynamicCommand(group, name, arguments, subcommands, description);

            commandLibrary.AddCommand(dynamicCommand);
        }
コード例 #27
0
ファイル: Hibernate.cs プロジェクト: Mavtak/roomie
        protected override void Execute_Definition(RoomieCommandContext context)
        {
            bool force = context.ReadParameter("Force").ToBoolean();

            Common.SuspendComputer(PowerState.Hibernate, force);
        }