Example #1
0
 internal void InternalRemoveConfigItem(string id)
 {
     using (ConfigDbContext context = new ConfigDbContext())
     {
         ConfigItem configItem = context.ConfigItems.Where(e => e.Id == id && !e.IsDeleted).SingleOrDefault();
         if (configItem == null)
         {
             return;
         }
         configItem.IsDeleted = true;
         context.SaveChanges();
     }
 }
Example #2
0
 public void SaveConfigItem(string id, string friendlyName, string desc, string val)
 {
     using (ConfigDbContext context = new ConfigDbContext())
     {
         ConfigItem item = context.ConfigItems.Where(e => e.Id == id && !e.IsDeleted)
                           .SingleOrDefault();
         if (item == null)
         {
             return;
         }
         item.FriendlyName = friendlyName;
         item.Description  = desc;
         item.Value        = val;
         item.ModifiedOn   = DateTime.Now;
         context.SaveChanges();
     }
 }
Example #3
0
        public ConfigItem AddConfigItem(string appName, string[] parentPathItemNames, string name, string friendlyName, string desc, string val, string sourceId, string valType, string valTypeEnum, bool isCompositeValue)
        {
            List <string> pathItemNames = new List <string>();
            string        parentId      = null;

            if (parentPathItemNames != null && parentPathItemNames.Length != 0)
            {
                parentId = ConfigHelper.GenerateConfigItemId(appName, parentPathItemNames);
                pathItemNames.AddRange(parentPathItemNames);
            }
            pathItemNames.Add(name);
            string id = ConfigHelper.GenerateConfigItemId(appName, pathItemNames.ToArray());

            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException("name");
            }
            ConfigItem item;
            bool       isNew = true;

            using (ConfigDbContext context = new ConfigDbContext())
            {
                item = context.ConfigItems.Where(e => e.Id == id).SingleOrDefault();
                //节点已经存在,并且没有标记为删除,直接返回
                if (item != null && !item.IsDeleted)
                {
                    return(item);
                }
                //节点已经存在,但是标记为已删除,添加时将其恢复
                if (item != null && item.IsDeleted)
                {
                    isNew            = false;
                    item.IsDeleted   = false;
                    item.ItemsInited = false;
                    item.ModifiedOn  = DateTime.Now;
                }
                else
                {
                    item = new ConfigItem();
                }
                item.Id               = id;
                item.ParentId         = parentId;
                item.AppName          = appName;
                item.Name             = name;
                item.FriendlyName     = friendlyName;
                item.Description      = desc;
                item.Value            = val;
                item.SourceId         = sourceId;
                item.ValueType        = valType;
                item.ValueTypeEnum    = valTypeEnum;
                item.IsCompositeValue = isCompositeValue;
                if (isNew)
                {
                    context.ConfigItems.Add(item);
                }

                try
                {
                    context.SaveChanges();
                    context.Entry(item).Reload();
                    return(item);
                }
                catch (Exception ex)
                {
                    LocalLoggingService.Error("添加配置项失败,详细信息:{0}", ex);
                    throw;
                }
            }
            return(item);
        }