private FeatureflowClient(string apiKey, IEnumerable <Feature> defaultFeatures, FeatureflowConfig config)
        {
            _config = config ?? new FeatureflowConfig();
            _featureControlCache = new SimpleMemoryFeatureCache();

            InitializeDefaultFeatures(defaultFeatures);

            if (!_config.Offline)
            {
                var restConfig = new RestConfig
                {
                    SdkVersion = ((AssemblyInformationalVersionAttribute)typeof(FeatureflowClient)
                                  .GetTypeInfo().Assembly.GetCustomAttribute(typeof(AssemblyInformationalVersionAttribute))).InformationalVersion
                };

                _restClient   = new RestClient(apiKey, _config, restConfig);
                _eventsClient = new FeatureflowEventsClient(_restClient, _config);

                switch (_config.GetFeaturesMethod)
                {
                case GetFeaturesMethod.Polling:
                    _pollingClient = new PollingClient(_config, _featureControlCache, _restClient);
                    _pollingClient.FeatureUpdated += OnFeatureUpdated;
                    _pollingClient.FeatureDeleted += OnFeatureDeleted;
                    break;

                case GetFeaturesMethod.Sse:
                    _streamClient = new FeatureflowStreamClient(_config, _featureControlCache, _restClient);
                    _streamClient.FeatureUpdated += OnFeatureUpdated;
                    _streamClient.FeatureDeleted += OnFeatureDeleted;
                    break;
                }
            }
        }
        private bool disposedValue = false; // To detect redundant calls

        internal PollingClient(FeatureflowConfig config, IFeatureControlCache featureControlCache, RestClient restClient)
        {
            _config = config;
            _featureControlCache = featureControlCache;
            _restClient          = restClient;
            _timer = new Timer(new TimerCallback(OnTimer), null, TimeSpan.FromMilliseconds(-1), TimeSpan.FromMilliseconds(-1));
        }
Esempio n. 3
0
        public FeatureflowClient(string apiKey, List <Feature> features, FeatureflowConfig config)
        {
            Logger.LogInformation("Initialising Featureflow...");
            features?.ForEach(feature => _featureDefaults[feature.Key] = feature);
            _featureControlCache = new SimpleMemoryFeatureCache();

            if (config.Offline)
            {
                Logger.LogWarning("Featureflow is in Offline mode. Registered defaults will be used.");
                return;
            }

            var restConfig = new RestConfig
            {
                sdkVersion = ((AssemblyInformationalVersionAttribute)typeof(FeatureflowClient)
                              .GetTypeInfo().Assembly.GetCustomAttribute(typeof(AssemblyInformationalVersionAttribute))).InformationalVersion
            };


            _restClient = new RestClient(apiKey, config, restConfig);
            //register feature coded failover values

            //start the featureControl Client
            _featureControlClient = new PollingClient(config, _featureControlCache, _restClient);

            var initTask = _featureControlClient.Init(); //initialise
            var unused   = initTask.Task.Wait(300000);   //wait
        }
 public PollingClient(FeatureflowConfig config, IFeatureControlCache featureControlCache, RestClient restClient)
 {
     _config = config;
     _featureControlCache = featureControlCache;
     _restClient          = restClient;
     _initTask            = new TaskCompletionSource <bool>();
 }
        private bool disposedValue = false; // To detect redundant calls

        internal FeatureflowStreamClient(FeatureflowConfig config, IFeatureControlCache controlCache, RestClient restClient)
        {
            _config                     = config;
            _controlCache               = controlCache;
            _reconnectionTimer          = new Timer(OnTimer, null, TimeSpan.FromMilliseconds(-1), TimeSpan.FromMilliseconds(-1));
            _sseClient                  = new SseClient(restClient, config);
            _sseClient.MessageReceived += OnSseClient_MessageReceived;
            _sseClient.Disconnected    += OnSseClient_Disconnected;
        }