Example #1
0
        public static List <Programacion> parseListaProgramaciones(string response)
        {
            List <Programacion> resultado = null;

            try
            {
                resultado = new List <Programacion>();
                JArray json = JArray.Parse(response);
                foreach (var item in json.Children())
                {
                    int      id         = item["id"].ToObject <int>();
                    Boolean  habilitado = item["habilitado"].ToObject <Boolean>();
                    Boolean  prender    = item["prender"].ToObject <Boolean>();
                    TimeSpan horario1   = item["horario1"].ToObject <TimeSpan>();

                    ConfigGPIO gpio   = (ConfigGPIO)item["configgpio"]["desc"].ToString();
                    Boolean    estado = item["configgpio"]["estado"].ToObject <Boolean>();
                    String     desc   = item["desc"].ToString();
                    if (item["duracion"] != null)
                    {
                        int duracion = 0;
                        Int32.TryParse(item["duracion"].ToString(), out duracion);
                        Programacion toAdd = null;
                        if (duracion != 0)
                        {
                            toAdd = new Programacion(id, gpio, horario1, duracion, prender, desc, habilitado);
                        }
                        else
                        {
                            toAdd = new Programacion(id, gpio, horario1, prender, desc, habilitado);
                        }
                        resultado.Add(toAdd);
                    }
                    else
                    {
                        resultado.Add(new Programacion(id, gpio, horario1, prender, desc, habilitado));
                    }
                }
            }
            catch (Exception ex)
            {
                Console.Write(ex);
            }
            return(resultado);
        }
Example #2
0
        //private const String dateFormat = "yyyy-MM-ddTHH:mm:ss";
        //private const String timeFormat = "HH:mm:ss";

        public static List <ConfigGPIO> parseListaConfiguraciones(String response)
        {
            List <ConfigGPIO> resultado = null;

            try
            {
                resultado = new List <ConfigGPIO>();
                JArray json = JArray.Parse(response);
                foreach (JObject obj in json)
                {
                    ConfigGPIO aux = (ConfigGPIO)obj["desc"].ToString();
                    resultado.Add(aux);
                }
            }
            catch (Exception ex)
            {
                resultado = null;
                Console.Write(ex);
            }
            return(resultado);
        }
Example #3
0
        public static List <Evento> parseListaEventos(string response)
        {
            List <Evento> resultado = null;

            try
            {
                resultado = new List <Evento>();
                JArray json = JArray.Parse(response);
                foreach (var item in json.Children())
                {
                    //int id = (from jit in item select Int32.Parse(jit["id"].ToString())).FirstOrDefault();
                    DateTime            fechaYHora = item["fechayhora"].ToObject <DateTime>();
                    ConfigGPIO          gpio       = (ConfigGPIO)item["configgpio"]["desc"].ToString();
                    Boolean             estado     = item["configgpio"]["estado"].ToObject <Boolean>();
                    String              desc       = item["desc"].ToString();
                    HumedadYTemperatura humytemp   = null;
                    if (gpio.ToString() == ConfigGPIO.SENSOR_HUM_Y_TEMP.ToString())
                    {
                        JObject jhyt = JObject.Parse(desc);
                        Decimal hum  = jhyt["humedad"].ToObject <Decimal>();
                        Decimal temp = jhyt["temperatura"].ToObject <Decimal>();
                        humytemp = new HumedadYTemperatura(hum, temp);
                        resultado.Add(new Evento(fechaYHora, humytemp));
                    }
                    else
                    {
                        resultado.Add(new Evento(fechaYHora, gpio, estado, desc));
                    }
                }
            }
            catch (Exception ex)
            {
                Console.Write(ex);
            }
            return(resultado);
        }
        public async Task <List <Evento> > GetEventosPorFechaYTipo(DateTime desde, DateTime hasta, ConfigGPIO tipo)
        {
            List <Evento> resultado = null;

            try
            {
                Uri uri      = new Uri(Configuracion.Instancia.restBaseUrl + "/obtenerEventosPorFecha/" + desde.ToString(formatoFecha) + "/" + hasta.ToString(formatoFecha) + "/" + tipo.ToString());
                var response = await cliente.GetAsync(uri);

                if (response.IsSuccessStatusCode)
                {
                    String contenido = await response.Content.ReadAsStringAsync();

                    resultado = ResponseParser.parseListaEventos(contenido);
                }
            }
            catch (Exception ex)
            {
                Console.Write(ex);
            }
            return(resultado);
        }
Example #5
0
        public async Task <List <Evento> > GetEventosPorFechaYTipo(DateTime desde, DateTime hasta, ConfigGPIO tipo)
        {
            List <Evento>        toReturn      = null;
            QueueMessageResponse response      = null;
            QueueMessageRequest  request       = null;
            List <string>        getParameters = new List <string>()
            {
                desde.ToString(formatoFecha), hasta.ToString(formatoFecha), tipo.ToString()
            };

            try
            {
                request = new QueueMessageRequest(Configuracion.Instancia.usuario, Configuracion.Instancia.contrasenia, "obtenerEventosPorFecha", getParameters);
                QueueMessageSenderReciever client = new QueueMessageSenderReciever(request);
                response = await client.CallForResponse();

                toReturn = ResponseParser.parseListaEventos(response.Result);
            }
            catch (Exception ex)
            {
                Console.Write(ex.StackTrace);
            }
            return(toReturn);
        }