Example #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);
        }
        /// <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;
        }
Example #3
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);
        }