private async Task ImportarXmlEvento(string path) { var regex = new Regex(@"[0-9]{52}-procEventoNFe"); var files = Directory.EnumerateFiles(path, "*.xml").Where(f => regex.IsMatch(f)); await Task.Run(() => { foreach (var file in files) { try { var xml = File.ReadAllText(file); var fullPath = GetFullPath(file); var eventoCancelamento = _eventoService.GetEventoCancelamentoFromXml(xml, fullPath, _notaFiscalRepository); var eventoDb = _eventoService.GetEventoPorNota(eventoCancelamento.NotaId, false); if (eventoDb != null) { return; } _eventoService.Salvar(eventoCancelamento); var notaFiscalEntity = _notaFiscalRepository.GetNotaFiscalById(eventoCancelamento.NotaId, false); notaFiscalEntity.Status = (int)Status.CANCELADA; _notaFiscalRepository.Salvar(notaFiscalEntity); } catch (Exception e) { log.Error(e); } } }); }