/// <summary>获取所有配置</summary> /// <returns></returns> protected virtual IDictionary <String, Object> GetAll() { var client = GetClient() as ApiHttpClient; // 特殊处理Apollo if (!NameSpace.IsNullOrEmpty()) { var ns = NameSpace.Split(new[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries).Distinct(); var dic = new Dictionary <String, Object>(); foreach (var item in ns) { var action = $"/configfiles/json/{AppId}/default/{item}"; var rs = client.Get <IDictionary <String, Object> >(action); Info = rs; foreach (var elm in rs) { if (!dic.ContainsKey(elm.Key)) { dic[elm.Key] = elm.Value; } } } return(dic); } else { var rs = client.Post <IDictionary <String, Object> >(Action, new { appId = AppId, secret = Secret, clientId = ClientId, scope = Scope, version = _version, usedKeys = UsedKeys.Join(), missedKeys = MissedKeys.Join(), }); Info = rs; // 增强版返回 if (rs.TryGetValue("configs", out var obj)) { var ver = rs["version"].ToInt(-1); if (ver > 0) { _version = ver; } if (obj is not IDictionary <String, Object> configs) { return(null); } return(configs); } return(rs); } }
protected override IDictionary <String, Object> GetAll() { var client = GetClient() as ApiHttpClient; var rs = client.Post <IDictionary <String, Object> >(Action, new { appId = AppId, secret = Secret, clientId = Factory.ClientId, scope = Scope, version = _version, usedKeys = UsedKeys.Join(), missedKeys = MissedKeys.Join(), }); Info = rs; // 增强版返回 if (rs.TryGetValue("configs", out var obj)) { var ver = rs["version"].ToInt(-1); if (ver > 0) { _version = ver; } if (obj is not IDictionary <String, Object> configs) { return(null); } rs = configs; } var inf = Info; if (inf != null && inf.TryGetValue("version", out var v) && v + "" != _version + "") { Factory.ConfigInfo = JsonHelper.Convert <ConfigInfo>(inf); var dic = new Dictionary <String, Object>(inf); dic.Remove("configs"); XTrace.WriteLine("从配置中心加载:{0}", dic.ToJson()); _version = v.ToInt(); } return(rs); }
// base cost of 15 (10 from Identifier, 5 for rest) // count Keys twice (to estimate cost of Json) // count each used key /// <inheritdoc /> public override long CalculateCacheSize() => 15 + (Keys?.Sum(p => p.Key?.Length ?? 0 + p.Value?.Length ?? 0) * 2 ?? 0) + (UsedKeys?.Sum(s => s?.Length ?? 0) ?? 0);