Ejemplo n.º 1
0
        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);
                });
            }
        }
Ejemplo n.º 2
0
 /// <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;
         }
     }
 }
Ejemplo n.º 3
0
 /// <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);
 }
Ejemplo n.º 4
0
        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());
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        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
        }