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.Repository.Interface; 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; using System; using System.Collections; 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.Runtime.CompilerServices; using System.Threading.Tasks; namespace Gestor.Application.Servicos.Generic { public class BaseServico { private const int UnathorizedSsoCode = 401; private const int NotFoundSsoCode = 404; public bool Sucesso { get; set; } public BaseServico() { } internal async Task AddOrUpdateUsuarioSso(Usuario usuario, string documentoEmpresa, string ssoId = null) { UserSso userSso; HttpResponseMessage httpResponseMessage; UserSso userSso1; using (HttpClient httpClient = new HttpClient()) { ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; Uri apiSso = Address.get_ApiSso(); string[] strArrays = new string[] { "user" }; Uri uri = apiSso.Append(strArrays); httpClient.get_DefaultRequestHeaders().TryAddWithoutValidation("Authorization", string.Concat("Bearer ", usuario.get_TokenSso())); UserSso userSso2 = usuario.ToUserSso(ApplicationHelper.NumeroSerial, documentoEmpresa, ssoId); httpResponseMessage = (userSso2.get_Id() != null ? await httpClient.PutAsync(uri, userSso2.ToHttpContent(null, "application/json")) : await httpClient.PostAsync(uri, userSso2.ToHttpContent(null, "application/json"))); HttpResponseMessage httpResponseMessage1 = httpResponseMessage; if (!httpResponseMessage1.get_IsSuccessStatusCode()) { userSso1 = null; } else { userSso1 = JsonConvert.DeserializeObject(await httpResponseMessage1.get_Content().ReadAsStringAsync()); } userSso = userSso1; } return userSso; } public async Task ArquivoDigital() { int num = 3; ControleArquivoDigital controleArquivoDigital1 = await Task.Run(() => { ControleArquivoDigital controleArquivoDigital; while (num > 0) { try { using (UnitOfWork read = Instancia.Read) { controleArquivoDigital = read.get_IndiceArquivoDigitalRepository().BuscarBanco(); } } catch (Exception exception) { num = this.Registrar(exception, 188, num, null, true); continue; } return controleArquivoDigital; } return new ControleArquivoDigital(); }); return controleArquivoDigital1; } public async Task ArquivoDigital(string banco) { int num = 3; ControleArquivoDigital controleArquivoDigital1 = await Task.Run(() => { ControleArquivoDigital controleArquivoDigital; while (num > 0) { try { using (UnitOfWork read = Instancia.Read) { controleArquivoDigital = read.get_IndiceArquivoDigitalRepository().ConsultarBanco(banco); } } catch (Exception exception) { num = this.Registrar(exception, 188, num, banco, true); continue; } return controleArquivoDigital; } return new ControleArquivoDigital(); }); return controleArquivoDigital1; } public async Task> ArquivoVinculo(List ids, TipoArquivoVinculo type) { int num = 3; List arquivoVinculos1 = await Task.Run>(() => { List arquivoVinculos; while (num > 0) { try { using (UnitOfWork read = Instancia.Read) { arquivoVinculos = read.get_VinculoDocumentoRepository().BuscarArquivos(ids, type); } } catch (Exception exception) { num = this.Registrar(exception, 293, num, null, true); continue; } return arquivoVinculos; } return null; }); return arquivoVinculos1; } private async Task AtualizarUsuarios() { bool count; try { if (!Gestor.Common.Validation.ValidationHelper.IsNullOrEmpty(Recursos.Usuario.get_TokenSso())) { List userSsos = await this.BuscarUsuariosSso(); List userSsos1 = userSsos; if (userSsos1 != null) { count = userSsos1.Count == 0; } else { count = false; } if (count || userSsos == null) { return; } else { List usuarios = await this.BuscarUsuariosAsync(); foreach (UserSso userSso in userSsos) { Usuario usuario = usuarios.FirstOrDefault((Usuario u) => { if (u.get_SsoId() != null) { return userSso.get_Id() == u.get_SsoId(); } return u.get_Login() == userSso.get_Username(); }); if (usuario != null && (userSso.get_IsDeleted() != usuario.get_Excluido() || Gestor.Common.Validation.ValidationHelper.NotEquals(userSso.get_Password(), usuario.get_Senha()) || Gestor.Common.Validation.ValidationHelper.NotEquals(userSso.get_Name(), usuario.get_Nome()) || Gestor.Common.Validation.ValidationHelper.IsNotNullOrEmpty(userSso.get_Email()) && Gestor.Common.Validation.ValidationHelper.NotEquals(userSso.get_Email(), usuario.get_Email()) || Gestor.Common.Validation.ValidationHelper.IsNotNullOrEmpty(userSso.get_Document()) && Gestor.Common.Validation.ValidationHelper.NotEquals(userSso.get_Document(), usuario.get_Documento().Clear()) || Gestor.Common.Validation.ValidationHelper.IsNotNullOrEmpty(userSso.get_Phone()) && Gestor.Common.Validation.ValidationHelper.NotEquals(userSso.get_Phone(), string.Concat(usuario.get_Prefixo(), usuario.get_Telefone()).Clear()) || Gestor.Common.Validation.ValidationHelper.IsNullOrEmpty(usuario.get_SsoId()))) { string phone = userSso.get_Phone(); usuario.set_Nome(userSso.get_Name()); usuario.set_Documento(userSso.get_Document()); if (Gestor.Common.Validation.ValidationHelper.IsNotNullOrEmpty(phone) && phone.Length > 3) { usuario.set_Prefixo(phone.Substring(0, 2)); usuario.set_Telefone(phone.Substring(2, phone.Length - 2)); } usuario.set_Login(userSso.get_Username()); usuario.set_Senha(userSso.get_Password()); usuario.set_Email(userSso.get_Email()); usuario.set_Excluido(userSso.get_IsDeleted()); usuario.set_SsoId(userSso.get_Id()); using (UnitOfWork commited = Instancia.Commited) { commited.get_UsuarioRepository().Merge(usuario); commited.Commit(); } } if (usuario != null) { continue; } using (UnitOfWork read = Instancia.Read) { Empresa empresa = read.get_EmpresaRepository().FindByDocumento(userSso.get_CustomerDocument()); Usuario usuario1 = new Usuario(); usuario1.set_IdEmpresa(empresa.get_Id()); usuario1.set_Nome(userSso.get_Name()); usuario1.set_Documento(userSso.get_Document()); usuario1.set_Login(userSso.get_Username()); usuario1.set_Senha(userSso.get_Password()); usuario1.set_Email(userSso.get_Email()); usuario1.set_SsoId(userSso.get_Id()); usuario1.set_Excluido(userSso.get_IsDeleted()); usuario1.set_Administrador(false); usuario1.set_PermissaoAggilizador(new long?((long)1)); usuario = usuario1; string str = userSso.get_Phone(); if (Gestor.Common.Validation.ValidationHelper.IsNotNullOrEmpty(str) && str.Length > 3) { usuario.set_Prefixo(str.Substring(0, 2)); usuario.set_Telefone(str.Substring(2, str.Length - 2)); } } using (UnitOfWork unitOfWork = Instancia.Commited) { unitOfWork.get_UsuarioRepository().SaveOrUpdate(usuario); unitOfWork.Commit(); } } userSsos = null; } } else { return; } } catch (Exception exception) { this.Registrar(exception, 239, 1, null, true); } } private static async Task AtualizaUsuariosSso(List usuarios) { List list; List usuarios1 = usuarios; IEnumerable excluido = from usuario in usuarios1 where !usuario.get_Excluido() select usuario; if (excluido != null) { list = excluido.ToList(); } else { list = null; } usuarios = list; foreach (Usuario usuario1 in usuarios) { UserSso userSso = new UserSso(); userSso.set_Name(usuario1.get_Nome()); userSso.set_Username(usuario1.get_Login()); userSso.set_Password(usuario1.get_Senha()); userSso.set_Email(usuario1.get_Email()); userSso.set_Phone(usuario1.get_Telefone()); userSso.set_IsDeleted(usuario1.get_Excluido()); userSso.set_Id(usuario1.get_SsoId()); string documento = Recursos.Empresas.FirstOrDefault((Empresa x) => x.get_Id() == usuario1.get_IdEmpresa()).get_Documento(); await (new BaseServico()).AddOrUpdateUsuarioSso(usuario1, documento, usuario1.get_SsoId()); } } public async Task BancosContasUtilizado(long id) { int num = 3; bool flag1 = await Task.Run(() => { bool flag; while (num > 0) { try { using (UnitOfWork read = Instancia.Read) { flag = read.get_LancamentoRepository().BancosContasUtilizado(id); } } catch (Exception exception) { num = this.Registrar(exception, 155, num, id, true); continue; } return flag; } return false; }); return flag1; } internal async Task> BuscaCoberturas() { int num = 3; List coberturaPadraos1 = await Task.Run>(() => { List list; while (num > 0) { try { using (UnitOfWork read = Instancia.Read) { List coberturaPadraos = read.get_CoberturaPadraoRepository().Find(); Func u003cu003e9_511 = BaseServico.u003cu003ec.u003cu003e9__51_1; if (u003cu003e9_511 == null) { u003cu003e9_511 = (CoberturaPadrao x) => x.get_Descricao(); BaseServico.u003cu003ec.u003cu003e9__51_1 = u003cu003e9_511; } list = coberturaPadraos.OrderBy(u003cu003e9_511).ToList(); } } catch (Exception exception) { num = this.Registrar(exception, 58, num, null, true); continue; } return list; } return new List(); }); return coberturaPadraos1; } public async Task> BuscarAdiantamentoAsync(Vendedor vendedor) { int num = 3; List adiantamentos2 = await Task.Run>(() => { List adiantamentos; while (num > 0) { try { using (UnitOfWork read = Instancia.Read) { List adiantamentos1 = read.get_AdiantamentoRepository().Find(vendedor.get_Id()); Func u003cu003e9_371 = BaseServico.u003cu003ec.u003cu003e9__37_1; if (u003cu003e9_371 == null) { u003cu003e9_371 = (Adiantamento x) => x.get_Id(); BaseServico.u003cu003ec.u003cu003e9__37_1 = u003cu003e9_371; } adiantamentos = new List(adiantamentos1.OrderBy(u003cu003e9_371)); } } catch (Exception exception) { num = this.Registrar(exception, 185, num, vendedor, true); continue; } return adiantamentos; } return new List(); }); return adiantamentos2; } public async Task> BuscarAgendasAsync() { int num = 3; List agendas2 = await Task.Run>(() => { List agendas; while (num > 0) { try { using (UnitOfWork read = Instancia.Read) { List agendas1 = read.get_AgendaRepository().Find(); Func u003cu003e9_461 = BaseServico.u003cu003ec.u003cu003e9__46_1; if (u003cu003e9_461 == null) { u003cu003e9_461 = (Agenda x) => x.get_Id(); BaseServico.u003cu003ec.u003cu003e9__46_1 = u003cu003e9_461; } agendas = new List(agendas1.OrderBy(u003cu003e9_461)); } } catch (Exception exception) { num = this.Registrar(exception, 129, num, null, true); continue; } return agendas; } return new List(); }); return agendas2; } internal async Task> BuscarAtividade(string value) { int num = 3; List atividades1 = await Task.Run>(() => { List list; while (num > 0) { try { using (UnitOfWork read = Instancia.Read) { List atividades = read.get_AtividadeRepository().Find(value); Func u003cu003e9_161 = BaseServico.u003cu003ec.u003cu003e9__16_1; if (u003cu003e9_161 == null) { u003cu003e9_161 = (Atividade x) => x.get_Nome(); BaseServico.u003cu003ec.u003cu003e9__16_1 = u003cu003e9_161; } list = atividades.OrderBy(u003cu003e9_161).ToList(); } } catch (Exception exception) { num = this.Registrar(exception, 181, num, value, true); continue; } return list; } return new List(); }); return atividades1; } internal async Task> BuscarBanco(string value) { int num = 3; List bancos1 = await Task.Run>(() => { List list; while (num > 0) { try { using (UnitOfWork read = Instancia.Read) { List bancos = read.get_BancoRepository().Find(value); Func u003cu003e9_171 = BaseServico.u003cu003ec.u003cu003e9__17_1; if (u003cu003e9_171 == null) { u003cu003e9_171 = (Banco x) => x.get_Nome(); BaseServico.u003cu003ec.u003cu003e9__17_1 = u003cu003e9_171; } list = bancos.OrderBy(u003cu003e9_171).ToList(); } } catch (Exception exception) { num = this.Registrar(exception, 144, num, value, true); continue; } return list; } return new List(); }); return bancos1; } internal async Task> BuscarBancosContas(string value) { int num = 3; List bancosContas1 = await Task.Run>(() => { List list; while (num > 0) { try { using (UnitOfWork read = Instancia.Read) { List bancosContas = read.get_BancosContasRepository().Find(value); Func u003cu003e9_181 = BaseServico.u003cu003ec.u003cu003e9__18_1; if (u003cu003e9_181 == null) { u003cu003e9_181 = (BancosContas x) => x.get_Descricao(); BaseServico.u003cu003ec.u003cu003e9__18_1 = u003cu003e9_181; } list = bancosContas.OrderBy(u003cu003e9_181).ToList(); } } catch (Exception exception) { num = this.Registrar(exception, 146, num, value, true); continue; } return list; } return new List(); }); return bancosContas1; } public async Task> BuscarCentroAsync() { int num = 3; List centros1 = await Task.Run>(() => { List list; while (num > 0) { try { using (UnitOfWork read = Instancia.Read) { List centros = read.get_CentroRepository().Find(); Func u003cu003e9_601 = BaseServico.u003cu003ec.u003cu003e9__60_1; if (u003cu003e9_601 == null) { u003cu003e9_601 = (Centro x) => x.get_Descricao(); BaseServico.u003cu003ec.u003cu003e9__60_1 = u003cu003e9_601; } list = centros.OrderBy(u003cu003e9_601).ToList(); } } catch (Exception exception) { num = this.Registrar(exception, 153, num, null, true); continue; } return list; } return new List(); }); return centros1; } internal async Task> BuscarClienteEmpresa(string value) { List clientes3; if (!string.IsNullOrWhiteSpace(value)) { int num = 3; clientes3 = await Task.Run>(() => { List clientes; while (num > 0) { try { using (UnitOfWork read = Instancia.Read) { List clientes1 = read.get_ClienteRepository().Find(value, (long)0, false, false); Func u003cu003e9_731 = BaseServico.u003cu003ec.u003cu003e9__73_1; if (u003cu003e9_731 == null) { u003cu003e9_731 = (Cliente x) => x.get_Nome(); BaseServico.u003cu003ec.u003cu003e9__73_1 = u003cu003e9_731; } List list = clientes1.OrderBy(u003cu003e9_731).ToList(); List clientes2 = read.get_EmpresaRepository().FindAsCliente(value); Func u003cu003e9_732 = BaseServico.u003cu003ec.u003cu003e9__73_2; if (u003cu003e9_732 == null) { u003cu003e9_732 = (Cliente x) => x.get_Nome(); BaseServico.u003cu003ec.u003cu003e9__73_2 = u003cu003e9_732; } list.AddRange(clientes2.OrderBy(u003cu003e9_732).ToList()); clientes = list; } } catch (Exception exception) { num = this.Registrar(exception, 29, num, value, true); continue; } return clientes; } return new List(); }); } else { clientes3 = new List(); } return clientes3; } public async Task BuscarControle() { ControleArquivoDigital controleArquivoDigital1 = await Task.Run(() => { ControleArquivoDigital controleArquivoDigital; try { using (UnitOfWork read = Instancia.Read) { controleArquivoDigital = read.get_IndiceArquivoDigitalRepository().BuscarBanco(); } } catch (Exception exception) { controleArquivoDigital = null; } return controleArquivoDigital; }); return controleArquivoDigital1; } public async Task> BuscarCredenciais() { int num = 3; List credencials1 = await Task.Run>(() => { List credencials; while (num > 0) { try { using (UnitOfWork read = Instancia.Read) { credencials = read.get_CredencialRepository().Find(Recursos.Empresa.get_Id()); } } catch (Exception exception) { num = this.Registrar(exception, 187, num, null, true); continue; } return credencials; } return new List(); }); return credencials1; } public async Task> BuscarDocumentosPorEstipulante(long id) { int num = 3; List documentos1 = await Task.Run>(() => { List documentos; while (num > 0) { try { using (UnitOfWork read = Instancia.Read) { documentos = read.get_DocumentoRepository().BuscarDocumentoPorEstipulante(id); } } catch (Exception exception) { num = this.Registrar(exception, 11, num, id, true); continue; } return documentos; } return new List(); }); return documentos1; } public async Task> BuscarDocumentosPorStatus(long id) { int num = 3; List documentos1 = await Task.Run>(() => { List documentos; while (num > 0) { try { using (UnitOfWork read = Instancia.Read) { documentos = read.get_DocumentoRepository().BuscarDocumentoPorStatus(id); } } catch (Exception exception) { num = this.Registrar(exception, 12, num, id, true); continue; } return documentos; } return new List(); }); return documentos1; } internal Empresa BuscarEmpresa(long id) { Empresa empresa; int num = 3; while (num > 0) { try { using (UnitOfWork read = Instancia.Read) { empresa = read.get_EmpresaRepository().FindById(id); } } catch (Exception exception1) { Exception exception = exception1; num = this.Registrar(exception, 114, num, id, true); continue; } return empresa; } return new Empresa(); } public async Task> BuscarEmpresasAsync() { int num = 3; List empresas2 = await Task.Run>(() => { List empresas; while (num > 0) { try { using (UnitOfWork read = Instancia.Read) { List empresas1 = read.get_EmpresaRepository().Find((long)0); Func u003cu003e9_251 = BaseServico.u003cu003ec.u003cu003e9__25_1; if (u003cu003e9_251 == null) { u003cu003e9_251 = (Empresa x) => x.get_Id(); BaseServico.u003cu003ec.u003cu003e9__25_1 = u003cu003e9_251; } empresas = new List(empresas1.OrderBy(u003cu003e9_251)); } } catch (Exception exception) { num = this.Registrar(exception, 113, num, null, true); continue; } return empresas; } return new List(); }); return empresas2; } public async Task> BuscarEstipulante(string value) { int num = 3; List estipulantes1 = await Task.Run>(() => { List list; while (num > 0) { try { using (UnitOfWork read = Instancia.Read) { List estipulantes = read.get_EstipulanteRepository().Find(value, (Recursos.Usuario.get_IdEmpresa() == (long)1 ? (long)0 : Recursos.Usuario.get_IdEmpresa())); Func u003cu003e9_221 = BaseServico.u003cu003ec.u003cu003e9__22_1; if (u003cu003e9_221 == null) { u003cu003e9_221 = (Estipulante x) => x.get_Nome(); BaseServico.u003cu003ec.u003cu003e9__22_1 = u003cu003e9_221; } list = estipulantes.OrderBy(u003cu003e9_221).ToList(); } } catch (Exception exception) { num = this.Registrar(exception, 111, num, value, true); continue; } return list; } return new List(); }); return estipulantes1; } public async Task> BuscarEstipulantes() { int num = 3; List estipulantes1 = await Task.Run>(() => { List estipulantes; while (num > 0) { try { using (UnitOfWork read = Instancia.Read) { Recursos.Estipulantes = read.get_EstipulanteRepository().Find(); estipulantes = Recursos.Estipulantes; } } catch (Exception exception) { num = this.Registrar(exception, 186, num, null, true); continue; } return estipulantes; } return Recursos.Estipulantes; }); return estipulantes1; } public async Task> BuscarEstipulantesAsync() { int num = 3; List estipulantes2 = await Task.Run>(() => { List estipulantes; while (num > 0) { try { using (UnitOfWork read = Instancia.Read) { List estipulantes1 = read.get_EstipulanteRepository().Find(); Func u003cu003e9_231 = BaseServico.u003cu003ec.u003cu003e9__23_1; if (u003cu003e9_231 == null) { u003cu003e9_231 = (Estipulante x) => x.get_Id(); BaseServico.u003cu003ec.u003cu003e9__23_1 = u003cu003e9_231; } estipulantes = new List(estipulantes1.OrderBy(u003cu003e9_231)); } } catch (Exception exception) { num = this.Registrar(exception, 112, num, null, true); continue; } return estipulantes; } return new List(); }); return estipulantes2; } internal async Task> BuscarFabricante(string value) { int num = 3; List fabricantes1 = await Task.Run>(() => { List list; while (num > 0) { try { using (UnitOfWork read = Instancia.Read) { List fabricantes = read.get_FabricanteRepository().Find(value); Func u003cu003e9_191 = BaseServico.u003cu003ec.u003cu003e9__19_1; if (u003cu003e9_191 == null) { u003cu003e9_191 = (Fabricante x) => x.get_Descricao(); BaseServico.u003cu003ec.u003cu003e9__19_1 = u003cu003e9_191; } list = fabricantes.OrderBy(u003cu003e9_191).ToList(); } } catch (Exception exception) { num = this.Registrar(exception, 182, num, value, true); continue; } return list; } return new List(); }); return fabricantes1; } public async Task> BuscarFornecedor(string value, bool ativo = false) { int num = 3; List fornecedors1 = await Task.Run>(() => { List list; while (num > 0) { try { using (UnitOfWork read = Instancia.Read) { List fornecedors = read.get_FornecedorRepository().Find(value, ativo); Func u003cu003e9_631 = BaseServico.u003cu003ec.u003cu003e9__63_1; if (u003cu003e9_631 == null) { u003cu003e9_631 = (Fornecedor x) => x.get_Nome(); BaseServico.u003cu003ec.u003cu003e9__63_1 = u003cu003e9_631; } list = fornecedors.OrderBy(u003cu003e9_631).ToList(); } } catch (Exception exception) { num = this.Registrar(exception, 159, num, value, true); continue; } return list; } return new List(); }); return fornecedors1; } public async Task> BuscarFornecedor() { int num = 3; List fornecedors1 = await Task.Run>(() => { List list; while (num > 0) { try { using (UnitOfWork read = Instancia.Read) { List fornecedors = read.get_FornecedorRepository().Find(); Func u003cu003e9_641 = BaseServico.u003cu003ec.u003cu003e9__64_1; if (u003cu003e9_641 == null) { u003cu003e9_641 = (Fornecedor x) => x.get_Nome(); BaseServico.u003cu003ec.u003cu003e9__64_1 = u003cu003e9_641; } list = fornecedors.OrderBy(u003cu003e9_641).ToList(); } } catch (Exception exception) { num = this.Registrar(exception, 166, num, null, true); continue; } return list; } return new List(); }); return fornecedors1; } public async Task> BuscarMetaSeguradoraAsync(Seguradora seguradora) { int num = 3; List metaSeguradoras2 = await Task.Run>(() => { List metaSeguradoras; while (num > 0) { try { using (UnitOfWork read = Instancia.Read) { List metaSeguradoras1 = read.get_MetaSeguradoraRepository().Find(seguradora.get_Id()); Func u003cu003e9_381 = BaseServico.u003cu003ec.u003cu003e9__38_1; if (u003cu003e9_381 == null) { u003cu003e9_381 = (MetaSeguradora x) => x.get_Id(); BaseServico.u003cu003ec.u003cu003e9__38_1 = u003cu003e9_381; } metaSeguradoras = new List(metaSeguradoras1.OrderBy(u003cu003e9_381)); } } catch (Exception exception) { num = this.Registrar(exception, 184, num, seguradora, true); continue; } return metaSeguradoras; } return new List(); }); return metaSeguradoras2; } public async Task> BuscarMetaVendedorAsync(Vendedor vendedor) { int num = 3; List metaVendedors2 = await Task.Run>(() => { List metaVendedors; while (num > 0) { try { using (UnitOfWork read = Instancia.Read) { List metaVendedors1 = read.get_MetaVendedorRepository().Find(vendedor.get_Id()); Func u003cu003e9_361 = BaseServico.u003cu003ec.u003cu003e9__36_1; if (u003cu003e9_361 == null) { u003cu003e9_361 = (MetaVendedor x) => x.get_Id(); BaseServico.u003cu003ec.u003cu003e9__36_1 = u003cu003e9_361; } metaVendedors = new List(metaVendedors1.OrderBy(u003cu003e9_361)); } } catch (Exception exception) { num = this.Registrar(exception, 183, num, vendedor, true); continue; } return metaVendedors; } return new List(); }); return metaVendedors2; } public async Task> BuscarParceirosAsync() { int num = 3; List parceiros2 = await Task.Run>(() => { List parceiros; while (num > 0) { try { using (UnitOfWork read = Instancia.Read) { List parceiros1 = read.get_ParceiroRepository().Find(); Func u003cu003e9_351 = BaseServico.u003cu003ec.u003cu003e9__35_1; if (u003cu003e9_351 == null) { u003cu003e9_351 = (Parceiro x) => x.get_Id(); BaseServico.u003cu003ec.u003cu003e9__35_1 = u003cu003e9_351; } parceiros = new List(parceiros1.OrderBy(u003cu003e9_351)); } } catch (Exception exception) { num = this.Registrar(exception, 72, num, null, true); continue; } return parceiros; } return new List(); }); return parceiros2; } public async Task BuscarParcelaPendente(long id) { int num = 3; ParcelaPendente parcelaPendente1 = await Task.Run(() => { ParcelaPendente parcelaPendente; while (num > 0) { try { using (UnitOfWork read = Instancia.Read) { parcelaPendente = read.get_ParcelaRepository().BuscarPendencia(id); } } catch (Exception exception) { num = this.Registrar(exception, 299, num, id, true); continue; } return parcelaPendente; } return null; }); return parcelaPendente1; } public async Task> BuscarPlanoAsync() { int num = 3; List planos2 = await Task.Run>(() => { List planos; while (num > 0) { try { using (UnitOfWork read = Instancia.Read) { List planos1 = read.get_PlanoRepository().Find(); Func u003cu003e9_611 = BaseServico.u003cu003ec.u003cu003e9__61_1; if (u003cu003e9_611 == null) { u003cu003e9_611 = (Plano x) => x.get_Descricao(); BaseServico.u003cu003ec.u003cu003e9__61_1 = u003cu003e9_611; } planos = new List(planos1.OrderBy(u003cu003e9_611)); } } catch (Exception exception) { num = this.Registrar(exception, 167, num, null, true); continue; } return planos; } return new List(); }); return planos2; } public async Task> BuscarPlanosAsync() { int num = 3; List planos1 = await Task.Run>(() => { List planos; while (num > 0) { try { using (UnitOfWork read = Instancia.Read) { planos = new List(read.get_PlanosRepository().Find()); } } catch (Exception exception) { num = this.Registrar(exception, 168, num, null, true); continue; } return planos; } return new List(); }); return planos1; } public async Task> BuscarProduto(string value) { int num = 3; List produtos1 = await Task.Run>(() => { List list; while (num > 0) { try { using (UnitOfWork read = Instancia.Read) { List produtos = read.get_ProdutoRepository().Find(value); Func u003cu003e9_411 = BaseServico.u003cu003ec.u003cu003e9__41_1; if (u003cu003e9_411 == null) { u003cu003e9_411 = (Produto x) => x.get_Nome(); BaseServico.u003cu003ec.u003cu003e9__41_1 = u003cu003e9_411; } list = produtos.OrderBy(u003cu003e9_411).ToList(); } } catch (Exception exception) { num = this.Registrar(exception, 117, num, value, true); continue; } return list; } return new List(); }); return produtos1; } public async Task> BuscarProdutosAsync() { int num = 3; List produtos2 = await Task.Run>(() => { List produtos; while (num > 0) { try { using (UnitOfWork read = Instancia.Read) { List produtos1 = read.get_ProdutoRepository().Find(); Func u003cu003e9_491 = BaseServico.u003cu003ec.u003cu003e9__49_1; if (u003cu003e9_491 == null) { u003cu003e9_491 = (Produto x) => x.get_Nome(); BaseServico.u003cu003ec.u003cu003e9__49_1 = u003cu003e9_491; } produtos = new List(produtos1.OrderBy(u003cu003e9_491)); } } catch (Exception exception) { num = this.Registrar(exception, 118, num, null, true); continue; } return produtos; } return new List(); }); return produtos2; } internal async Task> BuscarProfissao(string value) { int num = 3; List profissaos1 = await Task.Run>(() => { List list; while (num > 0) { try { using (UnitOfWork read = Instancia.Read) { List profissaos = read.get_ProfissaoRepository().Find(value); Func u003cu003e9_151 = BaseServico.u003cu003ec.u003cu003e9__15_1; if (u003cu003e9_151 == null) { u003cu003e9_151 = (Profissao x) => x.get_Nome(); BaseServico.u003cu003ec.u003cu003e9__15_1 = u003cu003e9_151; } list = profissaos.OrderBy(u003cu003e9_151).ToList(); } } catch (Exception exception) { num = this.Registrar(exception, 180, num, value, true); continue; } return list; } return new List(); }); return profissaos1; } public async Task BuscarQualificacaoAsync() { int num = 3; Qualificacao qualificacao1 = await Task.Run(() => { Qualificacao qualificacao; while (num > 0) { try { using (UnitOfWork read = Instancia.Read) { qualificacao = read.get_QualificacaoRepository().FindById((long)1); } } catch (Exception exception) { num = this.Registrar(exception, 170, num, null, true); continue; } return qualificacao; } return new Qualificacao(); }); return qualificacao1; } public async Task> BuscarRamosAsync() { int num = 3; List ramos2 = await Task.Run>(() => { List ramos; while (num > 0) { try { using (UnitOfWork read = Instancia.Read) { List ramos1 = read.get_RamoRepository().Find(); Func u003cu003e9_431 = BaseServico.u003cu003ec.u003cu003e9__43_1; if (u003cu003e9_431 == null) { u003cu003e9_431 = (Ramo x) => x.get_Nome(); BaseServico.u003cu003ec.u003cu003e9__43_1 = u003cu003e9_431; } ramos = new List(ramos1.OrderBy(u003cu003e9_431)); } } catch (Exception exception) { num = this.Registrar(exception, 169, num, null, true); continue; } return ramos; } return new List(); }); return ramos2; } public async Task> BuscarSeguradorasAsync() { int num = 3; List seguradoras2 = await Task.Run>(() => { List seguradoras; while (num > 0) { try { using (UnitOfWork read = Instancia.Read) { List seguradoras1 = read.get_SeguradoraRepository().Find(); Func u003cu003e9_451 = BaseServico.u003cu003ec.u003cu003e9__45_1; if (u003cu003e9_451 == null) { u003cu003e9_451 = (Seguradora x) => x.get_Id(); BaseServico.u003cu003ec.u003cu003e9__45_1 = u003cu003e9_451; } seguradoras = new List(seguradoras1.OrderBy(u003cu003e9_451)); } } catch (Exception exception) { num = this.Registrar(exception, 127, num, null, true); continue; } return seguradoras; } return new List(); }); return seguradoras2; } public async Task> BuscarSociosAsync(long id) { int num = 3; List socios1 = await Task.Run>(() => { List socios; while (num > 0) { try { using (UnitOfWork read = Instancia.Read) { socios = read.get_SocioRepository().FindByEmpresa(id); } } catch (Exception exception) { num = this.Registrar(exception, 122, num, id, true); continue; } return socios; } return new List(); }); return socios1; } public async Task> BuscarStatus(string value) { int num = 3; List statuses1 = await Task.Run>(() => { List list; while (num > 0) { try { using (UnitOfWork read = Instancia.Read) { List statuses = read.get_StatusRepository().Find(value); Func u003cu003e9_421 = BaseServico.u003cu003ec.u003cu003e9__42_1; if (u003cu003e9_421 == null) { u003cu003e9_421 = (Status x) => x.get_Nome(); BaseServico.u003cu003ec.u003cu003e9__42_1 = u003cu003e9_421; } list = statuses.OrderBy(u003cu003e9_421).ToList(); } } catch (Exception exception) { num = this.Registrar(exception, 120, num, value, true); continue; } return list; } return new List(); }); return statuses1; } public async Task> BuscarStatusAsync() { int num = 3; List statuses2 = await Task.Run>(() => { List statuses; while (num > 0) { try { using (UnitOfWork read = Instancia.Read) { List statuses1 = read.get_StatusRepository().Find(); Func u003cu003e9_501 = BaseServico.u003cu003ec.u003cu003e9__50_1; if (u003cu003e9_501 == null) { u003cu003e9_501 = (Status x) => x.get_Nome(); BaseServico.u003cu003ec.u003cu003e9__50_1 = u003cu003e9_501; } statuses = new List(statuses1.OrderBy(u003cu003e9_501)); } } catch (Exception exception) { num = this.Registrar(exception, 121, num, null, true); continue; } return statuses; } return new List(); }); return statuses2; } public async Task> BuscarTipoVendedoresAsync() { int num = 3; List tipoVendedors1 = await Task.Run>(() => { List list; while (num > 0) { try { using (UnitOfWork read = Instancia.Read) { List tipoVendedors = read.get_TipoVendedorRepository().Find(); Func u003cu003e9_481 = BaseServico.u003cu003ec.u003cu003e9__48_1; if (u003cu003e9_481 == null) { u003cu003e9_481 = (TipoVendedor x) => x.get_Id(); BaseServico.u003cu003ec.u003cu003e9__48_1 = u003cu003e9_481; } list = tipoVendedors.OrderBy(u003cu003e9_481).ToList(); } } catch (Exception exception) { num = this.Registrar(exception, 141, num, null, true); continue; } return list; } return new List(); }); return tipoVendedors1; } internal async Task> BuscarUsuario(string value) { int num = 3; List usuarios1 = await Task.Run>(() => { List list; while (num > 0) { try { using (UnitOfWork read = Instancia.Read) { List usuarios = read.get_UsuarioRepository().Find(value, (long)0); Func u003cu003e9_271 = BaseServico.u003cu003ec.u003cu003e9__27_1; if (u003cu003e9_271 == null) { u003cu003e9_271 = (Usuario x) => x.get_Nome(); BaseServico.u003cu003ec.u003cu003e9__27_1 = u003cu003e9_271; } list = usuarios.OrderBy(u003cu003e9_271).ToList(); } } catch (Exception exception) { num = this.Registrar(exception, 132, num, value, true); continue; } return list; } return new List(); }); return usuarios1; } internal async Task BuscarUsuario(string login, string password) { int num = 3; string str = (new Token()).AggerEncrypt(password); Usuario usuario2 = await Task.Run(() => { Usuario usuario; Usuario usuario1; while (num > 0) { try { using (UnitOfWork read = Instancia.Read) { Empresa empresa = read.get_EmpresaRepository().FindBySerial(ApplicationHelper.NumeroSerial); AuthSso result = this.BuscaUsuarioSso(login, str, empresa.get_Documento()).Result; if (result == null || result.get_Code() == 401) { usuario1 = null; } else if (result.get_Code() != 404) { usuario = read.get_UsuarioRepository().SsoId(result) ?? read.get_UsuarioRepository().FindFromSso(result.get_Data().get_User()); if (usuario != null) { if (usuario.get_Excluido()) { using (UnitOfWork commited = Instancia.Commited) { usuario.set_Excluido(false); commited.get_UsuarioRepository().Merge(usuario); commited.Commit(); } } usuario.set_TokenSso(result.get_Data().get_Token()); if (!Gestor.Common.Validation.ValidationHelper.IsNotNullOrEmpty(usuario.get_SsoId()) || !usuario.get_SsoId().Equals(result.get_Data().get_User().get_Id())) { using (UnitOfWork unitOfWork = Instancia.Commited) { usuario.set_SsoId(result.get_Data().get_User().get_Id()); unitOfWork.get_UsuarioRepository().Merge(usuario); unitOfWork.Commit(); } usuario1 = usuario; } else { usuario1 = usuario; } } else { using (UnitOfWork commited1 = Instancia.Commited) { usuario = commited1.get_UsuarioRepository().AddUsuarioFromSso(result.get_Data().get_User()); commited1.Commit(); } usuario.set_TokenSso(result.get_Data().get_Token()); usuario1 = usuario; } } else { usuario = read.get_UsuarioRepository().ValidateLogin(login, str); if (usuario != null) { usuario.set_TokenSso(result.get_Data().get_Token()); UserSso userSso = this.AddOrUpdateUsuarioSso(usuario, empresa.get_Documento(), null).Result; if (userSso != null) { using (UnitOfWork unitOfWork1 = Instancia.Commited) { usuario.set_SsoId(userSso.get_Id()); unitOfWork1.get_UsuarioRepository().Merge(usuario); unitOfWork1.Commit(); } usuario.set_TokenSso(this.BuscaUsuarioSso(login, str, empresa.get_Documento()).Result.get_Data().get_Token()); usuario1 = usuario; } else { usuario1 = usuario; } } else { usuario1 = null; } } } } catch (Exception exception) { num = this.Registrar(exception, 134, num, null, true); continue; } return usuario1; } return new Usuario(); }); return usuario2; } internal async Task BuscarUsuarioMesmoDocumento(string value, long id, long idempresa) { int num = 3; bool flag1 = await Task.Run(() => { bool flag; while (num > 0) { try { using (UnitOfWork read = Instancia.Read) { flag = read.get_UsuarioRepository().FindDocUsedByDocumento(value, id, idempresa); } } catch (Exception exception) { num = this.Registrar(exception, 134, num, value, true); continue; } return flag; } return false; }); return flag1; } internal async Task> BuscarUsuarioPorLoginInteiro(string value) { int num = 3; List usuarios1 = await Task.Run>(() => { List list; while (num > 0) { try { using (UnitOfWork read = Instancia.Read) { List usuarios = read.get_UsuarioRepository().FindByLoginInteiro(value); Func u003cu003e9_391 = BaseServico.u003cu003ec.u003cu003e9__39_1; if (u003cu003e9_391 == null) { u003cu003e9_391 = (Usuario x) => x.get_Nome(); BaseServico.u003cu003ec.u003cu003e9__39_1 = u003cu003e9_391; } list = usuarios.OrderBy(u003cu003e9_391).ToList(); } } catch (Exception exception) { num = this.Registrar(exception, 134, num, value, true); continue; } return list; } return new List(); }); return usuarios1; } public async Task> BuscarUsuariosAsync() { int num = 3; List usuarios2 = await Task.Run>(() => { List usuarios; while (num > 0) { try { using (UnitOfWork read = Instancia.Read) { List usuarios1 = read.get_UsuarioRepository().Find((Recursos.Usuario.get_IdEmpresa() == (long)1 ? (long)0 : Recursos.Usuario.get_IdEmpresa())); Func u003cu003e9_241 = BaseServico.u003cu003ec.u003cu003e9__24_1; if (u003cu003e9_241 == null) { u003cu003e9_241 = (Usuario x) => x.get_Id(); BaseServico.u003cu003ec.u003cu003e9__24_1 = u003cu003e9_241; } usuarios = new List(usuarios1.OrderBy(u003cu003e9_241)); } } catch (Exception exception) { num = this.Registrar(exception, 131, num, null, true); continue; } return usuarios; } return new List(); }); return usuarios2; } public async Task> BuscarUsuariosSso() { List userSsos; List userSsos1; try { using (HttpClient httpClient = new HttpClient()) { ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; Uri apiSso = Address.get_ApiSso(); string[] strArrays = new string[] { "user" }; Uri uri = apiSso.Append(strArrays); string[] strArrays1 = new string[] { "onlyempresa" }; Uri uri1 = uri.Append(strArrays1); string[] strArrays2 = new string[] { "list" }; Uri uri2 = uri1.Append(strArrays2); httpClient.get_DefaultRequestHeaders().TryAddWithoutValidation("Authorization", string.Concat("Bearer ", Recursos.Usuario.get_TokenSso())); HttpResponseMessage async = await httpClient.GetAsync(uri2); if (!async.get_IsSuccessStatusCode()) { userSsos1 = null; } else { userSsos1 = JsonConvert.DeserializeObject>(await async.get_Content().ReadAsStringAsync()); } userSsos = userSsos1; } } catch { userSsos = new List(); } return userSsos; } internal async Task> BuscarVendedor(string value) { int num = 3; List vendedors1 = await Task.Run>(() => { List list; while (num > 0) { try { using (UnitOfWork read = Instancia.Read) { List vendedors = read.get_VendedorRepository().Find((Recursos.Usuario.get_IdEmpresa() == (long)1 ? (long)0 : Recursos.Usuario.get_IdEmpresa())); Func u003cu003e9_211 = BaseServico.u003cu003ec.u003cu003e9__21_1; if (u003cu003e9_211 == null) { u003cu003e9_211 = (Vendedor x) => x.get_Nome(); BaseServico.u003cu003ec.u003cu003e9__21_1 = u003cu003e9_211; } list = vendedors.OrderBy(u003cu003e9_211).ToList(); } } catch (Exception exception) { num = this.Registrar(exception, 140, num, value, true); continue; } return list; } return new List(); }); return vendedors1; } public async Task> BuscarVendedoresAsync() { int num = 3; List vendedors2 = await Task.Run>(() => { List vendedors; while (num > 0) { try { using (UnitOfWork read = Instancia.Read) { List vendedors1 = read.get_VendedorRepository().Find((Recursos.Usuario.get_IdEmpresa() == (long)1 ? (long)0 : Recursos.Usuario.get_IdEmpresa())); Func u003cu003e9_471 = BaseServico.u003cu003ec.u003cu003e9__47_1; if (u003cu003e9_471 == null) { u003cu003e9_471 = (Vendedor x) => x.get_Id(); BaseServico.u003cu003ec.u003cu003e9__47_1 = u003cu003e9_471; } vendedors = new List(vendedors1.OrderBy(u003cu003e9_471)); } } catch (Exception exception) { num = this.Registrar(exception, 140, num, null, true); continue; } return vendedors; } return new List(); }); return vendedors2; } private async Task BuscaUsuarioByToken(Usuario usuario) { bool flag; using (HttpClient httpClient = new HttpClient()) { ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; Uri apiSso = Address.get_ApiSso(); string[] strArrays = new string[] { "user" }; Uri uri = apiSso.Append(strArrays); httpClient.get_DefaultRequestHeaders().TryAddWithoutValidation("Authorization", string.Concat("Bearer ", usuario.get_TokenSso())); JsonConvert.DeserializeObject(await await httpClient.GetAsync(uri).get_Content().ReadAsStringAsync()); flag = true; } return flag; } internal async Task BuscaUsuarioSso(string login, string password, string documentoEmpresa) { AuthSso authSso; AuthSso authSso1; using (HttpClient httpClient = new HttpClient()) { ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; Uri apiSso = Address.get_ApiSso(); string[] strArrays = new string[] { "auth" }; Uri uri = apiSso.Append(strArrays); object[] ticks = new object[] { login, password, ApplicationHelper.NumeroSerial, documentoEmpresa, null }; DateTime universalTime = Funcoes.GetNetworkTime().ToUniversalTime(); ticks[4] = universalTime.Ticks; string base64BasicEncode = string.Format("{0}:{1}:{2}:{3}:{4}", ticks).ToBase64BasicEncode(); httpClient.get_DefaultRequestHeaders().TryAddWithoutValidation("Authorization", base64BasicEncode); HttpResponseMessage async = await httpClient.GetAsync(uri); if (!async.get_IsSuccessStatusCode()) { authSso1 = null; } else { authSso1 = JsonConvert.DeserializeObject(await async.get_Content().ReadAsStringAsync()); } authSso = authSso1; } return authSso; } public async Task> CarregarUsuarios() { await this.AtualizarUsuarios(); return await this.BuscarUsuariosAsync(); } public RegistroLog CreateDynamicLog(long id, dynamic lista, TipoTela tela) { RegistroLog registroLog; string str; string str1; string str2; string str3; try { List diferencas = new List(); List valorOriginals = new List(); foreach (dynamic listum in (IEnumerable)lista) { if (listum == (dynamic)null) { continue; } if (!listum.GetType().Name.ToUpper().StartsWith("LIST")) { try { diferencas.AddRange(this.DynamicObjeto(listum)); } catch { } } else { foreach (dynamic obj1 in (IEnumerable)listum) { try { if (obj1.Id != 0) { diferencas.AddRange(this.DynamicObjeto(obj1)); } else { valorOriginals.AddRange(obj1.GetValorOriginal()); } } catch { } } } } DateTime networkTime = Funcoes.GetNetworkTime(); if (diferencas == null || diferencas.Count != 0) { JsonSerializerSettings jsonSerializerSetting = new JsonSerializerSettings(); jsonSerializerSetting.set_ReferenceLoopHandling(1); str = JsonConvert.SerializeObject(diferencas, jsonSerializerSetting).Replace("]", ",").Replace("[", ""); } else { str = ""; } string str4 = str; if (valorOriginals == null || valorOriginals.Count != 0) { JsonSerializerSettings jsonSerializerSetting1 = new JsonSerializerSettings(); jsonSerializerSetting1.set_ReferenceLoopHandling(1); str1 = JsonConvert.SerializeObject(valorOriginals, jsonSerializerSetting1).Replace("]", "").Replace("[", ""); } else { str1 = ""; } string str5 = str1; RegistroLog registroLog1 = new RegistroLog(); registroLog1.set_Acao(1); registroLog1.set_Usuario(Recursos.Usuario); registroLog1.set_DataHora(networkTime); if (!string.IsNullOrEmpty(str4) || !string.IsNullOrEmpty(str5)) { str2 = string.Concat("[", str4, str5, "]"); } else { str2 = null; } registroLog1.set_Descricao(str2); registroLog1.set_EntidadeId(id); registroLog1.set_Tela(tela); registroLog1.set_Versao(LoginViewModel.VersaoAtual); registroLog1.set_NomeMaquina(Environment.MachineName); registroLog1.set_UsuarioMaquina(Environment.UserName); IPAddress pAddress = ((IEnumerable)Recursos.Host.AddressList).FirstOrDefault((IPAddress ip) => ip.AddressFamily == AddressFamily.InterNetwork); if (pAddress != null) { str3 = pAddress.ToString(); } else { str3 = null; } registroLog1.set_Ip(str3); registroLog1.set_ModeloNovo(true); registroLog = registroLog1; } catch (Exception exception) { registroLog = null; } return registroLog; } public RegistroLog CreateLog(long id, dynamic obj, TipoTela tela) { RegistroLog registroLog; string str; string str1; try { List diferencas = (List)obj.Compare(); DateTime networkTime = Funcoes.GetNetworkTime(); RegistroLog registroLog1 = new RegistroLog(); registroLog1.set_Acao(1); registroLog1.set_Usuario(Recursos.Usuario); registroLog1.set_DataHora(networkTime); if (diferencas == null || diferencas.Count != 0) { JsonSerializerSettings jsonSerializerSetting = new JsonSerializerSettings(); jsonSerializerSetting.set_ReferenceLoopHandling(1); str = JsonConvert.SerializeObject(diferencas, jsonSerializerSetting); } else { str = null; } registroLog1.set_Descricao(str); registroLog1.set_EntidadeId(id); registroLog1.set_Tela(tela); registroLog1.set_Versao(LoginViewModel.VersaoAtual); registroLog1.set_NomeMaquina(Environment.MachineName); registroLog1.set_UsuarioMaquina(Environment.UserName); IPAddress pAddress = ((IEnumerable)Recursos.Host.AddressList).FirstOrDefault((IPAddress ip) => ip.AddressFamily == AddressFamily.InterNetwork); if (pAddress != null) { str1 = pAddress.ToString(); } else { str1 = null; } registroLog1.set_Ip(str1); registroLog1.set_ModeloNovo(true); registroLog = registroLog1; } catch (Exception exception) { registroLog = null; } return registroLog; } public RegistroLog CreateLog(long id, List diferenca, TipoTela tela) { RegistroLog registroLog; string str; try { DateTime networkTime = Funcoes.GetNetworkTime(); RegistroLog registroLog1 = new RegistroLog(); registroLog1.set_Acao(1); registroLog1.set_Usuario(Recursos.Usuario); registroLog1.set_DataHora(networkTime); JsonSerializerSettings jsonSerializerSetting = new JsonSerializerSettings(); jsonSerializerSetting.set_ReferenceLoopHandling(1); registroLog1.set_Descricao(JsonConvert.SerializeObject(diferenca, jsonSerializerSetting)); registroLog1.set_EntidadeId(id); registroLog1.set_Tela(tela); registroLog1.set_Versao(LoginViewModel.VersaoAtual); registroLog1.set_NomeMaquina(Environment.MachineName); registroLog1.set_UsuarioMaquina(Environment.UserName); IPAddress pAddress = ((IEnumerable)Recursos.Host.AddressList).FirstOrDefault((IPAddress ip) => ip.AddressFamily == AddressFamily.InterNetwork); if (pAddress != null) { str = pAddress.ToString(); } else { str = null; } registroLog1.set_Ip(str); registroLog1.set_ModeloNovo(true); registroLog = registroLog1; } catch (Exception exception) { registroLog = null; } return registroLog; } public RegistroLog CreateLog(long id, List diferenca, TipoTela tela, TipoAcao acao) { RegistroLog registroLog; string str; try { DateTime networkTime = Funcoes.GetNetworkTime(); RegistroLog registroLog1 = new RegistroLog(); registroLog1.set_Acao(acao); registroLog1.set_Usuario(Recursos.Usuario); registroLog1.set_DataHora(networkTime); JsonSerializerSettings jsonSerializerSetting = new JsonSerializerSettings(); jsonSerializerSetting.set_ReferenceLoopHandling(1); registroLog1.set_Descricao(JsonConvert.SerializeObject(diferenca, jsonSerializerSetting)); registroLog1.set_EntidadeId(id); registroLog1.set_Tela(tela); registroLog1.set_Versao(LoginViewModel.VersaoAtual); registroLog1.set_NomeMaquina(Environment.MachineName); registroLog1.set_UsuarioMaquina(Environment.UserName); IPAddress pAddress = ((IEnumerable)Recursos.Host.AddressList).FirstOrDefault((IPAddress ip) => ip.AddressFamily == AddressFamily.InterNetwork); if (pAddress != null) { str = pAddress.ToString(); } else { str = null; } registroLog1.set_Ip(str); registroLog1.set_ModeloNovo(true); registroLog = registroLog1; } catch (Exception exception) { registroLog = null; } return registroLog; } public RegistroLog CreateLog(long id, List valor, TipoTela tela, TipoAcao acao) { RegistroLog registroLog; string str; try { DateTime networkTime = Funcoes.GetNetworkTime(); RegistroLog registroLog1 = new RegistroLog(); registroLog1.set_Acao(acao); registroLog1.set_Usuario(Recursos.Usuario); registroLog1.set_DataHora(networkTime); JsonSerializerSettings jsonSerializerSetting = new JsonSerializerSettings(); jsonSerializerSetting.set_ReferenceLoopHandling(1); registroLog1.set_Descricao(JsonConvert.SerializeObject(valor, jsonSerializerSetting)); registroLog1.set_EntidadeId(id); registroLog1.set_Tela(tela); registroLog1.set_Versao(LoginViewModel.VersaoAtual); registroLog1.set_NomeMaquina(Environment.MachineName); registroLog1.set_UsuarioMaquina(Environment.UserName); IPAddress pAddress = ((IEnumerable)Recursos.Host.AddressList).FirstOrDefault((IPAddress ip) => ip.AddressFamily == AddressFamily.InterNetwork); if (pAddress != null) { str = pAddress.ToString(); } else { str = null; } registroLog1.set_Ip(str); registroLog1.set_ModeloNovo(true); registroLog = registroLog1; } catch (Exception exception) { registroLog = null; } return registroLog; } internal async Task DeleteUsuarioSso(Usuario usuario, string documentoEmpresa) { UserSso userSso; UserSso userSso1; using (HttpClient httpClient = new HttpClient()) { ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; Uri apiSso = Address.get_ApiSso(); string[] strArrays = new string[] { "user" }; Uri uri = apiSso.Append(strArrays).AddQuery("userId", usuario.get_SsoId()); httpClient.get_DefaultRequestHeaders().TryAddWithoutValidation("Authorization", string.Concat("Bearer ", usuario.get_TokenSso())); HttpResponseMessage httpResponseMessage = await httpClient.DeleteAsync(uri); if (!httpResponseMessage.get_IsSuccessStatusCode()) { userSso1 = null; } else { userSso1 = JsonConvert.DeserializeObject(await httpResponseMessage.get_Content().ReadAsStringAsync()); } userSso = userSso1; } return userSso; } public List DynamicObjeto(dynamic objeto) { dynamic obj = objeto.Compare(); if (obj.Count <= 0) { return new List(); } return (List)obj; } public async Task LoadInicialParameters() { int num = 3; bool flag1 = await Task.Run(() => { bool flag; while (num > 0) { try { using (UnitOfWork read = Instancia.Read) { List parceiros = read.get_ParceiroRepository().Find(); Func u003cu003e9_521 = BaseServico.u003cu003ec.u003cu003e9__52_1; if (u003cu003e9_521 == null) { u003cu003e9_521 = (Parceiro x) => x.get_Id(); BaseServico.u003cu003ec.u003cu003e9__52_1 = u003cu003e9_521; } Recursos.Parceiros = new List(parceiros.OrderBy(u003cu003e9_521)); List fabricantes = read.get_FabricanteRepository().Select(); Func u003cu003e9_522 = BaseServico.u003cu003ec.u003cu003e9__52_2; if (u003cu003e9_522 == null) { u003cu003e9_522 = (Fabricante x) => x.get_Descricao(); BaseServico.u003cu003ec.u003cu003e9__52_2 = u003cu003e9_522; } Recursos.Fabricantes = fabricantes.OrderBy(u003cu003e9_522).ToList(); Recursos.Configuracoes = read.get_ConfiguracaoRepository().BuscarConfiguracoes(); read.CriarAuxiliar(false); Recursos.Empresas = Auxiliar.get_Empresas(); Recursos.Ramos = Auxiliar.get_Ramos(); Recursos.Seguradoras = Auxiliar.get_Seguradoras(); Recursos.Produtos = Auxiliar.get_Produtos(); Recursos.Status = Auxiliar.get_StatusApolice(); Recursos.TipoVendedor = Auxiliar.get_TipoVendedores(); Recursos.Estipulantes = Auxiliar.get_Estipulantes(); Recursos.Vendedores = Auxiliar.get_Vendedores(); Recursos.Usuarios = Auxiliar.get_Usuarios(); Recursos.TiposTarefa = Auxiliar.get_TiposTarefa(); Recursos.StatusProspeccao = Auxiliar.get_StatusProspeccao(); Recursos.Coberturas = Auxiliar.get_CoberturasPadrao(); } flag = true; } catch (Exception exception) { num = this.Registrar(exception, 186, num, null, true); continue; } return flag; } return false; }); return flag1; } public async Task ParceiroUtilizado(long id) { int num = 3; bool flag1 = await Task.Run(() => { bool flag; while (num > 0) { try { using (UnitOfWork read = Instancia.Read) { flag = read.get_SinistroAutoRepository().ParceiroUtilizado(id); } } catch (Exception exception) { num = this.Registrar(exception, 156, num, id, true); continue; } return flag; } return false; }); return flag1; } public int Registrar(Exception e, TipoErro erro, int tries, object objeto = null, bool abrirTela = true) { string str; string nome; string nome1; long id; string str1; tries--; if (tries > 0) { return tries; } try { int fileLineNumber = (new StackTrace(e, true)).GetFrame(0).GetFileLineNumber(); if (objeto != null) { JsonSerializerSettings jsonSerializerSetting = new JsonSerializerSettings(); jsonSerializerSetting.set_ReferenceLoopHandling(1); str = JsonConvert.SerializeObject(objeto, 1, jsonSerializerSetting); } else { str = null; } string str2 = str; LogError logError = new LogError(); logError.set_IdFornecedor(ApplicationHelper.IdFornecedor); Empresa empresa = Recursos.Empresa; if (empresa != null) { nome = empresa.get_Nome(); } else { nome = null; } logError.set_Fornecedor(nome); Usuario usuario = Recursos.Usuario; if (usuario != null) { nome1 = usuario.get_Nome(); } else { nome1 = null; } logError.set_UsuarioLogado(nome1); Usuario usuario1 = Recursos.Usuario; if (usuario1 != null) { id = usuario1.get_Id(); } else { id = (long)0; } logError.set_IdUsuarioLogado(id); logError.set_Versao(ApplicationHelper.Versao.ToString()); logError.set_Data(Funcoes.GetNetworkTime()); logError.set_IdErro(erro); logError.set_Erro(Gestor.Common.Validation.ValidationHelper.GetDescription(erro)); logError.set_HResult(e.HResult); Exception innerException = e.InnerException; if (innerException != null) { str1 = innerException.ToString(); } else { str1 = null; } logError.set_InnerException(str1); logError.set_HelpLink(e.HelpLink); logError.set_Message(e.Message); logError.set_Source(e.Source); logError.set_StackTrace(e.StackTrace); logError.set_Maquina(Environment.MachineName); logError.set_UsuarioMaquina(Environment.UserName); logError.set_Linha(fileLineNumber.ToString()); logError.set_Objeto(str2); Erro.RegistrarErro(logError, abrirTela); this.Sucesso = false; } catch (Exception exception) { } return 0; } public async Task ReloadAuxiliar() { int num = 3; bool flag1 = await Task.Run(() => { bool flag; while (num > 0) { try { using (UnitOfWork read = Instancia.Read) { read.CriarAuxiliar(true); Recursos.Empresas = Auxiliar.get_Empresas(); Recursos.Ramos = Auxiliar.get_Ramos(); Recursos.Seguradoras = Auxiliar.get_Seguradoras(); Recursos.Produtos = Auxiliar.get_Produtos(); Recursos.Status = Auxiliar.get_StatusApolice(); Recursos.TipoVendedor = Auxiliar.get_TipoVendedores(); Recursos.Estipulantes = Auxiliar.get_Estipulantes(); Recursos.Vendedores = Auxiliar.get_Vendedores(); Recursos.Usuarios = Auxiliar.get_Usuarios(); Recursos.TiposTarefa = Auxiliar.get_TiposTarefa(); Recursos.StatusProspeccao = Auxiliar.get_StatusProspeccao(); } flag = true; } catch (Exception exception) { num = this.Registrar(exception, 186, num, null, true); continue; } return flag; } return false; }); return flag1; } public void SalvarAcao(RegistroAcao log, object obs = null) { string str; string str1; if (log == null || Recursos.Usuario.get_Id() == 0) { return; } try { using (UnitOfWork commited = Instancia.Commited) { log.set_Usuario(Recursos.Usuario); log.set_DataHora(Funcoes.GetNetworkTime()); log.set_Versao(LoginViewModel.VersaoAtual); log.set_NomeMaquina(Environment.MachineName); log.set_UsuarioMaquina(Environment.UserName); RegistroAcao registroAcao = log; IPAddress pAddress = ((IEnumerable)Dns.GetHostEntry(Dns.GetHostName()).AddressList).FirstOrDefault((IPAddress ip) => ip.AddressFamily == AddressFamily.InterNetwork); if (pAddress != null) { str = pAddress.ToString(); } else { str = null; } registroAcao.set_Ip(str); RegistroAcao registroAcao1 = log; if (obs == null) { str1 = ""; } else if (!(obs is string)) { JsonSerializerSettings jsonSerializerSetting = new JsonSerializerSettings(); jsonSerializerSetting.set_ReferenceLoopHandling(1); str1 = JsonConvert.SerializeObject(obs, jsonSerializerSetting); } else { str1 = obs.ToString(); } registroAcao1.set_Observacao(str1); commited.get_RegistroAcaoRepository().SaveOrUpdate(log); commited.Commit(); } } catch (Exception exception) { this.Registrar(exception, 0, 3, log, true); } } public async Task SalvarControle(ControleArquivoDigital controle) { int num = 3; await Task.Run(() => { while (num > 0) { try { using (UnitOfWork commited = Instancia.Commited) { commited.get_IndiceArquivoDigitalRepository().SaveOrUpdate(controle); commited.Commit(); } break; } catch (Exception exception) { num = this.Registrar(exception, 179, num, controle, true); } } }); } public void SaveLog(RegistroLog keyValues, UnitOfWork unitOfWork) { if (keyValues == null) { return; } try { unitOfWork.get_RegistroLogRepository().SaveOrUpdate(keyValues); } catch (Exception exception) { } } public void SaveLog(List keyValues, UnitOfWork unitOfWork) { if (keyValues == null) { return; } try { List list = keyValues.Where((RegistroLog x) => { if (string.IsNullOrEmpty((x != null ? x.get_Descricao() : null))) { return false; } return !string.IsNullOrEmpty(x.get_Versao()); }).ToList(); unitOfWork.get_RegistroLogRepository().AddRange(list); } catch (Exception exception) { } } public async Task Sincronizar(List dados, Filtros filtros) { int num2 = 3; int num3 = await Task.Run(() => { int num; while (num2 > 0) { try { using (UnitOfWork commited = Instancia.Commited) { int num1 = commited.get_VinculoDocumentoRepository().Sincronize(filtros.get_Inicio(), dados); commited.Commit(); num = num1; } } catch (Exception exception) { num2 = this.Registrar(exception, 293, num2, null, true); continue; } return num; } return 0; }); return num3; } public async Task Sincronizar(DateTime data, List ids = null) { int num = 3; int[] numArray2 = await Task.Run(() => { int[] numArray; while (num > 0) { try { using (UnitOfWork commited = Instancia.Commited) { int[] numArray1 = commited.get_ParcelaRepository().SincronizarPendencia(data, ids); commited.Commit(); numArray = numArray1; } } catch (Exception exception) { num = this.Registrar(exception, 300, num, false, true); continue; } return numArray; } return new int[2]; }); return numArray2; } public async Task TipoVendedorUtilizado(long id) { int num = 3; bool flag1 = await Task.Run(() => { bool flag; while (num > 0) { try { using (UnitOfWork read = Instancia.Read) { flag = read.get_VendedorParcelaRepository().TipoVendedorUtilizado(id); } } catch (Exception exception) { num = this.Registrar(exception, 155, num, id, true); continue; } return flag; } return false; }); return flag1; } internal async Task VerificaUsuarioSso(string login, string documentoEmpresa) { AuthSso authSso; AuthSso authSso1; using (HttpClient httpClient = new HttpClient()) { ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; Uri apiSso = Address.get_ApiSso(); string[] strArrays = new string[] { "exist" }; Uri uri = apiSso.Append(strArrays); object[] ticks = new object[] { login, login, ApplicationHelper.NumeroSerial, documentoEmpresa, null }; DateTime universalTime = Funcoes.GetNetworkTime().ToUniversalTime(); ticks[4] = universalTime.Ticks; string base64BasicEncode = string.Format("{0}:{1}:{2}:{3}:{4}", ticks).ToBase64BasicEncode(); httpClient.get_DefaultRequestHeaders().TryAddWithoutValidation("Authorization", base64BasicEncode); HttpResponseMessage async = await httpClient.GetAsync(uri); if (!async.get_IsSuccessStatusCode()) { authSso1 = null; } else { authSso1 = JsonConvert.DeserializeObject(await async.get_Content().ReadAsStringAsync()); } authSso = authSso1; } return authSso; } } }