From 225aa1499e37faf9d38257caabbadc68d78b427e Mon Sep 17 00:00:00 2001 From: Lucas Faria Mendes Date: Mon, 30 Mar 2026 12:29:41 -0300 Subject: decompiler.com --- .../BaseServico.cs | 2412 ++++++++++++++++++++ 1 file changed, 2412 insertions(+) create mode 100644 Decompiler/Gestor.Application.Servicos.Generic/BaseServico.cs (limited to 'Decompiler/Gestor.Application.Servicos.Generic/BaseServico.cs') diff --git a/Decompiler/Gestor.Application.Servicos.Generic/BaseServico.cs b/Decompiler/Gestor.Application.Servicos.Generic/BaseServico.cs new file mode 100644 index 0000000..be9b6fb --- /dev/null +++ b/Decompiler/Gestor.Application.Servicos.Generic/BaseServico.cs @@ -0,0 +1,2412 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Net; +using System.Net.Http; +using System.Net.Http.Headers; +using System.Net.Sockets; +using System.Threading.Tasks; +using Agger.Registro; +using Gestor.Application.Helpers; +using Gestor.Application.ViewModels; +using Gestor.Common.Security; +using Gestor.Common.Validation; +using Gestor.Infrastructure.Helpers; +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.Ferramentas; +using Gestor.Model.Domain.Financeiro; +using Gestor.Model.Domain.Generic; +using Gestor.Model.Domain.Relatorios; +using Gestor.Model.Domain.Seguros; +using Newtonsoft.Json; + +namespace Gestor.Application.Servicos.Generic; + +public class BaseServico +{ + private const int UnathorizedSsoCode = 401; + + private const int NotFoundSsoCode = 404; + + public bool Sucesso { get; set; } + + public int Registrar(Exception e, TipoErro erro, int tries, object objeto = null, bool abrirTela = true) + { + //IL_0029: Unknown result type (might be due to invalid IL or missing references) + //IL_002e: Unknown result type (might be due to invalid IL or missing references) + //IL_003a: Expected O, but got Unknown + //IL_003b: Unknown result type (might be due to invalid IL or missing references) + //IL_0040: Unknown result type (might be due to invalid IL or missing references) + //IL_004b: 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_0079: Unknown result type (might be due to invalid IL or missing references) + //IL_0091: Unknown result type (might be due to invalid IL or missing references) + //IL_00a1: Unknown result type (might be due to invalid IL or missing references) + //IL_00ac: Unknown result type (might be due to invalid IL or missing references) + //IL_00ad: Unknown result type (might be due to invalid IL or missing references) + //IL_00b3: Expected I4, but got Unknown + //IL_00b3: Unknown result type (might be due to invalid IL or missing references) + //IL_00b4: Unknown result type (might be due to invalid IL or missing references) + //IL_00c4: Unknown result type (might be due to invalid IL or missing references) + //IL_00d0: Unknown result type (might be due to invalid IL or missing references) + //IL_00e8: Unknown result type (might be due to invalid IL or missing references) + //IL_00f4: Unknown result type (might be due to invalid IL or missing references) + //IL_0100: Unknown result type (might be due to invalid IL or missing references) + //IL_010c: Unknown result type (might be due to invalid IL or missing references) + //IL_0118: Unknown result type (might be due to invalid IL or missing references) + //IL_0123: Unknown result type (might be due to invalid IL or missing references) + //IL_012e: Unknown result type (might be due to invalid IL or missing references) + //IL_013b: Unknown result type (might be due to invalid IL or missing references) + //IL_0149: Expected O, but got Unknown + tries--; + if (tries > 0) + { + return tries; + } + try + { + int fileLineNumber = new StackTrace(e, fNeedFileInfo: true).GetFrame(0).GetFileLineNumber(); + string objeto2 = ((objeto != null) ? JsonConvert.SerializeObject(objeto, (Formatting)1, new JsonSerializerSettings + { + ReferenceLoopHandling = (ReferenceLoopHandling)1 + }) : null); + LogError val = new LogError + { + IdFornecedor = ApplicationHelper.IdFornecedor + }; + Empresa empresa = Recursos.Empresa; + val.Fornecedor = ((empresa != null) ? empresa.Nome : null); + Usuario usuario = Recursos.Usuario; + val.UsuarioLogado = ((usuario != null) ? usuario.Nome : null); + Usuario usuario2 = Recursos.Usuario; + val.IdUsuarioLogado = ((usuario2 != null) ? ((DomainBase)usuario2).Id : 0); + val.Versao = ApplicationHelper.Versao.ToString(); + val.Data = Funcoes.GetNetworkTime(); + val.IdErro = (int)erro; + val.Erro = ValidationHelper.GetDescription((Enum)(object)erro); + val.HResult = e.HResult; + val.InnerException = e.InnerException?.ToString(); + val.HelpLink = e.HelpLink; + val.Message = e.Message; + val.Source = e.Source; + val.StackTrace = e.StackTrace; + val.Maquina = Environment.MachineName; + val.UsuarioMaquina = Environment.UserName; + val.Linha = fileLineNumber.ToString(); + val.Objeto = objeto2; + Erro.RegistrarErro(val, abrirTela); + Sucesso = false; + } + catch (Exception) + { + } + return 0; + } + + public RegistroLog CreateLog(long id, dynamic obj, TipoTela tela) + { + //IL_0092: Unknown result type (might be due to invalid IL or missing references) + //IL_0097: Unknown result type (might be due to invalid IL or missing references) + //IL_009e: Unknown result type (might be due to invalid IL or missing references) + //IL_00a9: Unknown result type (might be due to invalid IL or missing references) + //IL_00b0: Unknown result type (might be due to invalid IL or missing references) + //IL_00bd: Unknown result type (might be due to invalid IL or missing references) + //IL_00c2: Unknown result type (might be due to invalid IL or missing references) + //IL_00ce: Expected O, but got Unknown + //IL_00d6: Unknown result type (might be due to invalid IL or missing references) + //IL_00dd: Unknown result type (might be due to invalid IL or missing references) + //IL_00de: Unknown result type (might be due to invalid IL or missing references) + //IL_00e4: Unknown result type (might be due to invalid IL or missing references) + //IL_00ef: Unknown result type (might be due to invalid IL or missing references) + //IL_00fa: Unknown result type (might be due to invalid IL or missing references) + //IL_0105: 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_014d: Expected O, but got Unknown + try + { + List list = obj.Compare(); + DateTime networkTime = Funcoes.GetNetworkTime(); + return new RegistroLog + { + Acao = (TipoAcao)1, + Usuario = Recursos.Usuario, + DataHora = networkTime, + Descricao = ((list != null && list.Count == 0) ? null : JsonConvert.SerializeObject((object)list, new JsonSerializerSettings + { + ReferenceLoopHandling = (ReferenceLoopHandling)1 + })), + EntidadeId = id, + Tela = tela, + Versao = LoginViewModel.VersaoAtual, + NomeMaquina = Environment.MachineName, + UsuarioMaquina = Environment.UserName, + Ip = Recursos.Host.AddressList.FirstOrDefault((IPAddress ip) => ip.AddressFamily == AddressFamily.InterNetwork)?.ToString(), + ModeloNovo = true + }; + } + catch (Exception) + { + return null; + } + } + + public RegistroLog CreateDynamicLog(long id, dynamic lista, TipoTela tela) + { + //IL_063f: Unknown result type (might be due to invalid IL or missing references) + //IL_0644: Unknown result type (might be due to invalid IL or missing references) + //IL_0650: Expected O, but got Unknown + //IL_0682: Unknown result type (might be due to invalid IL or missing references) + //IL_0687: Unknown result type (might be due to invalid IL or missing references) + //IL_0693: Expected O, but got Unknown + //IL_06ba: Unknown result type (might be due to invalid IL or missing references) + //IL_06bf: Unknown result type (might be due to invalid IL or missing references) + //IL_06c6: Unknown result type (might be due to invalid IL or missing references) + //IL_06d1: Unknown result type (might be due to invalid IL or missing references) + //IL_06d8: Unknown result type (might be due to invalid IL or missing references) + //IL_0704: Unknown result type (might be due to invalid IL or missing references) + //IL_070b: Unknown result type (might be due to invalid IL or missing references) + //IL_070c: Unknown result type (might be due to invalid IL or missing references) + //IL_0712: Unknown result type (might be due to invalid IL or missing references) + //IL_071d: Unknown result type (might be due to invalid IL or missing references) + //IL_0728: Unknown result type (might be due to invalid IL or missing references) + //IL_0733: Unknown result type (might be due to invalid IL or missing references) + //IL_0773: Unknown result type (might be due to invalid IL or missing references) + //IL_077c: Expected O, but got Unknown + try + { + List list = new List(); + List list2 = new List(); + foreach (dynamic listum in lista) + { + if (listum == null) + { + continue; + } + if (listum.GetType().Name.ToUpper().StartsWith("LIST")) + { + foreach (dynamic item in listum) + { + try + { + if (!((item.Id == 0) ? true : false)) + { + list.AddRange(DynamicObjeto(item)); + } + else + { + list2.AddRange(item.GetValorOriginal()); + } + } + catch + { + } + } + } + else + { + try + { + list.AddRange(DynamicObjeto(listum)); + } + catch + { + } + } + } + DateTime networkTime = Funcoes.GetNetworkTime(); + string text = ((list != null && list.Count == 0) ? "" : JsonConvert.SerializeObject((object)list, new JsonSerializerSettings + { + ReferenceLoopHandling = (ReferenceLoopHandling)1 + }).Replace("]", ",").Replace("[", "")); + string text2 = ((list2 != null && list2.Count == 0) ? "" : JsonConvert.SerializeObject((object)list2, new JsonSerializerSettings + { + ReferenceLoopHandling = (ReferenceLoopHandling)1 + }).Replace("]", "").Replace("[", "")); + return new RegistroLog + { + Acao = (TipoAcao)1, + Usuario = Recursos.Usuario, + DataHora = networkTime, + Descricao = ((string.IsNullOrEmpty(text) && string.IsNullOrEmpty(text2)) ? null : ("[" + text + text2 + "]")), + EntidadeId = id, + Tela = tela, + Versao = LoginViewModel.VersaoAtual, + NomeMaquina = Environment.MachineName, + UsuarioMaquina = Environment.UserName, + Ip = Recursos.Host.AddressList.FirstOrDefault((IPAddress ip) => ip.AddressFamily == AddressFamily.InterNetwork)?.ToString(), + ModeloNovo = true + }; + } + catch (Exception) + { + return null; + } + } + + public List DynamicObjeto(dynamic objeto) + { + dynamic val = objeto.Compare(); + if (val.Count > 0) + { + return val; + } + return new List(); + } + + public RegistroLog CreateLog(long id, List diferenca, TipoTela tela) + { + //IL_0006: Unknown result type (might be due to invalid IL or missing references) + //IL_000b: Unknown result type (might be due to invalid IL or missing references) + //IL_0012: Unknown result type (might be due to invalid IL or missing references) + //IL_001d: Unknown result type (might be due to invalid IL or missing references) + //IL_0024: Unknown result type (might be due to invalid IL or missing references) + //IL_0026: Unknown result type (might be due to invalid IL or missing references) + //IL_002b: Unknown result type (might be due to invalid IL or missing references) + //IL_0037: Expected O, but got Unknown + //IL_003c: Unknown result type (might be due to invalid IL or missing references) + //IL_0043: Unknown result type (might be due to invalid IL or missing references) + //IL_0044: Unknown result type (might be due to invalid IL or missing references) + //IL_004a: Unknown result type (might be due to invalid IL or missing references) + //IL_0055: Unknown result type (might be due to invalid IL or missing references) + //IL_0060: Unknown result type (might be due to invalid IL or missing references) + //IL_006b: Unknown result type (might be due to invalid IL or missing references) + //IL_00ab: Unknown result type (might be due to invalid IL or missing references) + //IL_00b3: Expected O, but got Unknown + try + { + DateTime networkTime = Funcoes.GetNetworkTime(); + return new RegistroLog + { + Acao = (TipoAcao)1, + Usuario = Recursos.Usuario, + DataHora = networkTime, + Descricao = JsonConvert.SerializeObject((object)diferenca, new JsonSerializerSettings + { + ReferenceLoopHandling = (ReferenceLoopHandling)1 + }), + EntidadeId = id, + Tela = tela, + Versao = LoginViewModel.VersaoAtual, + NomeMaquina = Environment.MachineName, + UsuarioMaquina = Environment.UserName, + Ip = Recursos.Host.AddressList.FirstOrDefault((IPAddress ip) => ip.AddressFamily == AddressFamily.InterNetwork)?.ToString(), + ModeloNovo = true + }; + } + catch (Exception) + { + return null; + } + } + + public RegistroLog CreateLog(long id, List diferenca, TipoTela tela, TipoAcao acao) + { + //IL_0006: Unknown result type (might be due to invalid IL or missing references) + //IL_000b: Unknown result type (might be due to invalid IL or missing references) + //IL_000c: 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) + //IL_001e: Unknown result type (might be due to invalid IL or missing references) + //IL_0025: Unknown result type (might be due to invalid IL or missing references) + //IL_0027: Unknown result type (might be due to invalid IL or missing references) + //IL_002c: Unknown result type (might be due to invalid IL or missing references) + //IL_0038: Expected O, but got Unknown + //IL_003d: Unknown result type (might be due to invalid IL or missing references) + //IL_0044: Unknown result type (might be due to invalid IL or missing references) + //IL_0045: Unknown result type (might be due to invalid IL or missing references) + //IL_004b: Unknown result type (might be due to invalid IL or missing references) + //IL_0056: Unknown result type (might be due to invalid IL or missing references) + //IL_0061: Unknown result type (might be due to invalid IL or missing references) + //IL_006c: Unknown result type (might be due to invalid IL or missing references) + //IL_00ac: Unknown result type (might be due to invalid IL or missing references) + //IL_00b4: Expected O, but got Unknown + try + { + DateTime networkTime = Funcoes.GetNetworkTime(); + return new RegistroLog + { + Acao = acao, + Usuario = Recursos.Usuario, + DataHora = networkTime, + Descricao = JsonConvert.SerializeObject((object)diferenca, new JsonSerializerSettings + { + ReferenceLoopHandling = (ReferenceLoopHandling)1 + }), + EntidadeId = id, + Tela = tela, + Versao = LoginViewModel.VersaoAtual, + NomeMaquina = Environment.MachineName, + UsuarioMaquina = Environment.UserName, + Ip = Recursos.Host.AddressList.FirstOrDefault((IPAddress ip) => ip.AddressFamily == AddressFamily.InterNetwork)?.ToString(), + ModeloNovo = true + }; + } + catch (Exception) + { + return null; + } + } + + public RegistroLog CreateLog(long id, List valor, TipoTela tela, TipoAcao acao) + { + //IL_0006: Unknown result type (might be due to invalid IL or missing references) + //IL_000b: Unknown result type (might be due to invalid IL or missing references) + //IL_000c: 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) + //IL_001e: Unknown result type (might be due to invalid IL or missing references) + //IL_0025: Unknown result type (might be due to invalid IL or missing references) + //IL_0027: Unknown result type (might be due to invalid IL or missing references) + //IL_002c: Unknown result type (might be due to invalid IL or missing references) + //IL_0038: Expected O, but got Unknown + //IL_003d: Unknown result type (might be due to invalid IL or missing references) + //IL_0044: Unknown result type (might be due to invalid IL or missing references) + //IL_0045: Unknown result type (might be due to invalid IL or missing references) + //IL_004b: Unknown result type (might be due to invalid IL or missing references) + //IL_0056: Unknown result type (might be due to invalid IL or missing references) + //IL_0061: Unknown result type (might be due to invalid IL or missing references) + //IL_006c: Unknown result type (might be due to invalid IL or missing references) + //IL_00ac: Unknown result type (might be due to invalid IL or missing references) + //IL_00b4: Expected O, but got Unknown + try + { + DateTime networkTime = Funcoes.GetNetworkTime(); + return new RegistroLog + { + Acao = acao, + Usuario = Recursos.Usuario, + DataHora = networkTime, + Descricao = JsonConvert.SerializeObject((object)valor, new JsonSerializerSettings + { + ReferenceLoopHandling = (ReferenceLoopHandling)1 + }), + EntidadeId = id, + Tela = tela, + Versao = LoginViewModel.VersaoAtual, + NomeMaquina = Environment.MachineName, + UsuarioMaquina = Environment.UserName, + Ip = Recursos.Host.AddressList.FirstOrDefault((IPAddress ip) => ip.AddressFamily == AddressFamily.InterNetwork)?.ToString(), + ModeloNovo = true + }; + } + catch (Exception) + { + return null; + } + } + + public void SaveLog(RegistroLog keyValues, UnitOfWork unitOfWork) + { + if (keyValues == null) + { + return; + } + try + { + unitOfWork.RegistroLogRepository.SaveOrUpdate(keyValues); + } + catch (Exception) + { + } + } + + public void SaveLog(List keyValues, UnitOfWork unitOfWork) + { + if (keyValues == null) + { + return; + } + try + { + List list = keyValues.Where((RegistroLog x) => !string.IsNullOrEmpty((x != null) ? x.Descricao : null) && !string.IsNullOrEmpty(x.Versao)).ToList(); + unitOfWork.RegistroLogRepository.AddRange(list); + } + catch (Exception) + { + } + } + + internal async Task> BuscarProfissao(string value) + { + int tries = 3; + return await Task.Run(delegate + { + while (tries > 0) + { + try + { + UnitOfWork read = Instancia.Read; + try + { + return (from x in read.ProfissaoRepository.Find(value) + orderby x.Nome + select x).ToList(); + } + finally + { + ((IDisposable)read)?.Dispose(); + } + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)180, tries, value); + } + } + return new List(); + }); + } + + internal async Task> BuscarAtividade(string value) + { + int tries = 3; + return await Task.Run(delegate + { + while (tries > 0) + { + try + { + UnitOfWork read = Instancia.Read; + try + { + return (from x in read.AtividadeRepository.Find(value) + orderby x.Nome + select x).ToList(); + } + finally + { + ((IDisposable)read)?.Dispose(); + } + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)181, tries, value); + } + } + return new List(); + }); + } + + internal async Task> BuscarBanco(string value) + { + int tries = 3; + return await Task.Run(delegate + { + while (tries > 0) + { + try + { + UnitOfWork read = Instancia.Read; + try + { + return (from x in read.BancoRepository.Find(value) + orderby x.Nome + select x).ToList(); + } + finally + { + ((IDisposable)read)?.Dispose(); + } + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)144, tries, value); + } + } + return new List(); + }); + } + + internal async Task> BuscarBancosContas(string value) + { + int tries = 3; + return await Task.Run(delegate + { + while (tries > 0) + { + try + { + UnitOfWork read = Instancia.Read; + try + { + return (from x in read.BancosContasRepository.Find(value) + orderby x.Descricao + select x).ToList(); + } + finally + { + ((IDisposable)read)?.Dispose(); + } + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)146, tries, value); + } + } + return new List(); + }); + } + + internal async Task> BuscarFabricante(string value) + { + int tries = 3; + return await Task.Run(delegate + { + while (tries > 0) + { + try + { + UnitOfWork read = Instancia.Read; + try + { + return (from x in read.FabricanteRepository.Find(value) + orderby x.Descricao + select x).ToList(); + } + finally + { + ((IDisposable)read)?.Dispose(); + } + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)182, tries, value); + } + } + return new List(); + }); + } + + internal Empresa BuscarEmpresa(long id) + { + //IL_003d: Unknown result type (might be due to invalid IL or missing references) + //IL_0043: Expected O, but got Unknown + int num = 3; + while (num > 0) + { + try + { + UnitOfWork read = Instancia.Read; + try + { + return read.EmpresaRepository.FindById(id); + } + finally + { + ((IDisposable)read)?.Dispose(); + } + } + catch (Exception e) + { + num = Registrar(e, (TipoErro)114, num, id); + } + } + return new Empresa(); + } + + internal async Task> BuscarVendedor(string value) + { + int tries = 3; + return await Task.Run(delegate + { + while (tries > 0) + { + try + { + UnitOfWork read = Instancia.Read; + try + { + return (from x in read.VendedorRepository.Find((Recursos.Usuario.IdEmpresa == 1) ? 0 : Recursos.Usuario.IdEmpresa) + orderby x.Nome + select x).ToList(); + } + finally + { + ((IDisposable)read)?.Dispose(); + } + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)140, tries, value); + } + } + return new List(); + }); + } + + public async Task> BuscarEstipulante(string value) + { + int tries = 3; + return await Task.Run(delegate + { + while (tries > 0) + { + try + { + UnitOfWork read = Instancia.Read; + try + { + return (from x in read.EstipulanteRepository.Find(value, (Recursos.Usuario.IdEmpresa == 1) ? 0 : Recursos.Usuario.IdEmpresa) + orderby x.Nome + select x).ToList(); + } + finally + { + ((IDisposable)read)?.Dispose(); + } + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)111, tries, value); + } + } + return new List(); + }); + } + + public async Task> BuscarEstipulantesAsync() + { + int tries = 3; + return await Task.Run(delegate + { + while (tries > 0) + { + try + { + UnitOfWork read = Instancia.Read; + try + { + return new List(from x in read.EstipulanteRepository.Find() + orderby ((DomainBase)x).Id + select x); + } + finally + { + ((IDisposable)read)?.Dispose(); + } + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)112, tries); + } + } + return new List(); + }); + } + + public async Task> BuscarUsuariosAsync() + { + int tries = 3; + return await Task.Run(delegate + { + while (tries > 0) + { + try + { + UnitOfWork read = Instancia.Read; + try + { + return new List(from x in read.UsuarioRepository.Find((Recursos.Usuario.IdEmpresa == 1) ? 0 : Recursos.Usuario.IdEmpresa) + orderby ((DomainBase)x).Id + select x); + } + finally + { + ((IDisposable)read)?.Dispose(); + } + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)131, tries); + } + } + return new List(); + }); + } + + public async Task> BuscarEmpresasAsync() + { + int tries = 3; + return await Task.Run(delegate + { + while (tries > 0) + { + try + { + UnitOfWork read = Instancia.Read; + try + { + return new List(from x in read.EmpresaRepository.Find(0L) + orderby ((DomainBase)x).Id + select x); + } + finally + { + ((IDisposable)read)?.Dispose(); + } + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)113, tries); + } + } + return new List(); + }); + } + + public async Task> BuscarSociosAsync(long id) + { + int tries = 3; + return await Task.Run(delegate + { + while (tries > 0) + { + try + { + UnitOfWork read = Instancia.Read; + try + { + return read.SocioRepository.FindByEmpresa(id); + } + finally + { + ((IDisposable)read)?.Dispose(); + } + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)122, tries, id); + } + } + return new List(); + }); + } + + internal async Task> BuscarUsuario(string value) + { + int tries = 3; + return await Task.Run(delegate + { + while (tries > 0) + { + try + { + UnitOfWork read = Instancia.Read; + try + { + return (from x in read.UsuarioRepository.Find(value, 0L) + orderby x.Nome + select x).ToList(); + } + finally + { + ((IDisposable)read)?.Dispose(); + } + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)132, tries, value); + } + } + return new List(); + }); + } + + internal async Task BuscaUsuarioSso(string login, string password, string documentoEmpresa) + { + HttpClient client = new HttpClient(); + try + { + ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; + Uri uri = Address.ApiSso.Append("auth"); + string text = $"{login}:{password}:{ApplicationHelper.NumeroSerial}:{documentoEmpresa}:{Funcoes.GetNetworkTime().ToUniversalTime().Ticks}".ToBase64BasicEncode(); + ((HttpHeaders)client.DefaultRequestHeaders).TryAddWithoutValidation("Authorization", text); + HttpResponseMessage val = await client.GetAsync(uri); + return (!val.IsSuccessStatusCode) ? null : JsonConvert.DeserializeObject(await val.Content.ReadAsStringAsync()); + } + finally + { + ((IDisposable)client)?.Dispose(); + } + } + + internal async Task VerificaUsuarioSso(string login, string documentoEmpresa) + { + HttpClient client = new HttpClient(); + try + { + ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; + Uri uri = Address.ApiSso.Append("exist"); + string text = $"{login}:{login}:{ApplicationHelper.NumeroSerial}:{documentoEmpresa}:{Funcoes.GetNetworkTime().ToUniversalTime().Ticks}".ToBase64BasicEncode(); + ((HttpHeaders)client.DefaultRequestHeaders).TryAddWithoutValidation("Authorization", text); + HttpResponseMessage val = await client.GetAsync(uri); + return (!val.IsSuccessStatusCode) ? null : JsonConvert.DeserializeObject(await val.Content.ReadAsStringAsync()); + } + finally + { + ((IDisposable)client)?.Dispose(); + } + } + + internal async Task AddOrUpdateUsuarioSso(Usuario usuario, string documentoEmpresa, string ssoId = null) + { + HttpClient client = new HttpClient(); + try + { + ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; + Uri uri = Address.ApiSso.Append("user"); + ((HttpHeaders)client.DefaultRequestHeaders).TryAddWithoutValidation("Authorization", "Bearer " + usuario.TokenSso); + UserSso val = usuario.ToUserSso(ApplicationHelper.NumeroSerial, documentoEmpresa, ssoId); + HttpResponseMessage val2 = ((val.Id != null) ? (await client.PutAsync(uri, (HttpContent)(object)val.ToHttpContent())) : (await client.PostAsync(uri, (HttpContent)(object)val.ToHttpContent()))); + HttpResponseMessage val3 = val2; + return (!val3.IsSuccessStatusCode) ? null : JsonConvert.DeserializeObject(await val3.Content.ReadAsStringAsync()); + } + finally + { + ((IDisposable)client)?.Dispose(); + } + } + + internal async Task DeleteUsuarioSso(Usuario usuario, string documentoEmpresa) + { + HttpClient client = new HttpClient(); + try + { + ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; + Uri uri = Address.ApiSso.Append("user").AddQuery("userId", usuario.SsoId); + ((HttpHeaders)client.DefaultRequestHeaders).TryAddWithoutValidation("Authorization", "Bearer " + usuario.TokenSso); + HttpResponseMessage val = await client.DeleteAsync(uri); + return (!val.IsSuccessStatusCode) ? null : JsonConvert.DeserializeObject(await val.Content.ReadAsStringAsync()); + } + finally + { + ((IDisposable)client)?.Dispose(); + } + } + + private async Task BuscaUsuarioByToken(Usuario usuario) + { + HttpClient client = new HttpClient(); + try + { + ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; + Uri uri = Address.ApiSso.Append("user"); + ((HttpHeaders)client.DefaultRequestHeaders).TryAddWithoutValidation("Authorization", "Bearer " + usuario.TokenSso); + JsonConvert.DeserializeObject(await (await client.GetAsync(uri)).Content.ReadAsStringAsync()); + return true; + } + finally + { + ((IDisposable)client)?.Dispose(); + } + } + + internal async Task BuscarUsuario(string login, string password) + { + int tries = 3; + Token val = new Token(); + string encryptedPassword = val.AggerEncrypt(password); + return await Task.Run((Func)delegate + { + //IL_02a9: Unknown result type (might be due to invalid IL or missing references) + //IL_02af: Expected O, but got Unknown + while (tries > 0) + { + try + { + UnitOfWork read = Instancia.Read; + try + { + Empresa val2 = read.EmpresaRepository.FindBySerial(ApplicationHelper.NumeroSerial); + AuthSso result = BuscaUsuarioSso(login, encryptedPassword, val2.Documento).Result; + if (result == null || result.Code == 401) + { + return (Usuario)null; + } + Usuario val3; + if (result.Code == 404) + { + val3 = read.UsuarioRepository.ValidateLogin(login, encryptedPassword); + if (val3 == null) + { + return (Usuario)null; + } + val3.TokenSso = result.Data.Token; + UserSso result2 = AddOrUpdateUsuarioSso(val3, val2.Documento).Result; + if (result2 == null) + { + return val3; + } + UnitOfWork commited = Instancia.Commited; + try + { + val3.SsoId = result2.Id; + commited.UsuarioRepository.Merge(val3); + ((GenericUnitOfWork)commited).Commit(); + } + finally + { + ((IDisposable)commited)?.Dispose(); + } + AuthSso result3 = BuscaUsuarioSso(login, encryptedPassword, val2.Documento).Result; + val3.TokenSso = result3.Data.Token; + return val3; + } + val3 = read.UsuarioRepository.SsoId(result) ?? read.UsuarioRepository.FindFromSso(result.Data.User); + if (val3 == null) + { + UnitOfWork commited2 = Instancia.Commited; + try + { + val3 = commited2.UsuarioRepository.AddUsuarioFromSso(result.Data.User); + ((GenericUnitOfWork)commited2).Commit(); + } + finally + { + ((IDisposable)commited2)?.Dispose(); + } + val3.TokenSso = result.Data.Token; + return val3; + } + if (val3.Excluido) + { + UnitOfWork commited3 = Instancia.Commited; + try + { + val3.Excluido = false; + commited3.UsuarioRepository.Merge(val3); + ((GenericUnitOfWork)commited3).Commit(); + } + finally + { + ((IDisposable)commited3)?.Dispose(); + } + } + val3.TokenSso = result.Data.Token; + if (ValidationHelper.IsNotNullOrEmpty(val3.SsoId) && val3.SsoId.Equals(result.Data.User.Id)) + { + return val3; + } + UnitOfWork commited4 = Instancia.Commited; + try + { + val3.SsoId = result.Data.User.Id; + commited4.UsuarioRepository.Merge(val3); + ((GenericUnitOfWork)commited4).Commit(); + } + finally + { + ((IDisposable)commited4)?.Dispose(); + } + return val3; + } + finally + { + ((IDisposable)read)?.Dispose(); + } + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)134, tries); + } + } + return new Usuario(); + }); + } + + public async Task> BuscarUsuariosSso() + { + _ = 1; + try + { + HttpClient client = new HttpClient(); + try + { + ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; + Uri uri = Address.ApiSso.Append("user").Append("onlyempresa").Append("list"); + ((HttpHeaders)client.DefaultRequestHeaders).TryAddWithoutValidation("Authorization", "Bearer " + Recursos.Usuario.TokenSso); + HttpResponseMessage val = await client.GetAsync(uri); + return (!val.IsSuccessStatusCode) ? null : JsonConvert.DeserializeObject>(await val.Content.ReadAsStringAsync()); + } + finally + { + ((IDisposable)client)?.Dispose(); + } + } + catch + { + return new List(); + } + } + + public async Task> BuscarParceirosAsync() + { + int tries = 3; + return await Task.Run(delegate + { + while (tries > 0) + { + try + { + UnitOfWork read = Instancia.Read; + try + { + return new List(from x in read.ParceiroRepository.Find() + orderby ((DomainBase)x).Id + select x); + } + finally + { + ((IDisposable)read)?.Dispose(); + } + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)72, tries); + } + } + return new List(); + }); + } + + public async Task> BuscarMetaVendedorAsync(Vendedor vendedor) + { + int tries = 3; + return await Task.Run(delegate + { + while (tries > 0) + { + try + { + UnitOfWork read = Instancia.Read; + try + { + return new List(from x in read.MetaVendedorRepository.Find(((DomainBase)vendedor).Id) + orderby ((DomainBase)x).Id + select x); + } + finally + { + ((IDisposable)read)?.Dispose(); + } + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)183, tries, vendedor); + } + } + return new List(); + }); + } + + public async Task> BuscarAdiantamentoAsync(Vendedor vendedor) + { + int tries = 3; + return await Task.Run(delegate + { + while (tries > 0) + { + try + { + UnitOfWork read = Instancia.Read; + try + { + return new List(from x in read.AdiantamentoRepository.Find(((DomainBase)vendedor).Id) + orderby ((DomainBase)x).Id + select x); + } + finally + { + ((IDisposable)read)?.Dispose(); + } + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)185, tries, vendedor); + } + } + return new List(); + }); + } + + public async Task> BuscarMetaSeguradoraAsync(Seguradora seguradora) + { + int tries = 3; + return await Task.Run(delegate + { + while (tries > 0) + { + try + { + UnitOfWork read = Instancia.Read; + try + { + return new List(from x in read.MetaSeguradoraRepository.Find(((DomainBase)seguradora).Id) + orderby ((DomainBase)x).Id + select x); + } + finally + { + ((IDisposable)read)?.Dispose(); + } + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)184, tries, seguradora); + } + } + return new List(); + }); + } + + internal async Task> BuscarUsuarioPorLoginInteiro(string value) + { + int tries = 3; + return await Task.Run(delegate + { + while (tries > 0) + { + try + { + UnitOfWork read = Instancia.Read; + try + { + return (from x in read.UsuarioRepository.FindByLoginInteiro(value) + orderby x.Nome + select x).ToList(); + } + finally + { + ((IDisposable)read)?.Dispose(); + } + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)134, tries, value); + } + } + return new List(); + }); + } + + internal async Task BuscarUsuarioMesmoDocumento(string value, long id, long idempresa) + { + int tries = 3; + return await Task.Run(delegate + { + while (tries > 0) + { + try + { + UnitOfWork read = Instancia.Read; + try + { + return read.UsuarioRepository.FindDocUsedByDocumento(value, id, idempresa); + } + finally + { + ((IDisposable)read)?.Dispose(); + } + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)134, tries, value); + } + } + return false; + }); + } + + public async Task> BuscarProduto(string value) + { + int tries = 3; + return await Task.Run(delegate + { + while (tries > 0) + { + try + { + UnitOfWork read = Instancia.Read; + try + { + return (from x in read.ProdutoRepository.Find(value) + orderby x.Nome + select x).ToList(); + } + finally + { + ((IDisposable)read)?.Dispose(); + } + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)117, tries, value); + } + } + return new List(); + }); + } + + public async Task> BuscarStatus(string value) + { + int tries = 3; + return await Task.Run(delegate + { + while (tries > 0) + { + try + { + UnitOfWork read = Instancia.Read; + try + { + return (from x in read.StatusRepository.Find(value) + orderby x.Nome + select x).ToList(); + } + finally + { + ((IDisposable)read)?.Dispose(); + } + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)120, tries, value); + } + } + return new List(); + }); + } + + public async Task> BuscarRamosAsync() + { + int tries = 3; + return await Task.Run(delegate + { + while (tries > 0) + { + try + { + UnitOfWork read = Instancia.Read; + try + { + return new List(from x in read.RamoRepository.Find() + orderby x.Nome + select x); + } + finally + { + ((IDisposable)read)?.Dispose(); + } + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)169, tries); + } + } + return new List(); + }); + } + + public async Task BuscarQualificacaoAsync() + { + int tries = 3; + return await Task.Run((Func)delegate + { + //IL_004e: Unknown result type (might be due to invalid IL or missing references) + //IL_0054: Expected O, but got Unknown + while (tries > 0) + { + try + { + UnitOfWork read = Instancia.Read; + try + { + return read.QualificacaoRepository.FindById(1L); + } + finally + { + ((IDisposable)read)?.Dispose(); + } + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)170, tries); + } + } + return new Qualificacao(); + }); + } + + public async Task> BuscarSeguradorasAsync() + { + int tries = 3; + return await Task.Run(delegate + { + while (tries > 0) + { + try + { + UnitOfWork read = Instancia.Read; + try + { + return new List(from x in read.SeguradoraRepository.Find() + orderby ((DomainBase)x).Id + select x); + } + finally + { + ((IDisposable)read)?.Dispose(); + } + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)127, tries); + } + } + return new List(); + }); + } + + public async Task> BuscarAgendasAsync() + { + int tries = 3; + return await Task.Run(delegate + { + while (tries > 0) + { + try + { + UnitOfWork read = Instancia.Read; + try + { + return new List(from x in read.AgendaRepository.Find() + orderby ((DomainBase)x).Id + select x); + } + finally + { + ((IDisposable)read)?.Dispose(); + } + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)129, tries); + } + } + return new List(); + }); + } + + public async Task> BuscarVendedoresAsync() + { + int tries = 3; + return await Task.Run(delegate + { + while (tries > 0) + { + try + { + UnitOfWork read = Instancia.Read; + try + { + return new List(from x in read.VendedorRepository.Find((Recursos.Usuario.IdEmpresa == 1) ? 0 : Recursos.Usuario.IdEmpresa) + orderby ((DomainBase)x).Id + select x); + } + finally + { + ((IDisposable)read)?.Dispose(); + } + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)140, tries); + } + } + return new List(); + }); + } + + public async Task> BuscarTipoVendedoresAsync() + { + int tries = 3; + return await Task.Run(delegate + { + while (tries > 0) + { + try + { + UnitOfWork read = Instancia.Read; + try + { + return (from x in read.TipoVendedorRepository.Find() + orderby ((DomainBase)x).Id + select x).ToList(); + } + finally + { + ((IDisposable)read)?.Dispose(); + } + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)141, tries); + } + } + return new List(); + }); + } + + public async Task> BuscarProdutosAsync() + { + int tries = 3; + return await Task.Run(delegate + { + while (tries > 0) + { + try + { + UnitOfWork read = Instancia.Read; + try + { + return new List(from x in read.ProdutoRepository.Find() + orderby x.Nome + select x); + } + finally + { + ((IDisposable)read)?.Dispose(); + } + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)118, tries); + } + } + return new List(); + }); + } + + public async Task> BuscarStatusAsync() + { + int tries = 3; + return await Task.Run(delegate + { + while (tries > 0) + { + try + { + UnitOfWork read = Instancia.Read; + try + { + return new List(from x in read.StatusRepository.Find() + orderby x.Nome + select x); + } + finally + { + ((IDisposable)read)?.Dispose(); + } + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)121, tries); + } + } + return new List(); + }); + } + + internal async Task> BuscaCoberturas() + { + int tries = 3; + return await Task.Run(delegate + { + while (tries > 0) + { + try + { + UnitOfWork read = Instancia.Read; + try + { + return (from x in read.CoberturaPadraoRepository.Find() + orderby x.Descricao + select x).ToList(); + } + finally + { + ((IDisposable)read)?.Dispose(); + } + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)58, tries); + } + } + return new List(); + }); + } + + public async Task LoadInicialParameters() + { + int tries = 3; + return await Task.Run(delegate + { + while (tries > 0) + { + try + { + UnitOfWork read = Instancia.Read; + try + { + Recursos.Parceiros = new List(from x in read.ParceiroRepository.Find() + orderby ((DomainBase)x).Id + select x); + Recursos.Fabricantes = (from x in read.FabricanteRepository.Select() + orderby x.Descricao + select x).ToList(); + Recursos.Configuracoes = read.ConfiguracaoRepository.BuscarConfiguracoes(); + read.CriarAuxiliar(false); + Recursos.Empresas = Auxiliar.Empresas; + Recursos.Ramos = Auxiliar.Ramos; + Recursos.Seguradoras = Auxiliar.Seguradoras; + Recursos.Produtos = Auxiliar.Produtos; + Recursos.Status = Auxiliar.StatusApolice; + Recursos.TipoVendedor = Auxiliar.TipoVendedores; + Recursos.Estipulantes = Auxiliar.Estipulantes; + Recursos.Vendedores = Auxiliar.Vendedores; + Recursos.Usuarios = Auxiliar.Usuarios; + Recursos.TiposTarefa = Auxiliar.TiposTarefa; + Recursos.StatusProspeccao = Auxiliar.StatusProspeccao; + Recursos.Coberturas = Auxiliar.CoberturasPadrao; + } + finally + { + ((IDisposable)read)?.Dispose(); + } + return true; + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)186, tries); + } + } + return false; + }); + } + + public async Task ReloadAuxiliar() + { + int tries = 3; + return await Task.Run(delegate + { + while (tries > 0) + { + try + { + UnitOfWork read = Instancia.Read; + try + { + read.CriarAuxiliar(true); + Recursos.Empresas = Auxiliar.Empresas; + Recursos.Ramos = Auxiliar.Ramos; + Recursos.Seguradoras = Auxiliar.Seguradoras; + Recursos.Produtos = Auxiliar.Produtos; + Recursos.Status = Auxiliar.StatusApolice; + Recursos.TipoVendedor = Auxiliar.TipoVendedores; + Recursos.Estipulantes = Auxiliar.Estipulantes; + Recursos.Vendedores = Auxiliar.Vendedores; + Recursos.Usuarios = Auxiliar.Usuarios; + Recursos.TiposTarefa = Auxiliar.TiposTarefa; + Recursos.StatusProspeccao = Auxiliar.StatusProspeccao; + } + finally + { + ((IDisposable)read)?.Dispose(); + } + return true; + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)186, tries); + } + } + return false; + }); + } + + public async Task> BuscarDocumentosPorEstipulante(long id) + { + int tries = 3; + return await Task.Run(delegate + { + while (tries > 0) + { + try + { + UnitOfWork read = Instancia.Read; + try + { + return read.DocumentoRepository.BuscarDocumentoPorEstipulante(id); + } + finally + { + ((IDisposable)read)?.Dispose(); + } + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)11, tries, id); + } + } + return new List(); + }); + } + + public async Task> BuscarDocumentosPorStatus(long id) + { + int tries = 3; + return await Task.Run(delegate + { + while (tries > 0) + { + try + { + UnitOfWork read = Instancia.Read; + try + { + return read.DocumentoRepository.BuscarDocumentoPorStatus(id); + } + finally + { + ((IDisposable)read)?.Dispose(); + } + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)12, tries, id); + } + } + return new List(); + }); + } + + public async Task TipoVendedorUtilizado(long id) + { + int tries = 3; + return await Task.Run(delegate + { + while (tries > 0) + { + try + { + UnitOfWork read = Instancia.Read; + try + { + return read.VendedorParcelaRepository.TipoVendedorUtilizado(id); + } + finally + { + ((IDisposable)read)?.Dispose(); + } + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)155, tries, id); + } + } + return false; + }); + } + + public async Task BancosContasUtilizado(long id) + { + int tries = 3; + return await Task.Run(delegate + { + while (tries > 0) + { + try + { + UnitOfWork read = Instancia.Read; + try + { + return read.LancamentoRepository.BancosContasUtilizado(id); + } + finally + { + ((IDisposable)read)?.Dispose(); + } + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)155, tries, id); + } + } + return false; + }); + } + + public async Task ParceiroUtilizado(long id) + { + int tries = 3; + return await Task.Run(delegate + { + while (tries > 0) + { + try + { + UnitOfWork read = Instancia.Read; + try + { + return read.SinistroAutoRepository.ParceiroUtilizado(id); + } + finally + { + ((IDisposable)read)?.Dispose(); + } + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)156, tries, id); + } + } + return false; + }); + } + + public async Task> BuscarCredenciais() + { + int tries = 3; + return await Task.Run(delegate + { + while (tries > 0) + { + try + { + UnitOfWork read = Instancia.Read; + try + { + return read.CredencialRepository.Find(((DomainBase)Recursos.Empresa).Id); + } + finally + { + ((IDisposable)read)?.Dispose(); + } + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)187, tries); + } + } + return new List(); + }); + } + + public async Task> BuscarCentroAsync() + { + int tries = 3; + return await Task.Run(delegate + { + while (tries > 0) + { + try + { + UnitOfWork read = Instancia.Read; + try + { + return (from x in read.CentroRepository.Find() + orderby x.Descricao + select x).ToList(); + } + finally + { + ((IDisposable)read)?.Dispose(); + } + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)153, tries); + } + } + return new List(); + }); + } + + public async Task> BuscarPlanoAsync() + { + int tries = 3; + return await Task.Run(delegate + { + while (tries > 0) + { + try + { + UnitOfWork read = Instancia.Read; + try + { + return new List(from x in read.PlanoRepository.Find() + orderby x.Descricao + select x); + } + finally + { + ((IDisposable)read)?.Dispose(); + } + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)167, tries); + } + } + return new List(); + }); + } + + public async Task> BuscarPlanosAsync() + { + int tries = 3; + return await Task.Run(delegate + { + while (tries > 0) + { + try + { + UnitOfWork read = Instancia.Read; + try + { + return new List(read.PlanosRepository.Find()); + } + finally + { + ((IDisposable)read)?.Dispose(); + } + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)168, tries); + } + } + return new List(); + }); + } + + public async Task> BuscarFornecedor(string value, bool ativo = false) + { + int tries = 3; + return await Task.Run(delegate + { + while (tries > 0) + { + try + { + UnitOfWork read = Instancia.Read; + try + { + return (from x in read.FornecedorRepository.Find(value, ativo) + orderby x.Nome + select x).ToList(); + } + finally + { + ((IDisposable)read)?.Dispose(); + } + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)159, tries, value); + } + } + return new List(); + }); + } + + public async Task> BuscarFornecedor() + { + int tries = 3; + return await Task.Run(delegate + { + while (tries > 0) + { + try + { + UnitOfWork read = Instancia.Read; + try + { + return (from x in read.FornecedorRepository.Find() + orderby x.Nome + select x).ToList(); + } + finally + { + ((IDisposable)read)?.Dispose(); + } + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)166, tries); + } + } + return new List(); + }); + } + + public async Task ArquivoDigital() + { + int tries = 3; + return await Task.Run((Func)delegate + { + //IL_004c: Unknown result type (might be due to invalid IL or missing references) + //IL_0052: Expected O, but got Unknown + while (tries > 0) + { + try + { + UnitOfWork read = Instancia.Read; + try + { + return read.IndiceArquivoDigitalRepository.BuscarBanco(); + } + finally + { + ((IDisposable)read)?.Dispose(); + } + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)188, tries); + } + } + return new ControleArquivoDigital(); + }); + } + + public async Task ArquivoDigital(string banco) + { + int tries = 3; + return await Task.Run((Func)delegate + { + //IL_0057: Unknown result type (might be due to invalid IL or missing references) + //IL_005d: Expected O, but got Unknown + while (tries > 0) + { + try + { + UnitOfWork read = Instancia.Read; + try + { + return read.IndiceArquivoDigitalRepository.ConsultarBanco(banco); + } + finally + { + ((IDisposable)read)?.Dispose(); + } + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)188, tries, banco); + } + } + return new ControleArquivoDigital(); + }); + } + + public async Task SalvarControle(ControleArquivoDigital controle) + { + int tries = 3; + await Task.Run(delegate + { + while (tries > 0) + { + try + { + UnitOfWork commited = Instancia.Commited; + try + { + commited.IndiceArquivoDigitalRepository.SaveOrUpdate(controle); + ((GenericUnitOfWork)commited).Commit(); + break; + } + finally + { + ((IDisposable)commited)?.Dispose(); + } + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)179, tries, controle); + } + } + }); + } + + public async Task BuscarControle() + { + return await Task.Run((Func)delegate + { + try + { + UnitOfWork read = Instancia.Read; + try + { + return read.IndiceArquivoDigitalRepository.BuscarBanco(); + } + finally + { + ((IDisposable)read)?.Dispose(); + } + } + catch (Exception) + { + return (ControleArquivoDigital)null; + } + }); + } + + public async Task> BuscarEstipulantes() + { + int tries = 3; + return await Task.Run(delegate + { + while (tries > 0) + { + try + { + UnitOfWork read = Instancia.Read; + try + { + Recursos.Estipulantes = read.EstipulanteRepository.Find(); + return Recursos.Estipulantes; + } + finally + { + ((IDisposable)read)?.Dispose(); + } + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)186, tries); + } + } + return Recursos.Estipulantes; + }); + } + + public async Task Sincronizar(List dados, Filtros filtros) + { + int tries = 3; + return await Task.Run(delegate + { + while (tries > 0) + { + try + { + UnitOfWork commited = Instancia.Commited; + try + { + int result = commited.VinculoDocumentoRepository.Sincronize(filtros.Inicio, dados); + ((GenericUnitOfWork)commited).Commit(); + return result; + } + finally + { + ((IDisposable)commited)?.Dispose(); + } + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)293, tries); + } + } + return 0; + }); + } + + public async Task Sincronizar(DateTime data, List ids = null) + { + int tries = 3; + return await Task.Run(delegate + { + while (tries > 0) + { + try + { + UnitOfWork commited = Instancia.Commited; + try + { + int[] result = commited.ParcelaRepository.SincronizarPendencia(data, ids); + ((GenericUnitOfWork)commited).Commit(); + return result; + } + finally + { + ((IDisposable)commited)?.Dispose(); + } + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)300, tries, false); + } + } + return new int[2]; + }); + } + + public async Task> ArquivoVinculo(List ids, TipoArquivoVinculo type) + { + //IL_001e: Unknown result type (might be due to invalid IL or missing references) + //IL_001f: Unknown result type (might be due to invalid IL or missing references) + int tries = 3; + return await Task.Run(delegate + { + //IL_0016: Unknown result type (might be due to invalid IL or missing references) + while (tries > 0) + { + try + { + UnitOfWork read = Instancia.Read; + try + { + return read.VinculoDocumentoRepository.BuscarArquivos(ids, type); + } + finally + { + ((IDisposable)read)?.Dispose(); + } + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)293, tries); + } + } + return (List)null; + }); + } + + internal async Task> BuscarClienteEmpresa(string value) + { + if (string.IsNullOrWhiteSpace(value)) + { + return new List(); + } + int tries = 3; + return await Task.Run(delegate + { + while (tries > 0) + { + try + { + UnitOfWork read = Instancia.Read; + try + { + List list = (from x in read.ClienteRepository.Find(value, 0L, false, false) + orderby x.Nome + select x).ToList(); + list.AddRange((from x in read.EmpresaRepository.FindAsCliente(value) + orderby x.Nome + select x).ToList()); + return list; + } + finally + { + ((IDisposable)read)?.Dispose(); + } + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)29, tries, value); + } + } + return new List(); + }); + } + + public async Task BuscarParcelaPendente(long id) + { + int tries = 3; + return await Task.Run((Func)delegate + { + while (tries > 0) + { + try + { + UnitOfWork read = Instancia.Read; + try + { + return read.ParcelaRepository.BuscarPendencia(id); + } + finally + { + ((IDisposable)read)?.Dispose(); + } + } + catch (Exception e) + { + tries = Registrar(e, (TipoErro)299, tries, id); + } + } + return (ParcelaPendente)null; + }); + } + + public void SalvarAcao(RegistroAcao log, object obs = null) + { + //IL_00af: Unknown result type (might be due to invalid IL or missing references) + //IL_00b4: Unknown result type (might be due to invalid IL or missing references) + //IL_00c0: Expected O, but got Unknown + if (log == null || ((DomainBase)Recursos.Usuario).Id == 0L) + { + return; + } + try + { + UnitOfWork commited = Instancia.Commited; + try + { + log.Usuario = Recursos.Usuario; + log.DataHora = Funcoes.GetNetworkTime(); + log.Versao = LoginViewModel.VersaoAtual; + log.NomeMaquina = Environment.MachineName; + log.UsuarioMaquina = Environment.UserName; + log.Ip = Dns.GetHostEntry(Dns.GetHostName()).AddressList.FirstOrDefault((IPAddress ip) => ip.AddressFamily == AddressFamily.InterNetwork)?.ToString(); + log.Observacao = ((obs == null) ? "" : ((!(obs is string)) ? JsonConvert.SerializeObject(obs, new JsonSerializerSettings + { + ReferenceLoopHandling = (ReferenceLoopHandling)1 + }) : obs.ToString())); + commited.RegistroAcaoRepository.SaveOrUpdate(log); + ((GenericUnitOfWork)commited).Commit(); + } + finally + { + ((IDisposable)commited)?.Dispose(); + } + } + catch (Exception e) + { + Registrar(e, (TipoErro)0, 3, log); + } + } + + public async Task> CarregarUsuarios() + { + await AtualizarUsuarios(); + return await BuscarUsuariosAsync(); + } + + private async Task AtualizarUsuarios() + { + _ = 1; + try + { + if (ValidationHelper.IsNullOrEmpty(Recursos.Usuario.TokenSso)) + { + return; + } + List ssoUsuarios = await BuscarUsuariosSso(); + if ((ssoUsuarios != null && ssoUsuarios.Count == 0) || ssoUsuarios == null) + { + return; + } + List source = await BuscarUsuariosAsync(); + foreach (UserSso ssoUsuario in ssoUsuarios) + { + Usuario val = ((IEnumerable)source).FirstOrDefault((Func)((Usuario u) => (u.SsoId != null) ? (ssoUsuario.Id == u.SsoId) : (u.Login == ssoUsuario.Username))); + if (val != null && (ssoUsuario.IsDeleted != val.Excluido || ValidationHelper.NotEquals(ssoUsuario.Password, val.Senha) || ValidationHelper.NotEquals(ssoUsuario.Name, val.Nome) || (ValidationHelper.IsNotNullOrEmpty(ssoUsuario.Email) && ValidationHelper.NotEquals(ssoUsuario.Email, val.Email)) || (ValidationHelper.IsNotNullOrEmpty(ssoUsuario.Document) && ValidationHelper.NotEquals(ssoUsuario.Document, val.Documento.Clear())) || (ValidationHelper.IsNotNullOrEmpty(ssoUsuario.Phone) && ValidationHelper.NotEquals(ssoUsuario.Phone, (val.Prefixo + val.Telefone).Clear())) || ValidationHelper.IsNullOrEmpty(val.SsoId))) + { + string phone = ssoUsuario.Phone; + val.Nome = ssoUsuario.Name; + val.Documento = ssoUsuario.Document; + if (ValidationHelper.IsNotNullOrEmpty(phone) && phone.Length > 3) + { + val.Prefixo = phone.Substring(0, 2); + val.Telefone = phone.Substring(2, phone.Length - 2); + } + val.Login = ssoUsuario.Username; + val.Senha = ssoUsuario.Password; + val.Email = ssoUsuario.Email; + val.Excluido = ssoUsuario.IsDeleted; + val.SsoId = ssoUsuario.Id; + UnitOfWork commited = Instancia.Commited; + try + { + commited.UsuarioRepository.Merge(val); + ((GenericUnitOfWork)commited).Commit(); + } + finally + { + ((IDisposable)commited)?.Dispose(); + } + } + if (val != null) + { + continue; + } + UnitOfWork read = Instancia.Read; + try + { + Empresa val2 = read.EmpresaRepository.FindByDocumento(ssoUsuario.CustomerDocument); + val = new Usuario + { + IdEmpresa = ((DomainBase)val2).Id, + Nome = ssoUsuario.Name, + Documento = ssoUsuario.Document, + Login = ssoUsuario.Username, + Senha = ssoUsuario.Password, + Email = ssoUsuario.Email, + SsoId = ssoUsuario.Id, + Excluido = ssoUsuario.IsDeleted, + Administrador = false, + PermissaoAggilizador = 1L + }; + string phone2 = ssoUsuario.Phone; + if (ValidationHelper.IsNotNullOrEmpty(phone2) && phone2.Length > 3) + { + val.Prefixo = phone2.Substring(0, 2); + val.Telefone = phone2.Substring(2, phone2.Length - 2); + } + } + finally + { + ((IDisposable)read)?.Dispose(); + } + UnitOfWork commited2 = Instancia.Commited; + try + { + commited2.UsuarioRepository.SaveOrUpdate(val); + ((GenericUnitOfWork)commited2).Commit(); + } + finally + { + ((IDisposable)commited2)?.Dispose(); + } + } + } + catch (Exception e) + { + Registrar(e, (TipoErro)239, 1); + } + } + + private static async Task AtualizaUsuariosSso(List usuarios) + { + usuarios = usuarios.Where((Usuario usuario) => !usuario.Excluido)?.ToList(); + foreach (Usuario usuarioBanco in usuarios) + { + new UserSso + { + Name = usuarioBanco.Nome, + Username = usuarioBanco.Login, + Password = usuarioBanco.Senha, + Email = usuarioBanco.Email, + Phone = usuarioBanco.Telefone, + IsDeleted = usuarioBanco.Excluido, + Id = usuarioBanco.SsoId + }; + string documento = ((IEnumerable)Recursos.Empresas).FirstOrDefault((Func)((Empresa x) => ((DomainBase)x).Id == usuarioBanco.IdEmpresa)).Documento; + await new BaseServico().AddOrUpdateUsuarioSso(usuarioBanco, documento, usuarioBanco.SsoId); + } + } +} -- cgit v1.2.3