public void Delete(ConfigItem item, NodeVisit visit) { ValidateByRole(visit, SystemRoleType.Admin); if (!item.IsEditable) { throw new InvalidOperationException("The item cannot be saved since it is not editable."); } lock (_lockObject) { TransactionTemplate.Execute(delegate { _configDao.Delete(item.Id); lock (_lockObject) { if (_configItems.ContainsKey(item.Id.ToUpper())) { _configItems.Remove(item.Id.ToUpper()); } } ActivityManager.LogAudit(NodeMethod.None, null, visit, "{0} deleted configuration value: {1}.", visit.Account.NaasAccount, item.ToString()); return(null); }); } }
/// <summary> /// 修改配置的值 /// </summary> /// <param name="key">The key.</param> /// <param name="value">The value.</param> public void SetConfigValue(ConfigItem key, string value) { foreach (DataRow row in settingStore.Tables["setting"].Rows) { if (row["key"].ToString() == key.ToString()) { row["value"] = value; return; } } }
/// <summary> /// 按条件获取数据 /// </summary> /// <param name="key">The key.</param> /// <returns></returns> public string GetConfigValue(ConfigItem key) { foreach (DataRow row in settingStore.Tables["setting"].Rows) { if (row["key"].ToString() == key.ToString()) { return(row["value"].ToString()); } } return(string.Empty); }
public void EqTest2() { var target1 = new ConfigItem("Config1|Platform1"); Assert.Equal("Config1", target1.Configuration); Assert.Equal("Platform1", target1.Platform); var target2 = new ConfigItem(null); Assert.Null(target2.Configuration); Assert.Null(target2.ConfigurationByRule); Assert.Null(target2.Platform); Assert.Null(target2.PlatformByRule); var target3 = new ConfigItem("Config1", "Platform1"); Assert.Equal("Config1|Platform1", target3.ToString()); Assert.Equal("Config1|Platform1", target3.Format()); }
public ConfigItem Save(string curItemId, ConfigItem item, NodeVisit visit) { ValidateByRole(visit, SystemRoleType.Admin); ParsingHelper.ValidateKey(item.Id); if (!item.IsEditable) { throw new InvalidOperationException("The item cannot be saved since it is not editable."); } ConfigItem saveItem = new ConfigItem(item); saveItem.ModifiedById = visit.Account.Id; saveItem.Value = _cryptographyProvider.Encrypt(item.Value); lock (_lockObject) { TransactionTemplate.Execute(delegate { _configDao.Save(curItemId, saveItem); lock (_lockObject) { if (!string.IsNullOrEmpty(curItemId)) { if (_configItems.ContainsKey(curItemId.ToUpper())) { _configItems.Remove(curItemId.ToUpper()); } } _configItems[item.Id.ToUpper()] = item; } ActivityManager.LogAudit(NodeMethod.None, null, visit, "{0} updated configuration value: {1}.", visit.Account.NaasAccount, saveItem.ToString()); return(null); }); item.ModifiedById = saveItem.ModifiedById; item.ModifiedOn = saveItem.ModifiedOn; } return(item); }
public void EqTest2() { var target1 = new ConfigItem("Config1|Platform1"); Assert.Equal("Config1", target1.Configuration); Assert.Equal("Platform1", target1.Platform); var target2 = new ConfigItem(null); Assert.Null(target2.Configuration); Assert.Null(target2.ConfigurationByRule); Assert.Null(target2.Platform); Assert.Null(target2.PlatformByRule); var target3 = new ConfigItem("Config1", "Platform1"); Assert.Equal("Config1|Platform1", target3.ToString()); #pragma warning disable CS0618 // Type or member is obsolete Assert.Equal("Config1|Platform1", target3.Format()); #pragma warning restore CS0618 // Type or member is obsolete }