public string Get(string scope, string application, string section, string key)
        {
            using (new ProfileContext("ConsulConfigurationStore.Get"))
            {
                var formatedKey = KeyMaker.ConstructKey(scope, application, section, key).ToLowerInvariant();

                Profiling.Trace($"Key: {formatedKey}");

                QueryResult <KVPair> response = null;

                var waitHandle = new ManualResetEvent(false);

                Task.Factory.StartNew(async() =>
                {
                    try
                    {
                        response = await ConsulClientFactory.Instance.KV.Get(formatedKey);
                        await LogRQRS(formatedKey, response, application, "get");
                    }
                    finally
                    {
                        waitHandle.Set();
                    }
                });
                waitHandle.WaitOne();

                return(ParseResponse(response));
            }
        }
        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);
        }
Beispiel #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);
     }
 }
        public async Task <string> GetAsync(string scope, string application, string section, string key)
        {
            try
            {
                using (new ProfileContext("ConsulConfigurationStore.Get"))
                {
                    var formatedKey = KeyMaker.ConstructKey(scope, application, section, key).ToLowerInvariant();
                    Profiling.Trace($"Key: {formatedKey}");
                    var response = await ConsulClientFactory.Instance.KV.Get(formatedKey);
                    await LogRQRS(formatedKey, response, application, "get_async");

                    return(ParseResponse(response));
                }
            }

            catch (Exception ex)
            {
                Platform.Common.ExceptionPolicy.HandleException(ex, Constants.DefaultPolicy);
            }
            throw new ConfigurationException("Could not connect to consul", "100", System.Net.HttpStatusCode.InternalServerError);
        }
        public string Get(string scope, string application, string section, string key)
        {
            var formatedKey = KeyMaker.ConstructKey(scope, application, section, key).ToLowerInvariant();

            QueryResult <KVPair> response = null;

            var waitHandle = new ManualResetEvent(false);

            Task.Factory.StartNew(async() =>
            {
                try
                {
                    response = await ConsulClientFactory.Instance.KV.Get(formatedKey);
                }
                finally
                {
                    waitHandle.Set();
                }
            });
            waitHandle.WaitOne();

            return(ParseResponse(response));
        }
        public async Task <string> GetAsync(string scope, string application, string section, string key)
        {
            try
            {
                var formatedKey = KeyMaker.ConstructKey(scope, application, section, key).ToLowerInvariant();

                var response = await ConsulClientFactory.Instance.KV.Get(formatedKey);

                return(ParseResponse(response));
            }
            catch (System.Net.Http.HttpRequestException ex)
            {
                Platform.Common.ExceptionPolicy.HandleException(ex, Constants.DefaultPolicy);
                throw new ConfigurationException("Could not connect to consul", "100", ex);
            }

            catch (Exception ex)
            {
                Platform.Common.ExceptionPolicy.HandleException(ex, Constants.DefaultPolicy);
            }

            return(null);
        }