Beispiel #1
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 #2
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();
        }