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);
        }
Exemplo n.º 2
0
    // Internal methods
    private bool ShiftConfigFiles()
    {
        try
        {
            var previousConfig = $"{CoreConfig.ConfigFile}.previous";

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

            _file.Copy(CoreConfig.ConfigFile, previousConfig);
            _file.Delete(CoreConfig.ConfigFile);

            return(true);
        }
        catch (Exception ex)
        {
            _logger.LogUnexpectedException(ex);
            return(false);
        }
    }