Example #1
0
		protected void Page_Load(object sender, EventArgs e)
		{
			List<SensorElement> arrElements = new List<SensorElement>();
			SqlConnection conn = new SqlConnection();
			conn.ConnectionString = "Data Source=hrr4eyxqec.database.windows.net;Initial Catalog=SensorSource;User ID=SensorReader;Password=P}Sd8df&sdf5{sdf0f|>;";
			conn.Open();			
			SqlCommand cmd = new SqlCommand("SELECT * FROM Sensors", conn);
			SqlDataReader readerTmp = cmd.ExecuteReader();
			while (readerTmp.Read())
			{
				if (Boolean.Parse(readerTmp["IsMonitored"].ToString()) == true)
				{
					SensorElement elementTmp = new SensorElement
					{
						sensorId = int.Parse(readerTmp["ID"].ToString()),
						sensorName = readerTmp["Name"].ToString(),
						sensorDescription = readerTmp["Description"].ToString(),
						isMonitored = Boolean.Parse(readerTmp["IsMonitored"].ToString()),
						value = ""
					};
					arrElements.Add(elementTmp);
				}
			}
			
			readerTmp.Close();
			conn.Close();
			Response.ContentType = "application/json";
			Response.Write("{");
			Response.Write('"');
			Response.Write("data");
			Response.Write('"');
			Response.Write(":" + JsonConvert.SerializeObject(arrElements));
			Response.Write("}");
			Response.End();
		}
Example #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            List <SensorElement> arrElements = new List <SensorElement>();
            SqlConnection        conn        = new SqlConnection();

            conn.ConnectionString = "Data Source=hrr4eyxqec.database.windows.net;Initial Catalog=SensorSource;User ID=SensorReader;Password=P}Sd8df&sdf5{sdf0f|>;";
            conn.Open();
            SqlCommand    cmd       = new SqlCommand("SELECT * FROM Sensors", conn);
            SqlDataReader readerTmp = cmd.ExecuteReader();

            while (readerTmp.Read())
            {
                if (Boolean.Parse(readerTmp["IsMonitored"].ToString()) == true)
                {
                    SensorElement elementTmp = new SensorElement
                    {
                        sensorId          = int.Parse(readerTmp["ID"].ToString()),
                        sensorName        = readerTmp["Name"].ToString(),
                        sensorDescription = readerTmp["Description"].ToString(),
                        isMonitored       = Boolean.Parse(readerTmp["IsMonitored"].ToString()),
                        value             = ""
                    };
                    arrElements.Add(elementTmp);
                }
            }

            readerTmp.Close();
            conn.Close();
            Response.ContentType = "application/json";
            Response.Write("{");
            Response.Write('"');
            Response.Write("data");
            Response.Write('"');
            Response.Write(":" + JsonConvert.SerializeObject(arrElements));
            Response.Write("}");
            Response.End();
        }