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); }
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)); }
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()); }
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()); }
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; }
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); }
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); }
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()); } }
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()); }
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); }
protected override void Execute_Definition(RoomieCommandContext context) { var engine = context.Engine; var interpreter = context.Interpreter; bool value = context.ReadParameter("Value").ToBoolean(); engine.PrintCommandCalls = value; }
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\""); } }
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); } }
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); }
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: } } }
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); }
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; } }
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); } }
//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."); }
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); }
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); }
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--; } }
//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); } }
protected override void Execute_Definition(RoomieCommandContext context) { var path = context.ReadParameter("Path").Value; var player = new SoundPlayer(path); player.Play(); }
protected override void Execute_Definition(RoomieCommandContext context) { var interpreter = context.Interpreter; interpreter.WriteEvent(context.ReadParameter("Text").Value); }
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); }
protected override void Execute_Definition(RoomieCommandContext context) { bool force = context.ReadParameter("Force").ToBoolean(); Common.SuspendComputer(PowerState.Hibernate, force); }