public string get7DayLowAndHigh(string zip, DateTime beginDateTime) { // Get latitude and longitude from zip code string latLonXml = soapService.LatLonListZipCode(zip); string latLon = XmlParser.ParseZipXml(latLonXml); // Get the forecast string forecast = soapService.NDFDgenLatLonList(latLon, productType.glance, beginDateTime, beginDateTime.AddDays(7), unitType.e, new weatherParametersType() { mint = true, maxt = true }); // Parse and return a string with the forecast return(XmlParser.ParseLowsXml(forecast)); }
public async void ProcessZipcode(string zipcode) { XDocument xdoc; try { xdoc = await Task.Run(() => { ndfdXML weather = new ndfdXML(); string latLonXml = weather.LatLonListZipCode(zipcode); XDocument xdoc2 = XDocument.Parse(latLonXml); string[] latLon = xdoc2.Element("dwml").Element("latLonList").Value.Split(','); if (String.IsNullOrEmpty(latLon[0])) { return(null); } decimal lat = Convert.ToDecimal(latLon[0]); decimal lon = Convert.ToDecimal(latLon[1]); string weatherXml = weather.NDFDgenByDay(lat, lon, DateTime.Now, "1", "e", "24 hourly"); xdoc2 = XDocument.Parse(weatherXml); return(xdoc2); }); } catch (Exception ex) { EmitException(ex); return; } if (xdoc == null) { EmitException(new Exception("Bad zipcode: " + zipcode)); } ISemanticTypeStruct outProtocol = rsys.SemanticTypeSystem.GetSemanticTypeStruct("WeatherInfo"); dynamic outSignal = rsys.SemanticTypeSystem.Create("WeatherInfo"); try { outSignal.Zipcode = zipcode; outSignal.Low = xdoc.Element("dwml").Element("data").Element("parameters").Elements("temperature").Where(el => el.Attribute("type").Value == "minimum").Single().Element("value").Value.Trim(); outSignal.High = xdoc.Element("dwml").Element("data").Element("parameters").Elements("temperature").Where(el => el.Attribute("type").Value == "maximum").Single().Element("value").Value.Trim(); outSignal.Summary = xdoc.Element("dwml").Element("data").Element("parameters").Element("weather").Element("weather-conditions").Attribute("weather-summary").Value; outSignal.Conditions = new List <dynamic>(); outSignal.Hazards = new List <dynamic>(); // Process Conditions: var weatherElements = xdoc.Element("dwml").Element("data").Element("parameters").Element("weather").Element("weather-conditions").Elements("value"); weatherElements.ForEach(v => { dynamic condition = rsys.SemanticTypeSystem.Create("WeatherCondition"); if (v.Attribute("additive") != null) { condition.Additive = v.Attribute("additive").Value; } condition.Coverage = v.Attribute("coverage").Value; condition.Intensity = v.Attribute("intensity").Value; condition.WeatherType = v.Attribute("weather-type").Value; condition.Qualifier = v.Attribute("qualifier").Value; outSignal.Conditions.Add(condition); }); // Process hazards var hazardElements = xdoc.Element("dwml").Element("data").Element("parameters").Element("hazards").Element("hazard-conditions").Elements("hazard"); hazardElements.ForEach(h => { dynamic hazard = rsys.SemanticTypeSystem.Create("WeatherHazard"); hazard.Phenomena = h.Attribute("phenomena").Value; hazard.Significance = h.Attribute("significance").Value; outSignal.Hazards.Add(hazard); }); } catch (Exception ex) { EmitException(ex); return; } rsys.CreateCarrier(this, outProtocol, outSignal); }
public async void ProcessZipcode(string zipcode) { XDocument xdoc; try { xdoc = await Task.Run(() => { ndfdXML weather = new ndfdXML(); string latLonXml = weather.LatLonListZipCode(zipcode); XDocument xdoc2 = XDocument.Parse(latLonXml); string[] latLon = xdoc2.Element("dwml").Element("latLonList").Value.Split(','); if (String.IsNullOrEmpty(latLon[0])) { return null; } decimal lat = Convert.ToDecimal(latLon[0]); decimal lon = Convert.ToDecimal(latLon[1]); string weatherXml = weather.NDFDgenByDay(lat, lon, DateTime.Now, "1", "e", "24 hourly"); xdoc2 = XDocument.Parse(weatherXml); return xdoc2; }); } catch (Exception ex) { EmitException(ex); return; } if (xdoc == null) { EmitException(new Exception("Bad zipcode: "+zipcode)); } ISemanticTypeStruct outProtocol = rsys.SemanticTypeSystem.GetSemanticTypeStruct("WeatherInfo"); dynamic outSignal = rsys.SemanticTypeSystem.Create("WeatherInfo"); try { outSignal.Zip5.Value = zipcode; outSignal.Low = xdoc.Element("dwml").Element("data").Element("parameters").Elements("temperature").Where(el => el.Attribute("type").Value == "minimum").Single().Element("value").Value.Trim(); outSignal.High = xdoc.Element("dwml").Element("data").Element("parameters").Elements("temperature").Where(el => el.Attribute("type").Value == "maximum").Single().Element("value").Value.Trim(); outSignal.Summary = xdoc.Element("dwml").Element("data").Element("parameters").Element("weather").Element("weather-conditions").Attribute("weather-summary").Value; outSignal.Conditions = new List<dynamic>(); outSignal.Hazards = new List<dynamic>(); // Process Conditions: var weatherElements = xdoc.Element("dwml").Element("data").Element("parameters").Element("weather").Element("weather-conditions").Elements("value"); weatherElements.ForEach(v => { dynamic condition = rsys.SemanticTypeSystem.Create("WeatherCondition"); if (v.Attribute("additive") != null) { condition.Additive = v.Attribute("additive").Value; } condition.Coverage = v.Attribute("coverage").Value; condition.Intensity = v.Attribute("intensity").Value; condition.WeatherType = v.Attribute("weather-type").Value; condition.Qualifier = v.Attribute("qualifier").Value; outSignal.Conditions.Add(condition); }); // Process hazards var hazardElements = xdoc.Element("dwml").Element("data").Element("parameters").Element("hazards").Element("hazard-conditions").Elements("hazard"); hazardElements.ForEach(h => { dynamic hazard = rsys.SemanticTypeSystem.Create("WeatherHazard"); hazard.Phenomena = h.Attribute("phenomena").Value; hazard.Significance = h.Attribute("significance").Value; outSignal.Hazards.Add(hazard); }); } catch (Exception ex) { EmitException(ex); return; } rsys.CreateCarrier(this, outProtocol, outSignal); }