internal static IFeatureflowClient Create( string apiKey, IEnumerable <Feature> defaultFeatures, FeatureflowConfig featureflowConfig) { var client = new FeatureflowClient(apiKey, defaultFeatures, featureflowConfig); using (var evt = new ManualResetEventSlim(false)) { Task.Run(async() => { try { await client.InitializeAsync(CancellationToken.None).ConfigureAwait(false); } finally { evt.Set(); } }); evt.Wait(); } return(client); }
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 }
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; } } }
/// <summary> /// Async Featureflow client creation /// </summary> /// <param name="apiKey">Featureflow API key</param> /// <param name="defaultFeatures">Default features</param> /// <param name="featureflowConfig">Featureflow client configuration</param> /// <returns>Featureflow client</returns> public static Task <IFeatureflowClient> CreateAsync( string apiKey, IEnumerable <Feature> defaultFeatures, FeatureflowConfig featureflowConfig) { return(CreateAsync(apiKey, defaultFeatures, featureflowConfig, CancellationToken.None)); }
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)); }
/// <summary> /// Async Featureflow client creation /// </summary> /// <param name="apiKey">Featureflow API key</param> /// <param name="featureflowConfig">Featureflow client configuration</param> /// <param name="cancellationToken">Cancellation token</param> /// <returns>Featureflow client</returns> public static Task <IFeatureflowClient> CreateAsync( string apiKey, FeatureflowConfig featureflowConfig, CancellationToken cancellationToken) { return(CreateAsync(apiKey, null, featureflowConfig, cancellationToken)); }
public PollingClient(FeatureflowConfig config, IFeatureControlCache featureControlCache, RestClient restClient) { _config = config; _featureControlCache = featureControlCache; _restClient = restClient; _initTask = new TaskCompletionSource <bool>(); }
public RestClient(string apiKey, FeatureflowConfig config, RestConfig restConfig) { _apiKey = apiKey; _config = config; _restConfig = restConfig; _httpClient = CreateHttpClient(); }
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; }
private bool disposedValue = false; // To detect redundant calls internal FeatureflowEventsClient(RestClient restClient, FeatureflowConfig config) { _restClient = restClient; _config = config; if (!_config.Offline) { _events = new List <Event>(MaximumEventsInQueue); _timer = new Timer(OnTimer, null, EventsSendPeriod, EventsSendPeriod); } }
internal static async Task <IFeatureflowClient> CreateAsync( string apiKey, IEnumerable <Feature> defaultFeatures, FeatureflowConfig featureflowConfig, CancellationToken cancellationToken) { var client = new FeatureflowClient(apiKey, defaultFeatures, featureflowConfig); await client.InitializeAsync(cancellationToken).ConfigureAwait(false); return(client); }
internal SseClient(RestClient restClient, FeatureflowConfig config) { _restClient = restClient; _config = config; }
internal RestClient(string apiKey, FeatureflowConfig config, RestConfig restConfig) { _apiKey = apiKey; _config = config; _restConfig = restConfig; }
/// <summary> /// Sync Featureflow client creation /// </summary> /// <param name="apiKey">Featureflow API key</param> /// <param name="defaultFeatures">Default features</param> /// <param name="featureflowConfig">Featureflow client configuration</param> /// <returns>Featureflow client</returns> public static IFeatureflowClient Create(string apiKey, IEnumerable <Feature> defaultFeatures, FeatureflowConfig featureflowConfig) { return(FeatureflowClient.Create(apiKey, defaultFeatures, featureflowConfig)); }
/// <summary> /// Sync Featureflow client creation /// </summary> /// <param name="apiKey">Featureflow API key</param> /// <param name="featureflowConfig">Featureflow client configuration</param> /// <returns>Featureflow client</returns> public static IFeatureflowClient Create(string apiKey, FeatureflowConfig featureflowConfig) { return(Create(apiKey, null, featureflowConfig)); }