Esempio n. 1
0
        public WebSiteResponse <bool> getPresence(string period)
        {
            WebSiteResponse <bool> resp = new WebSiteResponse <bool>();

            DomoticDAOTableAdapters.presenceTableAdapter adapter = new DomoticDAOTableAdapters.presenceTableAdapter();
            resp.record = new List <Record <bool> >();
            switch (period)
            {
            case "LAST":
                DomoticDAO.presenceDataTable e = adapter.GetLastDatum();

                if (e.Count > 0)
                {
                    string date = e.ElementAt(0).time.ToString("o");
                    resp.record.Add(new Record <bool>(e.ElementAt(0).presence,
                                                      date.Substring(0, date.Length - 4) + "Z"));
                }
                break;

            case "TWELVE_HOUR":
                DomoticDAO.presenceDataTable rows = adapter.GetDataInLastHours(12);

                for (int i = 0; i < rows.Count; i++)
                {
                    string date = rows.ElementAt(i).time.ToString("o");
                    resp.record.Add(new Record <bool>(rows.ElementAt(i).presence,
                                                      date.Substring(0, date.Length - 4) + "Z"));
                }
                break;

            case "TWENTYFOUR_HOUR":
                DomoticDAO.presenceDataTable rows1 = adapter.GetDataInLastHours(24);

                for (int i = 0; i < rows1.Count; i++)
                {
                    string date = rows1.ElementAt(i).time.ToString("o");
                    resp.record.Add(new Record <bool>(rows1.ElementAt(i).presence,
                                                      date.Substring(0, date.Length - 4) + "Z"));
                }
                break;

            case "LAST_WEEK":
                DomoticDAO.presenceDataTable rows2 = adapter.GetDataInLastHours(24 * 7);

                for (int i = 0; i < rows2.Count; i++)
                {
                    string date = rows2.ElementAt(i).time.ToString("o");
                    resp.record.Add(new Record <bool>(rows2.ElementAt(i).presence,
                                                      date.Substring(0, date.Length - 4) + "Z"));
                }
                break;

            default:
                throw new WebFaultException(System.Net.HttpStatusCode.BadRequest);
            }
            return(resp);
        }
Esempio n. 2
0
        public string insertValue(string dataType, ValueType value)
        {
            switch (dataType)
            {
            case "temperature":
                try
                {
                    DomoticDAOTableAdapters.temperatureTableAdapter adapter =
                        new DomoticDAOTableAdapters.temperatureTableAdapter();
                    adapter.InsertValue(value.Value);
                }
                catch (Exception e)
                {
                    return(e.Message);
                }
                break;

            case "luminosity":
                try
                {
                    DomoticDAOTableAdapters.luminosityTableAdapter adapter =
                        new DomoticDAOTableAdapters.luminosityTableAdapter();
                    adapter.InsertValue(value.Value);
                }
                catch (Exception e)
                {
                    return(e.Message);
                }
                break;

            case "light":
                try
                {
                    DomoticDAOTableAdapters.lightTableAdapter adapter =
                        new DomoticDAOTableAdapters.lightTableAdapter();
                    adapter.InsertValue(value.Value == 0 ? false : true);
                }
                catch (Exception e)
                {
                    return(e.Message);
                }
                break;

            case "presence":
                try
                {
                    DomoticDAOTableAdapters.presenceTableAdapter adapter =
                        new DomoticDAOTableAdapters.presenceTableAdapter();
                    adapter.InsertValue(value.Value == 0 ? false : true);
                }
                catch (Exception e)
                {
                    return(e.Message);
                }
                break;

            case "heather":
                try
                {
                    DomoticDAOTableAdapters.heatherTableAdapter adapter =
                        new DomoticDAOTableAdapters.heatherTableAdapter();
                    adapter.InsertValue(value.Value == 0 ? false : true);
                }
                catch (Exception e) {
                    return(e.Message);
                }
                break;

            case "automatic_light":
                try
                {
                    AutomaticLightsState = value.Value == 0 ? false : true;
                }
                catch (Exception e) {
                    return(e.Message);
                }
                break;

            case "automatic_heather":
                try
                {
                    AutomaticHeatherState = value.Value == 0 ? false : true;
                }
                catch (Exception e)
                {
                    return(e.Message);
                }
                break;

            default:

                return("KO");
            }
            return("OK");
        }