private IConfigurationSettingItem Parse(string storeType, string providerName, string providerType, string databaseType, string key, string connectionString) { var setting = new StringInstanceSetting { ProviderName = providerName, ProviderType = providerType, DatabaseType = string.IsNullOrEmpty(databaseType) ? null : Type.GetType(databaseType, false, true) }; switch (string.Concat(string.Empty, storeType).ToLower()) { case "appsettings": #if !NETSTANDARD setting.ReferenceType = StringReferenceType.AppSettings; if (!string.IsNullOrEmpty(key)) { setting.ConnectionString = ConnectionStringHelper.GetConnectionString(ConfigurationManager.AppSettings[key]); } #endif break; case "connectionstrings": #if !NETSTANDARD setting.ReferenceType = StringReferenceType.ConnectionStrings; if (!string.IsNullOrEmpty(key)) { var connstr = ConfigurationManager.ConnectionStrings[key]; if (connstr != null) { setting.ConnectionString = ConnectionStringHelper.GetConnectionString(connstr.ConnectionString); } } #endif break; default: setting.ReferenceType = StringReferenceType.String; setting.ConnectionString = ConnectionStringHelper.GetConnectionString(connectionString); break; } return(setting); }
public IConfigurationSettingItem Parse(XmlNode node) { var setting = new StringInstanceSetting(); var storeType = node.GetAttributeValue("storeType"); setting.Name = node.GetAttributeValue("name"); setting.ProviderName = node.GetAttributeValue("providerName"); setting.ProviderType = node.GetAttributeValue("providerType"); setting.DatabaseType = Type.GetType(node.GetAttributeValue("databaseType"), false, true); var key = node.GetAttributeValue("key"); switch (storeType.ToLower()) { case "appsettings": setting.ReferenceType = StringReferenceType.AppSettings; if (!string.IsNullOrEmpty(key)) { setting.ConnectionString = ConnectionStringHelper.GetConnectionString(ConfigurationManager.AppSettings[key]); } break; case "connectionstrings": setting.ReferenceType = StringReferenceType.ConnectionStrings; if (!string.IsNullOrEmpty(key)) { var connstr = ConfigurationManager.ConnectionStrings[key]; if (connstr != null) { setting.ConnectionString = ConnectionStringHelper.GetConnectionString(connstr.ConnectionString); } } break; default: setting.ReferenceType = StringReferenceType.String; setting.ConnectionString = ConnectionStringHelper.GetConnectionString(node.GetAttributeValue("connectionString")); break; } return(setting); }
private IConfigurationSettingItem Parse(string storeType, string providerName, string providerType, string databaseType, string key, IConfiguration clusters) { var setting = new StringInstanceSetting { ProviderName = providerName, ProviderType = providerType, DatabaseType = string.IsNullOrEmpty(databaseType) ? null : Type.GetType(databaseType, false, true) }; var master = clusters.GetSection("master"); var slaves = clusters.GetSection("slaves"); if (master.Exists()) { var connstr = master["connectionString"]; var cluster = new ClusteredConnectionSetting { ConnectionString = ConnectionStringHelper.GetConnectionString(connstr), Mode = DistributedMode.Master }; setting.Clusters.Add(cluster); } if (slaves.Exists()) { foreach (var child in slaves.GetChildren()) { var connstr = child["connectionString"]; var cluster = new ClusteredConnectionSetting { ConnectionString = ConnectionStringHelper.GetConnectionString(connstr), Mode = DistributedMode.Slave, Weight = child["weight"].To(0) }; setting.Clusters.Add(cluster); } } return(setting); }
private IConfigurationSettingItem Parse(string storeType, string providerName, string providerType, string databaseType, string key, XmlNode clusters) { var setting = new StringInstanceSetting { ProviderName = providerName, ProviderType = providerType, DatabaseType = string.IsNullOrEmpty(databaseType) ? null : Type.GetType(databaseType, false, true) }; var master = clusters.SelectSingleNode("master"); var slaves = clusters.SelectSingleNode("slaves"); if (master != null) { var connstr = master.GetAttributeValue("connectionString"); var cluster = new ClusteredConnectionSetting { ConnectionString = ConnectionStringHelper.GetConnectionString(connstr), Mode = DistributedMode.Master }; setting.Clusters.Add(cluster); } if (slaves != null) { foreach (XmlNode node in slaves.ChildNodes) { var connstr = node.GetAttributeValue("connectionString"); var cluster = new ClusteredConnectionSetting { ConnectionString = ConnectionStringHelper.GetConnectionString(connstr), Mode = DistributedMode.Slave, Weight = node.GetAttributeValue("weight", 0) }; setting.Clusters.Add(cluster); } } return(setting); }