Exemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="WeatherNode"/> class.
 /// </summary>
 /// <param name="src">Object to copy.</param>
 public WeatherNode(WeatherNode src)
     : base(src)
 {
     m_weatherCondition = src.m_weatherCondition;
     m_strState         = src.m_strState;
     m_fTemperature     = src.m_fTemperature;
 }
Exemplo n.º 2
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");
            }
        }