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"); }
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); }