Exemple #1
0
        public ConfigInfo GetAll([FromBody] ConfigInModel model, String token)
        {
            if (model.AppId.IsNullOrEmpty() && token.IsNullOrEmpty()) throw new ArgumentNullException(nameof(model.AppId));

            // 验证
            var app = Valid(model.AppId, model.Secret, token);
            var ip = HttpContext.GetUserHost();

            // 使用键和缺失键
            if (!model.UsedKeys.IsNullOrEmpty()) app.UsedKeys = model.UsedKeys;
            if (!model.MissedKeys.IsNullOrEmpty()) app.MissedKeys = model.MissedKeys;
            app.Update();

            // 版本没有变化时,不做计算处理,不返回配置数据
            if (model.Version > 0 && model.Version >= app.Version) return new ConfigInfo { Version = app.Version, UpdateTime = app.UpdateTime };

            // 作用域为空时重写
            var scope = model.Scope;
            scope = scope.IsNullOrEmpty() ? AppRule.CheckScope(app.Id, ip) : scope;

            var dic = _configService.GetConfigs(app, scope);

            return new ConfigInfo
            {
                Version = app.Version,
                Scope = scope,
                SourceIP = ip,
                NextVersion = app.NextVersion,
                NextPublish = app.PublishTime.ToFullString(""),
                UpdateTime = app.UpdateTime,
                Configs = dic,
            };
        }
        public ConfigInfo GetAll([FromBody] ConfigInModel model, String token)
        {
            if (model.AppId.IsNullOrEmpty() && token.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(model.AppId));
            }

            // 验证
            var(app, online) = Valid(model.AppId, model.Secret, model.ClientId, token);
            var ip = HttpContext.GetUserHost();

            // 使用键和缺失键
            if (!model.UsedKeys.IsNullOrEmpty())
            {
                app.UsedKeys = model.UsedKeys;
            }
            if (!model.MissedKeys.IsNullOrEmpty())
            {
                app.MissedKeys = model.MissedKeys;
            }
            app.Update();

            // 作用域为空时重写
            var scope = model.Scope;

            scope = scope.IsNullOrEmpty() ? AppRule.CheckScope(app.Id, ip) : scope;

            // 作用域有改变时,也要返回配置数据
            var change = online.Scope != scope;

            online.Scope = scope;
            online.SaveAsync(3_000);

            // 版本没有变化时,不做计算处理,不返回配置数据
            if (!change && model.Version > 0 && model.Version >= app.Version)
            {
                return new ConfigInfo {
                           Version = app.Version, UpdateTime = app.UpdateTime
                }
            }
            ;

            var dic = _configService.GetConfigs(app, scope);

            return(new ConfigInfo
            {
                Version = app.Version,
                Scope = scope,
                SourceIP = ip,
                NextVersion = app.NextVersion,
                NextPublish = app.PublishTime.ToFullString(""),
                UpdateTime = app.UpdateTime,
                Configs = dic,
            });
        }