Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ajustes para CTe 4.00 #1454

Merged
merged 3 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CTe.Classes/ConfiguracaoServico.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public ConfiguracaoServico()
{
ConfiguracaoCertificado = new ConfiguracaoCertificado();
TipoEmissao = tpEmis.teNormal;
IsValidaSchemas = true;
}

/// <summary>
Expand Down Expand Up @@ -177,6 +178,8 @@ public static ConfiguracaoServico Instancia

public tpEmis TipoEmissao { get; set; }

public bool IsValidaSchemas { get; set; }

public bool NaoSalvarXml()
{
return !IsSalvarXml;
Expand Down
1 change: 1 addition & 0 deletions CTe.Servicos/Recepcao/ServicoCTeRecepcao.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public retCTe CTeRecepcaoSincronoV4(CTeEletronico cte, ConfiguracaoServico confi
cte.infCte.ide.tpEmis = instanciaConfiguracao.TipoEmissao;
cte.Assina(instanciaConfiguracao);
cte.infCTeSupl = cte.QrCode(instanciaConfiguracao.X509Certificate2, Encoding.UTF8, instanciaConfiguracao.IsAdicionaQrCode, UrlHelper.ObterUrlQrCode(instanciaConfiguracao));
cte.SalvarXmlEmDisco(instanciaConfiguracao); //salva em disco antes de validas os schemas, facilitando encontrar possíveis erros
cte.ValidaSchema(instanciaConfiguracao);
cte.SalvarXmlEmDisco(instanciaConfiguracao);

Expand Down
50 changes: 27 additions & 23 deletions CTe.Utils/CTe/ExtCTe.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,20 @@

var xmlValidacao = cte.ObterXmlString();

var servicoInstancia = configuracaoServico ?? ConfiguracaoServico.Instancia;
if (!servicoInstancia.IsValidaSchemas)
return;

switch (cte.infCte.versao)
{
case versao.ve200:
Validador.Valida(xmlValidacao, "cte_v2.00.xsd", configuracaoServico);
Validador.Valida(xmlValidacao, "cte_v2.00.xsd", servicoInstancia);
break;
case versao.ve300:
Validador.Valida(xmlValidacao, "cte_v3.00.xsd", configuracaoServico);
Validador.Valida(xmlValidacao, "cte_v3.00.xsd", servicoInstancia);
break;
case versao.ve400:
Validador.Valida(xmlValidacao, "cte_v4.00.xsd", configuracaoServico);
Validador.Valida(xmlValidacao, "cte_v4.00.xsd", servicoInstancia);
break;
default:
throw new InvalidOperationException("Nos achamos um erro na hora de validar o schema, " +
Expand All @@ -125,104 +129,104 @@
case versaoModal.veM200:
if (cte.infCte.infCTeNorm.infModal.ContainerModal.GetType() == typeof(aereo))
{
Validador.Valida(xmlModal, "cteModalAereo_v2.00.xsd", configuracaoServico);
Validador.Valida(xmlModal, "cteModalAereo_v2.00.xsd", servicoInstancia);
}

if (cte.infCte.infCTeNorm.infModal.ContainerModal.GetType() == typeof(aquav))
{
Validador.Valida(xmlModal, "cteModalAquaviario_v2.00.xsd", configuracaoServico);
Validador.Valida(xmlModal, "cteModalAquaviario_v2.00.xsd", servicoInstancia);
}

if (cte.infCte.infCTeNorm.infModal.ContainerModal.GetType() == typeof(duto))
{
Validador.Valida(xmlModal, "cteModalDutoviario_v2.00.xsd", configuracaoServico);
Validador.Valida(xmlModal, "cteModalDutoviario_v2.00.xsd", servicoInstancia);
}

if (cte.infCte.infCTeNorm.infModal.ContainerModal.GetType() == typeof(ferrov))
{
Validador.Valida(xmlModal, "cteModalFerroviario_v2.00.xsd", configuracaoServico);
Validador.Valida(xmlModal, "cteModalFerroviario_v2.00.xsd", servicoInstancia);
}

if (cte.infCte.infCTeNorm.infModal.ContainerModal.GetType() == typeof(rodo))
{
Validador.Valida(xmlModal, "cteModalRodoviario_v2.00.xsd", configuracaoServico);
Validador.Valida(xmlModal, "cteModalRodoviario_v2.00.xsd", servicoInstancia);
}

if (cte.infCte.infCTeNorm.infModal.ContainerModal.GetType() == typeof(multimodal))
{
Validador.Valida(xmlModal, "cteMultimodal_v2.00.xsd", configuracaoServico);
Validador.Valida(xmlModal, "cteMultimodal_v2.00.xsd", servicoInstancia);
}
break;
case versaoModal.veM300:
if (cte.infCte.infCTeNorm.infModal.ContainerModal.GetType() == typeof(aereo))
{
Validador.Valida(xmlModal, "cteModalAereo_v3.00.xsd", configuracaoServico);
Validador.Valida(xmlModal, "cteModalAereo_v3.00.xsd", servicoInstancia);
}

if (cte.infCte.infCTeNorm.infModal.ContainerModal.GetType() == typeof(aquav))
{
Validador.Valida(xmlModal, "cteModalAquaviario_v3.00.xsd", configuracaoServico);
Validador.Valida(xmlModal, "cteModalAquaviario_v3.00.xsd", servicoInstancia);
}

if (cte.infCte.infCTeNorm.infModal.ContainerModal.GetType() == typeof(duto))
{
Validador.Valida(xmlModal, "cteModalDutoviario_v3.00.xsd", configuracaoServico);
Validador.Valida(xmlModal, "cteModalDutoviario_v3.00.xsd", servicoInstancia);
}

if (cte.infCte.infCTeNorm.infModal.ContainerModal.GetType() == typeof(ferrov))
{
Validador.Valida(xmlModal, "cteModalFerroviario_v3.00.xsd", configuracaoServico);
Validador.Valida(xmlModal, "cteModalFerroviario_v3.00.xsd", servicoInstancia);
}

if (cte.infCte.infCTeNorm.infModal.ContainerModal.GetType() == typeof(rodo))
{
Validador.Valida(xmlModal, "cteModalRodoviario_v3.00.xsd", configuracaoServico);
Validador.Valida(xmlModal, "cteModalRodoviario_v3.00.xsd", servicoInstancia);
}

if (cte.infCte.infCTeNorm.infModal.ContainerModal.GetType() == typeof(multimodal))
{
Validador.Valida(xmlModal, "cteMultimodal_v3.00.xsd", configuracaoServico);
Validador.Valida(xmlModal, "cteMultimodal_v3.00.xsd", servicoInstancia);
}

if (cte.infCte.infCTeNorm.infModal.ContainerModal.GetType() == typeof(rodoOS))
{
Validador.Valida(xmlModal, "cteModalRodoviarioOS_v3.00.xsd", configuracaoServico);
Validador.Valida(xmlModal, "cteModalRodoviarioOS_v3.00.xsd", servicoInstancia);
}
break;
case versaoModal.veM400:
if (cte.infCte.infCTeNorm.infModal.ContainerModal.GetType() == typeof(aereo))
{
Validador.Valida(xmlModal, "cteModalAereo_v4.00.xsd", configuracaoServico);
Validador.Valida(xmlModal, "cteModalAereo_v4.00.xsd", servicoInstancia);
}

if (cte.infCte.infCTeNorm.infModal.ContainerModal.GetType() == typeof(aquav))
{
Validador.Valida(xmlModal, "cteModalAquaviario_v4.00.xsd", configuracaoServico);
Validador.Valida(xmlModal, "cteModalAquaviario_v4.00.xsd", servicoInstancia);
}

if (cte.infCte.infCTeNorm.infModal.ContainerModal.GetType() == typeof(duto))
{
Validador.Valida(xmlModal, "cteModalDutoviario_v4.00.xsd", configuracaoServico);
Validador.Valida(xmlModal, "cteModalDutoviario_v4.00.xsd", servicoInstancia);
}

if (cte.infCte.infCTeNorm.infModal.ContainerModal.GetType() == typeof(ferrov))
{
Validador.Valida(xmlModal, "cteModalFerroviario_v4.00.xsd", configuracaoServico);
Validador.Valida(xmlModal, "cteModalFerroviario_v4.00.xsd", servicoInstancia);
}

if (cte.infCte.infCTeNorm.infModal.ContainerModal.GetType() == typeof(rodo))
{
Validador.Valida(xmlModal, "cteModalRodoviario_v4.00.xsd", configuracaoServico);
Validador.Valida(xmlModal, "cteModalRodoviario_v4.00.xsd", servicoInstancia);
}

if (cte.infCte.infCTeNorm.infModal.ContainerModal.GetType() == typeof(multimodal))
{
Validador.Valida(xmlModal, "cteMultimodal_v4.00.xsd", configuracaoServico);
Validador.Valida(xmlModal, "cteMultimodal_v4.00.xsd", servicoInstancia);
}

if (cte.infCte.infCTeNorm.infModal.ContainerModal.GetType() == typeof(rodoOS))
{
Validador.Valida(xmlModal, "cteModalRodoviarioOS_v4.00.xsd", configuracaoServico);
Validador.Valida(xmlModal, "cteModalRodoviarioOS_v4.00.xsd", servicoInstancia);
}
break;
default:
Expand Down Expand Up @@ -309,7 +313,7 @@

RSAPKCS1SignatureFormatter rsaF = new RSAPKCS1SignatureFormatter(rsa);

SHA1CryptoServiceProvider sha1 = new SHA1CryptoServiceProvider();

Check warning on line 316 in CTe.Utils/CTe/ExtCTe.cs

View workflow job for this annotation

GitHub Actions / build (windows-2022)

'SHA1CryptoServiceProvider' is obsolete: 'Derived cryptographic types are obsolete. Use the Create method on the base type instead.'

Check warning on line 316 in CTe.Utils/CTe/ExtCTe.cs

View workflow job for this annotation

GitHub Actions / build (windows-2022)

'SHA1CryptoServiceProvider' is obsolete: 'Derived cryptographic types are obsolete. Use the Create method on the base type instead.'

Check warning on line 316 in CTe.Utils/CTe/ExtCTe.cs

View workflow job for this annotation

GitHub Actions / build (windows-2022)

'SHA1CryptoServiceProvider' is obsolete: 'Derived cryptographic types are obsolete. Use the Create method on the base type instead.'

Check warning on line 316 in CTe.Utils/CTe/ExtCTe.cs

View workflow job for this annotation

GitHub Actions / build (windows-2022)

'SHA1CryptoServiceProvider' is obsolete: 'Derived cryptographic types are obsolete. Use the Create method on the base type instead.'

byte[] hash = null;

Expand Down
Loading