コード例 #1
0
ファイル: MetarParserTest.cs プロジェクト: mlowijs/MetarLib
        public void Full_METAR_message_1()
        {
            const string metarText = "METAR EHBK 271025Z AUTO 23007KT 160V300 9999 NSC 18/04 Q1008 NOSIG=";

            var metars = _metarParser.Parse(metarText).ToArray();
            var metar  = metars.Single();

            Assert.AreEqual("EHBK", metar.IcaoLocationCode);

            Assert.AreEqual(27, metar.TimeOfObservation.Day);
            Assert.AreEqual(10, metar.TimeOfObservation.Hour);
            Assert.AreEqual(25, metar.TimeOfObservation.Minute);

            Assert.IsTrue(metar.IsAutomaticObservation);

            Assert.AreEqual(230, metar.WindDirection);
            Assert.AreEqual(7, metar.WindSpeed);
            Assert.AreEqual(UnitOfSpeed.Knots, metar.WindSpeedUnit);

            Assert.AreEqual(160, metar.WindVaryingFrom);
            Assert.AreEqual(300, metar.WindVaryingTo);

            Assert.AreEqual(9999, metar.Visibility);
            Assert.AreEqual(UnitOfLength.Meters, metar.VisibilityUnit);

            Assert.AreEqual(CloudCoverage.NoSignificantCloud, metar.Clouds.First().Coverage);

            Assert.AreEqual(18, metar.Temperature);
            Assert.AreEqual(4, metar.Dewpoint);

            Assert.AreEqual(1008, metar.AltimeterSetting);
            Assert.AreEqual(UnitOfPressure.Hectopascals, metar.AltimeterSettingUnit);
        }
コード例 #2
0
        public async Task <Metar> GetMetarAsync(string icao)
        {
            using (var httpClient = new HttpClient())
            {
                var response = await httpClient.GetAsync($"{BaseUrl}{icao}");

                var xmlStream = await response.Content.ReadAsStreamAsync();

                var doc = XDocument.Load(xmlStream);

                try
                {
                    var metarText = doc.Descendants().FirstOrDefault(element => element.Name == "raw_text").Value;
                    return(_metarParser.Parse(metarText));
                }
                catch
                {
                    return(null);
                }
            }
        }