public void Details()
 {
     ProConsole.WriteLine();
     Debug.WriteDebugLine(ControlSystem.Instance, "Supports Audio = '{0}'", ControlSystem.Instance.SupportsAudio);
     Debug.WriteDebugLine(ControlSystem.Instance, "Supports BACNet = '{0}'", ControlSystem.Instance.SupportsBACNet);
     Debug.WriteDebugLine(ControlSystem.Instance, "Supports Bluetooth = '{0}'", ControlSystem.Instance.SupportsBluetooth);
     Debug.WriteDebugLine(ControlSystem.Instance, "Supports Changing Video Resolution = '{0}'", ControlSystem.Instance.SupportsChangingVideoResolution);
     Debug.WriteDebugLine(ControlSystem.Instance, "Supports ComPorts = '{0}'", ControlSystem.Instance.SupportsComPort);
     Debug.WriteDebugLine(ControlSystem.Instance, "Supports Connect It Devices = '{0}'", ControlSystem.Instance.SupportsConnectItDevices);
     Debug.WriteDebugLine(ControlSystem.Instance, "Supports Cresnet = '{0}'", ControlSystem.Instance.SupportsCresnet);
     Debug.WriteDebugLine(ControlSystem.Instance, "Supports Digital Input = '{0}'", ControlSystem.Instance.SupportsDigitalInput);
     Debug.WriteDebugLine(ControlSystem.Instance, "Supports Display Slot = '{0}'", ControlSystem.Instance.SupportsDisplaySlot);
     Debug.WriteDebugLine(ControlSystem.Instance, "Supports ER Radio = '{0}'", ControlSystem.Instance.SupportsERRadio);
     Debug.WriteDebugLine(ControlSystem.Instance, "Supports Ethernet = '{0}'", ControlSystem.Instance.SupportsEthernet);
     Debug.WriteDebugLine(ControlSystem.Instance, "Supports Flash Projects = '{0}'", ControlSystem.Instance.SupportsFlashProjects);
     Debug.WriteDebugLine(ControlSystem.Instance, "Supports Internal AirMedia = '{0}'", ControlSystem.Instance.SupportsInternalAirMedia);
     Debug.WriteDebugLine(ControlSystem.Instance, "Supports Internal RF Gateway = '{0}'", ControlSystem.Instance.SupportsInternalRFGateway);
     Debug.WriteDebugLine(ControlSystem.Instance, "Supports Internal Streaming = '{0}'", ControlSystem.Instance.SupportsInternalStreaming);
     Debug.WriteDebugLine(ControlSystem.Instance, "Supports IR In = '{0}'", ControlSystem.Instance.SupportsIRIn);
     Debug.WriteDebugLine(ControlSystem.Instance, "Supports IR Out = '{0}'", ControlSystem.Instance.SupportsIROut);
     Debug.WriteDebugLine(ControlSystem.Instance, "Supports Microphones = '{0}'", ControlSystem.Instance.SupportsMicrophones);
     Debug.WriteDebugLine(ControlSystem.Instance, "Supports Relay = '{0}'", ControlSystem.Instance.SupportsRelay);
     Debug.WriteDebugLine(ControlSystem.Instance, "Supports SNMP = '{0}'", ControlSystem.Instance.SupportsSNMP);
     Debug.WriteDebugLine(ControlSystem.Instance, "Supports Switcher Inputs = '{0}'", ControlSystem.Instance.SupportsSwitcherInputs);
     Debug.WriteDebugLine(ControlSystem.Instance, "Supports Switcher Outputs = '{0}'", ControlSystem.Instance.SupportsSwitcherOutputs);
     Debug.WriteDebugLine(ControlSystem.Instance, "Supports System Monitor = '{0}'", ControlSystem.Instance.SupportsSystemMonitor);
     Debug.WriteDebugLine(ControlSystem.Instance, "Supports 3-Series Plug-In Cards = '{0}'", ControlSystem.Instance.SupportsThreeSeriesPlugInCards);
     Debug.WriteDebugLine(ControlSystem.Instance, "Supports USB HID = '{0}'", ControlSystem.Instance.SupportsUsbHid);
     Debug.WriteDebugLine(ControlSystem.Instance, "Supports Versiport = '{0}'", ControlSystem.Instance.SupportsVersiport);
 }
Exemple #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ControlSystem"/> class.
        /// </summary>
        public ControlSystem()
            : base()
        {
            try
            {
                Thread.MaxNumberOfUserThreads = 20;

                // Setup the static instance reference for the control system.
                Instance = this;

                // Setup the path the options are saved to and loaded from.
                Options.FilePath = "/USER/pellucid.console-options.toml";

                // Setup the global command(s).
                var appCommand = new GlobalCommand("app", "Application commands.", Access.Programmer);
                var regResult  = appCommand.AddToConsole();

                // Add a console writer to the console.
                // This could be done with the ProConsole class as well, or your own
                // implementation extending the ConsoleBase class.
                // Technically if no writer is registered then the CrestronConsoleWriter
                // gets registered by default, precluding the need for this, but it shows
                // how to hook your own console writers into the system.
                ConsoleBase.RegisterConsoleWriter(new Evands.Pellucid.Terminal.CrestronConsoleWriter());

                if (!regResult)
                {
                    Debug.WriteErrorLine(this, "Unable to add global app to the Crestron Console.");
                }

                // Initialize specific global commands.
                ProConsole.InitializeConsole("app");

                var csc = new ControlSystemCommands();
                csc.RegisterCommand("app");

                var exc = new ExampleCommands();
                exc.RegisterCommand("app");

                // Register log writers.
                Logger.RegisterLogWriter(new CrestronLogWriter());

                // In addition to the CrestronLogWriter we're registering an additional writer that targets another file.
                var path = Path.Combine(Directory.GetApplicationRootDirectory(), "/user");
                path = Path.Combine(path, "logs");
                path = Path.Combine(path, string.Format("App{0}SimpleLog.log", InitialParametersClass.ApplicationNumber));
                Logger.RegisterLogWriter(new Evands.Pellucid.Diagnostics.SimpleFileLogger(path));

                // Subscribe to the controller events (System, Program, and Ethernet)
                CrestronEnvironment.SystemEventHandler        += new SystemEventHandler(ControlSystem_ControllerSystemEventHandler);
                CrestronEnvironment.ProgramStatusEventHandler += new ProgramStatusEventHandler(ControlSystem_ControllerProgramEventHandler);
                CrestronEnvironment.EthernetEventHandler      += new EthernetEventHandler(ControlSystem_ControllerEthernetEventHandler);
            }
            catch (Exception e)
            {
                this.LogException(e, "Exception in the constructor.");
            }
        }
Exemple #3
0
        /// <summary>
        /// Attempts to execute a command with the specified argument text.
        /// <para>This text should be the contents of the command line, without this <see cref="GlobalCommand"/>'s command name.</para>
        /// <para>Example: 'sampleCommand verb defaultValue --flag --operand operandValue'</para>
        /// <para>This allows commands to be executed from a source other than the command prompt.</para>
        /// </summary>
        /// <param name="args">The command line arguments, including the command, verb, defaultValue, operands, and flags.</param>
        public void ExecuteCommand(string args)
        {
            try
            {
                var command = commandRegex.Match(args);

                if (command.Success)
                {
                    var cmdName      = command.Groups["name"].Value.ToLower(System.Globalization.CultureInfo.InvariantCulture).Trim();
                    var verb         = command.Groups["verb"].Value.ToLower(System.Globalization.CultureInfo.InvariantCulture).Trim();
                    var defaultValue = command.Groups["defaultValue"].Value.Trim();

                    var result   = parametersRegex.Matches(command.Groups["parameters"].Value.Trim());
                    var operands = new Dictionary <string, string>();

                    for (var i = 0; i < result.Count; i++)
                    {
                        if (result[i].Success && result[i].Groups["name"].Length > 0)
                        {
                            var val = result[i].Groups["name"].Value.ToLower().Trim();
                            if (!operands.ContainsKey(val))
                            {
                                operands.Add(val, result[i].Groups["value"].Value);
                            }
                            else
                            {
                                WriteErrorMethod(string.Format("The '{0}' operand or flag was used more than once.\r\n", result[i].Groups["name"].Value));
                                WriteErrorMethod(string.Format("Duplicate operand or flag names are not allowed!"));
                                return;
                            }
                        }
                        else if (result[i].Success && result[i].Groups["shortName"].Length > 0)
                        {
                            var values = result[i].Groups["shortName"].Value.ToCharArray();

                            for (var j = 0; j < values.Length; j++)
                            {
                                if (!operands.ContainsKey(values[j].ToString()))
                                {
                                    operands.Add(values[j].ToString(), string.Empty);
                                }
                            }
                        }
                    }

                    ProcessCommand(cmdName, verb, defaultValue, operands);
                }
                else if (args.ToLower().Contains("--help") || args.ToLower().Contains("-h"))
                {
                    PrintGlobalCommandsHelp();
                }
                else
                {
                    WriteErrorMethod("You must enter the name of a command. Enter '--help' for a list of available commands.");
                }
            }
            catch (TerminalCommandException e)
            {
                var cee = CommandExceptionEncountered;
                if (cee != null)
                {
                    cee.Invoke(this, new TerminalCommandExceptionEventArgs(e, args));
                }
                else
                {
                    throw e;
                }
            }
            catch (Exception ex)
            {
                var e   = new TerminalCommandException(ex, string.Format("Exception encountered while executing Terminal Command: '{0}'.", args));
                var cee = CommandExceptionEncountered;
                if (cee != null)
                {
                    cee.Invoke(this, new TerminalCommandExceptionEventArgs(e, args));
                }
                else
                {
                    ProConsole.WriteLine();
                    ProConsole.WriteError("Exception encountered while executing Terminal Command: '{0}'.\r\n{1}", args, ex.ToString());
                }
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ControlSystem"/> class.
        /// </summary>
        public ControlSystem()
            : base()
        {
            try
            {
                Thread.MaxNumberOfUserThreads = 20;

                // Setup the static instance reference for the control system.
                Instance = this;

                // Setup the path the options are saved to and loaded from.
                Options.FilePath = "/USER/pellucid.console-options.toml";

                // Add a console writer to the console.
                // This could be done with the ProConsole class as well, or your own
                // implementation extending the ConsoleBase class.
                // Technically if no writer is registered then the CrestronConsoleWriter
                // gets registered by default, precluding the need for this, but it shows
                // how to hook your own console nodes into the system.
                ConsoleBase.RegisterConsoleWriter(new Evands.Pellucid.Terminal.CrestronConsoleWriter());
                cws = new Crestron.SimplSharp.WebScripting.HttpCwsServer("/pellucid/");
                cws.Register();

                // This is the optional CwsConsoleWriter, usually used for something like VC-4 console access.
                if (CrestronEnvironment.DevicePlatform == eDevicePlatform.Server)
                {
                    ConsoleBase.RegisterConsoleWriter(new Evands.Pellucid.Cws.CwsConsoleWriter(cws, string.Format("console/{0}", InitialParametersClass.RoomId), 53000, false));
                }
                else
                {
                    if (CrestronEnvironment.ProgramCompatibility == eCrestronSeries.Series3)
                    {
                        ConsoleBase.RegisterConsoleWriter(new Evands.Pellucid.Cws.CwsConsoleWriter(cws, true, 53000, false));
                    }
                    else
                    {
                        ConsoleBase.RegisterConsoleWriter(new Evands.Pellucid.Cws.CwsConsoleWriter(cws, 53000, false));
                    }
                }

                // Setup the global command(s).
                var appCommand = new GlobalCommand("app", "Application commands.", Access.Programmer);
                var regResult  = appCommand.AddToConsole();
                appCommand.CommandExceptionEncountered += (o, a) => appCommand.LogException(a.Exception, "Exception while executing command '{0}'.", a.CommandContent);

                if (!regResult)
                {
                    Debug.WriteErrorLine(this, "Unable to add global app to the Crestron Console.");
                }

                // Initialize specific global commands.
                ProConsole.InitializeConsole("app");

                var csc = new ControlSystemCommands();
                csc.RegisterCommand("app");

                var exc1 = new ExampleCommands("1");
                exc1.RegisterCommand("app");

                var exc2 = new ExampleCommands("2");
                exc2.RegisterCommand("app");

                var cn1 = new CustomNameCommand("XCommand");
                cn1.RegisterCommand("app");

                var cn2 = new CustomNameCommand("ZedCommand");
                cn2.RegisterCommand("app");

                // Register log nodes.
                Logger.RegisterLogWriter(new CrestronLogWriter());

                // In addition to the CrestronLogWriter we're registering an additional writer that targets another file.
                var path = Path.Combine(Directory.GetApplicationRootDirectory(), "/user");
                path = Path.Combine(path, "logs");
                path = Path.Combine(path, string.Format("App{0}SimpleLog.log", InitialParametersClass.ApplicationNumber));
                Logger.RegisterLogWriter(new Evands.Pellucid.Diagnostics.SimpleFileLogger(path));

                // Subscribe to the controller events (System, Program, and Ethernet)
                CrestronEnvironment.SystemEventHandler        += new SystemEventHandler(ControlSystem_ControllerSystemEventHandler);
                CrestronEnvironment.ProgramStatusEventHandler += new ProgramStatusEventHandler(ControlSystem_ControllerProgramEventHandler);
                CrestronEnvironment.EthernetEventHandler      += new EthernetEventHandler(ControlSystem_ControllerEthernetEventHandler);
            }
            catch (Exception e)
            {
                this.LogException(e, "Exception in the constructor.");
            }
        }