Exemplo n.º 1
0
        private void BuildSplitClient()
        {
            _options = _options ?? new ConfigurationOptions();

            _apiKeyValidator.Validate(_apiKey);

            switch (_options.Mode)
            {
            case Mode.Standalone:
                if (string.IsNullOrEmpty(_apiKey))
                {
                    throw new Exception("API Key should be set to initialize Split SDK.");
                }
                if (_apiKey == "localhost")
                {
                    _client = new LocalhostClient(_options.LocalhostFilePath);
                }
                else
                {
                    _client = new SelfRefreshingClient(_apiKey, _options);
                }
                break;

            case Mode.Consumer:
                if (_options.CacheAdapterConfig != null && _options.CacheAdapterConfig.Type == AdapterType.Redis)
                {
                    try
                    {
                        if (string.IsNullOrEmpty(_options.CacheAdapterConfig.Host) || string.IsNullOrEmpty(_options.CacheAdapterConfig.Port))
                        {
                            throw new Exception("Redis Host and Port should be set to initialize Split SDK in Redis Mode.");
                        }

                        var redisAssembly = Assembly.Load(new AssemblyName("Splitio-net-core.Redis"));
                        var redisType     = redisAssembly.GetType("Splitio.Redis.Services.Client.Classes.RedisClient");

                        _client = (ISplitClient)Activator.CreateInstance(redisType, new object[] { _options, _apiKey, null });
                    }
                    catch (Exception e)
                    {
                        throw new Exception("Splitio.Redis package should be added as reference, to build split client in Redis Consumer mode.", e);
                    }
                }
                else
                {
                    throw new Exception("Redis config should be set to build split client in Consumer mode.");
                }
                break;

            case Mode.Producer:
                throw new Exception("Unsupported mode.");

            default:
                throw new Exception("Mode should be set to build split client.");
            }

            _factoryInstantiationsService.Increase(_apiKey);
        }
Exemplo n.º 2
0
        private void BuildSplitClient()
        {
            _options = _options ?? new ConfigurationOptions();

            if (!_options.Ready.HasValue)
            {
                _log.Warn("no ready parameter has been set - incorrect control treatments could be logged if no ready config has been set when building factory");
            }

            _apiKeyValidator.Validate(_apiKey);

            switch (_options.Mode)
            {
            case Mode.Standalone:
                if (string.IsNullOrEmpty(_apiKey))
                {
                    throw new Exception("API Key should be set to initialize Split SDK.");
                }
                if (_apiKey == "localhost")
                {
                    _client = new LocalhostClient(_options.LocalhostFilePath, _log);
                }
                else
                {
                    _client = new SelfRefreshingClient(_apiKey, _options, _log);
                }
                break;

            case Mode.Consumer:
                if (_options.CacheAdapterConfig != null && _options.CacheAdapterConfig.Type == AdapterType.Redis)
                {
                    try
                    {
                        if (string.IsNullOrEmpty(_options.CacheAdapterConfig.Host) || string.IsNullOrEmpty(_options.CacheAdapterConfig.Port))
                        {
                            throw new Exception("Redis Host and Port should be set to initialize Split SDK in Redis Mode.");
                        }

                        var handle = Activator.CreateInstance("Splitio.Redis", "Splitio.Redis.Services.Client.Classes.RedisClient", false, default(BindingFlags), default(Binder), new object[] { _options, _log, _apiKey }, default(CultureInfo), null);
                        _client = (ISplitClient)handle.Unwrap();
                    }
                    catch (Exception e)
                    {
                        throw new Exception("Splitio.Redis package should be added as reference, to build split client in Redis Consumer mode.", e);
                    }
                }
                else
                {
                    throw new Exception("Redis config should be set to build split client in Consumer mode.");
                }
                break;

            case Mode.Producer:
                throw new Exception("Unsupported mode.");

            default:
                throw new Exception("Mode should be set to build split client.");
            }

            _factoryInstantiationsService.Increase(_apiKey);
        }