Beispiel #1
0
 static void Check(OcelotConfigSection configSection)
 {
     if (string.IsNullOrWhiteSpace(configSection.Name))
     {
         throw new UserFriendlyException($"{nameof(OcelotConfigSection.Name)}不可以为空.");
     }
     if (string.IsNullOrWhiteSpace(configSection.JsonString))
     {
         throw new UserFriendlyException($"{nameof(OcelotConfigSection.JsonString)}不可以为空.");
     }
 }
Beispiel #2
0
 public void SaveOrUpdate(OcelotConfigSection configSection)
 {
     if (Exists(configSection.Name))
     {
         configSection.ModifiedTime = DateTime.Now;
         Update(configSection);
     }
     else
     {
         configSection.CreateTime = DateTime.Now;
         Create(configSection);
     }
 }
Beispiel #3
0
        void Create(OcelotConfigSection configSection)
        {
            Check(configSection);

            string sql = $"insert into {_tableName} " +
                         $"(name, jsonString, description, createTime, enable) " +
                         $"values ('{configSection.Name}', '{configSection.JsonString}', '{configSection.Description}', '{configSection.CreateTime}', {Convert.ToInt16(configSection.Enable)})";

            _logger.Debug($"{nameof(Create)} sql:{sql}");
            using (IDbConnection cone = _connectionProvider.Create())
            {
                cone.Open();
                cone.Execute(sql);
            }
        }
Beispiel #4
0
        public IActionResult SaveSection([Required] OcelotConfigSection configSection)
        {
            ConfigValidationResult result = _validator.Validate(configSection).Result;

            if (result.IsError)
            {
                _logger.Warn("Ocelot配置片段错误: " + JsonConvert.SerializeObject(result.Errors));
                return(BadRequest(result.Errors));
            }
            else
            {
                _sectionRepo.SaveOrUpdate(configSection);
                _logger.Info("保存Ocelot配置片段: " + JsonConvert.SerializeObject(configSection));
                return(Ok(configSection));
            }
        }
Beispiel #5
0
        void Update(OcelotConfigSection configSection)
        {
            Check(configSection);

            string sql = $"update {_tableName} set " +
                         $"jsonString = '{configSection.JsonString}', " +
                         $"description = '{configSection.Description}', " +
                         $"modifiedTime = '{configSection.ModifiedTime}', " +
                         $"enable = {Convert.ToInt16(configSection.Enable)} " +
                         $"where name = '{configSection.Name}'";

            _logger.Debug($"{nameof(Update)} sql:{sql}");
            using (IDbConnection cone = _connectionProvider.Create())
            {
                cone.Open();
                cone.Execute(sql);
            }
        }