public T GetApi <T>(string exchangeAbbrName) { IEnumerable <T> apis = Container.GetExportedValues <T>(); foreach (T api in apis) { ExchangeApi exchangeApi = api as ExchangeApi; if (exchangeApi.Exchange.AbbrName == exchangeAbbrName) { return(api); } } return(default(T)); }
public Dictionary <string, AuthKey> GetAuthKeyDict() { //缓存 if (authKeyDict != null) { return(authKeyDict); } //获取所有AuthApi Dictionary <string, AuthKey> allKeys = new Dictionary <string, AuthKey>(); ApiManager apiManager = ServiceLocator.Current.GetInstance <ApiManager>(); foreach (IAuthApi authApi in apiManager.AuthApis) { ExchangeApi api = authApi as ExchangeApi; allKeys.Add(api.Exchange.AbbrName, new AuthKey()); } //已经设置则获取 if (File.Exists("Api.key")) { string authKeyJson = Setting.ReadJsonFromCompressFile("Api.key"); Dictionary <string, AuthKey> authKeys = JsonConvert.DeserializeObject <Dictionary <string, AuthKey> >(authKeyJson); foreach (var authKey in authKeys) { allKeys[authKey.Key] = authKey.Value; } return(allKeys); } //未设置则生成空的 else { string json = JsonConvert.SerializeObject(allKeys); Setting.WriteJsonToCompressFile("Api.key", json); } authKeyDict = allKeys; return(authKeyDict); }