Skip to content

Commit 9fe0841

Browse files
authored
Merge pull request #4 from adeniltonbs/master
Update
2 parents 7337a45 + 75b5cee commit 9fe0841

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+2145
-197
lines changed

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,9 @@ Temporary Items
9090
/MDFe.AppTeste/bin
9191
/MDFe.Classes/obj
9292
/MDFe.Utils/obj
93+
/MDFe.Damdfe.AppTeste/obj
94+
/MDFe.Damdfe.AppTeste/bin
95+
/MDFe.Damdfe.Base/obj
96+
/MDFe.Damdfe.Base/bin
97+
/MDFe.Damdfe.Fast/obj
98+
/MDFe.Damdfe.Fast/bin

DFe.Utils/Assinatura/CertificadoDigital.cs

+31-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/********************************************************************************/
2-
/* Projeto: Biblioteca ZeusDFe */
3-
/* Biblioteca C# para auxiliar no desenvolvimento das demais bibliotecas DFe */
4-
/* */
2+
/* Projeto: Biblioteca ZeusNFe */
3+
/* Biblioteca C# para emissão de Nota Fiscal Eletrônica - NFe e Nota Fiscal de */
4+
/* Consumidor Eletrônica - NFC-e (http://www.nfe.fazenda.gov.br) */
55
/* */
66
/* Direitos Autorais Reservados (c) 2014 Adenilton Batista da Silva */
77
/* Zeusdev Tecnologia LTDA ME */
@@ -136,5 +136,33 @@ public static X509Certificate2 ObterDeArquivo(string arquivo, string senha)
136136
var certificado = new X509Certificate2(arquivo, senha, X509KeyStorageFlags.MachineKeySet);
137137
return certificado;
138138
}
139+
140+
private static X509Certificate2 _certificado;
141+
142+
/// <summary>
143+
/// Obtém um objeto contendo o certificado digital
144+
/// <para>Se for informado <see cref="ConfiguracaoCertificado.Arquivo"/>,
145+
/// o certificado digital será obtido pelo método <see cref="ObterDeArquivo(string,string)"/>,
146+
/// senão será obtido pelo método <see cref="ObterDoRepositorio()"/> </para>
147+
/// <para>Para liberar os recursos do certificado, após seu uso, invoque o método <see cref="X509Certificate2.Reset()"/></para>
148+
/// </summary>
149+
public static X509Certificate2 ObterCertificado(ConfiguracaoCertificado configuracaoCertificado)
150+
{
151+
if (!configuracaoCertificado.ManterDadosEmCache)
152+
return ObterDadosCertificado(configuracaoCertificado);
153+
if (_certificado != null)
154+
return _certificado;
155+
_certificado = ObterDadosCertificado(configuracaoCertificado);
156+
return _certificado;
157+
}
158+
159+
private static X509Certificate2 ObterDadosCertificado(ConfiguracaoCertificado configuracaoCertificado)
160+
{
161+
return string.IsNullOrEmpty(configuracaoCertificado.Arquivo)
162+
? ObterDoRepositorio(configuracaoCertificado.Serial,
163+
configuracaoCertificado.Senha)
164+
: ObterDeArquivo(configuracaoCertificado.Arquivo,
165+
configuracaoCertificado.Senha);
166+
}
139167
}
140168
}

NFe.Utils/ConfiguracaoCertificado.cs DFe.Utils/ConfiguracaoCertificado.cs

+4-3
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@
3030
/* http://www.zeusautomacao.com.br/ */
3131
/* Rua Comendador Francisco josé da Cunha, 111 - Itabaiana - SE - 49500-000 */
3232
/********************************************************************************/
33+
3334
using System.ComponentModel;
3435
using NFe.Utils.Annotations;
3536

36-
namespace NFe.Utils
37+
namespace DFe.Utils
3738
{
3839
public class ConfiguracaoCertificado : INotifyPropertyChanged
3940
{
@@ -82,13 +83,13 @@ public string Arquivo
8283
/// <para>Manter os dados do certificado em cache, aumentará o desempenho no consumo dos serviços, especialmente para certificados A3</para>
8384
/// </summary>
8485
public bool ManterDadosEmCache { get; set; }
85-
86+
8687
public event PropertyChangedEventHandler PropertyChanged;
8788

8889
[NotifyPropertyChangedInvocator]
8990
protected virtual void OnPropertyChanged(string propertyName)
9091
{
91-
if (PropertyChanged != null) PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
92+
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
9293
}
9394
}
9495
}

DFe.Utils/DFe.Utils.csproj

+2
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,11 @@
4040
<ItemGroup>
4141
<Compile Include="Assinatura\AssinaturaDigital.cs" />
4242
<Compile Include="Assinatura\CertificadoDigital.cs" />
43+
<Compile Include="ConfiguracaoCertificado.cs" />
4344
<Compile Include="DataHora.cs" />
4445
<Compile Include="FuncoesXml.cs" />
4546
<Compile Include="ChaveFiscal.cs" />
47+
<Compile Include="Properties\Annotations.cs" />
4648
<Compile Include="Properties\AssemblyInfo.cs" />
4749
</ItemGroup>
4850
<ItemGroup>

DFe.Utils/DataHora.cs

+10
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,16 @@ public static string ParaDataHoraStringUtc(this DateTime data)
5656
return data == DateTime.MinValue ? null : data.ToString("yyyy-MM-ddTHH:mm:sszzz");
5757
}
5858

59+
/// <summary>
60+
/// Retorna uma string no formato AAAA-MM-DDThh:mm:dd
61+
/// </summary>
62+
/// <param name="data"></param>
63+
/// <returns></returns>
64+
public static string ParaDataHoraStringSemUtc(this DateTime data)
65+
{
66+
return data.ToString("yyyy-MM-ddTHH:mm:dd");
67+
}
68+
5969
/// <summary>
6070
/// Retorna uma string no formato AAAA-MM-DDThh:mm:ssTZD (UTC - Universal Coordinated Time)
6171
/// </summary>
File renamed without changes.

MDFe.AppTeste/Entidades/ConfigCertificadoDigital.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ public class ConfigCertificadoDigital
77
{
88
public string NumeroDeSerie { get; set; }
99
public string CaminhoArquivo { get; set; }
10-
public string Senha { get; set; }
10+
public string Senha { get; set; }
11+
public bool ManterEmCache { get; set; }
1112
}
1213
}

MDFe.AppTeste/MDFeTeste.xaml

+3
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@
142142
Width="280"
143143
Text="{Binding Senha, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
144144
</StackPanel>
145+
<StackPanel Margin="0,10,0,0">
146+
<CheckBox Margin="10,0,0,0" IsChecked="{Binding ManterCertificadoEmCache}">Manter certificado em cache</CheckBox>
147+
</StackPanel>
145148
</StackPanel>
146149

147150
</StackPanel>

MDFe.AppTeste/MDFeTesteModel.cs

+15-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
using System.Windows.Forms;
3636
using DFe.Classes.Entidades;
3737
using DFe.Classes.Flags;
38-
using DFe.Utils;
3938
using DFe.Utils.Assinatura;
4039
using MDFe.Classes.Flags;
4140
using MDFe.Classes.Informacoes;
@@ -108,6 +107,7 @@ public class MDFeTesteModel : ViewModel
108107
private string _diretorioSalvarXml;
109108
private bool _isSalvarXml;
110109
private int _timeOut;
110+
private bool _manterCertificadoEmCache;
111111

112112
#region empresa
113113

@@ -295,6 +295,16 @@ public string Senha
295295
}
296296
}
297297

298+
public bool ManterCertificadoEmCache
299+
{
300+
get { return _manterCertificadoEmCache; }
301+
set
302+
{
303+
_manterCertificadoEmCache = value;
304+
OnPropertyChanged("ManterCertificadoEmCache");
305+
}
306+
}
307+
298308
#endregion
299309

300310
#region configWebService
@@ -490,7 +500,8 @@ public void SalvarConfiguracoesXml()
490500
{
491501
CaminhoArquivo = CaminhoArquivo,
492502
NumeroDeSerie = NumeroDeSerie,
493-
Senha = Senha
503+
Senha = Senha,
504+
ManterEmCache = ManterCertificadoEmCache
494505
},
495506
ConfigWebService =
496507
{
@@ -562,6 +573,7 @@ public void CarregarConfiguracoesMDFe()
562573
Rntrc = config.Empresa.RNTRC;
563574

564575
Senha = config.CertificadoDigital.Senha;
576+
ManterCertificadoEmCache = config.CertificadoDigital.ManterEmCache;
565577
CaminhoArquivo = config.CertificadoDigital.CaminhoArquivo;
566578
NumeroDeSerie = config.CertificadoDigital.NumeroDeSerie;
567579

@@ -1129,6 +1141,7 @@ private static void CarregarConfiguracoesMDFe(Configuracao config)
11291141
Utils.Configuracoes.MDFeConfiguracao.SenhaCertificadoDigital = config.CertificadoDigital.Senha;
11301142
Utils.Configuracoes.MDFeConfiguracao.CaminhoCertificadoDigital = config.CertificadoDigital.CaminhoArquivo;
11311143
Utils.Configuracoes.MDFeConfiguracao.NumeroSerieCertificadoDigital = config.CertificadoDigital.NumeroDeSerie;
1144+
Utils.Configuracoes.MDFeConfiguracao.ManterCertificadoEmCache = config.CertificadoDigital.ManterEmCache;
11321145
Utils.Configuracoes.MDFeConfiguracao.CaminhoSchemas = config.ConfigWebService.CaminhoSchemas;
11331146
Utils.Configuracoes.MDFeConfiguracao.CaminhoSalvarXml = config.DiretorioSalvarXml;
11341147
Utils.Configuracoes.MDFeConfiguracao.IsSalvarXml = config.IsSalvarXml;

MDFe.Classes/Informacoes/Evento/MDFeInfEvento.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public string COrgaoProxy
7474
[XmlElement(ElementName = "dhEvento")]
7575
public string ProxyDhEvento
7676
{
77-
get { return DhEvento.ParaDataHoraStringUtc(); }
77+
get { return DhEvento.ParaDataHoraStringSemUtc(); }
7878
set { DhEvento = DateTime.Parse(value); }
7979
}
8080

MDFe.Classes/Informacoes/MDFeIde.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public string ProxyCMDF
126126
[XmlElement(ElementName = "dhEmi")]
127127
public string ProxyDhEmi
128128
{
129-
get { return DhEmi.ParaDataHoraStringUtc(); }
129+
get { return DhEmi.ParaDataHoraStringSemUtc(); }
130130
set { DhEmi = DateTime.Parse(value); }
131131
}
132132

MDFe.Damdfe.AppTeste/App.config

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
5+
</startup>
6+
</configuration>

0 commit comments

Comments
 (0)