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)); } }
public async Task <Dictionary <string, string> > GetAllAsync() { try { using (new ProfileContext("ConsulConfigurationStore.GetAll")) { var formatedKey = "/"; var dataSet = await ConsulClientFactory.Instance.KV.List(formatedKey); await LogRQRS(formatedKey, dataSet, _applicationName, "get_all_async"); var response = ParseResponse(dataSet); if (response != null) { Profiling.Trace($"Key: {response.Count}"); } return(response); } } catch (Exception ex) { Platform.Common.ExceptionPolicy.HandleException(ex, Constants.DefaultPolicy); } throw new ConfigurationException("Could not connect to consul", "100", System.Net.HttpStatusCode.InternalServerError); }
private async Task <RowSet> ExecuteStatement(IStatement statement) { using (new TraceProfileContext("ExecuteQuery", "Execute query")) { RowSet rowSet = null; var numberOfAttempt = 0; do { try { rowSet = await _session.ExecuteAsync(statement); return(rowSet); } catch (NoHostAvailableException noHostAvailableEx) { ExceptionPolicy.HandleException(noHostAvailableEx, "logonly"); await Task.Delay(RetrySetting.DelayInMs); numberOfAttempt++; Profiling.Trace("Number of attempt(s) " + (numberOfAttempt).ToString()); if (numberOfAttempt > RetrySetting.NumberOfRetry) { throw noHostAvailableEx; } } catch (Exception ex) { throw ex; } } while (numberOfAttempt <= RetrySetting.NumberOfRetry); return(rowSet); } }
public static string Get(string key) { using (new ProfileContext("LocalConfigurationRepository.Get")) { Profiling.Trace($"Key: {key}"); string value = string.Empty; var result = _kvStorage.TryGetValue(key, out value) ? value : string.Empty; 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); }