Esempio n. 1
0
 internal static void MappedPropertyMustBeSet <TRunInfo, TProperty>(SetArgument <TRunInfo, TProperty> argument,
                                                                    int commandLevel) where TRunInfo : class
 {
     if (argument.Property == null)
     {
         throw new CommandValidationException("Set Argument is missing its property mapping expression.",
                                              CommandValidationError.NullPropertyExpression, commandLevel);
     }
 }
Esempio n. 2
0
 internal static void ValuesMustBeSet <TRunInfo, TProperty>(SetArgument <TRunInfo, TProperty> argument,
                                                            int commandLevel) where TRunInfo : class
 {
     if (argument.Values == null)
     {
         throw new CommandValidationException("List of values for the set must be provided.",
                                              CommandValidationError.NullObject, commandLevel);
     }
 }
Esempio n. 3
0
 internal static void ValueValuesMustBeUnique <TRunInfo, TProperty>(SetArgument <TRunInfo, TProperty> argument,
                                                                    int commandLevel) where TRunInfo : class
 {
     if (argument.Values.Select(v => v.Value).Distinct().Count() != argument.Values.Count)
     {
         throw new CommandValidationException("Set Argument values must be unique within a set.",
                                              CommandValidationError.DuplicateKey, commandLevel);
     }
 }
Esempio n. 4
0
 internal static void MappedPropertyIsWritable <TRunInfo, TProperty>(SetArgument <TRunInfo, TProperty> argument,
                                                                     int commandLevel) where TRunInfo : class
 {
     if (!ReflectionHelper <TRunInfo> .PropertyIsWritable(argument.Property, out string propertyName))
     {
         throw new CommandValidationException($"Set Argument's property '{propertyName}' "
                                              + "is not writable. Try adding a setter.",
                                              CommandValidationError.PropertyNotWritable, commandLevel);
     }
 }
Esempio n. 5
0
 private static Action <int> ValuesMustBeSet <TRunInfo, TProperty>(SetArgument <TRunInfo, TProperty> argument)
     where TRunInfo : class
 {
     return(commandLevel =>
     {
         if (argument.Values == null)
         {
             throw new CommandValidationException("List of values for the set must be provided.",
                                                  CommandValidationError.NullObject, commandLevel);
         }
     });
 }
Esempio n. 6
0
 internal static List <Action <int> > Rules <TRunInfo, TProperty>(SetArgument <TRunInfo, TProperty> argument)
     where TRunInfo : class
 {
     return(new List <Action <int> >
     {
         MappedPropertyMustBeSet(argument),
         MappedPropertyIsWritable(argument),
         ValuesMustBeSet(argument),
         ValuesMustContainAtLeastTwoItems(argument),
         ValueLabelsMustBeUnique(argument),
         ValueValuesMustBeUnique(argument)
     });
 }
        /// <summary>
        /// Sets the specified argument.
        /// </summary>
        /// <param name="argument">The argument.</param>
        /// <param name="elementId">The element identifier.</param>
        /// <param name="value">The optional value.</param>
        /// <returns></returns>
        public JObject Set(SetArgument argument, int elementId, string value = null)
        {
            var argumentValue = argument.GetEnumMemberValue();

            this.CheckDeviceIdRange(elementId, argumentValue);
            if (string.IsNullOrEmpty(value))
            {
                return(this.DoRequest($"Set{argumentValue}={this.FormatDeviceId(elementId, argumentValue)}"));
            }
            else
            {
                return(this.DoRequest($"Set{argumentValue}{this.FormatDeviceId(elementId, argumentValue)}={value}"));
            }
        }
        /// <summary>
        /// Toggles the specified argument.
        /// </summary>
        /// <param name="argument">The argument.</param>
        /// <param name="elementId">The element identifier.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentOutOfRangeException">argument - Unsupported argument for this action</exception>
        public JObject Toggle(SetArgument argument, int elementId)
        {
            switch (argument)
            {
            case SetArgument.Output:
            case SetArgument.VirtualInput:
            case SetArgument.VirtualOutput:
            case SetArgument.EnOcean:
                var argumentValue = argument.GetEnumMemberValue();
                this.CheckDeviceIdRange(elementId, argumentValue);
                return(this.DoRequest($"Toggle{argumentValue}={this.FormatDeviceId(elementId, argumentValue)}"));

            default:
                throw new ArgumentOutOfRangeException(nameof(argument), "Unsupported argument for this action");
            }
        }
Esempio n. 9
0
        private void SetValue(SetArgument type, string id, string value)
        {
            var args = string.IsNullOrEmpty(id) ? (type, Int32.MaxValue) : this.ParseIdentifier(id);

            if (args.Type == null)
            {
                throw new ArgumentException(nameof(id), "Invalid identifier");
            }
            else if (args.Type == type)
            {
                this.Interface.Set(type, args.DeviceId, value);
            }
            else
            {
                throw new NotSupportedException("This identifier doesn't support this command");
            }
        }
Esempio n. 10
0
 /// <summary>
 /// SetArgument as SubtractSetting
 /// </summary>
 public static SetArgument.SubtractSetting AsSubtractSetting(this SetArgument setArgument)
 {
     return((SetArgument.SubtractSetting)setArgument);
 }
Esempio n. 11
0
 /// <summary>
 /// SetArgument as MultiplySetting
 /// </summary>
 public static SetArgument.MultiplySetting AsMultiplySetting(this SetArgument setArgument)
 {
     return((SetArgument.MultiplySetting)setArgument);
 }
Esempio n. 12
0
 /// <summary>
 /// SetArgument as AddSetting
 /// </summary>
 public static SetArgument.AddSetting AsAddSetting(this SetArgument setArgument)
 {
     return((SetArgument.AddSetting)setArgument);
 }
Esempio n. 13
0
 /// <summary>
 /// SetArgument as InvertSetting
 /// </summary>
 public static SetArgument.InvertSetting AsInvertSetting(this SetArgument setArgument)
 {
     return((SetArgument.InvertSetting)setArgument);
 }
Esempio n. 14
0
 /// <summary>
 /// SetArgument as ToggleOffSetting
 /// </summary>
 public static SetArgument.ToggleOffSetting AsToggleOffSetting(this SetArgument setArgument)
 {
     return((SetArgument.ToggleOffSetting)setArgument);
 }
Esempio n. 15
0
 /// <summary>
 /// SetArgument as UseSetting
 /// </summary>
 public static SetArgument.UseSetting AsUseSetting(this SetArgument setArgument)
 {
     return((SetArgument.UseSetting)setArgument);
 }
Esempio n. 16
0
 /// <summary>
 /// SetArgument as SetArgument
 /// </summary>
 public static SetArgument.DisplaySetting AsDisplaySetting(this SetArgument setArgument)
 {
     return((SetArgument.DisplaySetting)setArgument);
 }
Esempio n. 17
0
 private static Action <int> MappedPropertyMustBeSet <TRunInfo, TProperty>(SetArgument <TRunInfo, TProperty> argument)
     where TRunInfo : class
 {
     return(commandLevel =>
     {
         if (argument.Property == null)
         {
             throw new CommandValidationException("Set Argument is missing its property mapping expression.",
                                                  CommandValidationError.NullPropertyExpression, commandLevel);
         }
     });
 }
Esempio n. 18
0
 internal static void ValuesMustContainAtLeastTwoItems <TRunInfo, TProperty>(SetArgument <TRunInfo, TProperty> argument,
                                                                             int commandLevel) where TRunInfo : class
 {
     if (argument.Values.Count <= 1)
     {
         throw new CommandValidationException("Set Arguments must contain at least two items.",
                                              CommandValidationError.InsufficientCount, commandLevel);
     }
 }
Esempio n. 19
0
 private static Action <int> ValuesMustContainAtLeastTwoItems <TRunInfo, TProperty>(SetArgument <TRunInfo, TProperty> argument)
     where TRunInfo : class
 {
     return(commandLevel =>
     {
         if (argument.Values.Count <= 1)
         {
             throw new CommandValidationException("Set Arguments must contain at least two items.",
                                                  CommandValidationError.InsufficientCount, commandLevel);
         }
     });
 }
Esempio n. 20
0
 private static Action <int> ValueLabelsMustBeUnique <TRunInfo, TProperty>(SetArgument <TRunInfo, TProperty> argument)
     where TRunInfo : class
 {
     return(commandLevel =>
     {
         if (argument.Values.Select(v => v.Label).Distinct().Count() != argument.Values.Count)
         {
             throw new CommandValidationException("Set Argument value labels must be unique within a set.",
                                                  CommandValidationError.DuplicateKey, commandLevel);
         }
     });
 }