Exemplo n.º 1
0
        private async Task DoLoad(bool reloading)
        {
            try
            {
                IConfigQueryResult configQueryResult = await _consulConfigClient.GetConfig();

                if (!configQueryResult.Exists && !_source.Optional)
                {
                    if (!reloading)
                    {
                        throw new Exception($"The configuration for key {_source.Key} was not found and is not optional.");
                    }
                    else
                    {
                        // Don't overwrite mandatory config with empty data if not found when reloading
                        return;
                    }
                }

                LoadIntoMemory(configQueryResult);
            }
            catch (Exception exception)
            {
                HandleLoadException(exception);
            }
        }
Exemplo n.º 2
0
        public async Task ShouldReturnResultWhenGetConfigReceivesValidResponse(HttpStatusCode statusCode)
        {
            var result = new QueryResult <KVPair>
            {
                StatusCode = statusCode
            };
            IConfigQueryResult configQueryResult = await SimulateGet(result);

            Assert.That(configQueryResult, Is.Not.Null);
        }
Exemplo n.º 3
0
        private void LoadIntoMemory(IConfigQueryResult configQueryResult)
        {
            if (!configQueryResult.Exists)
            {
                Data = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);
                return;
            }

            using (var configStream = new MemoryStream(configQueryResult.Value))
            {
                var parsedData = _source.Parser.Parse(configStream);
                Data = new Dictionary <string, string>(parsedData, StringComparer.OrdinalIgnoreCase);
            }
        }