Esempio n. 1
0
        public static TieLine TieLineFromStrings(string sourceKey, string sourcePortKey, string destinationKey, string destinationPortKey)
        {
            var sourceDev = DeviceManager.GetDeviceForKey(sourceKey) as IRoutingOutputs;

            if (sourceDev == null)
            {
                Debug.Console(1, "WARNING: Cannot create tie line, routable source '{0}' not found", sourceKey);
                return(null);
            }
            var destDev = DeviceManager.GetDeviceForKey(destinationKey) as IRoutingInputs;

            if (destDev == null)
            {
                Debug.Console(1, "WARNING: Cannot create tie line, routable destination '{0}' not found", destinationKey);
                return(null);
            }
            var sourcePort = sourceDev.OutputPorts[sourcePortKey];

            if (sourcePort == null)
            {
                Debug.Console(1, "WARNING: Cannot create tie line. Source '{0}' does not contain port '{1}'", sourceKey, sourcePortKey);
                return(null);
            }
            var destPort = destDev.InputPorts[destinationPortKey];

            if (destPort == null)
            {
                Debug.Console(1, "WARNING: Cannot create tie line. Destination '{0}' does not contain port '{1}'", destinationKey, destinationPortKey);
                return(null);
            }

            return(new TieLine(sourcePort, destPort));
        }
Esempio n. 2
0
        /// <summary>
        ///  Gets an ICec port from a RoutingInput or RoutingOutput on a device
        /// </summary>
        /// <param name="config"></param>
        /// <returns></returns>
        public static ICec GetCecPort(ControlPropertiesConfig config)
        {
            var dev = DeviceManager.GetDeviceForKey(config.ControlPortDevKey);

            if (dev != null)
            {
                var inputPort = (dev as IRoutingInputsOutputs).InputPorts[config.ControlPortName];

                if (inputPort != null)
                {
                    if (inputPort.Port is ICec)
                    {
                        return(inputPort.Port as ICec);
                    }
                }

                var outputPort = (dev as IRoutingInputsOutputs).OutputPorts[config.ControlPortName];

                if (outputPort != null)
                {
                    if (outputPort.Port is ICec)
                    {
                        return(outputPort.Port as ICec);
                    }
                }
            }
            Debug.Console(0, "GetCecPort: Device '{0}' does not have a CEC port called: '{1}'", config.ControlPortDevKey, config.ControlPortName);
            return(null);
        }
Esempio n. 3
0
        public RoomOnToDefaultSourceWhenOccupied(DeviceConfig config) :
            base(config)
        {
            PropertiesConfig = JsonConvert.DeserializeObject <RoomOnToDefaultSourceWhenOccupiedConfig>(config.Properties.ToString());

            FeatureEventGroup = new ScheduledEventGroup(this.Key);

            FeatureEventGroup.RetrieveAllEvents();

            // Add to the global class for tracking
            Scheduler.AddEventGroup(FeatureEventGroup);

            AddPostActivationAction(() =>
            {
                // Subscribe to room event to know when RoomOccupancy is set and ready to be subscribed to
                if (Room != null)
                {
                    Room.RoomOccupancyIsSet += new EventHandler <EventArgs>(RoomOccupancyIsSet);
                }

                else
                {
                    Debug.Console(1, this, "Room has no RoomOccupancy object set");
                }

                var fusionRoomKey = PropertiesConfig.RoomKey + "-fusion";

                FusionRoom = DeviceManager.GetDeviceForKey(fusionRoomKey) as Core.Fusion.EssentialsHuddleSpaceFusionSystemControllerBase;

                if (FusionRoom == null)
                {
                    Debug.Console(1, this, "Unable to get Fusion Room from Device Manager with key: {0}", fusionRoomKey);
                }
            });
        }
Esempio n. 4
0
        /// <summary>
        /// Finds either the ControlSystem or a device controller that contains IR ports and
        /// returns a port from the hardware device
        /// </summary>
        /// <param name="propsToken"></param>
        /// <returns>IrPortConfig object.  The port and or filename will be empty/null
        /// if valid values don't exist on config</returns>
        public static IrOutPortConfig GetIrPort(JToken propsToken)
        {
            var control = propsToken["control"];

            if (control == null)
            {
                return(null);
            }
            if (control["method"].Value <string>() != "ir")
            {
                Debug.Console(0, "IRPortHelper called with non-IR properties");
                return(null);
            }

            var port = new IrOutPortConfig();

            var portDevKey = control.Value <string>("controlPortDevKey");
            var portNum    = control.Value <uint>("controlPortNumber");

            if (portDevKey == null || portNum == 0)
            {
                Debug.Console(1, "WARNING: Properties is missing port device or port number");
                return(port);
            }

            IIROutputPorts irDev = null;

            if (portDevKey.Equals("controlSystem", StringComparison.OrdinalIgnoreCase) ||
                portDevKey.Equals("processor", StringComparison.OrdinalIgnoreCase))
            {
                irDev = Global.ControlSystem;
            }
            else
            {
                irDev = DeviceManager.GetDeviceForKey(portDevKey) as IIROutputPorts;
            }

            if (irDev == null)
            {
                Debug.Console(1, "[Config] Error, device with IR ports '{0}' not found", portDevKey);
                return(port);
            }

            if (portNum <= irDev.NumberOfIROutputPorts)             // success!
            {
                var file = IrDriverPathPrefix + control["irFile"].Value <string>();
                port.Port     = irDev.IROutputPorts[portNum];
                port.FileName = file;
                return(port);                // new IrOutPortConfig { Port = irDev.IROutputPorts[portNum], FileName = file };
            }
            else
            {
                Debug.Console(1, "[Config] Error, device '{0}' IR port {1} out of range",
                              portDevKey, portNum);
                return(port);
            }
        }
Esempio n. 5
0
 /// <summary>
 /// Helper to grab the IComPorts device for this PortDeviceKey. Key "controlSystem" will
 /// return the ControlSystem object from the Global class.
 /// </summary>
 /// <returns>IComPorts device or null if the device is not found or does not implement IComPorts</returns>
 public static IComPorts GetIComPortsDeviceFromManagedDevice(string ComPortDevKey)
 {
     if ((ComPortDevKey.Equals("controlSystem", System.StringComparison.OrdinalIgnoreCase) ||
          ComPortDevKey.Equals("processor", System.StringComparison.OrdinalIgnoreCase)) &&
         Global.ControlSystem is IComPorts)
     {
         return(Global.ControlSystem);
     }
     else
     {
         var dev = DeviceManager.GetDeviceForKey(ComPortDevKey) as IComPorts;
         if (dev == null)
         {
             Debug.Console(0, "ComPortConfig: Cannot find com port device '{0}'", ComPortDevKey);
         }
         return(dev);
     }
 }
Esempio n. 6
0
        /// <summary>
        /// Returns a ready-to-go IrOutputPortController from a DeviceConfig object.
        /// </summary>
        public static IrOutputPortController GetIrOutputPortController(DeviceConfig devConf)
        {
            var irControllerKey = devConf.Key + "-ir";

            if (devConf.Properties == null)
            {
                Debug.Console(0, "[{0}] WARNING: Device config does not include properties.  IR will not function.", devConf.Key);
                return(new IrOutputPortController(irControllerKey, null, ""));
            }

            var control = devConf.Properties["control"];

            if (control == null)
            {
                var c = new IrOutputPortController(irControllerKey, null, "");
                Debug.Console(0, c, "WARNING: Device config does not include control properties.  IR will not function");
                return(c);
            }

            var            portDevKey = control.Value <string>("controlPortDevKey");
            var            portNum    = control.Value <uint>("controlPortNumber");
            IIROutputPorts irDev      = null;

            if (portDevKey == null)
            {
                var c = new IrOutputPortController(irControllerKey, null, "");
                Debug.Console(0, c, "WARNING: control properties is missing ir device");
                return(c);
            }

            if (portNum == 0)
            {
                var c = new IrOutputPortController(irControllerKey, null, "");
                Debug.Console(0, c, "WARNING: control properties is missing ir port number");
                return(c);
            }

            if (portDevKey.Equals("controlSystem", StringComparison.OrdinalIgnoreCase) ||
                portDevKey.Equals("processor", StringComparison.OrdinalIgnoreCase))
            {
                irDev = Global.ControlSystem;
            }
            else
            {
                irDev = DeviceManager.GetDeviceForKey(portDevKey) as IIROutputPorts;
            }

            if (irDev == null)
            {
                var c = new IrOutputPortController(irControllerKey, null, "");
                Debug.Console(0, c, "WARNING: device with IR ports '{0}' not found", portDevKey);
                return(c);
            }

            if (portNum <= irDev.NumberOfIROutputPorts)             // success!
            {
                return(new IrOutputPortController(irControllerKey, irDev.IROutputPorts[portNum],
                                                  IrDriverPathPrefix + control["irFile"].Value <string>()));
            }
            else
            {
                var c = new IrOutputPortController(irControllerKey, null, "");
                Debug.Console(0, c, "WARNING: device '{0}' IR port {1} out of range",
                              portDevKey, portNum);
                return(c);
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Sets up device based on config values
        /// </summary>
        void SetUpDevice()
        {
            Room = DeviceManager.GetDeviceForKey(PropertiesConfig.RoomKey) as EssentialsRoomBase;

            if (Room != null)
            {
                try
                {
                    FeatureEnabledTime = DateTime.Parse(PropertiesConfig.OccupancyStartTime);

                    if (FeatureEnabledTime != null)
                    {
                        Debug.Console(1, this, "Enabled Time: {0}", FeatureEnabledTime.ToString());
                    }
                    else
                    {
                        Debug.Console(1, this, "Unable to parse {0} to DateTime", PropertiesConfig.OccupancyStartTime);
                    }
                }
                catch (Exception e)
                {
                    Debug.Console(1, this, "Unable to parse OccupancyStartTime property: {0} \n Error: {1}", PropertiesConfig.OccupancyStartTime, e);
                }

                try
                {
                    FeatureDisabledTime = DateTime.Parse(PropertiesConfig.OccupancyEndTime);

                    if (FeatureDisabledTime != null)
                    {
                        Debug.Console(1, this, "Disabled Time: {0}", FeatureDisabledTime.ToString());
                    }
                    else
                    {
                        Debug.Console(1, this, "Unable to parse {0} to DateTime", PropertiesConfig.OccupancyEndTime);
                    }
                }
                catch (Exception e)
                {
                    Debug.Console(1, this, "Unable to parse a DateTime config value \n Error: {1}", e);
                }

                if (!PropertiesConfig.EnableRoomOnWhenOccupied)
                {
                    FeatureEventGroup.ClearAllEvents();
                }
                else
                {
                    AddEnableEventToGroup();

                    AddDisableEventToGroup();

                    FeatureEventGroup.UserGroupCallBack += new ScheduledEventGroup.UserEventGroupCallBack(FeatureEventGroup_UserGroupCallBack);

                    FeatureEventGroup.EnableAllEvents();
                }

                FeatureEnabled = CheckIfFeatureShouldBeEnabled();
            }
            else
            {
                Debug.Console(1, this, "Unable to get room from Device Manager with key: {0}", PropertiesConfig.RoomKey);
            }
        }
Esempio n. 8
0
        /// <summary>
        ///  Walks down a dotted object path, starting with a Device, and returns the object
        ///  at the end of the path
        /// </summary>
        public static object FindObjectOnPath(string deviceObjectPath)
        {
            var path = deviceObjectPath.Split('.');

            var dev = DeviceManager.GetDeviceForKey(path[0]);

            if (dev == null)
            {
                Debug.Console(0, "Device {0} not found", path[0]);
                return(null);
            }

            // loop through any dotted properties
            object obj = dev;

            if (path.Length > 1)
            {
                for (int i = 1; i < path.Length; i++)
                {
                    var    objName   = path[i];
                    string indexStr  = null;
                    var    indexOpen = objName.IndexOf('[');
                    if (indexOpen != -1)
                    {
                        var indexClose = objName.IndexOf(']');
                        if (indexClose == -1)
                        {
                            Debug.Console(0, dev, "ERROR Unmatched index brackets");
                            return(null);
                        }
                        // Get the index and strip quotes if any
                        indexStr = objName.Substring(indexOpen + 1, indexClose - indexOpen - 1).Replace("\"", "");
                        objName  = objName.Substring(0, indexOpen);
                        Debug.Console(0, dev, "  Checking for collection '{0}', index '{1}'", objName, indexStr);
                    }

                    CType oType = obj.GetType();
                    var   prop  = oType.GetProperty(objName);
                    if (prop == null)
                    {
                        Debug.Console(0, dev, "Property {0} not found on {1}", objName, path[i - 1]);
                        return(null);
                    }
                    // if there's an index, try to get the property
                    if (indexStr != null)
                    {
                        if (!typeof(ICollection).IsAssignableFrom(prop.PropertyType))
                        {
                            Debug.Console(0, dev, "Property {0} is not collection", objName);
                            return(null);
                        }
                        var collection = prop.GetValue(obj, null) as ICollection;
                        // Get the indexed items "property"
                        var indexedPropInfo = prop.PropertyType.GetProperty("Item");
                        // These are the parameters for the indexing. Only care about one
                        var indexParams = indexedPropInfo.GetIndexParameters();
                        if (indexParams.Length > 0)
                        {
                            Debug.Console(0, "  Indexed, param type: {0}", indexParams[0].ParameterType.Name);
                            var properParam = Convert.ChangeType(indexStr, indexParams[0].ParameterType,
                                                                 System.Globalization.CultureInfo.InvariantCulture);
                            try
                            {
                                obj = indexedPropInfo.GetValue(collection, new object[] { properParam });
                            }
                            // if the index is bad, catch it here.
                            catch (Crestron.SimplSharp.Reflection.TargetInvocationException e)
                            {
                                if (e.InnerException is ArgumentOutOfRangeException)
                                {
                                    Debug.Console(0, "  Index Out of range");
                                }
                                else if (e.InnerException is KeyNotFoundException)
                                {
                                    Debug.Console(0, "  Key not found");
                                }
                                return(null);
                            }
                        }
                    }
                    else
                    {
                        obj = prop.GetValue(obj, null);
                    }
                }
            }
            return(obj);
        }