Пример #1
0
 static void Check(OcelotConfigTemplate template)
 {
     if (string.IsNullOrWhiteSpace(template.Version))
     {
         throw new UserFriendlyException($"{nameof(OcelotConfigTemplate.Version)}不可以为空.");
     }
     if (string.IsNullOrWhiteSpace(template.JsonString))
     {
         throw new UserFriendlyException($"{nameof(OcelotConfigTemplate.JsonString)}不可以为空.");
     }
 }
Пример #2
0
 public void SaveOrUpdate(OcelotConfigTemplate template)
 {
     if (Exists(template.Version))
     {
         template.ModifiedTime = DateTime.Now;
         Update(template);
     }
     else
     {
         template.CreateTime = DateTime.Now;
         Create(template);
     }
 }
Пример #3
0
        void Create(OcelotConfigTemplate template)
        {
            Check(template);

            string sql = $"insert into {_tableName} " +
                         $"(version, jsonString, description, createTime) " +
                         $"values ('{template.Version}', '{template.JsonString}', '{template.Description}', '{template.CreateTime}')";

            _logger.Debug($"{nameof(Create)} sql:{sql}");
            using (IDbConnection cone = _connectionProvider.Create())
            {
                cone.Open();
                cone.Execute(sql);
            }
        }
Пример #4
0
        void Update(OcelotConfigTemplate template)
        {
            Check(template);

            string sql = $"update {_tableName} set " +
                         $"jsonString = '{template.JsonString}', " +
                         $"description = '{template.Description}', " +
                         $"modifiedTime = '{template.ModifiedTime}' " +
                         $"where version = '{template.Version}'";

            _logger.Debug($"{nameof(Update)} sql:{sql}");
            using (IDbConnection cone = _connectionProvider.Create())
            {
                cone.Open();
                cone.Execute(sql);
            }
        }
Пример #5
0
        public Task <JsonResult> Get([Required, FromQuery] string version)
        {
            if (string.IsNullOrWhiteSpace(version))
            {
                throw new ArgumentNullException(nameof(version));
            }

            OcelotConfigTemplate template = _repo.Get(version);

            if (template == null)
            {
                template = new OcelotConfigTemplate
                {
                    Version    = DateTime.Now.ToString("yyyyMMdd"),
                    CreateTime = DateTime.Now,
                    JsonString = JsonConvert.SerializeObject(new FileConfiguration())
                };
            }

            return(Task.FromResult(new JsonResult(template)));
        }
Пример #6
0
 public Task Save([Required] OcelotConfigTemplate template)
 {
     _repo.SaveOrUpdate(template);
     return(Task.CompletedTask);
 }