Ejemplo n.º 1
0
        public SetChannelSettingParameters(int sensorId, int channelId, ChannelProperty property, object value)
        {
            var attrib = property.GetEnumAttribute <RequireValueAttribute>();

            if (value == null && (attrib == null || (attrib != null && attrib.ValueRequired)))
            {
                throw new ArgumentNullException($"Property '{property}' does not support null values.");
            }

            var customParams = GetChannelSetObjectPropertyCustomParams(channelId, property, value);

            SensorId         = sensorId;
            CustomParameters = customParams;
        }
Ejemplo n.º 2
0
        private List <CustomParameter> GetChannelSetObjectPropertyCustomParams(int channelId, ChannelProperty property, object value)
        {
            bool valAsBool;
            var  valIsBool = bool.TryParse(value?.ToString(), out valAsBool);

            List <CustomParameter> customParams = new List <CustomParameter>();

            if (valIsBool)
            {
                if (valAsBool)
                {
                    value = 1;
                }

                else //if we're disabling a property, check if there are values dependent on us. if so, disable them too!
                {
                    value = 0;

                    var associatedProperties = property.GetDependentProperties <ChannelProperty>();

                    customParams.AddRange(associatedProperties.Select(prop => ObjectSettings.CreateCustomParameter(channelId, prop, string.Empty)));
                }
            }
            else //if we're enabling a property, check if there are values we depend on. if so, enable them!
            {
                var dependentProperty = property.GetEnumAttribute <DependentPropertyAttribute>();

                if (dependentProperty != null)
                {
                    customParams.Add(ObjectSettings.CreateCustomParameter(channelId, dependentProperty.Name.ToEnum <ChannelProperty>(), "1"));
                }
            }

            customParams.Add(ObjectSettings.CreateCustomParameter(channelId, property, value));

            return(customParams);
        }