Ejemplo n.º 1
0
        public WebSiteResponse <bool> changeHeatherAutomatic(Stream input)
        {
            NameValueCollection nvc = parseFormString(input);

            switch (nvc["action"])
            {
            case "ON":
                if (sendRequestToBoard("PUT", "automatic_heather/on", null) != "\"OK\"")
                {
                    throw new WebFaultException(System.Net.HttpStatusCode.ServiceUnavailable);
                }
                break;

            case "OFF":
                if (sendRequestToBoard("PUT", "automatic_heather/off", null) != "\"OK\"")
                {
                    throw new WebFaultException(System.Net.HttpStatusCode.ServiceUnavailable);
                }
                break;

            default:
                throw new WebFaultException(System.Net.HttpStatusCode.BadRequest);
            }
            WebSiteResponse <bool> resp   = new WebSiteResponse <bool>();
            List <Record <bool> >  result = new List <Record <bool> >();

            result.Add(new Record <bool>(true, null));
            resp.record = result;
            return(resp);
        }
Ejemplo n.º 2
0
        public WebSiteResponse <bool> getHeatherStatus(string option)
        {
            WebSiteResponse <bool> response = new WebSiteResponse <bool>();
            List <Record <bool> >  result   = new List <Record <bool> >();

            switch (option)
            {
            case "status":
                DomoticDAOTableAdapters.heatherTableAdapter adapter =
                    new DomoticDAOTableAdapters.heatherTableAdapter();
                DomoticDAO.heatherDataTable last = adapter.GetLastDatum();
                if (last.Count > 0)
                {
                    string date = last.ElementAt(0).time.ToString("o");
                    result.Add(new Record <bool>(last.ElementAt(0).turned_on, date.Substring(0, date.Length - 4) + "Z"));
                }
                else
                {
                    result.Add(new Record <Boolean>(false, null));
                }
                break;

            case "automatic":
                result.Add(new Record <Boolean>(AutomaticHeatherState, null));
                break;

            default:
                throw new WebFaultException(System.Net.HttpStatusCode.BadRequest);
            }
            response.record = result;
            return(response);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
        public WebSiteResponse <double> getLuminosity()
        {
            List <Record <double> > result = new List <Record <double> >();

            DomoticDAOTableAdapters.luminosityTableAdapter adapter = new DomoticDAOTableAdapters.luminosityTableAdapter();
            DomoticDAO.luminosityDataTable e    = adapter.GetLastDatum();
            WebSiteResponse <double>       resp = new WebSiteResponse <double>();

            if (e.Count > 0)
            {
                string date = e.ElementAt(0).time.ToString("o");
                result.Add(new Record <double>(e.ElementAt(0).value,
                                               date.Substring(0, date.Length - 4) + "Z"));
            }
            resp.record = result;
            return(resp);
        }
Ejemplo n.º 5
0
        public WebSiteResponse <double> getTemperatureValues(string period)
        {
            WebSiteResponse <double> response = new WebSiteResponse <double>();

            switch (period)
            {
            case "LAST":
                DomoticDAOTableAdapters.temperatureTableAdapter adapter =
                    new DomoticDAOTableAdapters.temperatureTableAdapter();

                DomoticDAO.temperatureDataTable last = adapter.GetLastDatum();
                List <Record <double> >         res  = new List <Record <double> >();
                if (last.Count > 0)
                {
                    string date = last.ElementAt(0).time.ToString("o");
                    res.Add(new Record <double>(last.ElementAt(0).value, date.Substring(0, date.Length - 4) + "Z"));
                }
                response.record = res;
                break;

            case "TWELVE_HOUR":
                DomoticDAOTableAdapters.TemperatureByHoursTableAdapter qAdapter =
                    new DomoticDAOTableAdapters.TemperatureByHoursTableAdapter();
                DomoticDAO.TemperatureByHoursDataTable means12 = qAdapter.GetDataOverLast(12);
                List <Record <double> > res12 = new List <Record <double> >();
                for (int i = 0; i < means12.Count; i++)
                {
                    res12.Add(new Record <double>(means12.ElementAt(i).mean,
                                                  means12.ElementAt(i).anno + "-" + means12.ElementAt(i).mese.ToString("D2") + "-"
                                                  + means12.ElementAt(i).giorno.ToString("D2") + "T" + means12.ElementAt(i).hour.ToString("D2")
                                                  + ":00:00.000Z"));
                }
                response.record = res12;
                break;

            case "TWENTYFOUR_HOUR":
                DomoticDAOTableAdapters.TemperatureByHoursTableAdapter tAdapter =
                    new DomoticDAOTableAdapters.TemperatureByHoursTableAdapter();
                DomoticDAO.TemperatureByHoursDataTable means24 = tAdapter.GetDataOverLast(24);
                List <Record <double> > res24 = new List <Record <double> >();
                for (int i = 0; i < means24.Count; i++)
                {
                    res24.Add(new Record <double>(means24.ElementAt(i).mean,
                                                  means24.ElementAt(i).anno + "-" + means24.ElementAt(i).mese.ToString("D2") + "-"
                                                  + means24.ElementAt(i).giorno.ToString("D2") + "T" + means24.ElementAt(i).hour.ToString("D2")
                                                  + ":00:00.000Z"));
                }
                response.record = res24;
                break;

            case "LAST_WEEK":
                DomoticDAOTableAdapters.TemperatureByDaysTableAdapter wAdapter =
                    new DomoticDAOTableAdapters.TemperatureByDaysTableAdapter();
                DomoticDAO.TemperatureByDaysDataTable means_week = wAdapter.GetData(7);
                List <Record <double> > res_week = new List <Record <double> >();
                for (int i = 0; i < means_week.Count; i++)
                {
                    res_week.Add(new Record <double>(means_week.ElementAt(i).mean,
                                                     means_week.ElementAt(i).anno + "-" + means_week.ElementAt(i).mese.ToString("D2") + "-"
                                                     + means_week.ElementAt(i).giorno.ToString("D2")
                                                     + "T00:00:00.000Z"));
                }
                response.record = res_week;
                break;

            default:
                throw new WebFaultException(System.Net.HttpStatusCode.BadRequest);
            }
            return(response);
        }