示例#1
0
        private async Task Execute(string ecfTableName, FbConnection fbConnection, Func <FbConnection, EcfTableWriter, string[], Task <int> > action)
        {
            if (ShouldExportTable(ecfTableName, out var ecfFile))
            {
                // Report status
                Console.WriteLine($"[Extracting] [{ecfTableName}] Start...");

                // Init CSV file stream
                using var ecffileStream = new FileStream(Path.ChangeExtension(Path.Combine(_config.EcfExport?.TargetFolderName, ecfTableName), "csv"), FileMode.Create, FileAccess.ReadWrite, FileShare.None);

                // Init CSV Writer
                using var csvWriter = new CsvWriter(ecffileStream, Encoding.UTF8);

                // Init ECF Writer
                var ecfTablefWriter = new EcfTableWriter(csvWriter);

                if (_version < 7)
                {
                    ecfTablefWriter.AddConverter <object>(new CsvWin1251Converter());
                }

                // Call table specific action
                var ecfRecordCounter = await action(fbConnection, ecfTablefWriter, ecfFile?.Headers);

                // Inc counters
                _recordCounter += ecfRecordCounter;
                _tableCounter++;

                // Report status
                Console.WriteLine($"[Extracting] [{ecfTableName}] {ecfRecordCounter} record(s) extracted");
            }
        }