Ejemplo n.º 1
0
        /// <summary>
        /// Reads all devices from config and adds them to DeviceManager
        /// </summary>
        public void LoadDevices()
        {
            // Build the processor wrapper class
            DeviceManager.AddDevice(new PepperDash.Essentials.Core.Devices.CrestronProcessor("processor"));

            // Add global System Monitor device
            DeviceManager.AddDevice(new PepperDash.Essentials.Core.Monitoring.SystemMonitorController("systemMonitor"));

            foreach (var devConf in ConfigReader.ConfigObject.Devices)
            {
                try
                {
                    Debug.Console(0, Debug.ErrorLogLevel.Notice, "Creating device '{0}', type '{1}'", devConf.Key, devConf.Type);
                    // Skip this to prevent unnecessary warnings
                    if (devConf.Key == "processor")
                    {
                        if (devConf.Type.ToLower() != Global.ControlSystem.ControllerPrompt.ToLower())
                        {
                            Debug.Console(0,
                                          "WARNING: Config file defines processor type as '{0}' but actual processor is '{1}'!  Some ports may not be available",
                                          devConf.Type.ToUpper(), Global.ControlSystem.ControllerPrompt.ToUpper());
                        }

                        // Check if the processor is a DMPS model
                        if (this.ControllerPrompt.IndexOf("dmps", StringComparison.OrdinalIgnoreCase) > -1)
                        {
                            Debug.Console(2, "Adding DmpsRoutingController for {0} to Device Manager.", this.ControllerPrompt);

                            var propertiesConfig = JsonConvert.DeserializeObject <DM.Config.DmpsRoutingPropertiesConfig>(devConf.Properties.ToString());

                            if (propertiesConfig == null)
                            {
                                propertiesConfig = new DM.Config.DmpsRoutingPropertiesConfig();
                            }

                            var dmpsRoutingController = DmpsRoutingController.GetDmpsRoutingController("processor-avRouting", this.ControllerPrompt, propertiesConfig);

                            DeviceManager.AddDevice(dmpsRoutingController);
                        }
                        else if (this.ControllerPrompt.IndexOf("mpc3", StringComparison.OrdinalIgnoreCase) > -1)
                        {
                            Debug.Console(2, "MPC3 processor type detected.  Adding Mpc3TouchpanelController.");

                            var butToken = devConf.Properties["buttons"];
                            if (butToken != null)
                            {
                                var buttons      = butToken.ToObject <Dictionary <string, Essentials.Core.Touchpanels.KeypadButton> >();
                                var tpController = new Essentials.Core.Touchpanels.Mpc3TouchpanelController(devConf.Key, devConf.Name, Global.ControlSystem, buttons);
                                DeviceManager.AddDevice(tpController);
                            }
                            else
                            {
                                Debug.Console(0, Debug.ErrorLogLevel.Error, "Error: Unable to deserialize buttons collection for device: {0}", devConf.Key);
                            }
                        }
                        else
                        {
                            Debug.Console(2, "************Processor is not DMPS type***************");
                        }



                        continue;
                    }

                    // Try local factories first
                    IKeyed newDev = null;

                    if (newDev == null)
                    {
                        newDev = PepperDash.Essentials.Core.DeviceFactory.GetDevice(devConf);
                    }

                    //
                    //if (newDev == null)
                    //    newDev = PepperDash.Essentials.Devices.Displays.DisplayDeviceFactory.GetDevice(devConf);
                    //

                    if (newDev != null)
                    {
                        DeviceManager.AddDevice(newDev);
                    }
                    else
                    {
                        Debug.Console(0, Debug.ErrorLogLevel.Notice, "ERROR: Cannot load unknown device type '{0}', key '{1}'.", devConf.Type, devConf.Key);
                    }
                }
                catch (Exception e)
                {
                    Debug.Console(0, Debug.ErrorLogLevel.Notice, "ERROR: Creating device {0}. Skipping device. \r{1}", devConf.Key, e);
                }
            }
            Debug.Console(0, Debug.ErrorLogLevel.Notice, "All Devices Loaded.");
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Reads all devices from config and adds them to DeviceManager
        /// </summary>
        public void LoadDevices()
        {
            // Build the processor wrapper class

            DeviceManager.AddDevice(new PepperDash.Essentials.Core.Devices.CrestronProcessor("processor"));



            // Add global System Monitor device
            DeviceManager.AddDevice(new PepperDash.Essentials.Core.Monitoring.SystemMonitorController("systemMonitor"));

            foreach (var devConf in ConfigReader.ConfigObject.Devices)
            {
                try
                {
                    Debug.Console(0, Debug.ErrorLogLevel.Notice, "Creating device '{0}', type '{1}'", devConf.Key, devConf.Type);
                    // Skip this to prevent unnecessary warnings
                    if (devConf.Key == "processor")
                    {
                        if (devConf.Type.ToLower() != Global.ControlSystem.ControllerPrompt.ToLower())
                        {
                            Debug.Console(0,
                                          "WARNING: Config file defines processor type as '{0}' but actual processor is '{1}'!  Some ports may not be available",
                                          devConf.Type.ToUpper(), Global.ControlSystem.ControllerPrompt.ToUpper());
                        }

                        // Check if the processor is a DMPS model
                        if (this.ControllerPrompt.IndexOf("dmps", StringComparison.OrdinalIgnoreCase) > -1)
                        {
                            Debug.Console(2, "Adding DmpsRoutingController for {0} to Device Manager.", this.ControllerPrompt);

                            var propertiesConfig = JsonConvert.DeserializeObject <DM.Config.DmpsRoutingPropertiesConfig>(devConf.Properties.ToString());

                            if (propertiesConfig == null)
                            {
                                propertiesConfig = new DM.Config.DmpsRoutingPropertiesConfig();
                            }

                            var dmpsRoutingController = DmpsRoutingController.GetDmpsRoutingController("processor-avRouting", this.ControllerPrompt, propertiesConfig);

                            DeviceManager.AddDevice(dmpsRoutingController);
                        }
                        else
                        {
                            Debug.Console(2, "************Processor is not DMPS type***************");
                        }

                        continue;
                    }

                    // Try local factories first
                    var newDev = DeviceFactory.GetDevice(devConf);

                    if (newDev == null)
                    {
                        newDev = BridgeFactory.GetDevice(devConf);
                    }

                    // Then associated library factories
                    if (newDev == null)
                    {
                        newDev = PepperDash.Essentials.Core.DeviceFactory.GetDevice(devConf);
                    }
                    if (newDev == null)
                    {
                        newDev = PepperDash.Essentials.Devices.Common.DeviceFactory.GetDevice(devConf);
                    }
                    if (newDev == null)
                    {
                        newDev = PepperDash.Essentials.DM.DeviceFactory.GetDevice(devConf);
                    }
                    if (newDev == null)
                    {
                        newDev = PepperDash.Essentials.Devices.Displays.DisplayDeviceFactory.GetDevice(devConf);
                    }

                    //if (newDev == null) // might want to consider the ability to override an essentials "type"
                    //{
                    //    // iterate plugin factories
                    //    foreach (var f in FactoryObjects)
                    //    {
                    //        var cresFactory = f as IGetCrestronDevice;
                    //        if (cresFactory != null)
                    //        {
                    //            newDev = cresFactory.GetDevice(devConf, this);
                    //        }
                    //    }
                    //}

                    if (newDev != null)
                    {
                        DeviceManager.AddDevice(newDev);
                    }
                    else
                    {
                        Debug.Console(0, Debug.ErrorLogLevel.Notice, "ERROR: Cannot load unknown device type '{0}', key '{1}'.", devConf.Type, devConf.Key);
                    }
                }
                catch (Exception e)
                {
                    Debug.Console(0, Debug.ErrorLogLevel.Notice, "ERROR: Creating device {0}. Skipping device. \r{1}", devConf.Key, e);
                }
            }
            Debug.Console(0, Debug.ErrorLogLevel.Notice, "All Devices Loaded.");
        }