I am processing files .txt
, however I process more than 1 file at a time, but in the database only saves 1 file, debugando I see that it reads and processes the 2 files, or up to 3 depending on how many files I am processing.
Below is my controller
and Negocio
.
I would have to be merging the .txt
files so I can generate a single report later.
Before processing it, it cleans the database with method removerSabemi()
, but it processes 1 file and then returns to the removerSabemi()
method, and then processes the other file.
I need to pass the removerSabemi()
method only on first run.
I need to address somehow that I'm not finding.
Controller
if ((arquivosSabemi != null) && (arquivosSabemi.Any(f => f != null)))
{
foreach (var arquivo in arquivosSabemi.Where(s => s.ContentLength > 0))
{
InstanceResolverFor<IServicoFIDC>.Instance.SalvarSabemi(arquivo.InputStream);
}
}
Service
public void SalvarSabemi(Stream dados)
{
using (var arquivoSabemi = new StreamReader(dados))
{
var dal = InstanceResolverFor<IDadosFIDC>.Instance;
var primeiraLinha = true;
string linha;
dal.RemoverSabemi();
while (!arquivoSabemi.EndOfStream && !string.IsNullOrEmpty(linha = arquivoSabemi.ReadLine()))
{
if (primeiraLinha) { primeiraLinha = false; continue; }
var colunas = linha.Split("\t".ToCharArray());
dal.Inserir(new DadosSabemi
{
CEDNTE_CEDN = ParseValueOrNull<long>(colunas[0]),