Ejemplo n.º 1
0
            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);
            }
Ejemplo n.º 2
0
            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);
            }