public void HandleEvent()
        {
            var task = Task.Run(async() =>
            {
                try
                {
                    var kvStore = await _configurationStore.GetAllAsync();
                    if (kvStore == null || kvStore.Count == 0)
                    {
                        return;
                    }

                    LocalConfigurationRepository.ReplaceAll(new ConcurrentDictionary <string, string>(kvStore));
                }
                catch (Exception ex)
                {
                    Platform.Common.ExceptionPolicy.HandleException(ex, Constants.DefaultPolicy);
                }
            });

            task.ContinueWith(t =>
            {
                //raise an event on successful completion of above task.
                if (t.IsFaulted == false && t.IsCompleted)
                {
                    _applicationEventBus.Notify(GetCacheRefreshedEvent());
                }
            });
        }
        private string GetFromRemote(string scope, string application, string section, string key)
        {
            var value    = _remoteConfigurationStore.Get(scope, application, section, key);
            var cacheKey = KeyMaker.ConstructKey(scope, application, section, key);

            LocalConfigurationRepository.Update(cacheKey, value);
            return(value);
        }
        public async Task <string> GetAsync(string scope, string application, string section, string key)
        {
            var cacheKey = KeyMaker.ConstructKey(scope, application, section, key);
            var result   = LocalConfigurationRepository.IsKeyPresent(cacheKey)
                            ? await GetFromLocalAsync(cacheKey)
                            : await GetFromRemoteAsync(scope, application, section, key);

            return(result);
        }
Esempio n. 4
0
        public string Get(string scope, string application, string section, string key)
        {
            var cacheKey = KeyMaker.ConstructKey(scope, application, section, key);
            var result   = LocalConfigurationRepository.IsKeyPresent(cacheKey)
                            ? LocalConfigurationRepository.Get(cacheKey)
                            : GetFromRemote(scope, application, section, key);

            return(result);
        }
 public string Get(string scope, string application, string section, string key)
 {
     using (new ProfileContext("CachedConfigurationStore.Get"))
     {
         var cacheKey = KeyMaker.ConstructKey(scope, application, section, key);
         Profiling.Trace($"Key: {key}");
         var result = LocalConfigurationRepository.IsKeyPresent(cacheKey)
                         ? LocalConfigurationRepository.Get(cacheKey)
                         : GetFromRemote(scope, application, section, key);
         return(result);
     }
 }
        private Task <string> GetFromLocalAsync(string key)
        {
            string value = LocalConfigurationRepository.Get(key);

            return(Task.FromResult <string>(value));
        }