using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Net.Sockets; using System.Threading.Tasks; using Gestor.Application.Helpers; using Gestor.Application.Servicos.Generic; using Gestor.Application.ViewModels; using Gestor.Infrastructure.UnitOfWork.Generic; using Gestor.Infrastructure.UnitOfWork.Logic; using Gestor.Model.API; using Gestor.Model.Common; using Gestor.Model.Domain.Common; using Gestor.Model.Domain.Generic; using Gestor.Model.Domain.Seguros; using Newtonsoft.Json; namespace Gestor.Application.Servicos.Seguros; public class ExpedicaoServico : BaseServico { public async Task> BuscarExpedicoes(Documento documento) { int tries = 3; return await Task.Run(delegate { while (tries > 0) { try { UnitOfWork read = Instancia.Read; try { return read.ExpedicaoRepository.FindByIdDocumento(((DomainBase)documento).Id); } finally { ((IDisposable)read)?.Dispose(); } } catch (Exception e) { tries = Registrar(e, (TipoErro)289, tries, documento); } } return new List(); }); } public async Task Save(Expedicao expedicao) { int tries = 3; base.Sucesso = true; Expedicao expedicaoOriginal = expedicao; return await Task.Run((Func)delegate { //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_00d9: 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_00eb: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: Unknown result type (might be due to invalid IL or missing references) //IL_0103: Expected O, but got Unknown //IL_0108: Unknown result type (might be due to invalid IL or missing references) //IL_0119: Unknown result type (might be due to invalid IL or missing references) //IL_0121: Unknown result type (might be due to invalid IL or missing references) //IL_012c: Unknown result type (might be due to invalid IL or missing references) //IL_0137: Unknown result type (might be due to invalid IL or missing references) //IL_0142: Unknown result type (might be due to invalid IL or missing references) //IL_0180: Expected O, but got Unknown while (tries > 0) { expedicao = expedicaoOriginal; try { UnitOfWork commited = Instancia.Commited; try { TipoAcao acao = (TipoAcao)(((DomainBase)expedicao).Id != 0L); DateTime networkTime = Funcoes.GetNetworkTime(); if (((DomainBase)expedicao).Id == 0L) { expedicao.UsuarioCriacao = ((DomainBase)Recursos.Usuario).Id; expedicao.DataCriacao = networkTime; expedicao = commited.ExpedicaoRepository.SaveOrUpdate(expedicao); } else { expedicao.UsuarioAlteracao = ((DomainBase)Recursos.Usuario).Id; expedicao.DataAlteracao = networkTime; expedicao = commited.ExpedicaoRepository.Merge(expedicao); } IPHostEntry hostEntry = Dns.GetHostEntry(Dns.GetHostName()); RegistroLog keyValues = new RegistroLog { Acao = acao, Usuario = Recursos.Usuario, DataHora = networkTime, Descricao = JsonConvert.SerializeObject((object)expedicao, new JsonSerializerSettings { ReferenceLoopHandling = (ReferenceLoopHandling)1 }), EntidadeId = ((DomainBase)expedicao).Id, Tela = (TipoTela)46, Versao = LoginViewModel.VersaoAtual, NomeMaquina = Environment.MachineName, UsuarioMaquina = Environment.UserName, Ip = hostEntry.AddressList.FirstOrDefault((IPAddress ip) => ip.AddressFamily == AddressFamily.InterNetwork)?.ToString() }; SaveLog(keyValues, commited); ((GenericUnitOfWork)commited).Commit(); return expedicao; } finally { ((IDisposable)commited)?.Dispose(); } } catch (Exception e) { tries = Registrar(e, (TipoErro)290, tries, expedicao); } } return expedicaoOriginal; }); } public async Task Delete(Expedicao expedicao) { int tries = 3; return await Task.Run(delegate { //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Expected O, but got Unknown while (tries > 0) { try { UnitOfWork commited = Instancia.Commited; try { commited.ExpedicaoRepository.Delete(((DomainBase)expedicao).Id); DateTime networkTime = Funcoes.GetNetworkTime(); IPHostEntry hostEntry = Dns.GetHostEntry(Dns.GetHostName()); RegistroLog val = new RegistroLog(); val.Acao = (TipoAcao)2; val.Usuario = Recursos.Usuario; val.DataHora = networkTime; val.Descricao = $"O USUÁRIO {Recursos.Usuario.Nome} EXCLUIU, EM {networkTime}, A EXPEDIÇÃO DE " + $"ID: '{((DomainBase)expedicao).Id}'" + ", DOCUMENTO: '" + expedicao.Documento + "', DESTINO: '" + expedicao.Destino + "'" + $", DATA ENVIO: '{expedicao.DataEnvio}'" + $", DATA RECEBIMENTO: '{expedicao.DataRecebimento}'" + ", RESPONSÁVEL: 'R$" + expedicao.Responsavel + "'."; val.EntidadeId = ((DomainBase)expedicao).Id; val.Versao = LoginViewModel.VersaoAtual; val.Tela = (TipoTela)46; val.NomeMaquina = Environment.MachineName; val.UsuarioMaquina = Environment.UserName; val.Ip = hostEntry.AddressList.FirstOrDefault((IPAddress ip) => ip.AddressFamily == AddressFamily.InterNetwork)?.ToString(); RegistroLog keyValues = val; SaveLog(keyValues, commited); ((GenericUnitOfWork)commited).Commit(); return true; } finally { ((IDisposable)commited)?.Dispose(); } } catch (Exception e) { tries = Registrar(e, (TipoErro)291, tries, expedicao); } } return false; }); } }