IsBinaryFile() публичный Метод

public IsBinaryFile ( ) : bool
Результат bool
        static int Main(string[] args)
        {
            if (args.Length < 1 || !File.Exists(args[0]))
            {
                Console.WriteLine("FATAL: First command line parameter must be an existing file");
                return -1;
            }
            try
            {
                FileLoader loader = new FileLoader(json_tree.json_tree.encodingClass,json_tree.json_tree.unicodeDetection, args[0]);
                Debug.Assert(!loader.IsBinaryFile());
                string src;
                if (loader.LoadFile(out src))
                {
                    json_tree.json_tree jsonParser = new json_tree.json_tree(src, Console.Out);
                    bool bMatches = jsonParser.json_text();
                    if (bMatches)
                    {
                        Console.WriteLine("SUCCESS: Json Parser matched input file '{0}'", args[0]);
                        TreePrint tprint = new TreePrint(Console.Out, src, 60, new NodePrinter(jsonParser).GetNodeName, false);
                        tprint.PrintTree(jsonParser.GetRoot(), 0, 0);
                    }
                    else
                    {
                        Console.WriteLine("FAILURE: Json Parser did not match input file '{0]'", args[0]);
                    }
                    return 0;
                }
                else
                {
                    Console.WriteLine("FATAL: File '{0}' could not be loaded", args[0]);
                    return -1;
                }

            }
            catch (Exception e)
            {
                Console.WriteLine("FATAL: Program terminated by exception '{0}'",e.Message);
                return -1;
            }
        }
Пример #2
0
        void LoadSourceFile(string path)
        {
            txtSource.Tag = null;
            txtSource.ReadOnly = false;
            tvParseTree.Nodes.Clear();
            HidePostProcessButtons();
            cmbPostProcess.DataSource = null;

            SampleInfo selectedSample;
            if (path.Length == 0)
            {
                selectedSample = new SampleInfo();
                txtSource.Tag = new SourcefileInfo(path, EncodingClass.ascii, "");
            }else
            {
                if (cboGrammar.SelectedIndex < 0)
                {
                    MessageBox.Show("Grammar must be selected first");
                    return;
                }
                this.Text = "Parsing Expression Grammar Explorer (" + path.Substring(path.LastIndexOf('\\') + 1) + ")";
                selectedSample = (SampleInfo)cboGrammar.Items[cboGrammar.SelectedIndex];
                try
                {
                    FileLoader loader = new FileLoader(selectedSample.GetEncodingClass(), selectedSample.GetUnicodeDetection(), path);
                    if (loader.IsBinaryFile())
                    {
                        byte[] bytes;
                        loader.LoadFile(out bytes);
                        txtSource.Tag = new SourcefileInfo(path, selectedSample.GetEncodingClass(), bytes);
                        string src = BuildHexView(bytes);
                        DisplaySrc(src, path, src.Length);
                        txtSource.ReadOnly = true;
                    }
                    else
                    {
                        string src;
                        loader.LoadFile(out src);
                        txtSource.Tag = new SourcefileInfo(path, selectedSample.GetEncodingClass(), src);
                        DisplaySrc(src, path, src.Length);
                    }
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message);
                }
            }
        }