Beispiel #1
0
        private void btnLongInfo_Click(object sender, EventArgs e)
        {
            AddInfo("Performing long-info print...");

            ENG.WMOCodes.Codes.Metar mtr = GetMetar();
            ENG.WMOCodes.Codes.Taf   taf = GetTaf();

            if (mtr != null)
            {
                ENG.WMOCodes.Formatters.InfoFormatter.MetarFormatter formatter =
                    new ENG.WMOCodes.Formatters.InfoFormatter.MetarFormatter();

                string str = formatter.ToString(mtr);

                AddInfo(" === METAR ===");
                AddInfo(str);
            }

            if (taf != null)
            {
                ENG.WMOCodes.Formatters.InfoFormatter.TafFormatter tafFormatter =
                    new ENG.WMOCodes.Formatters.InfoFormatter.TafFormatter();

                string str = tafFormatter.ToString(taf);

                AddInfo(" === TAF ===");
                AddInfo(str);
            }

            AddInfo("...done");
        }
Beispiel #2
0
        private ENG.WMOCodes.Codes.Metar GetMetar()
        {
            if (txtMetar.Text == "")
            {
                return(null);
            }
            else
            {
                ENG.WMOCodes.Codes.Metar           ret     = null;
                ENG.WMOCodes.Decoders.MetarDecoder decoder = new ENG.WMOCodes.Decoders.MetarDecoder();
                //ENG.WMOCodes.Decoders.MetarDecoderWithAllOptional decoder =
                //  new ENG.WMOCodes.Decoders.MetarDecoderWithAllOptional();

                try
                {
                    ret =
                        decoder.Decode(txtMetar.Text);
                }
                catch (Exception ex)
                {
                    AddInfo("Error - " + ex.GetMessages());
                }
                return(ret);
            }
        }
Beispiel #3
0
        private static void PrintLongInfo()
        {
            string sourceMetar = "METAR LOWG 312320Z AUTO 00000KT 0200 R35/0650N R17/1200D BCFG 06/05 Q1010 RMK BASE S CLD004 N CLD007";

            ENG.WMOCodes.Codes.Metar           m   = null;
            ENG.WMOCodes.Decoders.MetarDecoder dec = new ENG.WMOCodes.Decoders.MetarDecoder();
            m = dec.Decode(sourceMetar);

            ENG.WMOCodes.Formatters.InfoFormatter.MetarFormatter mf = new ENG.WMOCodes.Formatters.InfoFormatter.MetarFormatter();

            string str = mf.ToString(m);

            Console.WriteLine(str);
            Console.ReadKey();
        }
Beispiel #4
0
        private void btnEncDec_Click(object sender, EventArgs e)
        {
            AddInfo("Performing encode-decode test...");

            ENG.WMOCodes.Codes.Metar mtr = GetMetar();

            if (mtr == null)
            {
                return;
            }

            AddInfo("Orig: \r\n" + txtMetar.Text.Trim());
            AddInfo("EnDe: \r\n" + mtr.ToCode());

            AddInfo("...done");
        }
Beispiel #5
0
        private static void PrintShortInfo()
        {
            string sourceMetar = "METAR LOWG 312320Z AUTO 00000KT 0200 R35/0650N R17/1200D BCFG 06/05 Q1010 RMK BASE S CLD004 N CLD007";

            // decoding
            ENG.WMOCodes.Decoders.MetarDecoder metarDecoder = new ENG.WMOCodes.Decoders.MetarDecoder();
            ENG.WMOCodes.Codes.Metar           metar        = metarDecoder.Decode(sourceMetar);

            // formatting to short info with US culture
            ENG.WMOCodes.Formatters.ShortInfoFormatter.MetarFormatter metarFormatter =
                new ENG.WMOCodes.Formatters.ShortInfoFormatter.MetarFormatter();

            string str = metarFormatter.ToString(metar);

            Console.WriteLine(str);
            Console.ReadKey();
        }
Beispiel #6
0
        private static void DecodeAndEncodeMetar()
        {
            // this is source example string
            string sourceMetar = "METAR LOWG 312320Z AUTO 00000KT 0200 R35/0650N R17/1200D BCFG 06/05 Q1010 RMK BASE S CLD004 N CLD007";

            // into this object decode metar will be stored
            ENG.WMOCodes.Codes.Metar metarObject = null;

            ENG.WMOCodes.Decoders.MetarDecoder decoder = new ENG.WMOCodes.Decoders.MetarDecoder();

            try
            {
                // try to decode metar - call static Create method
                metarObject =
                    decoder.Decode(sourceMetar);
            }
            catch (ENG.WMOCodes.Decoders.Internal.DecodeException ex)
            {
                // Error during decode
                Console.WriteLine("Unable to parse metar from string. " + ex.Message);
            }
            catch (Exception ex)
            {
                // Other error
                Console.WriteLine("Unknown error during decode. Info: " + ex.Message);
            }

            // If successfully decoded
            if (metarObject != null)
            {
                // creates back metar string
                string targetMetar = metarObject.ToCode();

                // and compare string. should be the same.
                Console.WriteLine("Original metar:");
                Console.WriteLine(sourceMetar);
                Console.WriteLine("Decoded and encoded metar:");
                Console.WriteLine(targetMetar);
            }

            Console.ReadKey();
        }
Beispiel #7
0
        private void btnShortInfo_Click(object sender, EventArgs e)
        {
            AddInfo("Performing short-info print...");

            ENG.WMOCodes.Codes.Metar mtr = GetMetar();

            if (mtr == null)
            {
                return;
            }

            ENG.WMOCodes.Formatters.ShortInfoFormatter.MetarFormatter formatter =
                new ENG.WMOCodes.Formatters.ShortInfoFormatter.MetarFormatter();

            string str = formatter.ToString(mtr);

            AddInfo(str);

            AddInfo("...done");
        }
Beispiel #8
0
        private void btnSanityCheck_Click(object sender, EventArgs e)
        {
            AddInfo("Performing sanity check...");

            ENG.WMOCodes.Codes.Metar mtr = GetMetar();

            if (mtr == null)
            {
                return;
            }

            List <string> er = new List <string>();
            List <string> w  = new List <string>();

            mtr.SanityCheck(ref er, ref w);

            er.ForEach(i => AddInfo("Sanity check error: " + i));
            w.ForEach(i => AddInfo("Sanity check warning: " + i));
            AddInfo("...done");
        }
Beispiel #9
0
        public async Task <Metar> GetMetarAsync(string icao, bool invalidateCache)
        {
            var ret = new Metar();

            var cacheHit = this.Cache.Keys.Contains(icao);

            if (cacheHit)
            {
                this.Cache[icao] = ret;
            }
            else
            {
                this.Cache.Add(icao, ret);
            }

            var needDownload = !cacheHit ||
                               invalidateCache ||
                               (cacheHit && !this.Cache[icao].IsValid) ||
                               (cacheHit && this.Cache[icao].TimePublished - DateTime.Now < TimeSpan.FromHours(1));

            if (!needDownload)
            {
                ret = this.Cache[icao];
            }
            else
            {
                var retriever = new ENG.WMOCodes.Downloaders.Retrievers.Metar.NoaaGovRetriever();
                var result    = await Downloader.DownloadAsync(icao, retriever);

                if (!result.IsSuccessful)
                {
                    ret.IsValid  = false;
                    ret.MetarObj = null;
                }
                else
                {
                    var decoder = new ENG.WMOCodes.Decoders.MetarDecoder();
                    ENG.WMOCodes.Codes.Metar metar = null;

                    try
                    {
                        metar = decoder.Decode(result.Result);
                    }
                    catch (ENG.WMOCodes.Decoders.Internal.DecodeException)
                    {
                    }

                    ret.Raw = result.Result;

                    if (metar == null)
                    {
                        ret.IsValid = false;
                    }
                    else
                    {
                        ret.IsValid         = true;
                        ret.DewPoint        = metar.DewPoint;
                        ret.Temperature     = metar.Temperature;
                        ret.Visibility      = (int)metar.Visibility.Distance;
                        ret.Wind            = new Wind();
                        ret.Wind.IsVariable = metar.Wind.IsVariable;
                        if (!metar.Wind.IsVariable)
                        {
                            ret.Wind.Direction = metar.Wind.Direction.Value;
                        }

                        ret.Wind.Speed = metar.Wind.Speed.Value;

                        var layers = new List <CloudLayer>();
                        foreach (var cl in metar.Clouds)
                        {
                            var layer = new CloudLayer();
                            layer.Altitude = cl.Altitude * 100;
                            switch (cl.Type)
                            {
                            case ENG.WMOCodes.Types.Cloud.eType.FEW:
                                layer.Type      = CloudLayerType.FEW;
                                layer.IsCeiling = false;
                                break;

                            case ENG.WMOCodes.Types.Cloud.eType.SCT:
                                layer.Type      = CloudLayerType.SCT;
                                layer.IsCeiling = false;
                                break;

                            case ENG.WMOCodes.Types.Cloud.eType.BKN:
                                layer.Type      = CloudLayerType.BKN;
                                layer.IsCeiling = true;
                                break;

                            case ENG.WMOCodes.Types.Cloud.eType.OVC:
                                layer.Type      = CloudLayerType.OVC;
                                layer.IsCeiling = true;
                                break;
                            }

                            layers.Add(layer);
                        }

                        ret.Clouds   = layers;
                        ret.MetarObj = metar;

                        ret.ComputeFlightRules();
                    }
                }
            }

            return(ret);
        }