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); } }
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); } }
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); } }
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); } }
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); } }); }
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"); } }
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"); } }
/// <summary> /// SetArgument as SubtractSetting /// </summary> public static SetArgument.SubtractSetting AsSubtractSetting(this SetArgument setArgument) { return((SetArgument.SubtractSetting)setArgument); }
/// <summary> /// SetArgument as MultiplySetting /// </summary> public static SetArgument.MultiplySetting AsMultiplySetting(this SetArgument setArgument) { return((SetArgument.MultiplySetting)setArgument); }
/// <summary> /// SetArgument as AddSetting /// </summary> public static SetArgument.AddSetting AsAddSetting(this SetArgument setArgument) { return((SetArgument.AddSetting)setArgument); }
/// <summary> /// SetArgument as InvertSetting /// </summary> public static SetArgument.InvertSetting AsInvertSetting(this SetArgument setArgument) { return((SetArgument.InvertSetting)setArgument); }
/// <summary> /// SetArgument as ToggleOffSetting /// </summary> public static SetArgument.ToggleOffSetting AsToggleOffSetting(this SetArgument setArgument) { return((SetArgument.ToggleOffSetting)setArgument); }
/// <summary> /// SetArgument as UseSetting /// </summary> public static SetArgument.UseSetting AsUseSetting(this SetArgument setArgument) { return((SetArgument.UseSetting)setArgument); }
/// <summary> /// SetArgument as SetArgument /// </summary> public static SetArgument.DisplaySetting AsDisplaySetting(this SetArgument setArgument) { return((SetArgument.DisplaySetting)setArgument); }
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); } }); }
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); } }
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); } }); }
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); } }); }