Пример #1
0
        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;
            }
        }
Пример #2
0
        protected override void Execute_Definition(RoomieCommandContext context)
        {
            var interpreter = context.Interpreter;

            interpreter.WriteEvent("Twitter Stats:");
            interpreter.WriteEvent("--Library Version: " + Common.LibraryVersion);
        }
Пример #3
0
 protected override void Execute_Definition(RoomieCommandContext context)
 {
     foreach (var commandGroup in context.CommandLibrary.Groups)
     {
         context.Interpreter.WriteEvent(commandGroup);
     }
 }
Пример #4
0
        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());
            }
        }
Пример #5
0
        protected override void Execute_Definition(RoomieCommandContext context)
        {
            var path   = context.ReadParameter("Path").Value;
            var player = new SoundPlayer(path);

            player.Play();
        }
Пример #6
0
        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--;
                }
            }
        }
Пример #7
0
        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);
            }
        }
Пример #8
0
        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();
            //    }
            //}
        }
Пример #9
0
        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());
        }
Пример #10
0
        protected override void Execute_Definition(RoomieCommandContext context)
        {
            var engine      = context.Engine;
            var interpreter = context.Interpreter;

            interpreter.WriteEvent("Shutting down...");
            engine.Shutdown();
        }
Пример #11
0
        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);
        }
Пример #12
0
        protected override void Execute_Definition(RoomieCommandContext context)
        {
            var engine      = context.Engine;
            var interpreter = context.Interpreter;

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

            engine.PrintCommandCalls = value;
        }
Пример #13
0
        internal static string GetComputerName(RoomieCommandContext context)
        {
            if (!WebHookPresent(context))
            {
                throw new RoomieRuntimeException("WebHook not present.");
            }

            return(WebHookCommands.Common.GetComputerName(context.DataStore));
        }
Пример #14
0
        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
        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();
            }
        }
Пример #16
0
        internal static Response <TData> Send <TData>(RoomieCommandContext context, string repository, Request request)
            where TData : class
        {
            //TODO: that's not too conclusive.
            if (!WebHookPresent(context))
            {
                throw new RoomieRuntimeException("WebHook not present.");
            }

            return(WebHookCommands.Common.Send <TData>(context.DataStore, repository, request));
        }
Пример #17
0
        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);
        }
Пример #18
0
        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.Add(value2);

            scope.Parent.Local.SetVariable(resultName, result.ToString());
        }
Пример #19
0
        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.Add(timeSpan);

            scope.Parent.Local.SetVariable(resultName, TimeUtils.DateTimeToString(result));
        }
Пример #20
0
        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());
        }
Пример #21
0
        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());
                }
            }
        }
Пример #22
0
        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;
        }
Пример #23
0
        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);
            }
        }
Пример #24
0
        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);
        }
Пример #25
0
        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\"");
            }
        }
Пример #26
0
        //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.");
        }
Пример #27
0
        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 + ".");
                    }
                }
            }
        }
Пример #28
0
        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...");
                }
            }
        }
Пример #29
0
        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);
            }
        }
Пример #30
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);
            }
        }