public static XmlDocument FabricarEnvelope(eTipoServico tipoServico, string xml)
        {
            switch (tipoServico)
            {
            case eTipoServico.AutorizarNFe:
                return(FabricarEnvelopeAutorizacaoNFe4(xml));

            case eTipoServico.CancelarNFe:
                return(FabricarEnvelopeEventoNFe(xml));

            case eTipoServico.InutilizacaoNFe:
                return(FabricarEnvelopeInutilizacaoNFe(xml));

            case eTipoServico.ConsultaSituacaoNFe:
                return(FabricarEnvelopeConsultarSituacaoNFe(xml));

            case eTipoServico.CartaCorrecao:
                return(FabricarEnvelopeEventoNFe(xml));

            case eTipoServico.ManifestacaoDestinatario:
                return(FabricarEnvelopeManifestacaoNacional(xml));

            case eTipoServico.NFeDistribuicaoDFe:
                return(FabricarEnvelopeNFeDistribuicaoDFe(xml));

            default:
                return(null);
            }
        }
Beispiel #2
0
 public UrlSefaz(eTipoServico servico, eUF uf, eTipoAmbiente tipoAmbiente, eModeloDocumento modeloDocumento, string url, string action)
 {
     Url             = url;
     Action          = action;
     UF              = uf;
     TipoAmbiente    = tipoAmbiente;
     ModeloDocumento = modeloDocumento;
     Servico         = servico;
 }
Beispiel #3
0
        public static UrlSefaz ObterUrl(eTipoServico tipoServico, eTipoAmbiente tipoAmbiente, eModeloDocumento modeloDocumento, eUF uf)
        {
            var urlAction = UrlsSefaz().Where(x => x.Servico == tipoServico && x.UF == uf && x.TipoAmbiente == tipoAmbiente && x.ModeloDocumento == modeloDocumento).FirstOrDefault();

            if (urlAction == null)
            {
                throw new ArgumentOutOfRangeException("Nenhuma URL do Webservice encontrada");
            }
            return(urlAction);
        }
Beispiel #4
0
        public static void ValidarSchema(eTipoServico tipoServico, string xml, ConfiguracaoServico cfgServico)
        {
            var caminhoSchema = cfgServico.DiretorioSchemas;
            var erros         = new List <string>();

            if (!Directory.Exists(caminhoSchema))
            {
                throw new Exception("Diretório de Schemas não encontrado: " + caminhoSchema);
            }

            var arquivoSchema = Path.Combine(caminhoSchema, ObterSchema(tipoServico));

            if (!File.Exists(arquivoSchema))
            {
                throw new FileNotFoundException($"Arquivo não encontrado: {arquivoSchema}");
            }

            var cfg = new XmlReaderSettings {
                ValidationType = ValidationType.Schema
            };

            cfg.Schemas.XmlResolver = new XmlUrlResolver();
            cfg.Schemas.Add(null, arquivoSchema);

            cfg.ValidationEventHandler += delegate(object sender, ValidationEventArgs args)
            {
                erros.Add($"[{args.Severity}] {args.Message}");
                //Console.WriteLine($"[{args.Severity}] - {args.Message} {args.Exception?.Message} na linha {args.Exception.LineNumber} posição {args.Exception.LinePosition} em {args.Exception.SourceUri}".ToString()));
            };

            var reader   = XmlReader.Create(new StringReader(xml), cfg);
            var document = new XmlDocument();

            document.Load(reader);

            if (erros.Count > 0)
            {
                var result = string.Join(Environment.NewLine, erros);
                throw new FalhaValidacaoException($"Erro ao validar XML contra Schema Xsd: {Environment.NewLine}{result}");
            }
        }
Beispiel #5
0
        public static string ObterSchema(eTipoServico tipoServico)
        {
            var schema = ListaSchemas.Where(x => x.TipoServico == tipoServico).SingleOrDefault();

            return(schema.Arquivo);
        }