示例#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 {
                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);
            });

            if (policyConfig.Pattern != null)
            {
                indexName = SmartFormat.Smart.Format(policyConfig.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);
 }