private async Task AtualizarNotasPendentes() { if (_isNotasPendentesVerificadas || NotasFiscais.Count == 0) { return; } _isNotasPendentesVerificadas = true; var notasFiscaisPendentes = _notaFiscalRepository.GetNotasPendentes(false); if (notasFiscaisPendentes.Count == 0) { return; } var codigoUf = UfToCodigoUfConversor.GetCodigoUf(_emissorService.GetEmissor().Endereco.UF); var certificado = _certificadoService.GetX509Certificate2(); var config = _configuracaoService.GetConfiguracao(); if (certificado == null) { throw new ArgumentNullException(nameof(certificado)); } var idsNotasPendentes = notasFiscaisPendentes.Select(n => n.Id); foreach (var idNotaPendente in idsNotasPendentes) { var nota = await ConsultarNotasAsync(idNotaPendente, codigoUf, certificado, config); if (nota == null) { continue; } var notaPendente = NotasFiscais.FirstOrDefault(n => n.Status == "Pendente" && n.Chave == nota.Chave); var index = NotasFiscais.IndexOf(notaPendente); var notaMemento = new NotaFiscalMemento(nota.Numero, nota.Modelo == "NFC-e" ? Modelo.Modelo65 : Modelo.Modelo55, nota.DataEmissao, nota.DataAutorizacao, nota.Destinatario, nota.UfDestinatario, nota.ValorTotal.ToString("N2", new CultureInfo("pt-BR")), (Status)nota.Status, nota.Chave); NotasFiscais[index] = notaMemento; } }