Exemple #1
0
        internal static void WriteHistory(IEnumerable<IEvent> history, RoomieCommandInterpreter interpreter)
        {
            var headers = new[] {"Time Stamp", "Entity", "Type", "Source", ""};
            var tableBuilder = new TextTable(new int[]
                {
                    Math.Max(history.Max(x => x.TimeStamp.ToLocalTime().ToString().Length), headers[0].Length),
                    Math.Max(history.Max(x => ((x.Entity == null || x.Entity.Name == null) ? string.Empty : x.Entity.Name).Length), headers[1].Length),
                    Math.Max(history.Max(x => ((x.Type == null) ? string.Empty : x.Type.Name).Length), headers[2].Length),
                    Math.Max(history.Max(x => ((x.Source == null || x.Source.Name == null) ? string.Empty : x.Source.Name).Length), headers[3].Length),
                    ExtraLength(history)
                });

            interpreter.WriteEvent(tableBuilder.StartOfTable(headers));

            foreach (var @event in history)
            {
                var extra = GetExtra(@event);

                var line = tableBuilder.ContentLine(
                    @event.TimeStamp.ToLocalTime().ToString(),
                    (@event.Entity == null) ? string.Empty : @event.Entity.Name,
                    (@event.Type == null) ? string.Empty : @event.Type.Name,
                    (@event.Source == null) ? string.Empty : @event.Source.Name,
                    extra
                    );

                interpreter.WriteEvent(line);
            }

            interpreter.WriteEvent(tableBuilder.EndOfTable());
        }
Exemple #2
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());
        }
Exemple #3
0
        protected override void Execute_HomeAutomationNetworkDefinition(HomeAutomationCommandContext context)
        {
            var interpreter = context.Interpreter;
            var network = context.Network;

            var poll = context.ReadParameter("Poll").ToBoolean();

            //TODO: list all devices on all networks.
            //TODO: add type

            const string addressLabel = "Address";
            const string typeLabel = "Type";
            const string connectedLabel = "Connected";
            const string statusLabel = "Status";

            var addressLength = addressLabel.Length;
            var typeLength = typeLabel.Length;
            var connectedLength = connectedLabel.Length;
            var statusLength = statusLabel.Length;

            foreach (var device in network.Devices)
            {
                addressLength = Math.Max(addressLength, device.BuildVirtualAddress(false, false).Length);
                typeLength = Math.Max(typeLength, device.Type.Name.Length);
                statusLength = Math.Max(statusLength, device.Describe().Length);
            }

            var tableBuilder = new TextTable(new[] { addressLength, typeLength, connectedLength, statusLength });

            interpreter.WriteEvent(tableBuilder.StartOfTable(addressLabel, typeLabel, connectedLabel, statusLabel));

            foreach (var device in network.Devices)
            {
                var address = device.BuildVirtualAddress(false, false);

                if (poll)
                {
                    try
                    {
                        device.Poll();
                    }
                    catch
                    { }
                }

                var status = device.Describe();

                var connected = (device.IsConnected == true)?"Yes":" - ";

                interpreter.WriteEvent(tableBuilder.ContentLine(address, device.Type, connected, status));
            }

            interpreter.WriteEvent(tableBuilder.EndOfTable());
        }
Exemple #4
0
        static void TableBuilderDemo()
        {
            var table = new TextTable(new int[] { 10, 15, 20 });

            Console.WriteLine(table.TopLine);
            Console.WriteLine(table.ContentLine(new string[] { "column 1", "column 2", "column 3" }));
            Console.WriteLine(table.DividerLine);
            Console.WriteLine(table.ContentLine(new string[] { "Item 1a", "Item 2b", "Item 1c" }));
            Console.WriteLine(table.ContentLine(new string[] { "Item 2", "Item 2b", "Item 2c" }));
            Console.WriteLine(table.ContentLine(new string[] { "Item 3a", "Item 3b", "Item 3c" }));
            Console.WriteLine(table.BottomLine);
        }
Exemple #5
0
        protected override void Execture_HomeAutomationSingleDeviceDefinition(HomeAutomationSingleDeviceContext context)
        {
            var interpreter = context.Interpreter;
            var device = context.Device as OpenZWaveDevice;

            var headers = new[]
            {
                "Command Class",
                "Index",
                "Instance",
                "Value",
                "Units",
                "Type",
                "Label",
                "Help"
            };

            var values = device.Values
                               .OrderBy(x => x.Index)
                               .OrderBy(x => x.Instance)
                               .OrderBy(x => x.CommandClass.ToString());

            var rows = values.Select(TransformValue).ToArray();

            var rowsAndHeaders = new[] {headers}.Concat(rows).ToArray();

            var columnWidths = new int[headers.Length];

            for (var i = 0; i < columnWidths.Length; i++)
            {
                columnWidths[i] = rowsAndHeaders.Max(x => x[i].Length);
            }

            var tableBuilder = new TextTable(columnWidths);

            interpreter.WriteEvent(tableBuilder.StartOfTable(headers));

            foreach (var row in rows)
            {
                interpreter.WriteEvent(tableBuilder.ContentLine(row));
            }

            interpreter.WriteEvent(tableBuilder.EndOfTable());
        }