/// <summary>
 /// Transfer 3-Hourly data
 /// </summary>
 /// <param name="dto"></param>
 /// <param name="xml"></param>
 private void Parse3HourWeatherData(METARDto dto, METAR xml)
 {
     if (xml.pcp3hr_inSpecified || xml.three_hr_pressure_tendency_mbSpecified)
     {
         dto.ThreeHourObsData = new ThreeHourObsData()
         {
             Precipitation    = ParserHelpers.GetValue(xml.pcp3hr_inSpecified, xml.pcp3hr_in),
             PressureTendency = ParserHelpers.GetValue(xml.three_hr_pressure_tendency_mbSpecified, xml.three_hr_pressure_tendency_mb)
         };
     }
 }
        private void ParseForecastData(TAFDto dto, forecast[] xml)
        {
            var lineNumber = 0;

            foreach (var line in xml)
            {
                var lineDto = new TAFLineDto();
                lineDto.Altimeter         = ParserHelpers.GetValue(line.altim_in_hgSpecified, line.altim_in_hg);
                lineDto.ForecastTimeEnd   = ParserHelpers.ParseDateTime(line.fcst_time_to);
                lineDto.ForecastTimeStart = ParserHelpers.ParseDateTime(line.fcst_time_from);
                if (line.sky_condition != null)
                {
                    lineDto.SkyCondition.AddRange(line.sky_condition
                                                  .Select(sc => GetSkyCondition(sc)));
                }

                // First line may not have an change type
                if (lineNumber > 0 &&
                    !String.IsNullOrWhiteSpace(line.change_indicator))
                {
                    lineDto.ChangeIndicator = ChangeIndicatorType.GetByName(line.change_indicator);
                }
                if (line.icing_condition != null)
                {
                    lineDto.IcingHazards.AddRange(line.icing_condition
                                                  .Where(ic => !String.IsNullOrWhiteSpace(ic.icing_intensity))
                                                  .Select(ic => GetHazard(ic)));
                }

                if (line.turbulence_condition != null)
                {
                    lineDto.TurbulenceHazards.AddRange(line.turbulence_condition
                                                       .Where(tb => !String.IsNullOrWhiteSpace(tb.turbulence_intensity))
                                                       .Select(tb => GetHazard(tb)));
                }

                lineDto.VerticalVisibility = ParserHelpers.GetValue(
                    line.vert_vis_ftSpecified, line.vert_vis_ft);
                lineDto.Visibility = ParserHelpers.GetValue(
                    line.visibility_statute_miSpecified, line.visibility_statute_mi);
                lineDto.Weather = line.wx_string;

                lineDto.Wind = GetWind(line);

                lineDto.WindShear = GetWindSheer(line);

                dto.TAFLine.Add(lineDto);
                lineNumber++;
            }
        }
 /// <summary>
 /// Transfers 24-hourly data
 /// </summary>
 /// <param name="dto"></param>
 /// <param name="xml"></param>
 private void Parse24HourWeatherData(METARDto dto, METAR xml)
 {
     if (xml.pcp24hr_inSpecified ||
         xml.maxT24hr_cSpecified ||
         xml.minT24hr_cSpecified)
     {
         dto.TwentyFourHourData = new TwentyFourHourObsDataDto()
         {
             Precipitation  = ParserHelpers.GetValue(xml.pcp24hr_inSpecified, xml.pcp24hr_in),
             MaxTemperature = ParserHelpers.GetValue(xml.maxT24hr_cSpecified, xml.maxT24hr_c),
             MinTemperature = ParserHelpers.GetValue(xml.minT24hr_cSpecified, xml.minT24hr_c)
         };
     }
 }
        public WindDto GetWind(forecast xml)
        {
            if (!xml.wind_dir_degreesSpecified &&
                !xml.wind_speed_ktSpecified)
            {
                return(null);
            }

            return(new WindDto()
            {
                Gust = ParserHelpers.GetValue(xml.wind_gust_ktSpecified, xml.wind_gust_kt),
                Speed = ParserHelpers.GetValue(xml.wind_speed_ktSpecified, xml.wind_speed_kt),
                Direction = ParserHelpers.GetValue(xml.wind_dir_degreesSpecified, xml.wind_dir_degrees)
            });
        }
        public WindShearDto GetWindSheer(forecast xml)
        {
            if (!xml.wind_shear_hgt_ft_aglSpecified &&
                !xml.wind_shear_dir_degreesSpecified &&
                !xml.wind_shear_speed_ktSpecified)
            {
                return(null);
            }

            return(new WindShearDto()
            {
                Direction = ParserHelpers.GetValue(xml.wind_shear_dir_degreesSpecified, xml.wind_shear_dir_degrees),
                Height = ParserHelpers.GetValue(xml.wind_shear_hgt_ft_aglSpecified, xml.wind_shear_hgt_ft_agl),
                Speed = ParserHelpers.GetValue(xml.wind_shear_speed_ktSpecified, xml.wind_shear_speed_kt)
            });
        }
 /// <summary>
 /// Trnasfers the core weather observation data
 /// </summary>
 /// <param name="dto"></param>
 /// <param name="xml"></param>
 private void ParseCurrentWeatherData(METARDto dto, METAR xml)
 {
     dto.Altimeter        = xml.altim_in_hg;
     dto.Dewpoint         = ParserHelpers.GetValue(xml.dewpoint_cSpecified, xml.dewpoint_c);
     dto.ObsTime          = ParserHelpers.ParseDateTime(xml.observation_time);
     dto.Precipitation    = ParserHelpers.GetValue(xml.precip_inSpecified, xml.precip_in);
     dto.Snow             = ParserHelpers.GetValue(xml.snow_inSpecified, xml.snow_in);
     dto.RawMETAR         = xml.raw_text;
     dto.SeaLevelPressure = ParserHelpers.GetValue(xml.sea_level_pressure_mbSpecified, xml.sea_level_pressure_mb);
     if (xml.sky_condition != null)
     {
         dto.SkyCondition.AddRange(xml.sky_condition.Select(sc => new SkyConditionDto()
         {
             SkyCondition = SkyConditionType.ByName(sc.sky_cover),
             CloudBase    = sc.cloud_base_ft_agl
         }));
     }
     dto.Temperature        = ParserHelpers.GetValue(xml.temp_cSpecified, xml.temp_c);
     dto.VerticalVisibility = ParserHelpers.GetValue(xml.vert_vis_ftSpecified, xml.vert_vis_ft);
     dto.Visibility         = ParserHelpers.GetValue(xml.visibility_statute_miSpecified, xml.visibility_statute_mi);
     dto.Weather            = xml.wx_string;
     dto.Wind = new WindDto()
     {
         Direction = ParserHelpers.GetValue(xml.wind_dir_degreesSpecified, xml.wind_dir_degrees),
         Gust      = ParserHelpers.GetValue(xml.wind_gust_ktSpecified, xml.wind_gust_kt),
         Speed     = ParserHelpers.GetValue(xml.wind_speed_ktSpecified, xml.wind_speed_kt)
     };
     dto.FlightCategory = FlightCategoryType.ByName(xml.flight_category);
     dto.ObsType        = METARType.ByName(xml.metar_type);
     if (xml.maxT_cSpecified || xml.minT_cSpecified)
     {
         dto.TemperatureRange = new TemperatureRangeDto()
         {
             MaxTemperature = ParserHelpers.GetValue(xml.maxT_cSpecified, xml.maxT_c),
             MinTemperature = ParserHelpers.GetValue(xml.minT_cSpecified, xml.minT_c)
         };
     }
 }