public void SaveJsonFile(string path, string json, bool format = false)
        {
            // TODO: [TESTS] (FileSystemHelper.SaveJsonFile) Add tests
            if (format)
            {
                if (!_jsonHelper.TryDeserializeObject(json, out object parsed))
                {
                    throw new Exception("Invalid JSON");
                }

                json = _jsonHelper.SerializeObject(parsed, true);
            }

            if (_file.Exists(path))
            {
                _file.Delete(path);
            }

            var directoryPath = _path.GetDirectoryName(path);

            if (!_directory.Exists(directoryPath))
            {
                _directory.CreateDirectory(directoryPath);
            }

            _file.WriteAllText(path, json);
        }
Exemple #2
0
    public void SaveConfigState()
    {
        if (!ShiftConfigFiles())
        {
            _logger.LogError("Unable to manage configuration files, quitting!");
            _environment.Exit(10);
        }

        try
        {
            var configJson = _jsonHelper.SerializeObject(_dnsEntriesConfig, true);
            _file.WriteAllText(CoreConfig.ConfigFile, configJson);
            _logger.LogDebug("Updated configuration file");
        }
        catch (Exception ex)
        {
            _logger.LogUnexpectedException(ex);
            _environment.Exit(11);
        }
    }
Exemple #3
0
 protected override bool ExecuteWithNoGuard()
 {
     _previousState = _fileAbstraction.ReadAllText(_filename);
     _fileAbstraction.WriteAllText(_filename, JsonConvert.SerializeObject(_versionData));
     return(true);
 }