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);
		}
Example #2
0
        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);
        }
Example #3
0
        /// <summary>
        /// Generate the reports
        /// </summary>
        private void GenerateReport()
        {
            records = new NodeCollection();
            maximum = states.Count;
            try
            {
                foreach (State state in states)
                {
                    weatherParametersType weatherType = new weatherParametersType();

                    //specifies parameters maximum temperature, weather condition and cloud amount
                    weatherType.maxt = true;
                    weatherType.sky  = true;
                    weatherType.wx   = true;


                    // call the weather service.
                    //weatherService.NDFDgenAsync(state.Latitude, state.Longitude, productType.timeseries, DateTime.Now.Date, DateTime.Now.AddDays(1).Date, unitType.e, weatherType, state);
                    string      str  = weatherService.NDFDgenByDay(state.Latitude, state.Longitude, DateTime.Now.Date, "1", unitType.e, formatType.Item24hourly);
                    WeatherNode node = new WeatherNode();

                    // get coordinates on map.
                    PointF location = ConvertCoordinates(state.Latitude, state.Longitude);
                    node.PinPoint = new PointF(location.X - node.Size.Width / 2, location.Y - node.Size.Height / 2);
                    node.State    = node.Name = state.Name;
                    if (!string.IsNullOrEmpty(str))
                    {
                        XmlDocument doc = new XmlDocument();
                        doc.LoadXml(str);
                        node.Temperature = XmlConvert.ToDecimal(doc.SelectSingleNode("dwml/data/parameters/temperature[@type='maximum']/value/text()").Value);
                        XmlNode n       = doc.SelectSingleNode("dwml/data/parameters/weather/weather-conditions/value");
                        string  weather = null;
                        if (n != null)
                        {
                            XmlAttribute attr = n.Attributes["weather-type"];
                            if (attr != null)
                            {
                                weather = n.Attributes["weather-type"].Value;
                            }
                        }
                        if (weather == "freezing rain" ||
                            weather == "rain" ||
                            weather == "hail" ||
                            weather == "rain showers" ||
                            weather == "freezing drizzle" ||
                            weather == "drizzle")
                        {
                            node.WeatherCondition = WeatherCondition.Rain;
                        }
                        else if (weather == "show showers" ||
                                 weather == "blowing snow" ||
                                 weather == "snow" ||
                                 weather == "ice pellets")
                        {
                            node.WeatherCondition = WeatherCondition.Snow;
                        }
                        else if (weather == "thunderstorms")
                        {
                            node.WeatherCondition = WeatherCondition.ThunderStorm;
                        }
                        else
                        {
                            node.WeatherCondition = WeatherCondition.None;
                        }

                        records.Add(node);
                        value++;
                        backgroundWorker1.ReportProgress(value);
                    }
                }
            }
            catch (Exception exp)
            {
                MessageBox.Show("Failed to establish connection with the service provider");
            }
        }