private List <ObservationDto> ConvertToDTO(response xmlObjs,
                                                   IList <string> icaos)
        {
            var            dtos = new List <ObservationDto>();
            ObservationDto obs  = null;

            if (xmlObjs.data?.METAR != null)
            {
                foreach (var metarXML in xmlObjs.data.METAR)
                {
                    obs = dtos.Where(o => o.ICAO == metarXML.station_id).FirstOrDefault();
                    if (obs == null)
                    {
                        obs = new ObservationDto();
                        ParseIdentifier(obs, metarXML);
                        ParseGeographicData(obs, metarXML);
                        dtos.Add(obs);
                    }
                    var metarDTO = new METARDto();
                    ParseCurrentWeatherData(metarDTO, metarXML);
                    Parse3HourWeatherData(metarDTO, metarXML);
                    Parse6HourWeatherData(metarDTO, metarXML);
                    Parse24HourWeatherData(metarDTO, metarXML);
                    ParseQualityControlFlags(metarDTO, metarXML);
                    obs.METAR.Add(metarDTO);
                }
            }

            dtos.AddRange(ParserHelpers.GetMissingStations(dtos, icaos));
            return(dtos);
        }
 private void Reset6HourDataIfNullValues(METARDto dto)
 {
     if (dto.SixHourData.Precipitation == null)
     {
         dto.SixHourData = null;
     }
 }
 private void ResetTemperatureRangeIfNullValues(METARDto dto)
 {
     if (dto.TemperatureRange.MaxTemperature == null &&
         dto.TemperatureRange.MinTemperature == null)
     {
         dto.TemperatureRange = null;
     }
 }
 private void Reset3HourDataIfNullValues(METARDto dto)
 {
     if (dto.ThreeHourObsData.Precipitation == null &&
         dto.ThreeHourObsData.PressureTendency == null)
     {
         dto.ThreeHourObsData = null;
     }
 }
 private void ResetWindDataIfNullValues(METARDto dto)
 {
     if (dto.Wind.Direction == null &&
         dto.Wind.Speed == null &&
         dto.Wind.Gust == null)
     {
         dto.Wind = null;
     }
 }
 private void Reset24HourDataIfNullValues(METARDto dto)
 {
     if (dto.TwentyFourHourData.MaxTemperature == null &&
         dto.TwentyFourHourData.MinTemperature == null &&
         dto.TwentyFourHourData.Precipitation == null)
     {
         dto.TwentyFourHourData = null;
     }
 }
 /// <summary>
 /// Transfers 6-hourly data
 /// </summary>
 /// <param name="dto"></param>
 /// <param name="xml"></param>
 private void Parse6HourWeatherData(METARDto dto, METAR xml)
 {
     if (xml.pcp6hr_inSpecified)
     {
         dto.SixHourData = new SixHourObsDataDto()
         {
             Precipitation = xml.pcp6hr_in
         };
     }
 }
 /// <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)
         };
     }
 }
 /// <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)
         };
     }
 }
        private void ParseQualityControlFlags(METARDto dto, METAR xml)
        {
            if (xml.quality_control_flags?.auto != null &&
                bool.Parse(xml.quality_control_flags.auto))
            {
                dto.QualityControlFlags.Add(QualityControlFlagType.Auto);
            }

            if (xml.quality_control_flags?.auto_station != null &&
                bool.Parse(xml.quality_control_flags.auto_station))
            {
                dto.QualityControlFlags.Add(QualityControlFlagType.AutoStation);
            }

            if (xml.quality_control_flags?.corrected != null &&
                bool.Parse(xml.quality_control_flags.corrected))
            {
                dto.QualityControlFlags.Add(QualityControlFlagType.Corrected);
            }

            if (xml.quality_control_flags?.freezing_rain_sensor_off != null &&
                bool.Parse(xml.quality_control_flags.freezing_rain_sensor_off))
            {
                dto.QualityControlFlags.Add(QualityControlFlagType.FreezingRainSensorOff);
            }

            if (xml.quality_control_flags?.lightning_sensor_off != null &&
                bool.Parse(xml.quality_control_flags.lightning_sensor_off))
            {
                dto.QualityControlFlags.Add(QualityControlFlagType.LightningSensorOff);
            }

            if (xml.quality_control_flags?.maintenance_indicator_on != null &&
                bool.Parse(xml.quality_control_flags.maintenance_indicator_on))
            {
                dto.QualityControlFlags.Add(QualityControlFlagType.MaintenanceIndicator);
            }

            if (xml.quality_control_flags?.no_signal != null &&
                bool.Parse(xml.quality_control_flags.no_signal))
            {
                dto.QualityControlFlags.Add(QualityControlFlagType.NoSignal);
            }

            if (xml.quality_control_flags?.present_weather_sensor_off != null &&
                bool.Parse(xml.quality_control_flags.present_weather_sensor_off))
            {
                dto.QualityControlFlags.Add(QualityControlFlagType.PresentWeatherSensorOff);
            }
        }
        /// <summary>
        /// Because not all properties will have values in each observation reset those fields that
        /// are objects which have no values
        /// </summary>
        /// <param name="dto"></param>
        private void ResetFieldsToNull(METARDto dto)
        {
            if (dto == null)
            {
                throw new ArgumentNullException($"'{nameof(dto)}' cannot be null.");
            }

            ResetWindDataIfNullValues(dto);

            ResetTemperatureRangeIfNullValues(dto);

            Reset3HourDataIfNullValues(dto);

            Reset6HourDataIfNullValues(dto);

            Reset24HourDataIfNullValues(dto);
        }
 /// <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)
         };
     }
 }