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

Transformada classe MDFeConfiguracao de static para singleton #50

Merged
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
36 changes: 18 additions & 18 deletions MDFe.AppTeste/MDFeTesteModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ public void CriarEnviar()
#endregion dados emitente (emit)

#region modal
if (MDFeConfiguracao.VersaoWebService.VersaoLayout == VersaoServico.Versao100)
if (MDFeConfiguracao.Instancia.VersaoWebService.VersaoLayout == VersaoServico.Versao100)
{
mdfe.InfMDFe.InfModal.Modal = new MDFeRodo
{
Expand Down Expand Up @@ -607,7 +607,7 @@ public void CriarEnviar()
}


if (MDFeConfiguracao.VersaoWebService.VersaoLayout == VersaoServico.Versao300)
if (MDFeConfiguracao.Instancia.VersaoWebService.VersaoLayout == VersaoServico.Versao300)
{
mdfe.InfMDFe.InfModal.Modal = new MDFeRodo
{
Expand Down Expand Up @@ -689,7 +689,7 @@ public void CriarEnviar()
};


if (MDFeConfiguracao.VersaoWebService.VersaoLayout == VersaoServico.Versao300)
if (MDFeConfiguracao.Instancia.VersaoWebService.VersaoLayout == VersaoServico.Versao300)
{
mdfe.InfMDFe.InfDoc.InfMunDescarga[0].InfCTe[0].Peri = new List<MDFePeri>
{
Expand All @@ -705,7 +705,7 @@ public void CriarEnviar()

#region seg

if (MDFeConfiguracao.VersaoWebService.VersaoLayout == VersaoServico.Versao300)
if (MDFeConfiguracao.Instancia.VersaoWebService.VersaoLayout == VersaoServico.Versao300)
{
mdfe.InfMDFe.Seg = new List<MDFeSeg>();

Expand Down Expand Up @@ -733,7 +733,7 @@ public void CriarEnviar()

#region Produto Predominante

if (MDFeConfiguracao.VersaoWebService.VersaoLayout == VersaoServico.Versao300)
if (MDFeConfiguracao.Instancia.VersaoWebService.VersaoLayout == VersaoServico.Versao300)
{
mdfe.InfMDFe.prodPred = new prodPred
{
Expand Down Expand Up @@ -865,7 +865,7 @@ public void GerarESalvar()
#endregion dados emitente (emit)

#region modal
if (MDFeConfiguracao.VersaoWebService.VersaoLayout == VersaoServico.Versao100)
if (MDFeConfiguracao.Instancia.VersaoWebService.VersaoLayout == VersaoServico.Versao100)
{
mdfe.InfMDFe.InfModal.VersaoModal = MDFeVersaoModal.Versao100;
mdfe.InfMDFe.InfModal.Modal = new MDFeRodo
Expand Down Expand Up @@ -894,7 +894,7 @@ public void GerarESalvar()
}


if (MDFeConfiguracao.VersaoWebService.VersaoLayout == VersaoServico.Versao300)
if (MDFeConfiguracao.Instancia.VersaoWebService.VersaoLayout == VersaoServico.Versao300)
{
mdfe.InfMDFe.InfModal.VersaoModal = MDFeVersaoModal.Versao300;
mdfe.InfMDFe.InfModal.Modal = new MDFeRodo
Expand Down Expand Up @@ -978,7 +978,7 @@ public void GerarESalvar()
};


if (MDFeConfiguracao.VersaoWebService.VersaoLayout == VersaoServico.Versao300)
if (MDFeConfiguracao.Instancia.VersaoWebService.VersaoLayout == VersaoServico.Versao300)
{
mdfe.InfMDFe.InfDoc.InfMunDescarga[0].InfCTe[0].Peri = new List<MDFePeri>
{
Expand All @@ -994,7 +994,7 @@ public void GerarESalvar()

#region seg

if (MDFeConfiguracao.VersaoWebService.VersaoLayout == VersaoServico.Versao300)
if (MDFeConfiguracao.Instancia.VersaoWebService.VersaoLayout == VersaoServico.Versao300)
{
mdfe.InfMDFe.Seg = new List<MDFeSeg>();

Expand Down Expand Up @@ -1346,17 +1346,17 @@ private static void CarregarConfiguracoesMDFe(Configuracao config)
ManterDadosEmCache = config.CertificadoDigital.ManterEmCache,
};

MDFeConfiguracao.ConfiguracaoCertificado = configuracaoCertificado;
MDFeConfiguracao.CaminhoSchemas = config.ConfigWebService.CaminhoSchemas;
MDFeConfiguracao.CaminhoSalvarXml = config.DiretorioSalvarXml;
MDFeConfiguracao.IsSalvarXml = config.IsSalvarXml;
MDFeConfiguracao.Instancia.ConfiguracaoCertificado = configuracaoCertificado;
MDFeConfiguracao.Instancia.CaminhoSchemas = config.ConfigWebService.CaminhoSchemas;
MDFeConfiguracao.Instancia.CaminhoSalvarXml = config.DiretorioSalvarXml;
MDFeConfiguracao.Instancia.IsSalvarXml = config.IsSalvarXml;

MDFeConfiguracao.VersaoWebService.VersaoLayout = config.ConfigWebService.VersaoLayout;
MDFeConfiguracao.Instancia.VersaoWebService.VersaoLayout = config.ConfigWebService.VersaoLayout;

MDFeConfiguracao.VersaoWebService.TipoAmbiente = config.ConfigWebService.Ambiente;
MDFeConfiguracao.VersaoWebService.UfEmitente = config.ConfigWebService.UfEmitente;
MDFeConfiguracao.VersaoWebService.TimeOut = config.ConfigWebService.TimeOut;
MDFeConfiguracao.IsAdicionaQrCode = true;
MDFeConfiguracao.Instancia.VersaoWebService.TipoAmbiente = config.ConfigWebService.Ambiente;
MDFeConfiguracao.Instancia.VersaoWebService.UfEmitente = config.ConfigWebService.UfEmitente;
MDFeConfiguracao.Instancia.VersaoWebService.TimeOut = config.ConfigWebService.TimeOut;
MDFeConfiguracao.Instancia.IsAdicionaQrCode = true;
}

protected virtual void OnSucessoSync(RetornoEEnvio e)
Expand Down
47 changes: 25 additions & 22 deletions MDFe.Classes/Extensoes/ExtMDFe.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,20 @@
{
public static class ExtMDFe
{
public static MDFEletronico Valida(this MDFEletronico mdfe)
public static MDFEletronico Valida(this MDFEletronico mdfe, MDFeConfiguracao cfgMdfe = null)
{
var config = cfgMdfe ?? MDFeConfiguracao.Instancia;
if (mdfe == null) throw new ArgumentException("Erro de assinatura, MDFe esta null");

var xmlMdfe = FuncoesXml.ClasseParaXmlString(mdfe);

switch (MDFeConfiguracao.VersaoWebService.VersaoLayout)
switch (config.VersaoWebService.VersaoLayout)
{
case VersaoServico.Versao100:
Validador.Valida(xmlMdfe, "mdfe_v1.00.xsd");
Validador.Valida(xmlMdfe, "mdfe_v1.00.xsd", config);
break;
case VersaoServico.Versao300:
Validador.Valida(xmlMdfe, "mdfe_v3.00.xsd");
Validador.Valida(xmlMdfe, "mdfe_v3.00.xsd", config);
break;
}

Expand All @@ -39,63 +40,64 @@

if (tipoModal == typeof (MDFeRodo))
{
switch (MDFeConfiguracao.VersaoWebService.VersaoLayout)
switch (config.VersaoWebService.VersaoLayout)
{
case VersaoServico.Versao100:
Validador.Valida(xmlModal, "mdfeModalRodoviario_v1.00.xsd");
Validador.Valida(xmlModal, "mdfeModalRodoviario_v1.00.xsd", config);
break;
case VersaoServico.Versao300:
Validador.Valida(xmlModal, "mdfeModalRodoviario_v3.00.xsd");
Validador.Valida(xmlModal, "mdfeModalRodoviario_v3.00.xsd", config);
break;
}
}

if (tipoModal == typeof (MDFeAereo))
{
switch (MDFeConfiguracao.VersaoWebService.VersaoLayout)
switch (config.VersaoWebService.VersaoLayout)
{
case VersaoServico.Versao100:
Validador.Valida(xmlModal, "mdfeModalAereo_v1.00.xsd");
Validador.Valida(xmlModal, "mdfeModalAereo_v1.00.xsd", config);
break;
case VersaoServico.Versao300:
Validador.Valida(xmlModal, "mdfeModalAereo_v3.00.xsd");
Validador.Valida(xmlModal, "mdfeModalAereo_v3.00.xsd", config);
break;
}
}

if (tipoModal == typeof (MDFeAquav))
{
switch (MDFeConfiguracao.VersaoWebService.VersaoLayout)
switch (config.VersaoWebService.VersaoLayout)
{
case VersaoServico.Versao100:
Validador.Valida(xmlModal, "mdfeModalAquaviario_v1.00.xsd");
Validador.Valida(xmlModal, "mdfeModalAquaviario_v1.00.xsd", config);
break;
case VersaoServico.Versao300:
Validador.Valida(xmlModal, "mdfeModalAquaviario_v3.00.xsd");
Validador.Valida(xmlModal, "mdfeModalAquaviario_v3.00.xsd", config);
break;
}
}

if (tipoModal == typeof (MDFeFerrov))
{
switch (MDFeConfiguracao.VersaoWebService.VersaoLayout)
switch (config.VersaoWebService.VersaoLayout)
{
case VersaoServico.Versao100:
Validador.Valida(xmlModal, "mdfeModalFerroviario_v1.00.xsd");
Validador.Valida(xmlModal, "mdfeModalFerroviario_v1.00.xsd", config);
break;
case VersaoServico.Versao300:
Validador.Valida(xmlModal, "mdfeModalFerroviario_v3.00.xsd");
Validador.Valida(xmlModal, "mdfeModalFerroviario_v3.00.xsd", config);
break;
}
}

return mdfe;
}

public static MDFEletronico Assina(this MDFEletronico mdfe, EventHandler<string> eventHandlerChaveMdfe = null, object quemInvocouEventoChaveMDFe = null)
public static MDFEletronico Assina(this MDFEletronico mdfe, EventHandler<string> eventHandlerChaveMdfe = null, object quemInvocouEventoChaveMDFe = null, MDFeConfiguracao cfgMdfe = null)
{
if(mdfe == null) throw new ArgumentException("Erro de assinatura, MDFe esta null");

var config = cfgMdfe ?? MDFeConfiguracao.Instancia;
var modeloDocumentoFiscal = mdfe.InfMDFe.Ide.Mod;
var tipoEmissao = (int) mdfe.InfMDFe.Ide.TpEmis;
var codigoNumerico = mdfe.InfMDFe.Ide.CMDF;
Expand All @@ -118,10 +120,10 @@
if (eventHandlerChaveMdfe != null)
eventHandlerChaveMdfe.Invoke(quemInvocouEventoChaveMDFe, dadosChave.Chave);

mdfe.InfMDFe.Versao = MDFeConfiguracao.VersaoWebService.VersaoLayout;
mdfe.InfMDFe.Versao = config.VersaoWebService.VersaoLayout;
mdfe.InfMDFe.Ide.CDV = dadosChave.DigitoVerificador;

var assinatura = AssinaturaDigital.Assina(mdfe, mdfe.InfMDFe.Id, MDFeConfiguracao.X509Certificate2);
var assinatura = AssinaturaDigital.Assina(mdfe, mdfe.InfMDFe.Id, config.X509Certificate2);

mdfe.Signature = assinatura;

Expand All @@ -133,12 +135,13 @@
return FuncoesXml.ClasseParaXmlString(mdfe);
}

public static void SalvarXmlEmDisco(this MDFEletronico mdfe, string nomeArquivo = null)
public static void SalvarXmlEmDisco(this MDFEletronico mdfe, string nomeArquivo = null, MDFeConfiguracao cfgMdfe = null)
{
if (MDFeConfiguracao.NaoSalvarXml()) return;
var config = cfgMdfe ?? MDFeConfiguracao.Instancia;
if (config.NaoSalvarXml()) return;

if (string.IsNullOrEmpty(nomeArquivo))
nomeArquivo = Path.Combine(MDFeConfiguracao.CaminhoSalvarXml, mdfe.Chave() + "-mdfe.xml");
nomeArquivo = Path.Combine(config.CaminhoSalvarXml, mdfe.Chave() + "-mdfe.xml");

FuncoesXml.ClasseParaArquivoXml(mdfe, nomeArquivo);
}
Expand Down Expand Up @@ -226,7 +229,7 @@

RSAPKCS1SignatureFormatter rsaF = new RSAPKCS1SignatureFormatter(rsa);

SHA1CryptoServiceProvider sha1 = new SHA1CryptoServiceProvider();

Check warning on line 232 in MDFe.Classes/Extensoes/ExtMDFe.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 232 in MDFe.Classes/Extensoes/ExtMDFe.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 232 in MDFe.Classes/Extensoes/ExtMDFe.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 232 in MDFe.Classes/Extensoes/ExtMDFe.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
16 changes: 9 additions & 7 deletions MDFe.Classes/Extensoes/ExtMDFeConsReciMDFe.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@ namespace MDFe.Classes.Extencoes
{
public static class ExtMDFeConsReciMDFe
{
public static void ValidaSchema(this MDFeConsReciMDFe consReciMDFe)
public static void ValidaSchema(this MDFeConsReciMDFe consReciMDFe, MDFeConfiguracao cfgMdfe = null)
{
var config = cfgMdfe ?? MDFeConfiguracao.Instancia;
var xmlValidacao = consReciMDFe.XmlString();

switch (MDFeConfiguracao.VersaoWebService.VersaoLayout)
switch (config.VersaoWebService.VersaoLayout)
{
case VersaoServico.Versao100:
Validador.Valida(xmlValidacao, "consReciMDFe_v1.00.xsd");
Validador.Valida(xmlValidacao, "consReciMDFe_v1.00.xsd", config);
break;
case VersaoServico.Versao300:
Validador.Valida(xmlValidacao, "consReciMDFe_v3.00.xsd");
Validador.Valida(xmlValidacao, "consReciMDFe_v3.00.xsd", config);
break;
}
}
Expand All @@ -38,11 +39,12 @@ public static XmlDocument CriaRequestWs(this MDFeConsReciMDFe consReciMDFe)
return request;
}

public static void SalvarXmlEmDisco(this MDFeConsReciMDFe consReciMDFe)
public static void SalvarXmlEmDisco(this MDFeConsReciMDFe consReciMDFe, MDFeConfiguracao cfgMdfe = null)
{
if (MDFeConfiguracao.NaoSalvarXml()) return;
var config = cfgMdfe ?? MDFeConfiguracao.Instancia;
if (config.NaoSalvarXml()) return;

var caminhoXml = MDFeConfiguracao.CaminhoSalvarXml;
var caminhoXml = config.CaminhoSalvarXml;

var arquivoSalvar = Path.Combine(caminhoXml, consReciMDFe.NRec + "-ped-rec.xml");

Expand Down
16 changes: 9 additions & 7 deletions MDFe.Classes/Extensoes/ExtMDFeConsSitMDFe.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@ namespace MDFe.Classes.Extencoes
{
public static class ExtMDFeConsSitMDFe
{
public static void ValidarSchema(this MDFeConsSitMDFe consSitMdfe)
public static void ValidarSchema(this MDFeConsSitMDFe consSitMdfe, MDFeConfiguracao cfgMdfe = null)
{
var config = cfgMdfe ?? MDFeConfiguracao.Instancia;
var xmlEnvio = consSitMdfe.XmlString();

switch (MDFeConfiguracao.VersaoWebService.VersaoLayout)
switch (config.VersaoWebService.VersaoLayout)
{
case VersaoServico.Versao100:
Validador.Valida(xmlEnvio, "consSitMDFe_v1.00.xsd");
Validador.Valida(xmlEnvio, "consSitMDFe_v1.00.xsd", config);
break;
case VersaoServico.Versao300:
Validador.Valida(xmlEnvio, "consSitMDFe_v3.00.xsd");
Validador.Valida(xmlEnvio, "consSitMDFe_v3.00.xsd", config);
break;
}
}
Expand All @@ -38,11 +39,12 @@ public static XmlDocument CriaRequestWs(this MDFeConsSitMDFe consSitMdfe)
return request;
}

public static void SalvarXmlEmDisco(this MDFeConsSitMDFe consSitMdfe)
public static void SalvarXmlEmDisco(this MDFeConsSitMDFe consSitMdfe, MDFeConfiguracao cfgMdfe = null)
{
if (MDFeConfiguracao.NaoSalvarXml()) return;
var config = cfgMdfe ?? MDFeConfiguracao.Instancia;
if (config.NaoSalvarXml()) return;

var caminhoXml = MDFeConfiguracao.CaminhoSalvarXml;
var caminhoXml = config.CaminhoSalvarXml;

var arquivoSalvar = Path.Combine(caminhoXml, consSitMdfe.ChMDFe + "-ped-sit.xml");

Expand Down
16 changes: 9 additions & 7 deletions MDFe.Classes/Extensoes/ExtMDFeConsStatServMDFe.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@ namespace MDFe.Classes.Extencoes
{
public static class ExtMDFeConsStatServMDFe
{
public static void ValidarSchema(this MDFeConsStatServMDFe consStatServMDFe)
public static void ValidarSchema(this MDFeConsStatServMDFe consStatServMDFe, MDFeConfiguracao cfgMdfe = null)
{
var config = cfgMdfe ?? MDFeConfiguracao.Instancia;
var xmlValidacao = consStatServMDFe.XmlString();

switch (MDFeConfiguracao.VersaoWebService.VersaoLayout)
switch (config.VersaoWebService.VersaoLayout)
{
case VersaoServico.Versao100:
Validador.Valida(xmlValidacao, "consStatServMDFe_v1.00.xsd");
Validador.Valida(xmlValidacao, "consStatServMDFe_v1.00.xsd", config);
break;
case VersaoServico.Versao300:
Validador.Valida(xmlValidacao, "consStatServMDFe_v3.00.xsd");
Validador.Valida(xmlValidacao, "consStatServMDFe_v3.00.xsd", config);
break;
}
}
Expand All @@ -38,11 +39,12 @@ public static XmlDocument CriaRequestWs(this MDFeConsStatServMDFe consStatServMd
return request;
}

public static void SalvarXmlEmDisco(this MDFeConsStatServMDFe consStatServMdFe)
public static void SalvarXmlEmDisco(this MDFeConsStatServMDFe consStatServMdFe, MDFeConfiguracao cfgMdfe = null)
{
if (MDFeConfiguracao.NaoSalvarXml()) return;
var config = cfgMdfe ?? MDFeConfiguracao.Instancia;
if (config.NaoSalvarXml()) return;

var caminhoXml = MDFeConfiguracao.CaminhoSalvarXml;
var caminhoXml = config.CaminhoSalvarXml;

var arquivoSalvar = Path.Combine(caminhoXml, "-pedido-status-servico.xml");

Expand Down
16 changes: 9 additions & 7 deletions MDFe.Classes/Extensoes/ExtMDFeCosMDFeNaoEnc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,18 @@ public static string XmlString(this MDFeCosMDFeNaoEnc consMDFeNaoEnc)
return FuncoesXml.ClasseParaXmlString(consMDFeNaoEnc);
}

public static void ValidarSchema(this MDFeCosMDFeNaoEnc consMdFeNaoEnc)
public static void ValidarSchema(this MDFeCosMDFeNaoEnc consMdFeNaoEnc, MDFeConfiguracao cfgMdfe = null)
{
var config = cfgMdfe ?? MDFeConfiguracao.Instancia;
var xmlValidacao = consMdFeNaoEnc.XmlString();

switch (MDFeConfiguracao.VersaoWebService.VersaoLayout)
switch (config.VersaoWebService.VersaoLayout)
{
case VersaoServico.Versao100:
Validador.Valida(xmlValidacao, "consMDFeNaoEnc_v1.00.xsd");
Validador.Valida(xmlValidacao, "consMDFeNaoEnc_v1.00.xsd", config);
break;
case VersaoServico.Versao300:
Validador.Valida(xmlValidacao, "consMDFeNaoEnc_v3.00.xsd");
Validador.Valida(xmlValidacao, "consMDFeNaoEnc_v3.00.xsd", config);
break;
}
}
Expand All @@ -38,11 +39,12 @@ public static XmlDocument CriaRequestWs(this MDFeCosMDFeNaoEnc cosMdFeNaoEnc)
return request;
}

public static void SalvarXmlEmDisco(this MDFeCosMDFeNaoEnc cosMdFeNaoEnc)
public static void SalvarXmlEmDisco(this MDFeCosMDFeNaoEnc cosMdFeNaoEnc, MDFeConfiguracao cfgMdfe = null)
{
if (MDFeConfiguracao.NaoSalvarXml()) return;
var config = cfgMdfe ?? MDFeConfiguracao.Instancia;
if (config.NaoSalvarXml()) return;

var caminhoXml = MDFeConfiguracao.CaminhoSalvarXml;
var caminhoXml = config.CaminhoSalvarXml;

var arquivoSalvar = Path.Combine(caminhoXml, cosMdFeNaoEnc.CNPJ + "-ped-sit.xml");

Expand Down
Loading
Loading