Ejemplo n.º 1
0
        protected static void ExportJsonToCsvInFileConsoleDataDirectory(IAddressService addressService)
        {
            var fileContents = File.ReadAllText(JsonFilePathImport);

            var jsonRecords =
                JsonSerializer.Deserialize <List <JsonAddressesReaderDtoDto> >(fileContents, _jsonSerializerOptions);

            CustomValidator.ValidateJsonCsvAddressesReaderDtos(jsonRecords);

            var mapper = MappingProfile.FromJsonAddressesToCsvAddressesDto(jsonRecords);

            using (var writer = new StreamWriter(CsvFilePathExport))
            {
                using (var csv = new CsvHelper.CsvWriter(writer))
                {
                    csv.WriteRecords(mapper);
                }
            }

            ClearScreenAfterInteraction("Exported json to csv file directory located @consoledata/export-addresses.csv on. Press any key to clear screen and use other options...");
        }