/* There are two ways of using this site. Either no parameters, then all graphs for all locations will * be generated, or with arguments (e.g. location=12345&duration=0) and only one graph will be generated */ public void update(String location, String duration) { String dbToUse = ""; dbToUse = "Surfvind_data"; WindData wd = new WindData(true, dbToUse); bool isMySQL = Convert.ToBoolean(ConfigurationManager.AppSettings["isMySQL"]); List <Location> loc = wd.GetLocations(); loc.Sort(); placeholder.InnerHtml += "Thomas " + loc.Count; if (!checkArguments(location, duration, loc)) { /* Update everything */ foreach (Location l in loc) { // Response.Write(l.imei.ToString()); this.location = l.imei.ToString(); wd.SetImei(this.location); for (int i = 0; i < 5; i++) { int interval = i; fetchData(i, wd); System.Web.UI.WebControls.Image a = new System.Web.UI.WebControls.Image(); a.Width = 800; a.Height = 200; a.ImageUrl = generateGraphOnServer(interval, 800, 200); placeholder.Controls.Add(a); } } } else { this.location = location; // Safe, we know this value can be parsed, we've tried it before int interval = int.Parse(duration); wd.SetImei(this.location); // Response.Write("Generate Graph"); fetchData(interval, wd); // Response.Write("Create Graph"); System.Web.UI.WebControls.Image a = new System.Web.UI.WebControls.Image(); a.Width = 800; a.Height = 200; a.ImageUrl = generateGraphOnServer(interval, 800, 200); placeholder.Controls.Add(a); } }
public void ProcessRequest(HttpContext context) { String imei = context.Request.QueryString["imei"]; String dbToUse = ""; dbToUse = "Surfvind_data"; WindData wd = new WindData(true, dbToUse); //bool isMySQL = true; wd.SetImei(imei); WindRecord wr = wd.GetCurrentWind(); Bitmap bitmap = new Bitmap(250, 100); Graphics g = Graphics.FromImage(bitmap); String text = "Speed: " + wr.AverageSpeed.ToString("F2") + " m/s"; String text2 = "Direction: " + wr.AverageDirection + " degrees"; String text3 = "Surfvind.se"; RectangleF rectH = new RectangleF(1, 5, 250, 30); RectangleF rect = new RectangleF(1, 40, 250, 30); RectangleF rect2 = new RectangleF(1, 70, 250, 30); StringFormat format = new StringFormat(); format.Alignment = StringAlignment.Center; Font font = new Font(FontFamily.GenericSansSerif, 15, FontStyle.Bold); Font font2 = new Font(FontFamily.GenericSansSerif, 20, FontStyle.Bold); g.DrawString(text, font, Brushes.Red, rect, format); g.DrawString(text2, font, Brushes.Red, rect2, format); g.DrawString(text3, font2, Brushes.Blue, rectH, format); Image img = null; /* * try * { * img = Image.FromFile(HttpContext.Current.Server.MapPath("~/Images/" + imei + "_img_compass.png")); * * } * catch { } * if (img != null) * { * g.DrawImage(img, 10, 10); * }*/ MemoryStream mem = new MemoryStream(); bitmap.Save(mem, ImageFormat.Png); byte[] buffer = mem.ToArray(); context.Response.ContentType = "image/png"; context.Response.BinaryWrite(buffer); context.Response.Flush(); }
/* There are two ways of using this site. Either no parameters, then all graphs for all locations will * be generated, or with arguments (e.g. location=12345&duration=0) and only one graph will be generated */ public void update(String location, String duration) { String dbToUse = ""; dbToUse = "Surfvind_data"; WindData wd = new WindData(true, dbToUse); bool isMySQL = Convert.ToBoolean(ConfigurationManager.AppSettings["isMySQL"]); List <Location> loc = wd.GetLocations(); loc.Sort(); if (!checkArguments(location, duration, loc)) { /* Update everything */ foreach (Location l in loc) { this.location = l.imei.ToString(); wd.SetImei(this.location); for (int i = 0; i < 5; i++) { this.interval = i; generateGraph(this.interval, this.location, wd); createGraph(); } } } else { this.location = location; /* Safe, we know this value can be parsed, we've tried it before */ this.interval = int.Parse(duration); wd.SetImei(this.location); generateGraph(this.interval, this.location, wd); createGraph(); } }
public void update2(String location) { String dbToUse = ""; dbToUse = "Surfvind_data"; WindData wd = new WindData(true, dbToUse); wd.SetImei(location); bool isMySQL = Convert.ToBoolean(ConfigurationManager.AppSettings["isMySQL"]); List <Location> loc = wd.GetLocations(); loc.Sort(); for (int i = 0; i < 3 /*5*/; i++) { this.interval = i; generateGraph(this.interval, location, wd); } }
protected void Page_Load(object sender, EventArgs e) { String location = Request.QueryString["location"]; Start = DateTime.Now; Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache); try { String dbToUse = "Surfvind_data"; bool isMySQL = Convert.ToBoolean(ConfigurationManager.AppSettings["isMySQL"]); WindData windData = new WindData(isMySQL, dbToUse); List <Location> allWeatherStations = windData.GetLocations(); allWeatherStations.Sort(); /* Populate location scrollbar */ populateLocationScrollbar(allWeatherStations); if (allWeatherStations.Count > 0) { imei = allWeatherStations.ToArray()[ddlWhere.SelectedIndex].imei.ToString(); } if (location != null) { int index = getIndexForLocation(allWeatherStations, location); if (index >= 0) { ddlWhere.SelectedIndex = index; imei = location; } } windData.SetImei(imei); /* Set google map location */ addGMap(allWeatherStations[ddlWhere.SelectedIndex]); GenGraphs graphGenerator = new GenGraphs(); graphGenerator.generateSensorImages(imei, windData); /* Get pre-stored direction and speed arrows */ imgSpeed.ImageUrl = "~/Images/" + imei + "_img_speed.png"; imgCompass.ImageUrl = "~/Images/" + imei + "_img_compass.png"; WindRecord wr = windData.GetCurrentWind(); if (wr.Moisture != 0) { // Set temp images air_temp.ImageUrl = "~/Images/" + imei + "_img_air_temp.png"; power.Text = wr.AverageWaterTemp + " V"; moisture.Text = wr.Moisture + " %"; air_temp.ToolTip = "Air temperature: " + wr.AverageAirTemp + " °C"; moisture_container.Visible = true; battery_container.Visible = true; temperature_container.Visible = true; } else { moisture_container.Visible = false; battery_container.Visible = false; temperature_container.Visible = false; } // Graphs are now generated on demand. graphGenerator.fetchData(2, windData); twentyFourHGraph.ImageUrl = graphGenerator.generateGraphOnServer(2, 1050, 250); graphGenerator.fetchData(1, windData); fiveHGraph.ImageUrl = graphGenerator.generateGraphOnServer(1, 1050, 250); /* Set the applet location */ setAppletLocation(windData); } catch (Exception eee) { debug.Width = 200; debug.Height = 200; debug.Text = eee.Message + "\n"; debug.Text += eee.StackTrace; } }
protected void Page_Load(object sender, EventArgs e) { String location = Request.QueryString["location"]; Start = DateTime.Now; Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache); try { LogTime(); String dbToUse = ""; dbToUse = "Surfvind_data"; LogTime(); WindData wd = new WindData(true, dbToUse); bool isMySQL = Convert.ToBoolean(ConfigurationManager.AppSettings["isMySQL"]); List <Location> loc = wd.GetLocations(); loc.Sort(); locations = loc; /* Populate location scrollbar */ populateLocationScrollbar(loc); if (loc.Count > 0) { imei = loc.ToArray()[ddlWhere.SelectedIndex].imei.ToString(); wd.SetImei(imei); /* Set google map location */ addGMap(loc[ddlWhere.SelectedIndex]); } GenGraphs t = new GenGraphs(); t.update2(imei); if (location != null) { OldSelectedIndex = ddlWhere.SelectedIndex; int index = getIndexForLocation(loc, location); if (index >= 0) { ddlWhere.SelectedIndex = index; imei = location; wd.SetImei(imei); } } /* Get pre-stored direction and speed arrows */ imgSpeed.ImageUrl = "~/Images/" + imei + "_img_speed.png"; imgCompass.ImageUrl = "~/Images/" + imei + "_img_compass.png"; if (imei == "12345") //Set this to the IMEI nbr that you use for developement of water air and humidity temp { // Set temp images water_temp.ImageUrl = "~/Images/" + imei + "_img_water_temp.png"; air_temp.ImageUrl = "~/Images/" + imei + "_img_air_temp.png"; int w_temp; int a_temp; WindRecord wr = wd.GetCurrentWind(); w_temp = wr.AverageWaterTemp; a_temp = wr.AverageAirTemp; water_temp.ToolTip = "Water temperature: " + w_temp + " °C"; air_temp.ToolTip = "Air temperature: " + a_temp + " °C"; Label1.Text = "Moisture: " + wr.Moisture + "%"; } else { air.Visible = false; moisture.Visible = false; water.Visible = false; } /* Set the applet location */ setAppletLocation(); twentyFourHGraph.ImageUrl = "~/Applet/" + imei + "/graph_2.png"; fiveHGraph.ImageUrl = "~/Applet/" + imei + "/graph_1.png"; } catch (Exception eee) { debug.Width = 200; debug.Height = 200; debug.Text = eee.Message + "\n"; debug.Text += eee.StackTrace; //Response.Redirect("~/ErrorPage.aspx"); } }