using System; using System.Data; using System.Configuration; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.Diagnostics; namespace WillemsWeerWachter { /// /// This friendly set of C# lines informs Willem of /// ultimate kiting possibilities. /// Created 8th of November, 2009 @ 22:54hrs /// public class WillemsWeerWachter : Worker { protected double minimumQuality = 85; public WillemsWeerWachter() : base("WillemsWeerWachter", 10) { Trace.WriteLine("WillemsWeerWachter: Up and running"); } protected override void doActualWork() { DateTime startSelect = DateTime.Now.AddDays(-1); DateTime endSelect = startSelect.AddDays(4); string select = "date>='" + startSelect + "' AND date<='" + endSelect + "'"; KiteForecast[] forecasts = WmDataIntermediar.getKiteForecasts(select); for (int i = 0; i < forecasts.Length; i++) { KiteForecast forecast = forecasts[i]; if (forecast.getConditionsQuality() >= minimumQuality && !forecast.WarnedWillem) { warnWillem(forecast); } } } protected void warnWillem(KiteForecast forecast) { double score = forecast.getConditionsQuality(); string subject = "Vliegermogelijkheid " + score.ToString() + "% op " + forecast.Date.ToShortDateString(); bool highPriority = false; if (score == 100) { highPriority = true; } string directionText = "-"; switch (forecast.WindDirection) { case WindDirection.EAST: directionText = "oost"; break; case WindDirection.NORTH: directionText = "noord"; break; case WindDirection.NORTH_EAST: directionText = "noordoost"; break; case WindDirection.NORTH_WEST: directionText = "noordwest"; break; case WindDirection.SOUTH: directionText = "zuid"; break; case WindDirection.SOUTH_EAST: directionText = "zuidoost"; break; case WindDirection.SOUTH_WEST: directionText = "zuidwest"; break; case WindDirection.WEST: directionText = "west"; break; } string lowTideText = "Laagwater om " + forecast.LowTide1Moment.ToShortTimeString()+" ("+forecast.LowTide1WaterPosition+" cm)"; if (forecast.LowTide2Moment.Date == forecast.Date.Date) { lowTideText = lowTideText + " en om " + forecast.LowTide2Moment.ToShortTimeString() + " ("+forecast.LowTide2WaterPosition+" cm)."; } else { lowTideText = lowTideText + "."; } string highTideText = "Hoogwater om " + forecast.HighTide1Moment.ToShortTimeString()+" ("+forecast.HighTide1WaterPosition+" cm)"; if (forecast.HighTide2Moment.Date == forecast.Date.Date) { highTideText = highTideText + " en om " + forecast.HighTide2Moment.ToShortTimeString() + " ("+forecast.HighTide2WaterPosition+" cm)."; } else { highTideText = highTideText + "."; } string body = "Hallo Willem, " + Environment.NewLine + Environment.NewLine + "Er is een vliegermogelijkheid op " + forecast.Date.ToShortDateString() + " met een Q waarde van " + score.ToString() + "%. Dat is " + Tools.getHumanDateString(forecast.Date, true, false, false) + "." + Environment.NewLine + Environment.NewLine + "Windkracht " + forecast.WindBeaufort + " " + directionText + "." + Environment.NewLine+ lowTideText + Environment.NewLine + highTideText + Environment.NewLine+ Environment.NewLine + "Kijk op http://kite.wmit.nl voor een compleet overzicht. " + Environment.NewLine + Environment.NewLine + "Groeten van Willem's Weerwachter"; if (Tools.sendMessage("W.L. Middelkoop", "wlm@wmit.nl", subject, body, highPriority)) { forecast.WarnedWillem = true; WmDataIntermediar.updateKiteForecast(forecast); Status status = WmDataIntermediar.getStatus(); status.WarningCount++; WmDataIntermediar.updateStatus(status); } } } }