private async Task <Metar> GetMetarAsync(string icao, bool isParse) { Metar met = null; if (!string.IsNullOrWhiteSpace(icao)) { var url = URL.Replace(@"#", icao.ToUpperInvariant()); using (var resp = await this.Client.GetAsync(url)) { using (var stream = await resp.Content.ReadAsStreamAsync()) { using (var reader = new StreamReader(stream)) { var date = new DateTime(DateTime.Parse(reader.ReadLine().Trim()).Ticks, DateTimeKind.Utc); var raw = reader.ReadLine().Trim(); met = new Metar(raw, date, icao); if (isParse) { met.Parse(); } } } } } return(met); }
//TODO Add above GetMetarAsync private IEnumerable <Metar> GetBulk(bool isParse) { var metList = new List <Metar>(); //TODO handle timeout etc using (var resp = this.Client.GetAsync(URLBULK).Result) { using (var stream = resp.Content.ReadAsStreamAsync().Result) { using (var gzStream = new GZipStream(stream, CompressionMode.Decompress)) { //TODO parallel using (var sr = new StreamReader(gzStream)) { //header flag (1st line) bool header = false; while (!sr.EndOfStream) { var line = sr.ReadLine(); var match = Regex.Match(line, SplittPatt); if (match.Success) { if (header) { var met = new Metar(match.Groups["rep"].Value, DateTime.Parse(match.Groups["time"].Value), match.Groups["icao"].Value); metList.Add(met); if (isParse) { met.Parse(); } } else { //Skip header line sr.ReadLine(); header = true; } } } } } } } return(metList); }