private async Task <Taf> GetTafAsync(string icao, bool isParse) { Taf taf = 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 serverDate = new DateTime(DateTime.Parse(reader.ReadLine().Trim()).Ticks, DateTimeKind.Utc); var temp = Regex.Replace(reader.ReadToEnd(), @"\s+", " "); //var raw = Regex.Split(temp.Replace('\n', ' '), SplitPatt); taf = new Taf(temp, serverDate); if (isParse) { taf.Parse(); } } } } } return(taf); }
private async Task <IEnumerable <Taf> > GetBulkAsync(bool isParse) { var tafList = new List <Taf>(); //TODO handle timeout etc using (var resp = await this.Client.GetAsync(URLBULK)) { using (var stream = await resp.Content.ReadAsStreamAsync()) { using (var gzStream = new GZipStream(stream, CompressionMode.Decompress)) { //TODO Parallel using (var sr = new StreamReader(gzStream)) { var header = false;//Skip header line while (!sr.EndOfStream) { var line = sr.ReadLine(); var match = Regex.Match(line, SplittPatt); if (match.Success) { if (header) { var taf = new Taf(match.Groups["rep"].Value.Replace("TAF ", string.Empty), DateTime.Parse(match.Groups["time"].Value), match.Groups["icao"].Value); tafList.Add(taf); if (isParse) { taf.Parse(); } } else { sr.ReadLine(); header = true; } } } } } } } return(tafList); }