Example #1
0
        private void LoadAll()
        {
            Dictionary <IVersionedDataKind, IDictionary <string, IVersionedData> > allData =
                new Dictionary <IVersionedDataKind, IDictionary <string, IVersionedData> >();

            foreach (var path in _paths)
            {
                try
                {
                    var content = _fileReader.ReadAllText(path);
                    var data    = _parser.Parse(content);
                    _dataMerger.AddToData(data, allData);
                }
                catch (FileNotFoundException) when(_skipMissingPaths)
                {
                    Log.DebugFormat("{0}: {1}", path, "File not found");
                }
                catch (Exception e)
                {
                    Log.ErrorFormat("{0}: {1}", path, e);
                    return;
                }
            }
            _featureStore.Init(allData);
            _loadedValidData = true;
        }
Example #2
0
        private async Task UpdateTaskAsync()
        {
            try
            {
                var allFeatures = await _featureRequestor.MakeAllRequestAsync();

                if (allFeatures != null)
                {
                    _featureStore.Init(allFeatures);

                    //We can't use bool in CompareExchange because it is not a reference type.
                    if (Interlocked.CompareExchange(ref _initialized, INITIALIZED, UNINITIALIZED) == 0)
                    {
                        _initTask.SetResult(true);
                        Logger.LogInformation("Initialized LaunchDarkly Polling Processor.");
                    }
                }
            }
            catch (AggregateException ex)
            {
                Logger.LogError(string.Format("Error Updating features: '{0}'", Util.ExceptionMessage(ex.Flatten())));
            }
            catch (Exception ex)
            {
                Logger.LogError(string.Format("Error Updating features: '{0}'", Util.ExceptionMessage(ex)));
            }
        }
Example #3
0
        private LdClient MakeClient(IFeatureStore featureStore, MockEventProcessor ep)
        {
            Configuration config = Configuration.Default("secret")
                                   .WithFeatureStoreFactory(TestUtils.SpecificFeatureStore(featureStore))
                                   .WithEventProcessorFactory(TestUtils.SpecificEventProcessor(ep))
                                   .WithUpdateProcessorFactory(Components.NullUpdateProcessor);
            LdClient client = new LdClient(config);

            featureStore.Init(new Dictionary <IVersionedDataKind, IDictionary <string, IVersionedData> >());
            return(client);
        }
Example #4
0
        protected void InitStore()
        {
            IDictionary <string, IVersionedData> items = new Dictionary <string, IVersionedData>();

            items[feature1.Key] = feature1;
            items[feature2.Key] = feature2;
            IDictionary <IVersionedDataKind, IDictionary <string, IVersionedData> > allData =
                new Dictionary <IVersionedDataKind, IDictionary <string, IVersionedData> >();

            allData[VersionedDataKind.Features] = items;
            store.Init(allData);
        }
        private async Task UpdateTaskAsync()
        {
            try
            {
                var allData = await _featureRequestor.GetAllDataAsync();

                if (allData != null)
                {
                    _featureStore.Init(allData.ToGenericDictionary());

                    //We can't use bool in CompareExchange because it is not a reference type.
                    if (Interlocked.CompareExchange(ref _initialized, INITIALIZED, UNINITIALIZED) == 0)
                    {
                        _initTask.SetResult(true);
                        Log.Info("Initialized LaunchDarkly Polling Processor.");
                    }
                }
            }
            catch (AggregateException ex)
            {
                Log.ErrorFormat("Error Updating features: '{0}'",
                                ex,
                                Util.ExceptionMessage(ex.Flatten()));
            }
            catch (UnsuccessfulResponseException ex)
            {
                Log.Error(Util.HttpErrorMessage(ex.StatusCode, "polling request", "will retry"));
                if (!Util.IsHttpErrorRecoverable(ex.StatusCode))
                {
                    try
                    {
                        // if client is initializing, make it stop waiting
                        _initTask.SetResult(true);
                    }
                    catch (InvalidOperationException)
                    {
                        // the task was already set - nothing more to do
                    }
                    ((IDisposable)this).Dispose();
                }
            }
            catch (Exception ex)
            {
                Log.ErrorFormat("Error Updating features: '{0}'",
                                ex,
                                Util.ExceptionMessage(ex));
            }
        }
Example #6
0
        private void LoadAll()
        {
            Dictionary <IVersionedDataKind, IDictionary <string, IVersionedData> > allData =
                new Dictionary <IVersionedDataKind, IDictionary <string, IVersionedData> >();

            foreach (var path in _paths)
            {
                try
                {
                    var content = ReadFileContent(path);
                    var data    = _parser.Parse(content);
                    data.AddToData(allData);
                }
                catch (Exception e)
                {
                    Log.ErrorFormat("{0}: {1}", path, e);
                    return;
                }
            }
            _featureStore.Init(allData);
            _loadedValidData = true;
        }
Example #7
0
        private async Task UpdateTaskAsync()
        {
            try
            {
                var allData = await _featureRequestor.GetAllDataAsync();

                if (allData != null)
                {
                    _featureStore.Init(allData.ToGenericDictionary());

                    //We can't use bool in CompareExchange because it is not a reference type.
                    if (Interlocked.CompareExchange(ref _initialized, INITIALIZED, UNINITIALIZED) == 0)
                    {
                        _initTask.SetResult(true);
                        Log.Info("Initialized LaunchDarkly Polling Processor.");
                    }
                }
            }
            catch (AggregateException ex)
            {
                Log.ErrorFormat("Error Updating features: '{0}'",
                                ex,
                                Util.ExceptionMessage(ex.Flatten()));
            }
            catch (FeatureRequestorUnsuccessfulResponseException ex) when(ex.StatusCode == 401)
            {
                Log.ErrorFormat("Error Updating features: '{0}'", Util.ExceptionMessage(ex));
                Log.Error("Received 401 error, no further polling requests will be made since SDK key is invalid");
                ((IDisposable)this).Dispose();
            }
            catch (Exception ex)
            {
                Log.ErrorFormat("Error Updating features: '{0}'",
                                ex,
                                Util.ExceptionMessage(ex));
            }
        }
Example #8
0
 public void Init(IDictionary <IVersionedDataKind, IDictionary <string, IVersionedData> > allData)
 {
     _store.Init(FeatureStoreDataSetSorter.SortAllCollections(allData));
 }
Example #9
0
 public Task <bool> Start()
 {
     _store.Init(_data);
     return(Task.FromResult(true));
 }