Esempio n. 1
0
        public async Task LoadConfigFileAsync()
        {
            var json = await _fileService.ReadFromFileAsync(ConfigName, CancellationToken.None);

            if (json == null)
            {
                LogHelper.LogWarning($"{ConfigName} file not found, a new file will be created");
                await SaveDefaultConfigFileAsync();

                return;
            }

            try
            {
                _localPackages = JsonConvert.DeserializeObject <List <LocalPackageInfo> >(json);
            }
            catch (JsonException ex)
            {
                var backupPath = await _fileService.BackupFileAsync(ConfigName, CancellationToken.None);

                LogHelper.LogWarningException($"An error occurred while reading {ConfigName} file, a new file will be created. Copy of old file placed at {backupPath}", ex);
                await SaveDefaultConfigFileAsync();
            }
        }