Beispiel #1
0
        private void ConfigurationChanged(PriusConfig config)
        {
            var oldRepositories = _repositories;

            if (config == null || config.Repositories == null || config.Repositories.Count == 0)
            {
                _repositories = new Dictionary<string, IRepository>();
            }
            else
            {
                _repositories = config.Repositories.ToDictionary(
                    r => r.Name.ToLower(),
                    r => new Repository(_connectionFactory, _configurationStore).Initialize(r.Name));
            }

            if (oldRepositories != null)
            {
                lock (oldRepositories)
                {
                    foreach (var repo in oldRepositories.Values)
                        repo.Dispose();
                }
            }
        }
Beispiel #2
0
        private void ConfigurationChanged(PriusConfig config)
        {
            Action nullConfig = () =>
                {
                    _groups = new Group[0];
                };

            if (config == null || config.Repositories == null)
            {
                nullConfig();
                return;
            }

            var repositoryConfiguration = config.Repositories.FirstOrDefault(r => string.Equals(r.Name, Name, StringComparison.InvariantCultureIgnoreCase));
            if (repositoryConfiguration == null)
            {
                nullConfig();
                return;
            }

            var fallbackPolicies = config.FallbackPolicies == null
                ? new Dictionary<string, FallbackPolicy>()
                : config.FallbackPolicies.ToDictionary(p => p.Name);

            var databases = config.Databases == null
                ? new Dictionary<string, Database>()
                : config.Databases.ToDictionary(s => s.Name);

            var groups = repositoryConfiguration.Clusters
                .Where(cluster => cluster.Enabled)
                .OrderBy(cluster => cluster.SequenceNumber)
                .Select(cluster =>
                {
                    FallbackPolicy fallbackPolicy;
                    if (!fallbackPolicies.TryGetValue(cluster.FallbackPolicyName, out fallbackPolicy))
                        fallbackPolicy = new FallbackPolicy();

                    var servers = cluster.DatabaseNames
                        .Select(databaseName =>
                        {
                            Database database;
                            return databases.TryGetValue(databaseName, out database)
                                ? database
                                : null;
                        })
                        .Where(database => database != null && database.Enabled)
                        .OrderBy(database => database.SequenceNumber)
                        .Select(database => new Server(
                            database.ServerType,
                            database.ConnectionString,
                            database.StoredProcedures == null ? null : database.StoredProcedures.ToDictionary(p => p.Name.ToLower(), p => p.TimeoutSeconds)));

                    return new Group().Initialize
                        (
                            this,
                            fallbackPolicy.FailureWindowSeconds,
                            fallbackPolicy.AllowedFailurePercent / 100f,
                            fallbackPolicy.WarningFailurePercent / 100f,
                            fallbackPolicy.BackOffTime,
                            servers
                        );
                });
            _groups = groups.ToArray();
        }