public void ValueFor() { try { var key = new ConfigurationKey <int>("Key1"); var connectionConfiguration = new ConstantConfiguration( new Dictionary <ConfigurationKeyBase, object> { [ConfigurationKeys.ConsulAddress] = "http://localhost:8500", [ConfigurationKeys.ConsulDatacenter] = "dc1", [ConfigurationKeys.ConsulConfigurationPrefix] = "all-my-keys-start-with-this-value", }); var configuration = new ConsulConfiguration( new[] { key }, connectionConfiguration); var value = configuration.Value(key); Assert.AreEqual(10, value); } catch (ArgumentException e) { Assert.IsInstanceOf <ArgumentException>(e); } }
public string GetConfigurationContents(ClxApplication application, ConfigurationKey key) { string appConfigPath = GetSourceConfigPath(application); XmlDocument configDoc = new XmlDocument(); configDoc.Load(appConfigPath); ConfigurationSettings settings = ConfigurationSettingsLoader.GetInstance().GetConfigurationSettings(application, key); string settingsNodeName = configDoc.SelectSingleNode("/configuration/configSections").FirstChild.FirstChild.Attributes["name"].Value; XmlNode appSettingsNode = configDoc.SelectSingleNode("/configuration/applicationSettings/" + settingsNodeName); foreach (XmlNode settingsNode in appSettingsNode.ChildNodes) { if (settingsNode.Attributes["name"].Value == "PawnSecDBHost") { settingsNode.FirstChild.InnerText = settings.PawnSecDBHost; } else if (settingsNode.Attributes["name"].Value == "PawnSecDBPassword") { settingsNode.FirstChild.InnerText = settings.PawnSecDBPassword; } else if (settingsNode.Attributes["name"].Value == "PawnSecDBPort") { settingsNode.FirstChild.InnerText = settings.PawnSecDBPort; } else if (settingsNode.Attributes["name"].Value == "PawnSecDBSchema") { settingsNode.FirstChild.InnerText = settings.PawnSecDBSchema; } else if (settingsNode.Attributes["name"].Value == "PawnSecDBService") { settingsNode.FirstChild.InnerText = settings.PawnSecDBService; } else if (settingsNode.Attributes["name"].Value == "PawnSecDBUser") { settingsNode.FirstChild.InnerText = settings.PawnSecDBUser; } else if (settingsNode.Attributes["name"].Value == "prodEnv") { settingsNode.FirstChild.InnerText = settings.DstrProdEnv; } } StringBuilder sb = null; using (var stringWriter = new StringWriter()) using (var xmlTextWriter = XmlWriter.Create(stringWriter, new XmlWriterSettings() { Indent = true })) { configDoc.WriteTo(xmlTextWriter); sb = stringWriter.GetStringBuilder(); } return(sb.ToString()); }
public void HasValue() { var key = new ConfigurationKey <int>("my_property"); var configuration = new NullConfiguration(); var hasValue = configuration.HasValueFor(key); Assert.IsFalse(hasValue); }
public void ValueFor() { var key = new ConfigurationKey <int>("my_property"); var configuration = new NullConfiguration(); var value = configuration.Value(key); Assert.AreEqual(default(int), value); }
public void HasValue() { var key = new ConfigurationKey <int>("Key1"); var configuration = new ApplicationConfiguration(new[] { key }, "samples"); var hasValue = configuration.HasValueFor(key); Assert.IsTrue(hasValue); }
public bool TryGet <T>(ConfigurationKey key, out T value) { if (!_values.TryGetValue(key, out var tmp)) { value = default(T); return(false); } value = (T)tmp; return(true); }
// TODO move to a database table public string GetConfiguration(ConfigurationKey key) { switch (key) { case ConfigurationKey.ComponentTranslationGroupPrefix: return("C:"); default: throw new NotImplementedException(); } }
// <inheritdoc> public string Get(ConfigurationKey key, string defaultValue) { var val = this.Get(key); if (string.IsNullOrEmpty(val)) { val = defaultValue; } return(val); }
/// <summary> /// Gets the value as a Int16. /// </summary> /// <param name="key">The key.</param> /// <returns> /// The output value /// </returns> public short GetInt16(ConfigurationKey key) { short value; if (short.TryParse(this.GetStringValue(key), NumberStyles.Integer, CultureInfo.InvariantCulture, out value)) { return(value); } throw new ArgumentException(string.Format("The parameter {0} is not an int16", key)); }
/// <summary> /// Gets the value as a DateTime. /// </summary> /// <param name="key">The key.</param> /// <returns> /// The output value /// </returns> public TimeSpan GetTimeSpan(ConfigurationKey key) { var valueAsString = this.GetStringValue(key); TimeSpan outValue; if (TimeSpan.TryParse(valueAsString, CultureInfo.InvariantCulture, out outValue)) { return(outValue); } throw new ArgumentException(string.Format("The specified key ({0}) doesn't represent a valid TimeSpan ({1})", key, valueAsString)); }
public static string GetSetting(ConfigurationKey key) { string keyString = key.ToString(); var value = GetConfigFromConfigFile(keyString); if (value == null) { throw new ArgumentOutOfRangeException("key", string.Format("Cannot find setting with key {0}", keyString)); } return(value); }
public void HasValue() { var key = new ConfigurationKey <int>("my_property"); var configuration = new ConstantConfiguration( new Dictionary <ConfigurationKeyBase, object> { [key] = 10 }); var hasValue = configuration.HasValueFor(key); Assert.IsTrue(hasValue); }
public void Has_all_provider_configuration_keys() { Assert.Equal(new[] { ConfigurationKey.BootstrapServers, ConfigurationKey.BrokerVersionFallback, ConfigurationKey.ApiVersionFallbackMs, ConfigurationKey.SslCaLocation, ConfigurationKey.SaslUsername, ConfigurationKey.SaslPassword, ConfigurationKey.SaslMechanisms, ConfigurationKey.SecurityProtocol, }, ConfigurationKey.GetAllProducerKeys()); }
public IOperationResult <string> GetString(ConfigurationKey key) { if (_currentProtectedConfiguration.TryGetValue(key, out var protectedResult)) { var result = _dataProtector.Unprotect(protectedResult); // We disallow blank configuration keys. They breech security. if (string.IsNullOrWhiteSpace(result)) { return(OperationResult.Failure <string>(new Exception($"Configuration value is blank for key: {key}."))); } return(OperationResult.Success(result)); } return(OperationResult.Failure <string>(new Exception($"Configuration missing for key: {key}."))); }
public void ValueFor() { var constantValue = 10; var key = new ConfigurationKey <int>("my_property"); var configuration = new ConstantConfiguration( new Dictionary <ConfigurationKeyBase, object> { [key] = constantValue }); var value = configuration.Value(key); Assert.AreEqual(constantValue, value); }
public ActionResult EditConfiguration(ConfigurationKey configurationKey) { if (ModelState.IsValid) { ConfigurationKey newConfiguration = new ConfigurationKey { Key = configurationKey.Key, Value = configurationKey.Value }; repoConfig.Save(newConfiguration); this.SetMessage(InfoMessageType.Success, Resources.ProperlyEditedConfig); } return(Redirect(Url.Action("EditConfiguration", "Admin"))); }
public void ValueFor() { try { var key = new ConfigurationKey <int>("Key1"); var configuration = new ApplicationConfiguration(new[] { key }, "samples"); var value = configuration.Value(key); Assert.AreEqual(10, value); } catch (ArgumentException e) { Assert.IsInstanceOf <ArgumentException>(e); } }
/// <summary> /// Default Constructor /// </summary> public ProjectConfiguration() { this.projectConfigurationId = ""; this.projectId = ""; this.projectName = ""; this.configurationKeyId = ""; this.key = ""; this.group = ""; this.description = ""; this.value = ""; this.isTool = false; this.isSensitiveData = false; this.validationRegex = ""; this.project = new Project(); this.configurationKey = new ConfigurationKey(); }
public void Has_all_consumer_configuration_keys() { Assert.Equal(new[] { ConfigurationKey.GroupId, ConfigurationKey.EnableAutoCommit, ConfigurationKey.BootstrapServers, ConfigurationKey.BrokerVersionFallback, ConfigurationKey.ApiVersionFallbackMs, ConfigurationKey.SslCaLocation, ConfigurationKey.SaslUsername, ConfigurationKey.SaslPassword, ConfigurationKey.SaslMechanisms, ConfigurationKey.SecurityProtocol, }, ConfigurationKey.GetAllConsumerKeys()); }
public void HasValue() { var key = new ConfigurationKey <int>("Key1"); var connectionConfiguration = new ConstantConfiguration( new Dictionary <ConfigurationKeyBase, object> { [ConfigurationKeys.ConsulAddress] = "http://localhost:8500", [ConfigurationKeys.ConsulDatacenter] = "dc1", [ConfigurationKeys.ConsulConfigurationPrefix] = "all-my-keys-start-with-this-value", }); var configuration = new ConsulConfiguration( new[] { key }, connectionConfiguration); var hasValue = configuration.HasValueFor(key); Assert.IsFalse(hasValue); }
public int Save(ConfigurationKey configurationKey) { ConfigurationKey dbEntry; if (configurationKey != null && configurationKey.Key != null) { dbEntry = context.ConfigurationKeys.FirstOrDefault(x => x.Key == configurationKey.Key); if (dbEntry != null) { dbEntry.Key = configurationKey.Key; dbEntry.Value = configurationKey.Value; } context.SaveChanges(); return(dbEntry.ConfigurationKeyID); } else { return(0); } }
/// <summary> /// Gets the value as an enumeration. /// </summary> /// <typeparam name="T">The type of enumeration</typeparam> /// <param name="key">The key.</param> /// <returns> /// The output value /// </returns> /// <exception> /// The specified type {0} is not an enumeration /// or /// The specified key ({0}) doesn't represent a valid Enumeration ({1}) of type {2} /// </exception> public T GetEnumValue <T>(ConfigurationKey key) where T : struct { if (!typeof(T).IsEnum) { throw new ArgumentException("The specified type {0} is not an enumeration", typeof(T).FullName); } var valueAsString = this.GetStringValue(key); T outValue; if (Enum.TryParse(valueAsString, out outValue)) { return(outValue); } throw new ArgumentException(string.Format( "The specified key ({0}) doesn't represent a valid Enumeration ({1}) of type {2}", key, valueAsString, typeof(T).FullName)); }
} //ConfigurationHelper /// <summary> /// GetConfiguration receives a configuration key /// @return the configuration first item asociated with this item. /// </summary> public static Configuration GetConfiguration(ConfigurationKey key) { IDictionary dictionary; dictionary = DbHelper.ExecuteGetFirstRow("SELECT ConfigValue from Configuration where KeyValue = " + ((int) key).ToString()); if (dictionary == null) return null; object configValue; switch (key) { case ConfigurationKey.TasksLogDuration: case ConfigurationKey.DataMaintenanceDays: configValue = Convert.ToInt32(dictionary["ConfigValue"]); break; default: configValue = dictionary["ConfigValue"].ToString().Trim(); break; } return new Configuration(key, configValue); } //GetConfiguration
public decimal GetDecimalValue(ConfigurationKey key) { throw new NotImplementedException(); }
public bool GetBooleanValue(ConfigurationKey key, bool fallbackValue) { return fallbackValue; }
public bool GetBooleanValue(ConfigurationKey key) { throw new NotImplementedException(); }
Repository <T> CreateRepository(SecureString passphrase, string salt, ConfigurationKey filePathConfigurationKey) { var serializer = _encryptionSerializersFactory.GetSerializer(passphrase, salt); return(new Repository <T>(serializer, new UserFileStorageProvider(_configuration, filePathConfigurationKey, _logger))); }
/// <summary> /// Gets the string value. /// </summary> /// <param name="key">The key.</param> /// <returns> /// The value /// </returns> private string GetStringValue(ConfigurationKey key) { return(this.GetStringValue(key.ToString())); }
internal UserIsolatedStreamStorageProvider(IConfiguration configuration, ConfigurationKey filePathConfigurationKey, Logger logger) { _logger = logger; _storageFilePath = new Lazy <Task <string> >(() => configuration.GetAsync(filePathConfigurationKey)); }
public ConfigurationTypeException(ConfigurationKey key, string value, Type type) : base($"Cannot convert '{value}' to type '{type.Name}' for configuration '{key}'.") { }
internal Repository <T> GetRepository(SecureString passphrase, string salt, ConfigurationKey filePathConfigurationKey) => _repositories.GetOrAdd(passphrase.ToUnicodeSha512Base64() + salt, _ => CreateRepository(passphrase, salt, filePathConfigurationKey));
public string GetStringValue(ConfigurationKey key, string fallbackValue) { return fallbackValue; }
public int GetIntValue(ConfigurationKey key, int fallbackValue) { return fallbackValue; }
public decimal GetDecimalValue(ConfigurationKey key, decimal fallbackValue) { return fallbackValue; }
/// <summary> /// Returns the value for the given configuration key. /// </summary> /// <typeparam name="T">The type of the return value.</typeparam> /// <param name="key">The configuration key.</param> /// <returns> /// The desired value. /// </returns> public T Value <T>(ConfigurationKey <T> key) { return(default(T)); }
public IEnumerable <Contracts.Models.Configuration> GetConfigurationSettingsByKey(ConfigurationKey configurationKey) { return(GetAll(s => s .Where($"{nameof(Contracts.Models.Configuration.ConfigurationKeyId):C}=@ConfigurationKeyId") .WithParameters(new { ConfigurationKeyId = configurationKey.Id }))); }
public NullConfigurationException(ConfigurationKey key) : base($"No value found for configuration '{key}'.") { }
public int GetIntValue(ConfigurationKey key) { throw new NotImplementedException(); }
public Configuration(ConfigurationKey key, object value) { this.key = key; this.value = value; }
public string GetStringValue(ConfigurationKey key) { throw new NotImplementedException(); }
/// <summary> /// GetConfiguration receives a configuration key /// @return the configuration first item asociated with this item. /// </summary> public static Configuration GetConfiguration(ConfigurationKey key) { IDictionary dictionary; dictionary = DbHelper.ExecuteGetFirstRow("SELECT ConfigValue from Configuration where KeyValue = " + ((int) key).ToString()); if (dictionary == null) return null; object configValue; switch (key) { case ConfigurationKey.TasksLogDuration: case ConfigurationKey.DataMaintenanceDays: configValue = Convert.ToInt32(dictionary["ConfigValue"]); break; default: configValue = dictionary["ConfigValue"].ToString().Trim(); break; } return new Configuration(key, configValue); }
public void SetValue(int gameId, ConfigurationKey key, string value) { throw new NotImplementedException(); }
/// <summary> /// Gets the value as a string. /// </summary> /// <param name="key">The key.</param> /// <returns> /// The output value /// </returns> public string GetString(ConfigurationKey key) { return(this.GetStringValue(key)); }