示例#1
0
        public async Task <bool> Run()
        {
            var app = await _userPollService.AskApplication();

            var env = await _userPollService.AskEnvironment(app);

            var cfgProfile = await _userPollService.AskConfigurationProfile(app);

            Console.Write("Client id: ");
            var clientId = Console.ReadLine();

            var version = _userPollService.AskVersion();

            var config = await _client.GetConfigurationAsync(new GetConfigurationRequest
            {
                Application   = app.Id,
                Environment   = env.Id,
                Configuration = cfgProfile.Id,
                ClientId      = clientId,
                ClientConfigurationVersion = version
            });

            Console.WriteLine($"Config version: {config.ConfigurationVersion}");
            Console.WriteLine($"Config content type: {config.ContentType}");

            var strContent = Encoding.ASCII.GetString(config.Content.ToArray());

            Console.WriteLine("Config content:");
            Console.WriteLine(strContent);


            return(false);
        }
示例#2
0
        public async Task <string> GetConfig()
        {
            var config = await _client.GetConfigurationAsync(new GetConfigurationRequest
            {
                Application   = _application.Id,
                Environment   = _environment.Id,
                Configuration = _configurationProfile.Id,
                ClientId      = _clientId,
                ClientConfigurationVersion = _currentVersion
            });

            var cfgIsUpToDate = config.Content == null || config.ContentLength == 0;

            if (cfgIsUpToDate)
            {
                if (string.IsNullOrWhiteSpace(_currentConfig))
                {
                    throw new Exception("Fatal error. Aws returned empty content which means we requested a config with version and must to have cached value for this version, " +
                                        $"but we don't have. ClientId: {_clientId}; Application: {_application.Id}; Environment: {_environment.Id}; " +
                                        $"Configuration: {_configurationProfile.Id}; ClientConfigurationVersion: {_currentVersion};");
                }


                _logger.WriteConsistently(() =>
                {
                    Console.Write($"{_clientId}, configuration {_configurationProfile.Name}. ");
                    Console.BackgroundColor = ConsoleColor.Green;
                    Console.Write($"Returns preserved version {_currentVersion}. \r\n");
                });

                return(_currentConfig);
            }

            _currentVersion = config.ConfigurationVersion;
            _currentConfig  = Encoding.ASCII.GetString(config.Content.ToArray());

            _logger.WriteConsistently(() =>
            {
                Console.Write($"{_clientId}, configuration {_configurationProfile.Name}. ");
                Console.BackgroundColor = ConsoleColor.Red;
                Console.Write($"Returns remote version {_currentVersion}. \r\n");
            });

            return(_currentConfig);
        }