/// <summary> /// Sets the value of a configuration. /// </summary> /// <param name="name">The configuration value to set.</param> /// <param name="value">The value to assign to the configuration.</param> private void SetValue(ConfigurationNames name, object value) { ConfigurationAssocAttribute attribute = ReflectionHelper.GetAttribute <ConfigurationNames, ConfigurationAssocAttribute>(name); if (attribute == null) { return; } ConfigurationValidation validation = attribute.Validation; if (validation != ConfigurationValidation.None) { if (validation.HasFlag(ConfigurationValidation.NonNull) && value == null) { throw new ArgumentNullException("value"); } if (validation.HasFlag(ConfigurationValidation.NonZero) || validation.HasFlag(ConfigurationValidation.NonNegative) || validation.HasFlag(ConfigurationValidation.PortRange)) { int converted = Convert.ToInt32(value); if (validation.HasFlag(ConfigurationValidation.NonZero) && converted == 0) { throw new ArgumentOutOfRangeException("value", "The value of this configuration cannot be zero"); } if (validation.HasFlag(ConfigurationValidation.NonNegative) && converted < 0) { throw new ArgumentOutOfRangeException("value", "The value of this configuration cannot be below zero"); } if (validation.HasFlag(ConfigurationValidation.PortRange) && (converted <= 0 || short.MaxValue < converted)) { throw new ArgumentOutOfRangeException("value", "The value of this configuration must be within a valid port range"); } } if (validation.HasFlag(ConfigurationValidation.SizeDivision)) { double converted = Convert.ToDouble(value); if (converted % 1024 != 0) { throw new ArgumentException("The value of this configuration must be divisible by 1024"); } } } values[name] = value; if (PropertyChanged != null) { PropertyChanged(client, new PropertyChangedEventArgs(attribute.Name)); } SetConfCommand command = new SetConfCommand(attribute.Name, ReflectionHelper.Convert(value, typeof(string)) as string); Response response = command.Dispatch(client); }
/// <summary> /// Gets the value of a configuration. /// </summary> /// <param name="name">The configuration value to retrieve.</param> /// <returns>The value of the configuration.</returns> private object GetValue(ConfigurationNames name) { if (values.ContainsKey(name)) { return(values[name]); } return(null); }
/// <summary> /// Sets the value of a configuration directly, without raising any <c>setconf</c> commands. /// </summary> /// <param name="name">The name of the configuration value to set.</param> /// <param name="value">The value to assign to the configuration.</param> internal void SetValueDirect(string name, string value) { if (name == null) { throw new ArgumentNullException("name"); } ConfigurationNames association = ReflectionHelper.GetEnumerator <ConfigurationNames, ConfigurationAssocAttribute>(attr => attr.Name.Equals(name, StringComparison.CurrentCultureIgnoreCase)); ConfigurationAssocAttribute attribute = ReflectionHelper.GetAttribute <ConfigurationNames, ConfigurationAssocAttribute>(association); if (attribute.Name.Equals(name, StringComparison.CurrentCultureIgnoreCase)) { values[association] = ReflectionHelper.Convert(value, attribute.Type); if (PropertyChanged != null) { PropertyChanged(client, new PropertyChangedEventArgs(attribute.Name)); } } }
/// <summary> /// Checks if the configuration exists in the active document /// </summary> /// <param name="name">Name of the configuration to check for</param> /// <returns></returns> public bool ConfigurationExists(string name) => ConfigurationNames.Exists(x => x == name);
/// <summary> /// Sets the value of a configuration supplied with the process arguments. Setting a configuration value within the create /// parameters overrides any values stored in the configuration file. The control port can also be set using this method. /// </summary> /// <param name="configuration">The configuration which should be overridden.</param> /// <param name="value">The value of the configuration. This should align with the type specified in the <see cref="Tor.Config.Configuration"/> class.</param> public void SetConfig(ConfigurationNames configuration, object value) { ConfigurationAssocAttribute attribute = ReflectionHelper.GetAttribute <ConfigurationNames, ConfigurationAssocAttribute>(configuration); if (attribute == null) { return; } if (value != null && !value.GetType().Equals(attribute.Type)) { throw new ArgumentException("The value of this configuration should be of type " + attribute.Type, "value"); } ConfigurationValidation validation = attribute.Validation; if (validation != ConfigurationValidation.None) { if (validation.HasFlag(ConfigurationValidation.NonNull) && value == null) { throw new ArgumentNullException("value"); } if (validation.HasFlag(ConfigurationValidation.NonZero) || validation.HasFlag(ConfigurationValidation.NonNegative) || validation.HasFlag(ConfigurationValidation.PortRange)) { int converted = Convert.ToInt32(value); if (validation.HasFlag(ConfigurationValidation.NonZero) && converted == 0) { throw new ArgumentOutOfRangeException("value", "The value of this configuration cannot be zero"); } if (validation.HasFlag(ConfigurationValidation.NonNegative) && converted < 0) { throw new ArgumentOutOfRangeException("value", "The value of this configuration cannot be below zero"); } if (validation.HasFlag(ConfigurationValidation.PortRange) && (converted <= 0 || short.MaxValue < converted)) { throw new ArgumentOutOfRangeException("value", "The value of this configuration must be within a valid port range"); } } if (validation.HasFlag(ConfigurationValidation.SizeDivision)) { double converted = Convert.ToDouble(value); if (converted % 1024 != 0) { throw new ArgumentException("The value of this configuration must be divisible by 1024"); } } } if (configuration == ConfigurationNames.ControlPort) { controlPort = Convert.ToInt32(value); } else { overrides[configuration] = value; } }
static Type FindType(CellProcessor processor, string facilityName, string action) { return(processor.ApplicationUnderTest.FindType(new GracefulNameMatcher(ConfigurationNames.TypeName(facilityName, action))).Type); }