public static AccountConfig GetByName(string name) { var keys = WebConfigurationManager.AppSettings.AllKeys; AccountConfig res; // Get from appSettings or the dictionary if (keys.Where(x => x.StartsWith(Constants.AppSettings.Prefix)).Any()) { // Try appSettings first res = new AccountConfig(WebConfigurationManager.AppSettings, name); } else { // Try the dictionary DictionaryUtils uDic = new DictionaryUtils(); var dictItems = uDic .GetDictionaryItemsSimple() .Where(x => x.Key.StartsWith(Constants.AppSettings.Prefix)); NameValueCollection nvc = dictItems .Aggregate(new NameValueCollection(), (seed, current) => { seed.Add(current.Key, current.Value); return(seed); }); res = new AccountConfig(nvc, name); } return(res); }
public static IEnumerable <AccountConfig> GetAll() { var prefix = Constants.AppSettings.Prefix + ":"; var keys = WebConfigurationManager.AppSettings.AllKeys; var names = new HashSet <string>(); if (!keys.Where(x => x.StartsWith(Constants.AppSettings.Prefix)).Any()) { // Probably need to try the dictionary DictionaryUtils uDic = new DictionaryUtils(); var dictItems = uDic.GetDictionaryItemsSimple(); keys = dictItems.Where(x => x.Key.StartsWith(Constants.AppSettings.Prefix)).Select(x => x.Key).ToArray(); } foreach (var key in keys) { if (!key.StartsWith(prefix)) { continue; } var parts = key.Split(':'); if (parts.Length == 2) { names.Add(string.Empty); } else if (parts.Length == 3) { names.Add(parts[1]); } } return(names.Select(GetByName).Where(x => !string.IsNullOrEmpty(x.GoogleProfileId))); }
private static Initializer CreateFlowInitializer(AccountConfig config) { DictionaryUtils uDic = new DictionaryUtils(); var dictItems = uDic.GetDictionaryItemsSimple(); return(new Initializer { ClientSecrets = new ClientSecrets { ClientId = WebConfigurationManager.AppSettings[Constants.AppSettings.GoogleClientId] ?? dictItems.Where(x => x.Key == Constants.AppSettings.GoogleClientId).FirstOrDefault()?.Value, ClientSecret = WebConfigurationManager.AppSettings[Constants.AppSettings.GoogleClientSecret] ?? dictItems.Where(x => x.Key == Constants.AppSettings.GoogleClientSecret).FirstOrDefault()?.Value }, Scopes = new[] { AnalyticsService.Scope.AnalyticsEdit }, DataStore = new FileDataStore(GetStoragePath(config), true), UserDefinedQueryParams = new [] { new KeyValuePair <string, string>("testkey", "testvalue"), }, }); }