summaryrefslogtreecommitdiff
path: root/Decompiler/Gestor.Application.Servicos/ArquivoDigitalServico.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Decompiler/Gestor.Application.Servicos/ArquivoDigitalServico.cs')
-rw-r--r--Decompiler/Gestor.Application.Servicos/ArquivoDigitalServico.cs594
1 files changed, 594 insertions, 0 deletions
diff --git a/Decompiler/Gestor.Application.Servicos/ArquivoDigitalServico.cs b/Decompiler/Gestor.Application.Servicos/ArquivoDigitalServico.cs
new file mode 100644
index 0000000..637a396
--- /dev/null
+++ b/Decompiler/Gestor.Application.Servicos/ArquivoDigitalServico.cs
@@ -0,0 +1,594 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Threading.Tasks;
+using ArquivoDigital.Infrastructure.UnitOfWork.Generic;
+using ArquivoDigital.Infrastructure.UnitOfWork.Logic;
+using CsQuery.ExtensionMethods.Internal;
+using Gestor.Application.Helpers;
+using Gestor.Application.Servicos.Generic;
+using Gestor.Infrastructure.UnitOfWork.Generic;
+using Gestor.Infrastructure.UnitOfWork.Logic;
+using Gestor.Model.API;
+using Gestor.Model.Common;
+using Gestor.Model.Domain.Aggilizador;
+using Gestor.Model.Domain.Common;
+using Gestor.Model.Domain.Generic;
+using Gestor.Model.License;
+
+namespace Gestor.Application.Servicos;
+
+public class ArquivoDigitalServico : BaseServico
+{
+ public async Task<List<IndiceArquivoDigital>> BuscarPorTipo(TipoArquivoDigital tipo, long id)
+ {
+ //IL_0016: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0017: Unknown result type (might be due to invalid IL or missing references)
+ int tries = 3;
+ long usuario = ((DomainBase)Recursos.Usuario).Id;
+ return await Task.Run(delegate
+ {
+ //IL_0071: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0013: Unknown result type (might be due to invalid IL or missing references)
+ while (tries > 0)
+ {
+ try
+ {
+ UnitOfWork read = Instancia.Read;
+ try
+ {
+ return read.IndiceArquivoDigitalRepository.Find(tipo, id, usuario, LicenseHelper.Produtos.Any((Licenca x) => (int)x.Produto == 86 && x.Status != 3));
+ }
+ finally
+ {
+ ((IDisposable)read)?.Dispose();
+ }
+ }
+ catch (Exception e)
+ {
+ tries = Registrar(e, (TipoErro)64, tries, new { tipo, id });
+ }
+ }
+ return new List<IndiceArquivoDigital>();
+ });
+ }
+
+ public async Task<ArquivoDigital> BuscarPorId(long id, string banco)
+ {
+ int tries = 3;
+ return await Task.Run((Func<ArquivoDigital>)delegate
+ {
+ while (tries > 0)
+ {
+ try
+ {
+ Gestor.Application.Helpers.ArquivoDigital.SetConnection(banco);
+ if (string.IsNullOrEmpty(banco))
+ {
+ banco = Gestor.Application.Helpers.ArquivoDigital.Banco;
+ }
+ UnitOfWork read = Gestor.Application.Helpers.ArquivoDigital.Read;
+ try
+ {
+ ArquivoDigital val = read.ArquivoDigitalRepository.FindById(id, true);
+ if (val == null)
+ {
+ return (ArquivoDigital)null;
+ }
+ if (val.AzureGuid.HasValue)
+ {
+ byte[] result = Connection.DownloadFile(val.AzureStorage, val.DataCriacao.Value.Year, val.AzureGuid.Value, val.Extensao).Result;
+ if (result == null)
+ {
+ return (ArquivoDigital)null;
+ }
+ val.Arquivo = result;
+ }
+ return val;
+ }
+ finally
+ {
+ ((IDisposable)read)?.Dispose();
+ }
+ }
+ catch (Exception e)
+ {
+ tries = Registrar(e, (TipoErro)65, tries, new { id, banco });
+ }
+ }
+ return (ArquivoDigital)null;
+ });
+ }
+
+ public async Task<ArquivoDigital> BuscarPorId(long id)
+ {
+ int tries = 3;
+ return await Task.Run((Func<ArquivoDigital>)delegate
+ {
+ while (tries > 0)
+ {
+ try
+ {
+ UnitOfWork read = Instancia.Read;
+ try
+ {
+ ArquivoDigital val = read.IndiceArquivoDigitalRepository.FindAssinatura(id);
+ if (val.AzureGuid.HasValue)
+ {
+ byte[] result = Connection.DownloadFile(val.AzureStorage, val.DataCriacao.Value.Year, val.AzureGuid.Value, Path.GetExtension(val.Descricao), "siggner").Result;
+ if (result == null)
+ {
+ return (ArquivoDigital)null;
+ }
+ val.Arquivo = result;
+ }
+ return val;
+ }
+ finally
+ {
+ ((IDisposable)read)?.Dispose();
+ }
+ }
+ catch (Exception e)
+ {
+ tries = Registrar(e, (TipoErro)64, tries, id);
+ }
+ }
+ return (ArquivoDigital)null;
+ });
+ }
+
+ public async Task<bool> DeleteAttachment(IndiceArquivoDigital indice)
+ {
+ int tries = 3;
+ DateTime now = Funcoes.GetNetworkTime();
+ return await Task.Run(delegate
+ {
+ //IL_0023: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0028: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0033: Unknown result type (might be due to invalid IL or missing references)
+ //IL_003e: Unknown result type (might be due to invalid IL or missing references)
+ //IL_005c: Expected O, but got Unknown
+ //IL_005d: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0062: Unknown result type (might be due to invalid IL or missing references)
+ //IL_006d: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0078: Unknown result type (might be due to invalid IL or missing references)
+ //IL_008e: Expected O, but got Unknown
+ //IL_0101: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0106: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0111: Unknown result type (might be due to invalid IL or missing references)
+ //IL_011c: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0141: Expected O, but got Unknown
+ while (tries > 0)
+ {
+ List<RegistroLog> list = new List<RegistroLog>();
+ try
+ {
+ UnitOfWork commited = Instancia.Commited;
+ try
+ {
+ indice.Excluido = true;
+ List<Diferenca> list2 = new List<Diferenca>
+ {
+ new Diferenca
+ {
+ Campo = "Id",
+ Descricao = "ID",
+ ValorAtual = ((DomainBase)indice).Id.ToString()
+ },
+ new Diferenca
+ {
+ Campo = "Descricao",
+ Descricao = "DESCRIÇÃO",
+ ValorAtual = indice.Descricao
+ }
+ };
+ if (indice.AzureGuid.HasValue && Connection.DeleteFile(indice.AzureStorage, indice.DataCriacao.Value.Year, indice.AzureGuid.Value, indice.Extensao).Result)
+ {
+ list2.Add(new Diferenca
+ {
+ Campo = "AzureGuid",
+ Descricao = "AzureGuid",
+ ValorAtual = indice.AzureGuid.ToString()
+ });
+ }
+ list.Add(CreateLog(((DomainBase)indice).Id, list2, (TipoTela)6, (TipoAcao)2));
+ indice.DataAtualizacao = now;
+ if (!indice.DataCriacao.HasValue || indice.DataCriacao.Value.Year < 1754)
+ {
+ indice.DataCriacao = now;
+ }
+ commited.IndiceArquivoDigitalRepository.Merge(indice);
+ SaveLog(list, commited);
+ ((GenericUnitOfWork)commited).Commit();
+ }
+ finally
+ {
+ ((IDisposable)commited)?.Dispose();
+ }
+ return true;
+ }
+ catch (Exception e)
+ {
+ tries = Registrar(e, (TipoErro)253, tries, indice);
+ }
+ }
+ return false;
+ });
+ }
+
+ public async Task<IndiceArquivoDigital> Save(IndiceArquivoDigital indice)
+ {
+ int tries = 3;
+ base.Sucesso = true;
+ IndiceArquivoDigital indiceOriginal = indice;
+ DateTime now = Funcoes.GetNetworkTime();
+ return await Task.Run((Func<IndiceArquivoDigital>)delegate
+ {
+ //IL_002e: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0066: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0068: Invalid comparison between Unknown and I4
+ //IL_008e: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0090: Invalid comparison between Unknown and I4
+ //IL_00bb: Unknown result type (might be due to invalid IL or missing references)
+ //IL_00bd: Invalid comparison between Unknown and I4
+ //IL_00c5: Unknown result type (might be due to invalid IL or missing references)
+ //IL_00ca: Unknown result type (might be due to invalid IL or missing references)
+ //IL_00d5: Unknown result type (might be due to invalid IL or missing references)
+ //IL_00e0: Unknown result type (might be due to invalid IL or missing references)
+ //IL_00f6: Expected O, but got Unknown
+ //IL_010b: Unknown result type (might be due to invalid IL or missing references)
+ while (tries > 0)
+ {
+ indice = indiceOriginal;
+ List<RegistroLog> list = new List<RegistroLog>();
+ try
+ {
+ UnitOfWork commited = Instancia.Commited;
+ try
+ {
+ TipoAcao val = (TipoAcao)(((DomainBase)indice).Id != 0L);
+ indice.DataAtualizacao = now;
+ indice.UsuarioAtualizacao = ((DomainBase)Recursos.Usuario).Id;
+ indice.Excluido = false;
+ if ((int)val == 1)
+ {
+ list.Add(CreateLog(((DomainBase)indice).Id, indice, (TipoTela)6));
+ }
+ indice = (((int)val == 1) ? commited.IndiceArquivoDigitalRepository.Merge(indice) : commited.IndiceArquivoDigitalRepository.SaveOrUpdate(indice));
+ if ((int)val != 1)
+ {
+ List<Diferenca> diferenca = new List<Diferenca>
+ {
+ new Diferenca
+ {
+ Campo = "Descricao",
+ Descricao = "DESCRIÇÃO",
+ ValorAtual = indice.Descricao
+ }
+ };
+ list.Add(CreateLog(((DomainBase)indice).Id, diferenca, (TipoTela)6, val));
+ }
+ SaveLog(list, commited);
+ ((GenericUnitOfWork)commited).Commit();
+ }
+ finally
+ {
+ ((IDisposable)commited)?.Dispose();
+ }
+ return indice;
+ }
+ catch (Exception e)
+ {
+ tries = Registrar(e, (TipoErro)252, tries, indice);
+ }
+ }
+ return indiceOriginal;
+ });
+ }
+
+ public async Task<List<IndiceArquivoDigital>> Insert(List<ArquivoDigital> files)
+ {
+ int tries = 3;
+ base.Sucesso = true;
+ DateTime now = Funcoes.GetNetworkTime();
+ List<ArquivoDigital> filesOriginal = files;
+ return await Task.Run(delegate
+ {
+ while (tries > 0)
+ {
+ List<RegistroLog> logs = new List<RegistroLog>();
+ files = filesOriginal;
+ try
+ {
+ List<IndiceArquivoDigital> indices = new List<IndiceArquivoDigital>();
+ files.ForEach(delegate(ArquivoDigital file)
+ {
+ //IL_0035: Unknown result type (might be due to invalid IL or missing references)
+ //IL_003a: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0050: Unknown result type (might be due to invalid IL or missing references)
+ //IL_005b: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0076: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0083: Expected O, but got Unknown
+ //IL_00c9: Unknown result type (might be due to invalid IL or missing references)
+ //IL_00ce: Unknown result type (might be due to invalid IL or missing references)
+ //IL_00da: Unknown result type (might be due to invalid IL or missing references)
+ //IL_00e5: Unknown result type (might be due to invalid IL or missing references)
+ //IL_00f1: Unknown result type (might be due to invalid IL or missing references)
+ //IL_00fd: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0109: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0115: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0121: Unknown result type (might be due to invalid IL or missing references)
+ //IL_012d: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0139: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0145: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0151: Unknown result type (might be due to invalid IL or missing references)
+ //IL_015d: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0169: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0175: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0181: Unknown result type (might be due to invalid IL or missing references)
+ //IL_018d: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0199: Unknown result type (might be due to invalid IL or missing references)
+ //IL_01a5: Unknown result type (might be due to invalid IL or missing references)
+ //IL_01b1: Unknown result type (might be due to invalid IL or missing references)
+ //IL_01bd: Unknown result type (might be due to invalid IL or missing references)
+ //IL_01c9: Unknown result type (might be due to invalid IL or missing references)
+ //IL_01d5: Unknown result type (might be due to invalid IL or missing references)
+ //IL_01e1: Unknown result type (might be due to invalid IL or missing references)
+ //IL_01ed: Unknown result type (might be due to invalid IL or missing references)
+ //IL_01f9: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0206: Expected O, but got Unknown
+ //IL_0268: Unknown result type (might be due to invalid IL or missing references)
+ //IL_026d: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0278: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0283: Unknown result type (might be due to invalid IL or missing references)
+ //IL_0294: Expected O, but got Unknown
+ file.UsuarioCriacao = ((DomainBase)Recursos.Usuario).Id;
+ file.DataCriacao = now;
+ file.DataAtualizacao = null;
+ UploadFile val = new UploadFile
+ {
+ Ano = now.Year,
+ Id = Guid.NewGuid(),
+ Extensao = file.Extensao.Replace(".", string.Empty),
+ Arquivo = file.Arquivo
+ };
+ if (Connection.ConnectionAddress.UsaAzureStorage && Connection.UploadFile(val).Result)
+ {
+ file.AzureGuid = val.Id;
+ file.Arquivo = null;
+ file.AzureStorage = Connection.ConnectionAddress.AzureStorage;
+ }
+ IndiceArquivoDigital val2 = new IndiceArquivoDigital
+ {
+ Descricao = file.Descricao,
+ Bd = Gestor.Application.Helpers.ArquivoDigital.Banco,
+ Extensao = file.Extensao,
+ IdCliente = file.IdCliente,
+ IdDocumento = file.IdDocumento,
+ IdEmpresa = file.IdEmpresa,
+ IdParcela = file.IdParcela,
+ IdItem = file.IdItem,
+ IdExtrato = file.IdExtrato,
+ IdSinistro = file.IdSinistro,
+ IdSeguradora = file.IdSeguradora,
+ IdVendedor = file.IdVendedor,
+ IdUsuario = file.IdUsuario,
+ IdLancamento = file.IdLancamento,
+ IdFornecedor = file.IdFornecedor,
+ IdProspeccao = file.IdProspeccao,
+ IdSocio = file.IdSocio,
+ IdTarefa = file.IdTarefa,
+ IdNotaFiscal = file.IdNotaFiscal,
+ IdEstipulante = file.IdEstipulante,
+ Excluido = file.Excluido,
+ UsuarioCriacao = file.UsuarioCriacao,
+ DataCriacao = file.DataCriacao,
+ DataAtualizacao = file.DataAtualizacao,
+ AzureGuid = file.AzureGuid,
+ AzureStorage = file.AzureStorage
+ };
+ Gestor.Application.Helpers.ArquivoDigital.SetConnection();
+ val2.Bd = Gestor.Application.Helpers.ArquivoDigital.Banco;
+ UnitOfWork commited = Gestor.Application.Helpers.ArquivoDigital.Commited;
+ try
+ {
+ file = commited.ArquivoDigitalRepository.SaveOrUpdate(file);
+ val2.IdArquivoDigital = ((DomainBase)file).Id;
+ ((GenericUnitOfWork)commited).Commit();
+ }
+ finally
+ {
+ ((IDisposable)commited)?.Dispose();
+ }
+ UnitOfWork commited2 = Instancia.Commited;
+ try
+ {
+ val2 = commited2.IndiceArquivoDigitalRepository.SaveOrUpdate(val2);
+ List<Diferenca> diferenca = new List<Diferenca>
+ {
+ new Diferenca
+ {
+ Campo = "Descricao",
+ Descricao = "DESCRIÇÃO",
+ ValorAtual = val2.Descricao
+ }
+ };
+ logs.Add(CreateLog(((DomainBase)val2).Id, diferenca, (TipoTela)6, (TipoAcao)0));
+ SaveLog(logs, commited2);
+ ((GenericUnitOfWork)commited2).Commit();
+ }
+ finally
+ {
+ ((IDisposable)commited2)?.Dispose();
+ }
+ indices.Add(val2);
+ });
+ return indices;
+ }
+ catch (Exception e)
+ {
+ tries = Registrar(e, (TipoErro)252, tries, files);
+ }
+ }
+ return new List<IndiceArquivoDigital>();
+ });
+ }
+
+ public async Task<List<ArquivoDigital>> Buscar(List<IndiceArquivoDigital> ids)
+ {
+ int tries = 3;
+ return await Task.Run(delegate
+ {
+ while (tries > 0)
+ {
+ try
+ {
+ List<ArquivoDigital> arquivos = new List<ArquivoDigital>();
+ (from x in ids
+ group x by x.Bd).ToList().ForEach(delegate(IGrouping<string, IndiceArquivoDigital> x)
+ {
+ Gestor.Application.Helpers.ArquivoDigital.SetConnection(x.Key);
+ List<long> list = (from l in x
+ where !l.Assinado
+ select l.IdArquivoDigital).ToList();
+ List<long> list2 = (from l in x
+ where l.Assinado
+ select ((DomainBase)l).Id).ToList();
+ if (list2.Any())
+ {
+ List<ArquivoDigital> _arquivos2 = new List<ArquivoDigital>();
+ UnitOfWork unitOfWork2 = Instancia.Read;
+ try
+ {
+ list2.ForEach(delegate(long a)
+ {
+ ArquivoDigital val2 = unitOfWork2.IndiceArquivoDigitalRepository.FindAssinatura(a);
+ if (val2.AzureGuid.HasValue)
+ {
+ val2.Arquivo = Connection.DownloadFile(val2.AzureStorage, val2.DataCriacao.Value.Year, val2.AzureGuid.Value, Path.GetExtension(val2.Descricao), "siggner").Result;
+ }
+ if (val2.Arquivo != null)
+ {
+ _arquivos2.Add(val2);
+ }
+ });
+ }
+ finally
+ {
+ if (unitOfWork2 != null)
+ {
+ ((IDisposable)unitOfWork2).Dispose();
+ }
+ }
+ arquivos.AddRange(_arquivos2);
+ }
+ if (list.Any())
+ {
+ List<ArquivoDigital> _arquivos = new List<ArquivoDigital>();
+ UnitOfWork unitOfWork = Gestor.Application.Helpers.ArquivoDigital.Read;
+ try
+ {
+ list.ForEach(delegate(long a)
+ {
+ ArquivoDigital val = unitOfWork.ArquivoDigitalRepository.FindById(a, true);
+ if (val.AzureGuid.HasValue)
+ {
+ val.Arquivo = Connection.DownloadFile(val.AzureStorage, val.DataCriacao.Value.Year, val.AzureGuid.Value, val.Extensao).Result;
+ }
+ if (val.Arquivo != null)
+ {
+ _arquivos.Add(val);
+ }
+ });
+ }
+ finally
+ {
+ if (unitOfWork != null)
+ {
+ ((IDisposable)unitOfWork).Dispose();
+ }
+ }
+ arquivos.AddRange(_arquivos);
+ }
+ });
+ return arquivos;
+ }
+ catch (Exception e)
+ {
+ tries = Registrar(e, (TipoErro)66, tries, ids);
+ }
+ }
+ return new List<ArquivoDigital>();
+ });
+ }
+
+ public async Task Criar()
+ {
+ int tries = 3;
+ await Task.Run(delegate
+ {
+ while (tries > 0)
+ {
+ try
+ {
+ UnitOfWork read = Gestor.Application.Helpers.ArquivoDigital.Read;
+ try
+ {
+ read.ArquivoDigitalRepository.FindById(1L, false);
+ break;
+ }
+ finally
+ {
+ ((IDisposable)read)?.Dispose();
+ }
+ }
+ catch (Exception e)
+ {
+ tries = Registrar(e, (TipoErro)288, tries);
+ }
+ }
+ });
+ }
+
+ public async Task<List<ArquivoVinculo>> BaixarArquivosPendentes(List<ArquivoVinculo> arquivos)
+ {
+ string banco = Gestor.Application.Helpers.ArquivoDigital.Banco;
+ int tries = 3;
+ return await Task.Run(delegate
+ {
+ while (tries > 0)
+ {
+ try
+ {
+ UnitOfWork read = Gestor.Application.Helpers.ArquivoDigital.Read;
+ try
+ {
+ foreach (ArquivoVinculo arquivo in arquivos)
+ {
+ if (arquivo.Arquivo == null && !ExtensionMethods.IsNullOrEmpty<char>((IEnumerable<char>)arquivo.Chave))
+ {
+ byte[] result = Connection.DownloadFile(arquivo.Storage, arquivo.Ano, Guid.Parse(arquivo.Chave), ".pdf", "aggilizador").Result;
+ if (result != null)
+ {
+ arquivo.Arquivo = result;
+ }
+ }
+ }
+ return arquivos;
+ }
+ finally
+ {
+ ((IDisposable)read)?.Dispose();
+ }
+ }
+ catch (Exception e)
+ {
+ tries = Registrar(e, (TipoErro)65, tries, new { arquivos, banco });
+ }
+ }
+ return (List<ArquivoVinculo>)null;
+ });
+ }
+}