public void RewriteJson(JsonFormatting formatting, string input, string expected, bool expectedRewrite)
        {
            File.WriteAllText(_path, input);
            var actualRewrite = JsonFileHelper.RewriteJson(_path, formatting);

            Assert.Equal(expected, File.ReadAllText(_path));
            Assert.Equal(expectedRewrite, actualRewrite);
        }
Exemplo n.º 2
0
        public void Write(DateTimeOffset value)
        {
            var cursorDir = Path.GetDirectoryName(_cursorPath);

            Directory.CreateDirectory(cursorDir);
            JsonFileHelper.WriteJson(_cursorPath, value);
            Value = value;
            _logger.LogDebug("Wrote {Path} cursor: {Value:O}", _cursorPath, Value);
        }
Exemplo n.º 3
0
 public void Read()
 {
     if (!File.Exists(_cursorPath))
     {
         Value = _defaultCursorValue;
         _logger.LogDebug("Cursor {Path} does not exist. Using minimum value: {Value:O}", _cursorPath, Value);
     }
     else
     {
         Value = JsonFileHelper.ReadJson <DateTimeOffset>(_cursorPath);
         _logger.LogDebug("Read {Path} cursor: {Value:O}", _cursorPath, Value);
     }
 }
Exemplo n.º 4
0
        async Task <string> SaveToDiskAsync(string url, string destPath)
        {
            var destDir = Path.GetDirectoryName(destPath);

            Directory.CreateDirectory(destDir);

            await SaveToDiskWithRetryAsync(url, destPath);

            var rewrite = JsonFileHelper.RewriteJson(destPath, _config.JsonFormatting);

            if (rewrite)
            {
                _logger.LogDebug("The JSON at path {DestinationPath} was rewritten.", destPath);
            }

            return(destPath);
        }
Exemplo n.º 5
0
        async Task <ParsedFile <T> > DownloadAndParseAsync <T>(string url)
        {
            var destPath = GetDestinationPath(url);
            T   value;

            if (_config.SaveToDisk)
            {
                await SaveToDiskAsync(url, destPath);

                value = JsonFileHelper.ReadJson <T>(destPath);
            }
            else
            {
                value = await ParseWithRetryAsync <T>(url);
            }

            return(new ParsedFile <T>(destPath, value));
        }
Exemplo n.º 6
0
 async Task <T> ParseWithRetryAsync <T>(string url)
 {
     return(await DownloadWithRetryAsync(
                url,
                responseStream => Task.FromResult(JsonFileHelper.ReadJson <T>(responseStream))));
 }