예제 #1
0
        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);
        }
예제 #2
0
        private static string GetTemperatures(Taf taf)
        {
            StringBuilder sb = new StringBuilder();

            if (taf.MaxTemperature != null)
            {
                sb.Append(Get(taf.MaxTemperature));
            }
            sb.Append(R.Space + R.Dot);
            if (taf.MinTemperature != null)
            {
                sb.Append(Get(taf.MinTemperature));
            }
            sb.Append(R.Dot);

            return(sb.ToString());
        }
예제 #3
0
        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);
        }
예제 #4
0
 public DecodeTafResponse(Taf taf)
 {
     this.OriginalTaf = taf.OriginalTaf;
 }