示例#1
0
文件: Form1.cs 项目: Numpsy/Dubrovnik
        private void BrowseButton_Click(object sender, EventArgs e)
        {
            // get input path
            string inputPath = Properties.Settings.Default.InputPath;

            OpenFileDialog dialog = new OpenFileDialog { Filter = "XML file (*.xml)|*.xml;" };
            if (!String.IsNullOrEmpty(inputPath))
            {
                dialog.InitialDirectory = inputPath;
            }

            if (dialog.ShowDialog(this) != DialogResult.OK || !File.Exists(dialog.FileName)) return;
            _XMLFileName = FilePathTextBox.Text = dialog.FileName;

            // do persistence
            inputPath = Path.GetDirectoryName(_XMLFileName);
            Properties.Settings.Default.InputPath = inputPath;

            // create the generator
            try {
                _codeGen = new CodeGenerator(_XMLFileName);
                XMLTextBox.Text = _codeGen.codeDoc.ToString();

                genCode.Enabled = true;

                ResetTextBoxes();
                tabs.SelectedTab = tabs.TabPages["tabXML"];
                ExportButton.Enabled = false;
            }
            catch (Exception ex)
            {
                XMLTextBox.Text = "";
                MessageBox.Show(this, "The selected file could not be parsed as XML. " + ex.Message);
            }
        }
示例#2
0
        static int Main(string[] args)
        {
            // parse the command line
            // https://github.com/gsscoder/commandline
            var options = new CommandLineOptions();
            if (CommandLine.Parser.Default.ParseArguments(args, options))
            {

                if (options.Verbose == "true")
                {
                    Console.WriteLine("Assembly target : {0}", options.InputFile);
                    Console.WriteLine("Output folder : {0}", options.OutputPath);
                }

            }
            else
            {
                Console.WriteLine("ERROR: Command line arguments failed to parse");
                return -1;
            }

            try {

                // input file must exist
                if (!File.Exists(options.InputFile))
                {
                    Console.WriteLine("ERROR: Input file does not exist.");
                    return -1;
                }

                // output path must exist
                if (!Directory.Exists(options.OutputPath))
                {

                    Console.WriteLine("ERROR: Output path does not exist.");
                    return -1;
                }

                // instantiate code generator
                CodeGenerator codeGen = new CodeGenerator(options.InputFile);

                // execute
                codeGen.Execute();

                // write output
                codeGen.WriteOutput(options.OutputPath);
            }
            catch (Exception e)
            {
                Console.WriteLine("ERROR: An Exception Occurred : {0}", e.ToString());
                return -1;
            }

            return 0;
        }