Exemple #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            getLongitudeLatitudeFromAddress();
            ndfdXML ndfd = new ndfdXML();

            ndfd.UserAgent = "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.107 Safari/537.36";
            outputBox.Text = ndfd.NDFDgen(Convert.ToDecimal(lat), Convert.ToDecimal(lon), "time-series", DateTime.Now.Date, DateTime.Now.Date, string.Empty, null);
        }
Exemple #2
0
 /// <summary>
 /// Initiate state nodes
 /// </summary>
 private void InitStates()
 {
     weatherService = new ndfdXML();
     states         = new List <State>();
     states.Add(new State("WA", 47.3030m, -120.1245m));
     states.Add(new State("TX", 31.1060m, -99.6475m));
     states.Add(new State("CA", 37.1700m, -119.7462m));
     states.Add(new State("GA", 32.9866m, -84.6487m));
     states.Add(new State("MT", 46.9048m, -110.3261m));
     states.Add(new State("CO", 39.0646m, -106.3272m));
     states.Add(new State("NV", 39.4199m, -117.1219m));
     states.Add(new State("AZ", 34.1112m, -112.0131m));
     states.Add(new State("MO", 38.4623m, -93.3020m));
     states.Add(new State("PA", 40.5773m, -79.2640m));
     states.Add(new State("WI", 44.2563m, -90.6385m));
     states.Add(new State("ND", 47.5362m, -100.7930m));
     states.Add(new State("NE", 41.1289m, -99.2883m));
 }
Exemple #3
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);
        }
        /// <summary>
        /// Gets the forecast for upcoming market day.
        /// </summary>
        /// <returns></returns>
        private static WeatherForecastData GetForecastForUpcomingMarket()
        {
            WeatherForecastData result;

            // determine the local date/time for the start of this Saturday's market
            int daysTilSaturday = DayOfWeek.Saturday - DateTime.Today.DayOfWeek;
            DateTime marketStarts = DateTime.Today.AddDays(daysTilSaturday).AddHours(8);

            // geographic location of Carpterter Village
            const decimal latitude = (decimal)35.8188612;
            const decimal longitude = (decimal)-78.8594969;

            // create an instance of the web service proxy
            var weatherFetcher = new ndfdXML {Proxy = WebRequest.DefaultWebProxy};

            // setup the parameters to tell the service what data we want
            // see http://www.nws.noaa.gov/forecasts/xml/docs/elementInputNames.php for parameters
            var weatherParams = new weatherParametersType
                                    {
                                        appt = true,
                                        icons = true,
                                        maxt = true,
                                        mint = true,
                                        pop12 = true,
                                        rh = true,
                                        wx = true,
                                        wwa = true,
                                        wspd = true
                                    };

            try
            {
                result = WeatherForecastData.Parse(weatherFetcher.NDFDgen(latitude, longitude, "time-series",
                    marketStarts.ToUniversalTime(), marketStarts.AddHours(4).ToUniversalTime(), weatherParams));
            }
            catch (Exception)
            {
                result = new WeatherForecastData();
            }

            return result;
        }
		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);
		}
Exemple #6
0
        public static void SetupNOAA(FlexCelReport reportStart, string CityName, string DataPath, bool UseOfflineData, Dictionary <string, LatLong> Cities)
        {
            LatLong CityCoords;

            GetCity(Cities, CityName, out CityCoords);
            reportStart.SetValue("Date", DateTime.Now);
            string   forecasts;
            DateTime dtStart = DateTime.Now;

            if (UseOfflineData)
            {
                using (StreamReader fs = new StreamReader(Path.Combine(DataPath, "OfflineData.xml")))
                {
                    forecasts = fs.ReadToEnd();
                }
            }
            else
            {
                ndfdXML nd = new ndfdXML();
                forecasts = nd.NDFDgen(CityCoords.Latitude, CityCoords.Longitude, productType.glance, dtStart, dtStart.AddDays(7), unitType.m, new weatherParametersType());

#if (SAVEOFFLINEDATA)
                using (StreamWriter sw = new StreamWriter(Path.Combine(DataPath, "OfflineData.xml")))
                {
                    sw.Write(forecasts);
                }
#endif
            }

            if (String.IsNullOrEmpty(forecasts))
            {
                throw new Exception("Can't find the place " + CityName);
            }

            DataSet ds = new DataSet();
            //Load the data into a dataset. On this web service, we cannot just call DataSet.ReadXml as the data is not on the correct format.
            XmlDocument xmlDoc = new XmlDocument();
            {
                xmlDoc.LoadXml(forecasts);
                XmlNodeList HighList = xmlDoc.SelectNodes("/dwml/data/parameters/temperature[@type='maximum']/value/text()");
                XmlNodeList LowList  = xmlDoc.SelectNodes("/dwml/data/parameters/temperature[@type='minimum']/value/text()");
                XmlNodeList IconList = xmlDoc.SelectNodes("/dwml/data/parameters/conditions-icon/icon-link/text()");

                DataTable WeatherTable = ds.Tables.Add("Weather");

                WeatherTable.Columns.Add("Day", typeof(DateTime));
                WeatherTable.Columns.Add("Low", typeof(double));
                WeatherTable.Columns.Add("High", typeof(double));
                WeatherTable.Columns.Add("Icon", typeof(byte[]));

                for (int i = 0; i < Math.Min(Math.Min(HighList.Count, LowList.Count), IconList.Count); i++)
                {
                    WeatherTable.Rows.Add(new object[] {
                        dtStart.AddDays(i),
                        Convert.ToDouble(LowList[i].Value),
                        Convert.ToDouble(HighList[i].Value),
                        LoadIcon(IconList[i].Value, UseOfflineData, DataPath)
                    });
                }
            }


            reportStart.AddTable(ds, TDisposeMode.DisposeAfterRun);
            reportStart.SetValue("Latitude", CityCoords.Latitude);
            reportStart.SetValue("Longitude", CityCoords.Longitude);
            reportStart.SetValue("Place", CityName);
        }