public IActionResult GetId(int idObject)
        {
            ObjectRastreio objectRastreio = objectRastreioDML.GetObjectRastreioId2(idObject);

            util.buscaAtualiacao(idObject);
            return(Ok("Ok Atualizado " + idObject));
        }
        public string HandleSQSEvent(SQSEvent sqsEvent, ILambdaContext context)
        {
            foreach (var record in sqsEvent.Records)
            {
                ObjectRastreio json = JsonConvert.DeserializeObject <ObjectRastreio>(record.Body);

                Console.WriteLine(json.objectCode);

                Util util = new Util();
                util.buscaAtualiacao(json.idObject);
            }

            return($"Processed {sqsEvent.Records.Count} records.");
        }
        public IActionResult Put(int idObject, [FromBody] ObjectRastreio objectRastreio)
        {
            int idUser = util.ValidaTokenHash(HttpContext);

            if (idUser <= 0)
            {
                Error error = new Error(true, "Not Authorized.");
                return(BadRequest(error));
            }

            ObjectRastreio objectRastreioRet = objectDML.Update(idUser, idObject, objectRastreio);

            if (objectRastreioRet.idObject == 0)
            {
                Error error = new Error(true, "Record not found.");
                return(NotFound(error));
            }

            return(Ok(objectRastreioRet));
        }
        public IActionResult GetId(int idObject)
        {
            int idUser = util.ValidaTokenHash(HttpContext);

            if (idUser <= 0)
            {
                Error error = new Error(true, "Not Authorized.");
                return(BadRequest(error));
            }

            ObjectRastreio objectRastreio = objectDML.GetObjectRastreioId(idUser, idObject);


            if (objectRastreio.idObject == 0)
            {
                Error error = new Error(true, "Record not found.");
                return(NotFound(error));
            }

            return(Ok(objectRastreio));
        }
Exemplo n.º 5
0
        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--;
                    }

                }

            }
        }