internal CSDataProvider GetDB(string contextName) { lock (_globalDbMap) { if (_globalDbMapChanged.ContainsKey(contextName) && _globalDbMapChanged[contextName]) { _globalDbMapChanged[contextName] = false; if (_threadDbMap.ContainsKey(contextName)) { _threadDbMap[contextName].Dispose(); _threadDbMap.Remove(contextName); } } } if (_threadDbMap.ContainsKey(contextName)) { return(_threadDbMap[contextName]); } lock (_globalDbMap) { if (!_globalDbMap.ContainsKey(contextName)) { #if !MONOTOUCH && !WINDOWS_PHONE && !SILVERLIGHT && !MONO4ANDROID NameValueCollection configurationSection = (NameValueCollection)System.Configuration.ConfigurationManager.GetSection("CoolStorage"); if (configurationSection != null) { string key = (contextName == DEFAULT_CONTEXTNAME) ? "Connection" : ("Connection." + contextName); string value = configurationSection[key]; if (value.IndexOf('/') > 0) { string dbType = value.Substring(0, value.IndexOf('/')).Trim(); string connString = value.Substring(value.IndexOf('/') + 1).Trim(); string typeName = "Vici.CoolStorage." + dbType; Type type = Type.GetType(typeName); if (type == null) { throw new CSException("Unable to load type <" + typeName + ">"); } _globalDbMap[contextName] = (CSDataProvider)Activator.CreateInstance(type, new object[] { connString }); } } #endif if (!_globalDbMap.ContainsKey(contextName)) { throw new CSException("GetDB(): context [" + contextName + "] not found"); } } } CSDataProvider db = _globalDbMap[contextName]; db = db.Clone(); _threadDbMap[contextName] = db; return(db); }
internal CSDataProvider GetDB(string contextName) { lock (_globalDbMap) { if (_globalDbMapChanged.ContainsKey(contextName) && _globalDbMapChanged[contextName]) { _globalDbMapChanged[contextName] = false; if (_threadDbMap.ContainsKey(contextName)) { _threadDbMap[contextName].Dispose(); _threadDbMap.Remove(contextName); } } } if (_threadDbMap.ContainsKey(contextName)) { return(_threadDbMap[contextName]); } lock (_globalDbMap) { if (!_globalDbMap.ContainsKey(contextName)) { #if !PCL object configurationSection = System.Configuration.ConfigurationManager.GetSection("CoolStorage"); string[] settings = GetCustomConfig(configurationSection, contextName); if (settings == null) { settings = GetLegacyConfig(configurationSection, contextName); } if (settings != null) { Type type = Type.GetType(settings[0]); if (type == null) { throw new CSException("Unable to load type <" + settings[0] + ">"); } _globalDbMap[contextName] = (CSDataProvider)Activator.CreateInstance(type, new object[] { settings[1] }); } #endif if (!_globalDbMap.ContainsKey(contextName)) { throw new CSException("GetDB(): context [" + contextName + "] not found"); } } } CSDataProvider db = _globalDbMap[contextName]; db = db.Clone(); _threadDbMap[contextName] = db; return(db); }