public List <NfeProc> GetNfeProcList(List <Stream> pStreamList)
        {
            List <NfeProc> nfeProcList = new List <NfeProc>();

            if (pStreamList != null && pStreamList.Any())
            {
                NfeXmlSerializer xmlSerializer = new NfeXmlSerializer();

                pStreamList.Select(stream => stream)
                .ToList()
                .ForEach(inputStream =>
                {
                    NfeProc nfeProc = null;
                    try
                    {
                        nfeProc = xmlSerializer.DeserializeFromStream <NfeProc>(inputStream);
                    }
                    catch (InvalidOperationException)
                    {
                        if (nfeProc == null)
                        {
                            try
                            {
                                NotaFiscalEletronica nota = xmlSerializer.DeserializeFromStream <NotaFiscalEletronica>(inputStream);

                                nfeProc = new NfeProc
                                {
                                    ProtNfe = new ProtNfe
                                    {
                                        InfProt = new InfProt
                                        {
                                            ChaveNFe = nota.InfNfe.Id.Replace("NFe", ""),
                                            tpAmb    = nota.InfNfe.Ide.tpAmb,
                                            VerAplic = nota.InfNfe.Ide.VerProc,
                                            Motivo   = "Protocolo não encontrado"
                                        }
                                    },

                                    Nfe = nota
                                };
                            }
                            catch (InvalidOperationException)
                            {
                                nfeProc = new NfeProc {
                                    ProtNfe = new ProtNfe {
                                        InfProt = new InfProt {
                                            Motivo = "Falha ao processar arquivo"
                                        }
                                    }
                                };
                            }
                        }
                    }
                    nfeProcList.Add(nfeProc);
                });
            }

            return(nfeProcList);
        }
        public List <NfeValidation> GetNfeValidationMessages(string path, List <Stream> pStreamList)
        {
            List <NfeValidation> NfeValidationList = new List <NfeValidation>();

            if (pStreamList != null && pStreamList.Any())
            {
                NfeXmlSerializer xmlSerializer  = new NfeXmlSerializer();
                string           xsdFileName    = null;
                List <string>    validationList = null;

                pStreamList.Select(stream => stream)
                .ToList()
                .ForEach(inputStream =>
                {
                    NfeProc nfeProc = null;
                    try
                    {
                        nfeProc             = xmlSerializer.DeserializeFromStream <NfeProc>(inputStream);
                        xsdFileName         = NfeSchemaFileResolver <NfeProc> .GetByNfeVersion(nfeProc.Versao);
                        var xsdFileNamePath = Path.Combine(path, xsdFileName);
                        validationList      = xmlSerializer.Validate(inputStream, xsdFileNamePath);
                        validationList.ForEach(msg => NfeValidationList.Add(new NfeValidation {
                            NumNf = nfeProc.Nfe.InfNfe.Ide.NumNf, Message = msg
                        }));

                        if (!validationList.Any())
                        {
                            NfeValidationList.Add(new NfeValidation {
                                NumNf = nfeProc.Nfe.InfNfe.Ide.NumNf, Message = "Nenhuma inconsistência encontrada"
                            });
                        }
                    }
                    catch (InvalidOperationException)
                    {
                        if (nfeProc == null)
                        {
                            try
                            {
                                NotaFiscalEletronica nota = xmlSerializer.DeserializeFromStream <NotaFiscalEletronica>(inputStream);
                                xsdFileName         = NfeSchemaFileResolver <NotaFiscalEletronica> .GetByNfeVersion(nota.InfNfe.Versao);
                                var xsdFileNamePath = Path.Combine(path, xsdFileName);
                                validationList      = xmlSerializer.Validate(inputStream, xsdFileNamePath);
                                validationList.ForEach(msg => NfeValidationList.Add(new NfeValidation {
                                    NumNf = nota.InfNfe.Ide.NumNf, Message = msg
                                }));

                                if (!validationList.Any())
                                {
                                    NfeValidationList.Add(new NfeValidation {
                                        NumNf = nota.InfNfe.Ide.NumNf, Message = "Nenhuma inconsistência encontrada"
                                    });
                                }
                            }
                            catch (Exception e)
                            {
                                NfeValidationList.Add(new NfeValidation {
                                    NumNf = "", Message = e.Message
                                });
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        NfeValidationList.Add(new NfeValidation {
                            NumNf = "", Message = e.Message
                        });
                    }
                });
            }

            return(NfeValidationList);
        }