public void buscaAtualiacao(int idObject){ ObjectRastreioDML objectRastreioDML = new ObjectRastreioDML(); ObjectRastreio objectRastreio = objectRastreioDML.GetObjectRastreioId2(idObject); string user = Environment.GetEnvironmentVariable("USER_LINK_TRACE"); string token = Environment.GetEnvironmentVariable("TOKEN_LINK_TRACE"); string urlLinkeTrace = Environment.GetEnvironmentVariable("URL_LINK_TRACE"); string url = $"{urlLinkeTrace}?user={user}&token={token}&codigo={objectRastreio.objectCode}"; var client = new Client(new NewtonsoftSerializationAdapter(), new Uri(url)); var response = client.GetAsync<LinkTack>(); LinkTack retultado = response.Result.Body; ObjectLocationDML objectLocationDML = new ObjectLocationDML(); NotificationDML notificationDML = new NotificationDML(); List<ObjectLocation> objectLocations = objectLocationDML.GetObjectLocation(objectRastreio.idObject); if (retultado.quantidade > objectLocations.Count){ int dif = retultado.quantidade - objectLocations.Count; foreach(var eventos in retultado.eventos){ if (dif > 0){ string source = ""; string sourceAddress = ""; string sourceLat = ""; string sourceLng = ""; string destiny = ""; string destinyAddress = ""; string destinyLat = ""; string destinyLng = ""; foreach(var sub in eventos.subStatus){ if (sub.ToUpper().Contains("LOCAL") || sub.ToUpper().Contains("ORIGEM") || sub.Contains("Registrado por")) { var sub2 = sub.Replace("Local: ", "").Replace("Origem: ", "").Replace("Registrado por ", ""); Endereco end = buscaEndereco(sub2); if (end.achou) { source = sub2; sourceAddress = end.address; sourceLat = end.lat; sourceLng = end.lng; }else{ source = sub2; } }else if (sub.ToUpper().Contains("DESTINO")) { var sub2 = sub.Replace("Destino: ", ""); Endereco end = buscaEndereco(sub2); if (end.achou) { destiny = sub2; destinyAddress = end.address; destinyLat = end.lat; destinyLng = end.lng; }else{ destiny = sub2; } }else{ source = sub; } } string[] formats= {"dd/MM/yyyy H:mm"}; DateTime data = DateTime.ParseExact(eventos.data + " " + eventos.hora, formats, new CultureInfo("en-US"), DateTimeStyles.None); ObjectLocation novo = new ObjectLocation{ idObject = objectRastreio.idObject, data = data, local = eventos.local, status = eventos.status, source = source, sourceAddress = sourceAddress, sourceLat = sourceLat, sourceLng = sourceLng, destiny = destiny, destinyAddress = destinyAddress, destinyLat = destinyLat, destinyLng = destinyLng }; objectLocationDML.Insert(novo); if (eventos.status == "Objeto entregue ao destinatário"){ objectRastreioDML.UpdateStatus(objectRastreio.idObject, "F"); } Notification notification = new Notification{ idUser = objectRastreio.idUser, idObject = objectRastreio.idObject, idObjectLocation = novo.idObjectLocation, title = "Nova Atualização", message = "Mensagem", flagSend = false, flagRead = false, date = DateTime.Now }; notificationDML.Insert(notification); dif--; } } } }