public int[] GetForcastedHighs() { string dwmlReturn; //Cache by Zip and Process if (!IsCached("ForcasedHighs")) { gov.weather.graphical.weatherParametersType weatherParameters = new gov.weather.graphical.weatherParametersType(); //Set Weather Parameters to get max temp. weatherParameters.maxt = true; //Call web service dwmlReturn = CallWebService(weatherParameters); if (dwmlReturn == null) { return(null); } CacheXML(dwmlReturn, "ForcasedHighs"); } else { dwmlReturn = GetCachedXMLbyProcess("ForcasedHighs"); if (dwmlReturn == null) { return(null); } } var temperatureXElement = XElement.Parse(dwmlReturn); var maxTemps = temperatureXElement.Descendants("temperature") .Where(e => (string)e.Element("name") == "Daily Maximum Temperature") .SelectMany(e => e.Elements("value")) .Select(e => (int)e); //Return Array return(maxTemps.ToArray()); }
public string getWeather(string zip) { gov.weather.graphical.ndfdXML gg = new gov.weather.graphical.ndfdXML(); gov.weather.graphical.weatherParametersType pa = new gov.weather.graphical.weatherParametersType(); pa.maxt = true; pa.mint = true; // pa.iceaccum = true; pa.dryfireo = true; //pa.dew = true; string information = gg.LatLonListZipCode("85281"); int x = information.IndexOf("</latLonList>"); int y = information.IndexOf("<latLonList>"); string location = information.Substring(information.IndexOf("<latLonList>") + 12, information.IndexOf("</latLonList>") - information.IndexOf("<latLonList>") - 12); string[] lat = location.Split(','); //33.4357,-111.917 string w = gg.NDFDgen(Convert.ToDecimal(lat[0]), Convert.ToDecimal(lat[1]), "time-series", DateTime.Now, DateTime.Now.AddDays(4), "e", pa); string TMbeg = "<name>Daily Maximum Temperature</name>"; string TMend = "</temperature>"; string Mtemepeture = w.Substring(w.IndexOf(TMbeg) + TMbeg.Length, w.IndexOf(TMend) - w.IndexOf(TMbeg) - TMbeg.Length); Mtemepeture = Mtemepeture.Trim(); string[] max = System.Text.RegularExpressions.Regex.Split(Mtemepeture, "\n"); returnTempeture = "Max Temepture: " + Regex.Replace(max[0], @"[^\d.\d]", ""); for (int i = 1; i < max.Length; i++) { returnTempeture = returnTempeture + ","; returnTempeture = returnTempeture + Regex.Replace(max[i], @"[^\d.\d]", ""); } string TNbeg = "<name>Daily Minimum Temperature</name>"; string duplicate = "</temperature>"; string TNend = "<fire"; int ee = w.IndexOf(TNend); int e = w.IndexOf(TMend); string Ntemepeture = w.Substring(w.IndexOf(TNbeg) + TNbeg.Length, w.IndexOf(TNend) - w.IndexOf(TNbeg) - TNbeg.Length); Ntemepeture = Ntemepeture.Trim(); Ntemepeture = Ntemepeture.Substring(0, Ntemepeture.Length - duplicate.Length).Trim(); string[] min = System.Text.RegularExpressions.Regex.Split(Ntemepeture, "\n"); returnTempeture = returnTempeture + "\n"; returnTempeture = returnTempeture + "Min Temepture: " + Regex.Replace(min[0], @"[^\d.\d]", ""); for (int i = 1; i < min.Length; i++) { returnTempeture = returnTempeture + ","; returnTempeture = returnTempeture + Regex.Replace(min[i], @"[^\d.\d]", ""); } return(returnTempeture); }
/* This portion of code is executed when the submit button is clicked * * Instantiation of a new Service reference ndfdXML ~ for client's SOAP connection to the weather service * * Accept input from textboxes (Location coordinate) * --+ Latitude => lat * --+ Longitude => lng * * Call the method for the current weather observation (NDFDgenByDay) from the weather service class * --+ return result as a string * --+ write the result to a file in form of XML * --+ handle the appropriate nodes and get their values */ protected void submitButton_Click(object sender, EventArgs e) { gov.weather.graphical.ndfdXML myweather = new gov.weather.graphical.ndfdXML(); try { // Get input form textboxes decimal lat = Decimal.Parse(txtLatitude.Text); // latitude value decimal lng = Decimal.Parse(txtLongitude.Text); // longitude value string numOfDays = "1"; // number of days for weather observations to be fetched gov.weather.graphical.weatherParametersType wth_para = new gov.weather.graphical.weatherParametersType(); wth_para.temp = true; // call the method for the current observation (NDFDgenByDay) to get weather information string result = myweather.NDFDgenByDay(lat, lng, DateTime.UtcNow, numOfDays, gov.weather.graphical.unitType.e, gov.weather.graphical.formatType.Item12hourly); // define the directory path to write result (current observation) from the national weather service station string result_path = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "", "result.xml"); // write the result to a file on the created path System.IO.StreamWriter file = new System.IO.StreamWriter(result_path); file.WriteLine(result); file.Close(); XmlDocument result_xml = new XmlDocument(); result_xml.Load(result_path); // load the XML file from the path // process the nodes needed from the XML file XmlNode max_temp_node = result_xml.SelectSingleNode("//data/parameters/temperature[@type ='maximum']/value/text()"); XmlNode min_temp_node = result_xml.SelectSingleNode("//data/parameters/temperature[@type ='minimum']/value/text()"); XmlNode prob_prep = result_xml.SelectSingleNode("//data/parameters/probability-of-precipitation/value/text()"); XmlNode weather_icon = result_xml.SelectSingleNode("//data/parameters/conditions-icon/icon-link/text()"); string maxTemperature = max_temp_node.Value; // get maximum temperature value string minTemperature = min_temp_node.Value; // get minimum temperature value string probOfPrepipitation = prob_prep.Value; // get probability of precipitation value string weatherIcon = weather_icon.Value; // get the weather icon value // pass the corresponding values from the nodes to its specific label Label3.Text = maxTemperature; Label5.Text = minTemperature; Label10.Text = probOfPrepipitation; Label12.Text = "<img alt='' src='" + weatherIcon + "' />"; }catch (Exception ex) { System.Web.HttpContext.Current.Response.Write("<SCRIPT LANGUAGE='JavaScript'>alert('" + ex.Message + "')</SCRIPT>"); } }
private string CallWebService(gov.weather.graphical.weatherParametersType weatherParameters) { try { gov.weather.graphical.ndfdXML ndfdClient = new gov.weather.graphical.ndfdXML(); string latlonglist = GetLatLongListFromZip(); if (latlonglist == ",") { return(null); } string dwmlReturn = ndfdClient.NDFDgenLatLonList(latlonglist, gov.weather.graphical.productType.timeseries, DateTime.Today, DateTime.Today.AddDays(7), gov.weather.graphical.unitType.e, weatherParameters); return(dwmlReturn); } catch (Exception e) { NdfdErrorHandler(e); return(null); } }