Example #1
0
    private DnsEntriesConfig LoadConfiguration(DnsUpdaterConfig config)
    {
        var configDir = _path.GetDirectoryName(config.ConfigFile);

        // Ensure that the configuration directory exists
        if (!_directory.Exists(configDir))
        {
            _logger.LogInformation("Creating configuration directory: {path}", configDir);
            _directory.CreateDirectory(configDir);
        }

        // Ensure that we have a configuration file to work with
        if (!_file.Exists(config.ConfigFile))
        {
            _logger.LogInformation("Generating sample configuration file: {path}", config.ConfigFile);
            var sampleJson = _jsonHelper.SerializeObject(GenerateSampleConfig(), true);
            _file.WriteAllText(config.ConfigFile, sampleJson);
        }

        // Load, parse and return our configuration
        var rawConfig = _file.ReadAllText(config.ConfigFile);

        return(_jsonHelper.DeserializeObject <DnsEntriesConfig>(rawConfig));
    }
Example #2
0
        private string GetResponseBody(DevHttpResponse response)
        {
            // TODO: [TESTS] (DevGrafanaHttpClient.GetResponseBody) Add tests
            if (response.ResponseType == DevHttpClientResponseType.File)
            {
                if (string.IsNullOrWhiteSpace(response.GeneratedResponseBody))
                {
                    if (!_file.Exists(response.FilePath))
                    {
                        // TODO: [EX] (DevGrafanaHttpClient.GetResponseBody) Throw better exception here
                        _logger.Error("Unable to find response file: {path}", response.FilePath);
                        throw new Exception($"Unable to find response file: {response.FilePath}");
                    }

                    response.GeneratedResponseBody = _file.ReadAllText(response.FilePath);
                    _logger.Trace("Set GeneratedResponseBody using {path}", response.FilePath);
                }

                return(response.GeneratedResponseBody);
            }

            // TODO: [COMPLETE] (DevGrafanaHttpClient.GetResponseBody) Complete me
            return(string.Empty);
        }
Example #3
0
 protected override bool ExecuteWithNoGuard()
 {
     _previousState = _fileAbstraction.ReadAllText(_filename);
     _fileAbstraction.WriteAllText(_filename, JsonConvert.SerializeObject(_versionData));
     return(true);
 }