private void Init(string _Key) { _UPPCONFIG = _UPPCONFIGCACHE.Where(w => w.Key == _Key).FirstOrDefault().Value; if (_UPPCONFIG == null) { using (var dbContext = new DbContextContainer(DbName.UPPDb)._DataAccess) { List <Db_App> dbAppList = null; if (_Key.Contains("#")) { var _HCode = _Key.Split('#')[0]; var _HBCode = _Key.Split('#')[1] == _HCode ? "" : _Key.Split('#')[1]; var appId = "AppId".ConfigValue(); //AppId为空则为App根据HosCode查询 if (appId.IsNullOrEmptyOfVar()) { _HBCode = _HCode == "00030" ? "" : _HBCode; dbAppList = dbContext.Set <Db_App>().Where(w => w.HosCode == _HCode && w.Active == 0).AsNoTracking().ToList(); } else { dbAppList = dbContext.Set <Db_App>().Where(w => w.HosCode == _HCode && w.Active == 0 && w.AppCode == appId).AsNoTracking().ToList(); } if (!_HBCode.IsNullOrEmptyOfVar()) { dbAppList = dbAppList.Where(w => w.BranchCode == _HBCode).ToList(); } } else { dbAppList = dbContext.Set <Db_App>().Where(w => w.AppCode == _Key && w.Active == 0).AsNoTracking().ToList(); if (dbAppList.Count == 0) { dbAppList = dbContext.Database.Connection.Query <Db_App>("SELECT A.* FROM UT_APP A,UT_APPLINK B WHERE A.APPCODE = B.APPCODE AND A.ACTIVE = 0 AND B.ACTIVE = 0 AND B.APPID = " + _Key).ToList(); } } if (dbAppList.Count == 0) { throw new Exception("UPPClient未找到相关配置"); } if (dbAppList.FirstOrDefault().Url.IsNullOrEmptyOfVar()) { throw new Exception("UPPClient未找到URL配置"); } _UPPCONFIG = new UPPConfig() { AppId = dbAppList.FirstOrDefault().AppCode, Key = dbAppList.FirstOrDefault().DevKey, Url = dbAppList.FirstOrDefault().Url.ToLower().Contains("api") ? dbAppList.FirstOrDefault().Url : dbAppList.FirstOrDefault().Url + "api" }; _UPPCONFIGCACHE.AddOrUpdate(_Key, _UPPCONFIG, (key, value) => value); } } }
/// <summary> /// used by free config /// </summary> /// <param name="_UPPConfig"></param> public UPPClient(UPPConfig _UPPConfig) { _UPPCONFIG = _UPPConfig; }