コード例 #1
0
        public ConnectionParameters GetConnectionParameters(string type, string name, params object[] parameters)
        {
            string              indexName = null;
            JObject             indexConfig;
            ESIndexPolicyConfig policyConfig;

            if (_config.Indices.TryGetValue(name, out indexConfig))
            {
                policyConfig = indexConfig.ToObject <ESIndexPolicyConfig>();
            }
            else
            {
                policyConfig = new ESIndexPolicyConfig();
            }

            var formatCtx = new IndexNameFormatContext
            {
                account     = _account,
                application = _application,
                deployment  = _deploymentId,
                args        = parameters,
                type        = type,
                name        = name
            };

            _eventHandlers().RunEventHandler <IESClientFactoryEventHandler>(e => e.OnCreatingIndexName(formatCtx), ex =>
            {
                _logger.Log(Stormancer.Diagnostics.LogLevel.Error, LOG_CATEGORY, "An error occured while running an 'database.OnCreate' event handler", ex);
            });

            var pattern = policyConfig.Pattern;

            if (pattern == null)
            {
                pattern = _config.defaultPattern;
            }

            {
                indexName = SmartFormat.Smart.Format(pattern, formatCtx);
            }

            if (string.IsNullOrWhiteSpace(indexName))
            {
                indexName = $"{name}-{type}";
            }

            return(new ConnectionParameters {
                ConnectionPool = policyConfig.ConnectionPool, IndexName = indexName.ToLowerInvariant(), maxRetries = policyConfig.MaxRetries, retryTimeout = policyConfig.RetryTimeout
            });
        }
コード例 #2
0
 public void OnCreatingIndexName(IndexNameFormatContext ctx)
 {
     ctx.ctx.Add("season", _config.Settings.season);
 }