Skip to content

Commit

Permalink
Merge pull request #4 from adeniltonbs/master
Browse files Browse the repository at this point in the history
Update
  • Loading branch information
adrbarros authored Jan 19, 2017
2 parents 7337a45 + 75b5cee commit 9fe0841
Show file tree
Hide file tree
Showing 45 changed files with 2,145 additions and 197 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,9 @@ Temporary Items
/MDFe.AppTeste/bin
/MDFe.Classes/obj
/MDFe.Utils/obj
/MDFe.Damdfe.AppTeste/obj
/MDFe.Damdfe.AppTeste/bin
/MDFe.Damdfe.Base/obj
/MDFe.Damdfe.Base/bin
/MDFe.Damdfe.Fast/obj
/MDFe.Damdfe.Fast/bin
34 changes: 31 additions & 3 deletions DFe.Utils/Assinatura/CertificadoDigital.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/********************************************************************************/
/* Projeto: Biblioteca ZeusDFe */
/* Biblioteca C# para auxiliar no desenvolvimento das demais bibliotecas DFe */
/* */
/* Projeto: Biblioteca ZeusNFe */
/* Biblioteca C# para emissão de Nota Fiscal Eletrônica - NFe e Nota Fiscal de */
/* Consumidor Eletrônica - NFC-e (http://www.nfe.fazenda.gov.br) */
/* */
/* Direitos Autorais Reservados (c) 2014 Adenilton Batista da Silva */
/* Zeusdev Tecnologia LTDA ME */
Expand Down Expand Up @@ -136,5 +136,33 @@ public static X509Certificate2 ObterDeArquivo(string arquivo, string senha)
var certificado = new X509Certificate2(arquivo, senha, X509KeyStorageFlags.MachineKeySet);
return certificado;
}

private static X509Certificate2 _certificado;

/// <summary>
/// Obtém um objeto contendo o certificado digital
/// <para>Se for informado <see cref="ConfiguracaoCertificado.Arquivo"/>,
/// o certificado digital será obtido pelo método <see cref="ObterDeArquivo(string,string)"/>,
/// senão será obtido pelo método <see cref="ObterDoRepositorio()"/> </para>
/// <para>Para liberar os recursos do certificado, após seu uso, invoque o método <see cref="X509Certificate2.Reset()"/></para>
/// </summary>
public static X509Certificate2 ObterCertificado(ConfiguracaoCertificado configuracaoCertificado)
{
if (!configuracaoCertificado.ManterDadosEmCache)
return ObterDadosCertificado(configuracaoCertificado);
if (_certificado != null)
return _certificado;
_certificado = ObterDadosCertificado(configuracaoCertificado);
return _certificado;
}

private static X509Certificate2 ObterDadosCertificado(ConfiguracaoCertificado configuracaoCertificado)
{
return string.IsNullOrEmpty(configuracaoCertificado.Arquivo)
? ObterDoRepositorio(configuracaoCertificado.Serial,
configuracaoCertificado.Senha)
: ObterDeArquivo(configuracaoCertificado.Arquivo,
configuracaoCertificado.Senha);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@
/* http://www.zeusautomacao.com.br/ */
/* Rua Comendador Francisco josé da Cunha, 111 - Itabaiana - SE - 49500-000 */
/********************************************************************************/

using System.ComponentModel;
using NFe.Utils.Annotations;

namespace NFe.Utils
namespace DFe.Utils
{
public class ConfiguracaoCertificado : INotifyPropertyChanged
{
Expand Down Expand Up @@ -82,13 +83,13 @@ public string Arquivo
/// <para>Manter os dados do certificado em cache, aumentará o desempenho no consumo dos serviços, especialmente para certificados A3</para>
/// </summary>
public bool ManterDadosEmCache { get; set; }

public event PropertyChangedEventHandler PropertyChanged;

[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null) PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}
2 changes: 2 additions & 0 deletions DFe.Utils/DFe.Utils.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@
<ItemGroup>
<Compile Include="Assinatura\AssinaturaDigital.cs" />
<Compile Include="Assinatura\CertificadoDigital.cs" />
<Compile Include="ConfiguracaoCertificado.cs" />
<Compile Include="DataHora.cs" />
<Compile Include="FuncoesXml.cs" />
<Compile Include="ChaveFiscal.cs" />
<Compile Include="Properties\Annotations.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
Expand Down
10 changes: 10 additions & 0 deletions DFe.Utils/DataHora.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ public static string ParaDataHoraStringUtc(this DateTime data)
return data == DateTime.MinValue ? null : data.ToString("yyyy-MM-ddTHH:mm:sszzz");
}

/// <summary>
/// Retorna uma string no formato AAAA-MM-DDThh:mm:dd
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public static string ParaDataHoraStringSemUtc(this DateTime data)
{
return data.ToString("yyyy-MM-ddTHH:mm:dd");
}

/// <summary>
/// Retorna uma string no formato AAAA-MM-DDThh:mm:ssTZD (UTC - Universal Coordinated Time)
/// </summary>
Expand Down
File renamed without changes.
3 changes: 2 additions & 1 deletion MDFe.AppTeste/Entidades/ConfigCertificadoDigital.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public class ConfigCertificadoDigital
{
public string NumeroDeSerie { get; set; }
public string CaminhoArquivo { get; set; }
public string Senha { get; set; }
public string Senha { get; set; }
public bool ManterEmCache { get; set; }
}
}
3 changes: 3 additions & 0 deletions MDFe.AppTeste/MDFeTeste.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@
Width="280"
Text="{Binding Senha, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
</StackPanel>
<StackPanel Margin="0,10,0,0">
<CheckBox Margin="10,0,0,0" IsChecked="{Binding ManterCertificadoEmCache}">Manter certificado em cache</CheckBox>
</StackPanel>
</StackPanel>

</StackPanel>
Expand Down
17 changes: 15 additions & 2 deletions MDFe.AppTeste/MDFeTesteModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
using System.Windows.Forms;
using DFe.Classes.Entidades;
using DFe.Classes.Flags;
using DFe.Utils;
using DFe.Utils.Assinatura;
using MDFe.Classes.Flags;
using MDFe.Classes.Informacoes;
Expand Down Expand Up @@ -108,6 +107,7 @@ public class MDFeTesteModel : ViewModel
private string _diretorioSalvarXml;
private bool _isSalvarXml;
private int _timeOut;
private bool _manterCertificadoEmCache;

#region empresa

Expand Down Expand Up @@ -295,6 +295,16 @@ public string Senha
}
}

public bool ManterCertificadoEmCache
{
get { return _manterCertificadoEmCache; }
set
{
_manterCertificadoEmCache = value;
OnPropertyChanged("ManterCertificadoEmCache");
}
}

#endregion

#region configWebService
Expand Down Expand Up @@ -490,7 +500,8 @@ public void SalvarConfiguracoesXml()
{
CaminhoArquivo = CaminhoArquivo,
NumeroDeSerie = NumeroDeSerie,
Senha = Senha
Senha = Senha,
ManterEmCache = ManterCertificadoEmCache
},
ConfigWebService =
{
Expand Down Expand Up @@ -562,6 +573,7 @@ public void CarregarConfiguracoesMDFe()
Rntrc = config.Empresa.RNTRC;

Senha = config.CertificadoDigital.Senha;
ManterCertificadoEmCache = config.CertificadoDigital.ManterEmCache;
CaminhoArquivo = config.CertificadoDigital.CaminhoArquivo;
NumeroDeSerie = config.CertificadoDigital.NumeroDeSerie;

Expand Down Expand Up @@ -1129,6 +1141,7 @@ private static void CarregarConfiguracoesMDFe(Configuracao config)
Utils.Configuracoes.MDFeConfiguracao.SenhaCertificadoDigital = config.CertificadoDigital.Senha;
Utils.Configuracoes.MDFeConfiguracao.CaminhoCertificadoDigital = config.CertificadoDigital.CaminhoArquivo;
Utils.Configuracoes.MDFeConfiguracao.NumeroSerieCertificadoDigital = config.CertificadoDigital.NumeroDeSerie;
Utils.Configuracoes.MDFeConfiguracao.ManterCertificadoEmCache = config.CertificadoDigital.ManterEmCache;
Utils.Configuracoes.MDFeConfiguracao.CaminhoSchemas = config.ConfigWebService.CaminhoSchemas;
Utils.Configuracoes.MDFeConfiguracao.CaminhoSalvarXml = config.DiretorioSalvarXml;
Utils.Configuracoes.MDFeConfiguracao.IsSalvarXml = config.IsSalvarXml;
Expand Down
2 changes: 1 addition & 1 deletion MDFe.Classes/Informacoes/Evento/MDFeInfEvento.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public string COrgaoProxy
[XmlElement(ElementName = "dhEvento")]
public string ProxyDhEvento
{
get { return DhEvento.ParaDataHoraStringUtc(); }
get { return DhEvento.ParaDataHoraStringSemUtc(); }
set { DhEvento = DateTime.Parse(value); }
}

Expand Down
2 changes: 1 addition & 1 deletion MDFe.Classes/Informacoes/MDFeIde.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public string ProxyCMDF
[XmlElement(ElementName = "dhEmi")]
public string ProxyDhEmi
{
get { return DhEmi.ParaDataHoraStringUtc(); }
get { return DhEmi.ParaDataHoraStringSemUtc(); }
set { DhEmi = DateTime.Parse(value); }
}

Expand Down
6 changes: 6 additions & 0 deletions MDFe.Damdfe.AppTeste/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
</configuration>
Loading

0 comments on commit 9fe0841

Please sign in to comment.