Example #1
0
        /// <summary>
        /// Gets value indicating if device is enabled.
        /// </summary>
        /// <param name="parent">The root device.</param>
        /// <param name="child">The device.</param>
        /// <returns></returns>
        public bool GetDeviceEnabled(DeviceDataBase parent, DeviceDataBase child)
        {
            configLock.EnterReadLock();
            try
            {
                if (enabledDevices.TryGetValue(parent.Name, out var childEnabled))
                {
                    if (childEnabled.TryGetValue(child.Name, out bool enabled))
                    {
                        return(enabled);
                    }
                }
            }
            finally
            {
                configLock.ExitReadLock();
            }

            return(false);
        }
Example #2
0
        /// <summary>
        /// Sets the device enabled value.
        /// </summary>
        /// <param name="parent">The parent device.</param>
        /// <param name="child">The device.</param>
        /// <param name="enabled">if set to <c>true</c> [enabled].</param>
        /// <exception cref="ArgumentException">Invalid values</exception>
        public void SetDeviceEnabled(DeviceDataBase parent, DeviceDataBase child, bool enabled)
        {
            configLock.EnterWriteLock();
            try
            {
                IDictionary <string, bool> childEnabled;
                if (enabledDevices.TryGetValue(parent.Name, out childEnabled))
                {
                    if (childEnabled.ContainsKey(child.Name))
                    {
                        bool tmpOldValue = childEnabled[child.Name];
                        SetValue(child.Name, enabled, ref tmpOldValue, parent.Name);
                        childEnabled[child.Name] = enabled;
                        return;
                    }
                }

                throw new ArgumentException("Invalid values");
            }
            finally
            {
                configLock.ExitWriteLock();
            }
        }
Example #3
0
        /// <summary>
        /// Creates the HS device.
        /// </summary>
        /// <param name="parent">The data for parent of device.</param>
        /// <param name="rootDeviceData">The root device data.</param>
        /// <param name="deviceData">The device data.</param>
        /// <returns>New Device</returns>
        private DeviceClass CreateDevice([AllowNull] DeviceClass parent, [AllowNull] RootDeviceData rootDeviceData, DeviceDataBase deviceData)
        {
            if (rootDeviceData != null)
            {
                LogDebug(Invariant($"Creating {deviceData.Name} under {rootDeviceData.Name}"));
            }
            else
            {
                LogDebug(Invariant($"Creating Root {deviceData.Name}"));
            }

            DeviceClass device = null;
            int         refId  = HS.NewDeviceRef(rootDeviceData != null ? Invariant($"{rootDeviceData.Name} {deviceData.Name}") : deviceData.Name);

            if (refId > 0)
            {
                device = (DeviceClass)HS.GetDeviceByRef(refId);
                string address = rootDeviceData != null?CreateChildAddress(rootDeviceData.Name, deviceData.Name) : deviceData.Name;

                device.set_Address(HS, address);
                device.set_Device_Type_String(HS, deviceData.HSDeviceTypeString);
                var deviceType = new DeviceTypeInfo_m.DeviceTypeInfo();
                deviceType.Device_API  = DeviceTypeInfo_m.DeviceTypeInfo.eDeviceAPI.Plug_In;
                deviceType.Device_Type = deviceData.HSDeviceType;

                device.set_DeviceType_Set(HS, deviceType);
                device.set_Interface(HS, Name);
                device.set_InterfaceInstance(HS, string.Empty);
                device.set_Last_Change(HS, DateTime.Now);
                device.set_Location(HS, Name);
                var pairs = deviceData.StatusPairs;
                foreach (var pair in pairs)
                {
                    HS.DeviceVSP_AddPair(refId, pair);
                }

                var gPairs = deviceData.GraphicsPairs;
                foreach (var gpair in gPairs)
                {
                    HS.DeviceVGP_AddPair(refId, gpair);
                }

                device.MISC_Set(HS, Enums.dvMISC.STATUS_ONLY);
                device.MISC_Set(HS, Enums.dvMISC.SHOW_VALUES);
                device.MISC_Clear(HS, Enums.dvMISC.AUTO_VOICE_COMMAND);
                device.MISC_Clear(HS, Enums.dvMISC.SET_DOES_NOT_CHANGE_LAST_CHANGE);
                device.set_Status_Support(HS, false);

                if (parent != null)
                {
                    parent.set_Relationship(HS, Enums.eRelationship.Parent_Root);
                    device.set_Relationship(HS, Enums.eRelationship.Child);
                    device.AssociatedDevice_Add(HS, parent.get_Ref(HS));
                    parent.AssociatedDevice_Add(HS, device.get_Ref(HS));
                }
                deviceData.SetInitialData(HS, device);
            }

            return(device);
        }
Example #4
0
 private static string NameToId(DeviceDataBase parent, DeviceDataBase child)
 {
     return(Invariant($"{NameToId(parent.Name)}_{NameToId(child.Name)}"));
 }