protected override void Execute_Definition(RoomieCommandContext context) { foreach (var commandGroup in context.CommandLibrary.Groups) { context.Interpreter.WriteEvent(commandGroup); } }
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) { throw new NotImplementedException(); //var interpreter = context.Interpreter; //var scope = context.Scope; //var originalXml = context.OriginalCommand; //bool value = scope.GetBoolean("Value"); //XmlNode nodeToExecute; //if (value) // nodeToExecute = originalXml.SelectSingleNode("True"); //else // nodeToExecute = originalXml.SelectSingleNode("False"); //if (nodeToExecute == null) // return; //List<XmlNode> commands = new List<XmlNode>(nodeToExecute.ChildNodes.Count); //foreach (XmlNode commandNode in nodeToExecute.ChildNodes) // commands.Add(commandNode); //RoomieCommandInterpreter subInterpreter = interpreter.GetSubinterpreter(); //subInterpreter.AddCommands(commands); //bool success = subInterpreter.ProcessQueue(); //if (!success) //{ // lock (interpreter) // { // interpreter.WriteEvent("Breaking if"); // interpreter.ClearCommandQueue(); // } //} }
protected override void Execute_Definition(RoomieCommandContext context) { //TODO: make this include plugins' private threadpools. var interpreter = context.Interpreter; var engine = context.Engine; var threads = context.Threads; var headers = new [] { "ID", "Name", "Busy"}; var maxThreadIdLength = threads.Max(x => x.Id.Length); var maxThreadNameLength = threads.Max(thread => (thread.Name ?? string.Empty).Length); var tableBuilder = new TextTable(new int [] { Math.Max(maxThreadIdLength, headers[0].Length), Math.Max(maxThreadNameLength, headers[1].Length), headers[2].Length }); interpreter.WriteEvent(tableBuilder.StartOfTable(headers)); foreach (var thread in threads) { interpreter.WriteEvent(tableBuilder.ContentLine(new [] { thread.Id, thread.Name, thread.IsBusy ? "yes" : " - " })); } interpreter.WriteEvent(tableBuilder.EndOfTable()); }
protected override void Execute_Definition(RoomieCommandContext context) { var interpreter = context.Interpreter; interpreter.WriteEvent("WakeOnLAN Stats:"); interpreter.WriteEvent("--Library Version: " + Common.LibraryVersion); }
protected override void Execute_Definition(RoomieCommandContext context) { var interpreter = context.Interpreter; interpreter.WriteEvent("WebHook Stats:"); interpreter.WriteEvent("--Library Version: " + Common.LibraryVersion); interpreter.WriteEvent("--Web Communicator Version: " + WebCommunicator.Common.LibraryVersion); }
protected override void Execute_Definition(RoomieCommandContext context) { var engine = context.Engine; var interpreter = context.Interpreter; interpreter.WriteEvent("Shutting down..."); engine.Shutdown(); }
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 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 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) { var homeAutomationContext = new HomeAutomationCommandContext(context); var zWaveNetworks = homeAutomationContext.Networks.OfType<ZWaveNetwork>(); var workQueues = zWaveNetworks.Select(x => x.WorkQueue); foreach (var workQueue in workQueues) { workQueue.ShutDown(); } }
protected override void Execute_Definition(RoomieCommandContext context) { if (hasBeenRun) { throw new RoomieRuntimeException("This is a startup command, and can only be run once."); } hasBeenRun = true; Execute_StartupDefinition(context); }
protected override void Execute_Definition(RoomieCommandContext context) { var interpreter = context.Interpreter; interpreter.WriteEvent("ZWave Stats:"); interpreter.WriteEvent("--Library Version: " + Common.LibraryVersion); System.Reflection.Assembly sdkAssembly = System.Reflection.Assembly.GetAssembly(typeof(global::ControlThink.ZWave.ZWaveController)); interpreter.WriteEvent("--ControlThink Z-Wave SDK Version: " + sdkAssembly.GetName().Version); //interpreter.WriteEvent("--Devices Registerd: " + network.Devices.Count); }
protected override void Execute_Definition(RoomieCommandContext context) { if (hasBeenRun) { throw new RoomieRuntimeException("This is a startup command, and can only be run once."); } hasBeenRun = true; Execute_StartupDefinition(context); }
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)); }
internal static Message SendMessage(RoomieCommandContext context, Message outMessage) { //TODO: that's not too conclusive. if (!WebHookPresent(context)) { throw new RoomieRuntimeException("WebHook not present."); } Message response = WebHookCommands.Common.SendMessage(context.DataStore, outMessage); return response; }
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 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) { 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 commands = context.CommandLibrary; var interpreter = context.Interpreter; foreach (var command in commands) { if (command.IsDynamic) { interpreter.WriteEvent(command.ToConsoleFriendlyString()); } } }
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; }
internal void Execute(RoomieCommandContext context) { var interpreter = context.Interpreter; var scope = context.Scope; if (!Finalized) { throw new CommandImplementationException(this, "Can not execute a command that is not finalized."); } scope.PrepareForCall(this, interpreter); Execute_Definition(context); }
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) { 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); } }
protected override void Execute_Definition(RoomieCommandContext context) { var interpreter = context.Interpreter; //TODO: define variables? var subInterpreter = interpreter.GetSubinterpreter(); foreach (var parameter in context.OriginalCommand.Parameters) { subInterpreter.Scope.Local.DeclareVariable(parameter.Name, parameter.Value); } subInterpreter.CommandQueue.Add(subcommands); subInterpreter.ProcessQueue(); }
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); }
//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 interpreter = context.Interpreter; //TODO: define variables? var subInterpreter = interpreter.GetSubinterpreter(); foreach (var parameter in context.OriginalCommand.Parameters) { subInterpreter.Scope.Local.DeclareVariable(parameter.Name, parameter.Value); } subInterpreter.CommandQueue.Add(subcommands); subInterpreter.ProcessQueue(); }
protected override void Execute_Definition(RoomieCommandContext context) { var commands = context.CommandLibrary; var types = context.ArgumentTypes; var interpreter = context.Interpreter; foreach (var command in commands) { foreach (var argument in command.Arguments) { if (!types.Contains(argument.Type)) { interpreter.WriteEvent("Invalid type \"" + argument.Type + "\" for argument \"" + argument.Name + "\" in command " + command.FullName + "."); } } } }
protected override void Execute_Definition(RoomieCommandContext context) { var interpreter = context.Interpreter; var originalCommand = context.OriginalCommand; var innerCommands = originalCommand.InnerCommands; var subinterpreter = interpreter.GetSubinterpreter(); foreach (var command in innerCommands) { subinterpreter.CommandQueue.Add(command); var result = subinterpreter.ProcessQueue(); if (!result) { subinterpreter.WriteEvent("Previous command failed. Continuing..."); } } }
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 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\""); } }
//TODO: work with multiple engines protected override void Execute_Definition(RoomieCommandContext context) { var engine = context.Engine; var interpreter = context.Interpreter; var scope = context.Scope; var originalXml = context.OriginalXml; var webhookEngines = Common.GetWebHookEngines(engine); var outMessage = new Message(); foreach (string variableName in scope.Names) outMessage.Values.Add(variableName, scope.GetValue(variableName)); foreach (XmlNode node in originalXml.ChildNodes) outMessage.Payload.Add(node); Common.SendMessage(engine, outMessage); }
protected RoomieCommandContext(RoomieCommandContext that) : this(that.Interpreter, that.Scope, that.OriginalCommand) { }
protected abstract void Execute_StartupDefinition(RoomieCommandContext context);
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); }