internal static bool IsDisabledBySetting(string settingName, MethodInfo method, INameResolver nameResolver) { if (nameResolver != null) { settingName = nameResolver.ResolveWholeString(settingName); } BindingTemplate bindingTemplate = BindingTemplate.FromString(settingName); Dictionary <string, string> bindingData = new Dictionary <string, string>(); bindingData.Add("MethodName", string.Format(CultureInfo.InvariantCulture, "{0}.{1}", method.DeclaringType.Name, method.Name)); bindingData.Add("MethodShortName", method.Name); settingName = bindingTemplate.Bind(bindingData); // check the target setting and return false (disabled) if the value exists // and is "falsey" string value = ConfigurationUtility.GetSettingFromConfigOrEnvironment(settingName); if (!string.IsNullOrEmpty(value) && (string.Compare(value, "1", StringComparison.OrdinalIgnoreCase) == 0 || string.Compare(value, "true", StringComparison.OrdinalIgnoreCase) == 0)) { return(true); } return(false); }
/// <summary> /// Initializes a new instance of the <see cref="JobHostConfiguration"/> class, using the /// specified connection string for both reading and writing data as well as Dashboard logging. /// </summary> /// <param name="dashboardAndStorageConnectionString">The Azure Storage connection string to use. /// </param> public JobHostConfiguration(string dashboardAndStorageConnectionString) { if (!string.IsNullOrEmpty(dashboardAndStorageConnectionString)) { _storageAccountProvider = new DefaultStorageAccountProvider(this, dashboardAndStorageConnectionString); } else { _storageAccountProvider = new DefaultStorageAccountProvider(this); } Singleton = new SingletonConfiguration(); // add our built in services here IExtensionRegistry extensions = new DefaultExtensionRegistry(); ITypeLocator typeLocator = new DefaultTypeLocator(ConsoleProvider.Out, extensions); AddService <IExtensionRegistry>(extensions); AddService <StorageClientFactory>(new StorageClientFactory()); AddService <INameResolver>(new DefaultNameResolver()); AddService <IJobActivator>(DefaultJobActivator.Instance); AddService <ITypeLocator>(typeLocator); string value = ConfigurationUtility.GetSettingFromConfigOrEnvironment(Constants.EnvironmentSettingName); IsDevelopment = string.Compare(Constants.DevelopmentEnvironmentValue, value, StringComparison.OrdinalIgnoreCase) == 0; }
public void GetSettingFromConfigOrEnvironment_ConfigAndEnvironment_ConfigWins() { Environment.SetEnvironmentVariable("DisableSetting0", "1"); string value = ConfigurationUtility.GetSettingFromConfigOrEnvironment("DisableSetting0"); Assert.Equal("0", value); Environment.SetEnvironmentVariable("EnvironmentSetting", null); }
public void GetSettingFromConfigOrEnvironment_EnvironmentSetting_NoConfigSetting() { Environment.SetEnvironmentVariable("EnvironmentSetting", "1"); string value = ConfigurationUtility.GetSettingFromConfigOrEnvironment("EnvironmentSetting"); Assert.Equal("1", value); Environment.SetEnvironmentVariable("EnvironmentSetting", null); }
/// <summary> /// Attempts to first read a setting from the appSettings configuration section. /// If not found there, it will attempt to read from environment variables. /// </summary> /// <param name="settingName">The name of the setting to look up.</param> /// <returns>The setting, or <see langword="null"/> if no setting was found.</returns> public string GetSetting(string settingName) { // first try prefixing string prefixedSettingName = GetPrefixedSettingName(settingName); string setting = ConfigurationUtility.GetSettingFromConfigOrEnvironment(prefixedSettingName); if (string.IsNullOrEmpty(setting)) { // next try a direct unprefixed lookup setting = ConfigurationUtility.GetSettingFromConfigOrEnvironment(settingName); } return(setting); }
/// <summary> /// Initializes a new instance of the <see cref="JobHostConfiguration"/> class, using the /// specified connection string for both reading and writing data as well as Dashboard logging. /// </summary> /// <param name="dashboardAndStorageConnectionString">The Azure Storage connection string to use. /// </param> public JobHostConfiguration(string dashboardAndStorageConnectionString) { if (!string.IsNullOrEmpty(dashboardAndStorageConnectionString)) { _storageAccountProvider = new DefaultStorageAccountProvider(this, dashboardAndStorageConnectionString); } else { _storageAccountProvider = new DefaultStorageAccountProvider(this); } Singleton = new SingletonConfiguration(); Aggregator = new FunctionResultAggregatorConfiguration(); // add our built in services here _tooling = new JobHostMetadataProvider(this); IExtensionRegistry extensions = new DefaultExtensionRegistry(_tooling); ITypeLocator typeLocator = new DefaultTypeLocator(ConsoleProvider.Out, extensions); IConverterManager converterManager = new ConverterManager(); IWebJobsExceptionHandler exceptionHandler = new WebJobsExceptionHandler(); AddService <IQueueConfiguration>(_queueConfiguration); AddService <IConsoleProvider>(ConsoleProvider); AddService <IStorageAccountProvider>(_storageAccountProvider); AddService <IExtensionRegistry>(extensions); AddService <StorageClientFactory>(new StorageClientFactory()); AddService <INameResolver>(new DefaultNameResolver()); AddService <IJobActivator>(DefaultJobActivator.Instance); AddService <ITypeLocator>(typeLocator); AddService <IConverterManager>(converterManager); AddService <IWebJobsExceptionHandler>(exceptionHandler); AddService <IFunctionResultAggregatorFactory>(new FunctionResultAggregatorFactory()); string value = ConfigurationUtility.GetSettingFromConfigOrEnvironment(Host.Constants.EnvironmentSettingName); IsDevelopment = string.Compare(Host.Constants.DevelopmentEnvironmentValue, value, StringComparison.OrdinalIgnoreCase) == 0; }
/// <summary> /// Resolves tokens by looking first in App Settings and then in environment variables. /// </summary> /// <param name="name">The token to resolve.</param> /// <returns>The token value from App Settings or environment variables. If the token is not found, null is returned.</returns> public virtual string Resolve(string name) { return(ConfigurationUtility.GetSettingFromConfigOrEnvironment(name)); }
public void GetSettingFromConfigOrEnvironment_ConfigSetting_NoEnvironmentSetting() { string value = ConfigurationUtility.GetSettingFromConfigOrEnvironment("DisableSetting0"); Assert.Equal("0", value); }
public void GetSettingFromConfigOrEnvironment_NotFound_ReturnsEmpty() { string value = ConfigurationUtility.GetSettingFromConfigOrEnvironment("DNE"); Assert.Equal(null, value); }