private static Configuration CreateCsvConfiguration(FileStructureMetadata fileStructureMetadata)
        {
            var csvConfiguration = CreateDefaultCsvConfiguration(fileStructureMetadata.SourceKind);

            csvConfiguration.CultureInfo = fileStructureMetadata.GetCultureInfo();
            csvConfiguration.Encoding    = Encoding.GetEncoding(fileStructureMetadata.Encoding);
            return(csvConfiguration);
        }
        private static Configuration CreateDefaultCsvConfiguration(SourceKind sourceKind)
        {
            var configuration = new Configuration();

            switch (sourceKind)
            {
            case SourceKind.FortisCsvArchive:
                configuration.RegisterClassMap <FortisOperationArchiveCsvMap>();
                configuration.Encoding          = Encoding.UTF8;
                configuration.CultureInfo       = FileStructureMetadata.GetCultureInfo("fr-BE", ",");
                configuration.Delimiter         = ";";
                configuration.QuoteAllFields    = true;
                configuration.TrimOptions       = TrimOptions.InsideQuotes;
                configuration.MissingFieldFound = LogMissingFieldFound;
                configuration.HeaderValidated   = LogHeaderValidatationFailed;
                break;

            case SourceKind.FortisCsvExport:
                configuration.RegisterClassMap <FortisOperationExportCsvMap>();
                var ansiEncoding = Encoding.GetEncoding(1252);
                configuration.Encoding          = ansiEncoding;
                configuration.CultureInfo       = FileStructureMetadata.GetCultureInfo("fr-BE", ".");
                configuration.Delimiter         = ";";
                configuration.QuoteAllFields    = false;
                configuration.TrimOptions       = TrimOptions.Trim;
                configuration.MissingFieldFound = LogMissingFieldFound;
                configuration.HeaderValidated   = LogHeaderValidatationFailed;
                break;

            case SourceKind.SodexoCsvExport:
                configuration.RegisterClassMap <SodexoOperationCsvMap>();
                configuration.Encoding          = Encoding.UTF8;
                configuration.CultureInfo       = FileStructureMetadata.GetCultureInfo("fr-BE", ".");
                configuration.Delimiter         = ";";
                configuration.QuoteAllFields    = true;
                configuration.TrimOptions       = TrimOptions.InsideQuotes;
                configuration.MissingFieldFound = LogMissingFieldFound;
                configuration.HeaderValidated   = LogHeaderValidatationFailed;
                break;

            case SourceKind.InternalCsvExport:
                configuration.RegisterClassMap <UnifiedAccountOperationCsvMap>();
                configuration.Encoding          = Encoding.UTF8;
                configuration.CultureInfo       = FileStructureMetadata.GetCultureInfo("fr-BE", ".");
                configuration.Delimiter         = ";";
                configuration.QuoteAllFields    = true;
                configuration.TrimOptions       = TrimOptions.InsideQuotes;
                configuration.MissingFieldFound = LogMissingFieldFound;
                configuration.HeaderValidated   = LogHeaderValidatationFailed;
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(sourceKind), sourceKind, null);
            }

            return(configuration);
        }
        public static FileStructureMetadata CreateDefault(SourceKind sourceKind)
        {
            var metadata = new FileStructureMetadata {
                SourceKind = sourceKind
            };

            if (CsvAccountOperationManager.DefaultCsvConfigurations.ContainsKey(sourceKind))
            {
                var defaultConfig = CsvAccountOperationManager.DefaultCsvConfigurations[sourceKind];
                metadata.Encoding         = defaultConfig.Encoding.WebName;
                metadata.Culture          = defaultConfig.CultureInfo.Name;
                metadata.DecimalSeparator = defaultConfig.CultureInfo.NumberFormat.CurrencyDecimalSeparator;
            }

            return(metadata);
        }
        public async Task <List <AccountOperationBase> > ReadAsync(Stream sourceStream, FileStructureMetadata structureMetadata)
        {
            var        result     = new List <AccountOperationBase>();
            SourceKind sourceKind = structureMetadata.SourceKind;
            var        config     = CreateCsvConfiguration(structureMetadata);

            using (var textReader = new StreamReader(sourceStream, config.Encoding, true, 1024, true))
                using (var reader = new CsvReader(textReader, config))
                {
                    while (await reader.ReadAsync())
                    {
                        AccountOperationBase record;

                        switch (sourceKind)
                        {
                        case SourceKind.FortisCsvArchive:
                        case SourceKind.FortisCsvExport:
                            record = reader.GetRecord <FortisOperation>();
                            break;

                        case SourceKind.SodexoCsvExport:
                            record = reader.GetRecord <SodexoOperation>();
                            break;

                        case SourceKind.InternalCsvExport:
                            record = reader.GetRecord <UnifiedAccountOperation>();
                            break;

                        default:
                            throw new ArgumentOutOfRangeException(nameof(sourceKind));
                        }

                        record.SourceKind = sourceKind;
                        result.Add(record);
                    }
                }

            return(result);
        }