Exemplo n.º 1
0
        public bool delRecipe(int id)
        {
            /* Modifica sul database (eliminazione della ricetta) */
            try
            {
                sqlQuery = "DELETE from Recipes where id_recipe = @idRecipe";
                Database.setValues(sqlQuery, id);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }

            /* Invio richiesta delete al server web */
            try
            {
                ServerRequest.DeleteRequest(id);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }

            return(true);
        }
Exemplo n.º 2
0
        public bool newRecipe([FromBody] Recipe jsonObject)
        {
            listRecipes.Clear();
            listRecipes.Add(jsonObject);
            result = true;

            /* Memorizzazione dati ricevuti su Database */
            try
            {
                sqlQuery = "INSERT INTO Recipes (Name, AirTemperature, WaterTemperature, Humidity, PH, Conductivity, RGB, Light, AddressImage) VALUES (@name, @airTemperature, @waterTemperature, @humidity, @pH, @conductivity, @rgb, @light, @addressImage)";
                Database.setValues(sqlQuery, jsonObject);
            }
            catch (Exception ex)
            {
                //throw new Exception(ex.Message);
            }

            /* Invio dati al server web */
            try
            {
                ServerRequest.PostRequest(listRecipes);
            }
            catch (Exception ex)
            {
                //throw new Exception(ex.Message);
            }

            return(result);
        }
Exemplo n.º 3
0
        private void serialReceived_options(object sender, string e)
        {
            SerialConfig.dataReceived -= serialReceived_options;
            Console.WriteLine("Ricevuto: " + e);
            if (e.Contains("Z0"))
            {
                internalSetOption(receivedOptionFromClient);
            }
            else
            {
                try
                {
                    sqlQuery = "UPDATE Options SET RGB = @rgb, Light = @light, AddressImage = @addressImage LIMIT 1";
                    Database.setValues(sqlQuery, receivedOptionFromClient);
                }
                catch (Exception ex)
                {
                    //throw new Exception(ex.Message);
                }
                finally
                {
                }

                /* Invio dati al server web */
                try
                {
                    ServerRequest.PutRequest(receivedOptionFromClient);
                }
                catch (Exception ex)
                {
                    //throw new Exception(ex.Message);
                }
            }
        }
Exemplo n.º 4
0
        public bool applyRecipe([FromBody] Recipe jsonObject)
        {
            result = true;
            /* Invio parametri ai circuiti elettronici */
            Parameters param = new Parameters(DateTime.Now, jsonObject.AirTemperature, jsonObject.WaterTemperature, jsonObject.Humidity, jsonObject.PH, jsonObject.Conductivity);

            internalSetParameter(param);

            /* Invio opzioni ai circuiti elettronici */
            Options opt = new Options(jsonObject.RGB, jsonObject.Light);

            internalSetOption(opt);

            /* Eliminazione dei parametri vecchi */
            sqlQuery = "DELETE FROM Parameters WHERE id_parameters>0";
            Database.setValues(sqlQuery);
            /* Creazione primo record */
            DateTime   timeStamp = DateTime.Now;
            Parameters obj       = new Parameters(timeStamp, 0.0f, 0.0f, 0, 7, 0);

            sqlQuery = "INSERT INTO Parameters (TimeStamp, AirTemperature, WaterTemperature, Humidity, PH, Conductivity) VALUES (@timeStamp, @airTemperature, @waterTemperature, @humidity, @pH, @conductivity)";
            Database.setValues(sqlQuery, obj);

            /* Memorizzazione dati ricevuti su Database */
            Options modified = new Options(jsonObject.RGB, jsonObject.Light, jsonObject.AddressImage);

            try
            {
                sqlQuery = "UPDATE Options SET RGB = @rgb, Light = @light, AddressImage = @addressImage LIMIT 1";
                Database.setValues(sqlQuery, modified);
            }
            catch (Exception ex)
            {
                //throw new Exception(ex.Message);
            }

            /* Invio dati al server web */
            try
            {
                ServerRequest.DeleteRequest();
                ServerRequest.PutRequest(modified);
                listRecipes.Clear();
            }
            catch (Exception ex)
            {
                //throw new Exception(ex.Message);
            }

            return(result);
        }
Exemplo n.º 5
0
        private static void serialReceived_parameter(object sender, string e)
        {
            SerialConfig.dataReceived -= serialReceived_parameter;
            Console.WriteLine("Ricevuto: " + e);

            Random rnd = new Random();

            Options  jsonObject = null;
            DateTime timeStamp;
            float    airTemperature   = 26.5f;
            float    waterTemperature = 23.5f;
            int      humidity         = 70;
            float    pH           = 6.5f;
            int      conductivity = 1500;
            string   rgb          = "213-000-043";
            bool     light        = true;
            bool     dataReceived = true; // true if received useful data from circuits
            string   packet;              // data packet received from circuits


            try
            {
                packet = e;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            Console.WriteLine("Ricevuto:" + packet);

            if (packet.Length > 10 && packet[0] == '#')
            {
                string app = ""; // stringa d'appoggio
                // eseguo il ciclo fino ad arrivare a fine stringa o fino al carattere terminatore
                string toParse = packet.Substring(1, packet.Length - 2);
                Console.WriteLine("To parse " + toParse);

                string[] tmpArray = toParse.Split(';');
                foreach (string value in tmpArray)
                {
                    switch (value[0])
                    {
                    case 'A':
                        airTemperature = Convert.ToSingle(value.Substring(1).Replace(".", CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator));
                        Console.WriteLine("airTemperature " + airTemperature);
                        break;

                    case 'B':
                        waterTemperature = Convert.ToSingle(value.Substring(1).Replace(".", CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator));
                        Console.WriteLine("waterTemperature " + waterTemperature);
                        break;

                    case 'C':
                        humidity = (int)Math.Round(Convert.ToSingle(value.Substring(1).Replace(".", CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator)));
                        Console.WriteLine("humidity " + humidity);
                        break;

                    case 'D':
                        pH = Convert.ToSingle(value.Substring(1).Replace(".", CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator));
                        Console.WriteLine("pH " + pH);
                        break;

                    case 'E':
                        conductivity = (int)Math.Round(Convert.ToSingle(value.Substring(1).Replace(".", CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator)));
                        Console.WriteLine("conductivity " + conductivity);
                        break;

                    case 'F':
                        rgb = value.Substring(1);
                        Console.WriteLine("rgb " + rgb);
                        break;

                    case 'H':
                        light = (value[1] == '1' ? true : false);
                        break;
                    }
                }



                /* Generazione random del dato della temperatura dell'acqua */
                waterTemperature = Convert.ToSingle(rnd.NextDouble());
                waterTemperature = (float)Math.Round(waterTemperature, 1);
                waterTemperature = airTemperature - (3 + waterTemperature);

                /* Generazione random del dato della conducibilità */
                conductivity = ValuesController.getParameterFromDB()[0].Conductivity;

                // do this only if received something useful
                if (dataReceived)
                {
                    // creazione di un nuovo nodo nella lista
                    timeStamp = DateTime.Now;
                    listParameters.Add(new Parameters(timeStamp, airTemperature, waterTemperature, humidity, pH, conductivity));

                    /* Memorizzazione dati ricevuti su Database */
                    try
                    {
                        Parameters obj = new Parameters(timeStamp, airTemperature, waterTemperature, humidity, pH, conductivity);
                        sqlQuery = "INSERT INTO Parameters (TimeStamp, AirTemperature, WaterTemperature, Humidity, PH, Conductivity) VALUES (@timeStamp, @airTemperature, @waterTemperature, @humidity, @pH, @conductivity)";
                        Database.setValues(sqlQuery, obj);
                    }
                    catch (Exception ex)
                    {
                        //throw new Exception(ex.Message);
                    }

                    try
                    {
                        var    sqlQuery = "SELECT * from Options";
                        string address  = Database.getValuesObject(sqlQuery).AddressImage;
                        jsonObject = new Options(rgb, light, address);
                        sqlQuery   = "UPDATE Options SET RGB = @rgb, Light = @light, AddressImage = @addressImage LIMIT 1";
                        Database.setValues(sqlQuery, jsonObject);
                    }
                    catch (Exception ex)
                    {
                        //throw new Exception(ex.Message);
                    }

                    /* Invio dati al server web */
                    // POST dei parametri
                    try
                    {
                        ServerRequest.PostRequest(listParameters);
                        listParameters.Clear();
                    }
                    catch (Exception ex)
                    {
                        //throw new Exception(ex.Message);
                    }
                    // PUT delle opzioni
                    try
                    {
                        ServerRequest.PutRequest(jsonObject);
                    }
                    catch (Exception ex)
                    {
                        //throw new Exception(ex.Message);
                    }
                }
            }
        }