public void GetAsNameValueCollection_ShouldReturnNull_WhenValueIsNullAndNoDefaultValue() { var configValue = new ConfigurationValue(null, new JsonSerializer()); var configAsNameValueCollection = configValue.GetAsNameValueCollcetion(); Assert.IsNull(configAsNameValueCollection); }
public async Task <IActionResult> Edit(string id, [Bind("Key,Value")] ConfigurationValue vm) { if (id != vm.Key) { return(NotFound()); } if (!ModelState.IsValid) { return(View(vm)); } var item = new ConfigurationValue() { Key = vm.Key, Value = vm.Value }; _config.ConfigurationValues.Update(item); try { await _config.SaveChangesAsync(); } catch (Exception ex) { _logger.LogError(ex, "存储参数时发生异常!"); throw ex; } return(RedirectToAction(nameof(Index))); }
/// <summary> /// Gibt einen Konfigurationswert zurück /// </summary> /// <param name="configurationName">Konfigurationswert</param> /// <param name="pluginName">PlugInName</param> /// <param name="userName">Benutzername</param> /// <param name="noCaching">Wenn true, wird kein Cache verwendet</param> /// <returns>Wert</returns> public T GetValue <T>(string configurationName, string pluginName, string userName, bool noCaching = false) { var returnValue = cacheService.Get <ConfigurationValue>( ConfigurationValue.GetKeyName(configurationName, pluginName, userName)); if (returnValue == null || noCaching == true) { var value = configurationRepository.GetValue(pluginName, userName, configurationName); // If no configuration value exists, try to load a user independent setting if (string.IsNullOrWhiteSpace(value)) { value = configurationRepository.GetValue(pluginName, "", configurationName); } returnValue = new ConfigurationValue(configurationName, pluginName, userName, value); returnValue.Value = CastConfigurationValue <T>(value); if (noCaching == false) { cacheService.Set(returnValue); } } return((T)returnValue.Value); }
public void GetAsT_ShouldReturnNull_WhenValueIsNullAndNoDefaultValue() { var configValue = new ConfigurationValue(null, new JsonSerializer()); var configAsT = configValue.GetAs <Configurations>(); Assert.IsNull(configAsT); }
/// <summary> /// Add or replace a setting in the configuration. /// </summary> /// <param name="services">The service registration collection.</param> /// <param name="key">The key of the setting to add or replace.</param> /// <param name="value">The value of the setting to add or replace.</param> /// <returns>The same <see cref="ICakeServices"/> instance so that multiple calls can be chained.</returns> public static ICakeServices UseSetting(this ICakeServices services, string key, string value) { var info = new ConfigurationValue(key, value); services.RegisterInstance(info).AsSelf().Singleton(); return(services); }
public async Task <IActionResult> Edit(int?id, [Bind("Id,Name,Desc")] ConfigurationValue configurationValue) { if (id != configurationValue.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(configurationValue); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ConfigurationValueExists(configurationValue.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(configurationValue)); }
/// <summary> /// Setzt einen Konfigurationswert /// </summary> /// <param name="configurationName">Name der Konfiguration</param> /// <param name="pluginName">PlugIn-Name</param> /// <param name="userName">Benutzername</param> /// <param name="value">Wert</param> public void SetValue <T>(string configurationName, string pluginName, string userName, T value) { object _value = value; if (_value != null) { if (value is bool || value is Boolean) { _value = Convert.ToInt32(value).ToString(); } } configurationRepository.SetValue(pluginName, userName, configurationName, _value == null ? null : _value.ToString()); var configValue = cacheService.Get <ConfigurationValue>( ConfigurationValue.GetKeyName(configurationName, pluginName, userName)); if (configValue != null) { configValue.Value = value; } else { cacheService.Set(new ConfigurationValue(configurationName, pluginName, userName, value)); } }
public void GetConfigurationValue_EmptyKeyName_Failure() { ConfigurationValue oNewValue; var res = ConfigurationValue.GetConfigurationValue(out oNewValue, _mockServer, ""); Assert.IsFalse(res.Success, "Call to GetConfigurationValue static method did not fail with empty key name"); }
public void GetAsString_ShouldReturnNull_WhenValueIsEmptyAndNoDefaultValue() { var configValue = new ConfigurationValue("", new JsonSerializer()); var configAsString = configValue.GetAsString(); Assert.IsNull(configAsString); }
public async Task <IActionResult> Create([Bind("Key,Value")] ConfigurationValue vm) { if (!ModelState.IsValid) { return(View(vm)); } var item = new ConfigurationValue() { Key = vm.Key, Value = vm.Value }; await _config.ConfigurationValues.AddAsync(item); try { var saveResult = await _config.SaveChangesAsync(); if (saveResult < 1) { AddError("未能成功存入数据库"); return(View(vm)); } } catch (Exception ex) { _logger.LogError(ex, "存储参数时发生异常!"); throw ex; } return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> PutConfigValue([FromBody] KeyValueViewModel kv) { var item = new ConfigurationValue() { Key = kv.Key, Value = kv.Value }; var exists = await _config.ConfigurationValues .AsNoTracking() .FirstOrDefaultAsync(x => x.Key == kv.Key); if (exists == null) { _config.ConfigurationValues.Add(item); } else { _config.ConfigurationValues.Update(item); } try { var result = await _config.SaveChangesAsync(); if (result > 0) { return(Json(EfConfigJson.Ok())); } } catch (Exception ex) { _logger.LogError(ex, "存储配置数据时发生异常!"); } return(Json(new { ErrorMessage = "数据更新失败" })); }
public void GetConfigurationValues_NullConnectionServer_Failure() { List <ConfigurationValue> oValues; var res = ConfigurationValue.GetConfigurationValues(null, out oValues, 1, 20, "query=(FullName startswith System)"); Assert.IsFalse(res.Success, "Static method to fetch configuration values did not fail with null ConnectionServer"); }
public void GetAsT_ShouldThrowSerializationException_WhenValueIsNotSerializable() { var value = "{\"redisConnection\": \"192.168.2.2\"}"; var configValue = new ConfigurationValue(value, new JsonSerializer()); var exception = Xunit.Assert.Throws <SerializationException>(() => configValue.GetAs <Configurations>()); Assert.IsNotNull(exception); }
public void GetAsNameValueCollection_ShouldReturnNull_WhenValueIsNotJsonReadable() { var value = "{}"; var configValue = new ConfigurationValue(value, new JsonSerializer()); var nameValueCollection = configValue.GetAsNameValueCollcetion(); Assert.IsNull(nameValueCollection); }
public void GetAsNameValueCollection_ShouldThrowSerializationException_WhenValueIsInvalid() { var value = "{\"redisConnection\":{\"ipAddress\":\"192.168.2.2\",\"port\":\"8600\"}}"; var configValue = new ConfigurationValue(value, new JsonSerializer()); var exception = Xunit.Assert.Throws <SerializationException>(() => configValue.GetAsNameValueCollcetion()); Assert.IsNotNull(exception); }
public void GetConfigurationValue_NullConnectionServer_Failure() { ConfigurationValue oNewValue; var res = ConfigurationValue.GetConfigurationValue(out oNewValue, null, "dummy"); Assert.IsFalse(res.Success, "Call to GetConfigurationValue static method did not fail with null ConnectionServer"); }
public void GetConfigurationValues_EmptyQuery_Success() { List <ConfigurationValue> oValues; var res = ConfigurationValue.GetConfigurationValues(_mockServer, out oValues); Assert.IsTrue(res.Success, "Static method to fetch configuration values failed with empty query construction:" + res); }
public void GetAsT_ShouldThrowSerializationException_WhenValueIsNotJsonReadable() { var value = "something"; var configValue = new ConfigurationValue(value, new JsonSerializer()); var exception = Xunit.Assert.Throws <SerializationException>(() => configValue.GetAs <Configurations>()); Assert.IsNotNull(exception); }
public void GetAsString_ShouldReturnValue_WhenValueIsValid() { var configValue = new ConfigurationValue("validValue", new JsonSerializer()); var configAsString = configValue.GetAsString("defaultValue"); Assert.IsNotNull(configAsString); Assert.AreEqual(configAsString, "validValue"); }
private IConfigurationEntry RebuildConfigurationEntry(MongoDbConfigurationDocument doc) { var entry = new ConfigurationEntry { Component = doc.Component, Path = doc.Path, Label = doc.Label ?? doc.Path, ValueMeaning = Enum.TryParse(doc.Meaning, out ConfigurationValueMeaning meaning) ? meaning : ConfigurationValueMeaning.String, ValueType = Enum.TryParse(doc.ValueType, out ConfigurationValueType type) ? type : ConfigurationValueType.String, VisibleToPages = doc.VisibleToPages }; switch (entry.ValueType) { case ConfigurationValueType.Boolean: entry.Value = doc.BooleanValue; break; case ConfigurationValueType.DateTime: entry.Value = new DateTime(doc.LongValue.Value, DateTimeKind.Utc); break; case ConfigurationValueType.Null: entry.Value = ConfigurationValue.NullValue; break; case ConfigurationValueType.String: entry.Value = doc.StringValue; break; case ConfigurationValueType.Integer: entry.Value = doc.LongValue.GetValueOrDefault(); break; case ConfigurationValueType.Double: entry.Value = doc.DoubleValue.GetValueOrDefault(); break; case ConfigurationValueType.TimeSpan: entry.Value = TimeSpan.FromTicks(doc.LongValue.Value); break; case ConfigurationValueType.Bytes: entry.Value = doc.BytesValue; break; case ConfigurationValueType.Json: entry.Value = ConfigurationValue.FromJSON(doc.StringValue); break; case ConfigurationValueType.Object: throw new NotSupportedException("Raw objects loading does not supported in current version"); default: throw new NotImplementedException("Decoding from Mongo configuration document to Configuration value for arbitary types is not supported"); } return(entry); }
public static ConfigurationValue AssignTags(this ConfigurationValue value, IEnumerable <Tag> tags) { foreach (var tag in tags) { value.Tags.Add(tag); tag.ConfigurationValues.Add(value); } return(value); }
public void GetConfigurationValues_ValidQuery_Success() { List <ConfigurationValue> oValues; var res = ConfigurationValue.GetConfigurationValues(_mockServer, out oValues, 1, 20, "query=(FullName startswith System)"); Assert.IsTrue(res.Success, "Static method to fetch configuration values failed with query construction:" + res); }
public void GetAsT_ShouldReturnValue_WhenValueIsValid() { var value = "{\"redisConnection\":{\"ipAddress\":\"192.168.2.2\",\"port\":\"8600\"}}"; var configValue = new ConfigurationValue(value, new JsonSerializer()); var configAsT = configValue.GetAs <Configurations>(); Assert.IsNotNull(configAsT); Assert.AreEqual(configAsT.RedisConnection.IpAddress, "192.168.2.2"); }
public void ConfigurationValue_Test() { _errorString = ""; List <ConfigurationValue> oValues; var res = ConfigurationValue.GetConfigurationValues(_connectionServer, out oValues, 1, 10); Assert.IsTrue(res.Success, "Failed to fetch configuration value:" + res); Assert.IsTrue(string.IsNullOrEmpty(_errorString), "Error parsing Json for configuration value:" + _errorString); }
/// <summary> /// Gets the configuration value. /// </summary> /// <param name="controls">The controls.</param> /// <returns></returns> public override Dictionary <string, ConfigurationValue> ConfigurationValues(List <Control> controls) { var fileType = new ConfigurationValue("File Type", "The type of files to list", Rock.SystemGuid.BinaryFiletype.CHECKIN_LABEL); return(new Dictionary <string, ConfigurationValue>() { { "binaryFileType", fileType } }); }
public void TestValuesFromDynamic() { var dynamicEntry = ConfigurationValue.FromJSON(@"{ ""value1"": true, ""value2"": 1, ""value3"": ""Some text"" }"); Assert.AreEqual(1, dynamicEntry.DynamicValue.value2); Assert.AreEqual("Some text", dynamicEntry.DynamicValue.value3); Assert.IsTrue(dynamicEntry.DynamicValue.value1); }
public void GetAsNameValueCollection_ShouldReturnValue_WhenValueIsValid_Scenario_1() { var value = "{\"firstKey\":\"firstValue\",\"secondKey\":\"secondValue\",\"thirdKey\":\"thirdValue\"}"; var configValue = new ConfigurationValue(value, new JsonSerializer()); var configAsNameValueCollection = configValue.GetAsNameValueCollcetion(); Assert.IsNotNull(configAsNameValueCollection); Assert.AreEqual(configAsNameValueCollection["firstKey"], "firstValue"); Assert.AreEqual(configAsNameValueCollection["secondKey"], "secondValue"); }
public void GetAsT_ShouldReturnEmptyObject_WhenValueIsInValid() { var value = "{\"firstKey\":\"firstValue\",\"secondKey\":\"secondValue\",\"thirdKey\":\"thirdValue\"}"; var configValue = new ConfigurationValue(value, new JsonSerializer()); var configAsT = configValue.GetAs <Configurations>(); Assert.IsNotNull(configAsT); Assert.IsNull(configAsT.RedisConnection); Assert.IsNull(configAsT.ConsulConnection); }
public void StaticCallFailure_GetConfigurationValues() { List <ConfigurationValue> oValues; var res = ConfigurationValue.GetConfigurationValues(_connectionServer, out oValues, 1, 20, "query=(FullName startswith System)"); Assert.IsTrue(res.Success, "Static method to fetch configuration values failed with query construction:" + res); res = ConfigurationValue.GetConfigurationValues(_connectionServer, out oValues, 1, 20, "", "query=(bogus)"); Assert.IsFalse(res.Success, "Static method to fetch configuration values did not fail with invalid query construction"); }
public async Task <IActionResult> Create([Bind("Id,Name,Desc")] ConfigurationValue configurationValue) { if (ModelState.IsValid) { _context.Add(configurationValue); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(configurationValue)); }
/// <summary> /// Process a configuration block /// </summary> /// <param name="defaultLang"></param> /// <param name="element"></param> /// <returns></returns> private static IConfigurationDescription ProcessConfiguration(string defaultLang, XElement parent) { List<IConfigurationValue> values = new List<IConfigurationValue>(); IEnumerable<XElement> nodes = from node in parent.Descendants(ValueTag) where (node.Attribute(NameAttribute) != null) && (node.Attribute(TypeAttribute) != null) && (node.Attribute(DefaultAttribute) != null) select node; foreach (XElement node in nodes) { // Get required attributes (name, type and default) Dictionary<string, string> attributes = new Dictionary<string, string>(); attributes[NameAttribute] = node.Attribute(NameAttribute).Value; attributes[TypeAttribute] = node.Attribute(TypeAttribute).Value; attributes[DefaultAttribute] = node.Attribute(DefaultAttribute).Value; LogHost.Default.Debug("Adding configuration entry '{0}' ({1})", attributes[NameAttribute], attributes[TypeAttribute]); // Verify the type ConfigurationValueType valueType; if (!Enum.TryParse(attributes[TypeAttribute], false, out valueType)) { LogHost.Default.Warn("Unrecognised configuration type '{0}'", attributes[TypeAttribute]); continue; } // Process the description of the entry ObjectDescription description = ProcessDescription(defaultLang, node); // Do type specific configuration List<IObjectDescription> options = null; if (valueType == ConfigurationValueType.OptionList) { // Build a list of individual options IEnumerable<XElement> optionNodes = from option in node.Descendants(SelectionTag) where option.Attribute(NameAttribute) != null select option; if (optionNodes.Count() == 0) { LogHost.Default.Error("Configuration values of type 'OptionList' require options."); return null; } options = new List<IObjectDescription>(); foreach (XElement item in optionNodes) options.Add(ProcessDescription(defaultLang, item)); } UserObjectType objectType = UserObjectType.None; if ((valueType == ConfigurationValueType.ObjectList) || (valueType == ConfigurationValueType.ObjectValue)) { if (!Enum.TryParse(node.Attribute(SubtypeAttribute).Value, true, out objectType)) { LogHost.Default.Error("Fields of type {0} require a valid '{1}' attribute.", valueType, SubtypeAttribute); return null; } } // Create and add the value ConfigurationValue configValue = new ConfigurationValue( attributes[NameAttribute], valueType, attributes[DefaultAttribute], description, options, objectType ); values.Add(configValue); } return new ConfigurationDescription(values); }
public override void Merge( ConfigurationValue value) { this.Value.AddRangeUnique((value as MultiConfigurationValue).Value); }
public abstract void Merge( ConfigurationValue value);
public override void Merge( ConfigurationValue value) { var newValue = (value as UniqueConfigurationValue).Value; if (this.Value == newValue) { return; } Bam.Core.Log.Info("Warning: Replacing '{0}' with '{1}'", this.Value, newValue); this.Value = (value as UniqueConfigurationValue).Value; }
/// <summary> /// Gets the configuration value. /// </summary> /// <param name="controls">The controls.</param> /// <returns></returns> public override Dictionary<string, ConfigurationValue> ConfigurationValues( List<Control> controls ) { Dictionary<string, ConfigurationValue> configurationValues = new Dictionary<string, ConfigurationValue>(); var configurationValue = new ConfigurationValue( "Values", "The source of the values to display in a list. Format is either 'value1,value2,value3,...', 'value1^text1,value2^text2,value3^text3,...', or a SQL Select statement that returns result set with a 'Value' and 'Text' column.", string.Empty ); configurationValues.Add( "values", configurationValue ); if ( controls != null && controls.Count == 1 ) { if ( controls[0] != null && controls[0] is TextBox ) { configurationValues["values"].Value = ( (TextBox)controls[0] ).Text; } } return configurationValues; }