コード例 #1
0
        // Event handler for Parse button click
        private void parse_Click(object sender, EventArgs e)
        {
            // Get input text and reset parser variables
            manipulatedFile = InputParser.Parse(rawFile.Text);
            FlexNetWords.ResetReservedWords();
            cleanFile        = "";
            cleanedFile.Text = "";

            // Attempt to clean file
            try
            {
                keepThese = parser.CleanedLic(manipulatedFile);
            }
            // Handle XML lookup file not being found in the specified location (or not having a set location)
            catch (LicensesNotFoundException lnfe)
            {
                var result = MessageBox.Show(lnfe.Message + " Would you like to set the file path for the XML lookup file now?" +
                                             " The path can be set at any time via Edit > Preferences, but you will not be able to parse any files" +
                                             " without having a valid XML file path set. If you would like more details, please see the help link " +
                                             "under Help > Help Documentation.",
                                             "File Could Not Be Cleaned", MessageBoxButtons.YesNo);

                // Let user immediately specify XML location if he/she wants to
                if (result == DialogResult.Yes)
                {
                    OpenFileDialog openDialog = new OpenFileDialog();
                    openDialog.Filter = "XML Files | *.xml";
                    openDialog.ShowDialog();
                    if (!string.IsNullOrEmpty(openDialog.FileName))
                    {
                        PrefsForm.SetXML(openDialog.FileName);
                        DisplayStatus("XML selected.");
                    }
                }
                return;
            }
            // Handle an invalid license being found in the license file (e.g. missing a quote)
            catch (InvalidLicenseException ile)
            {
                var result = MessageBox.Show(ile.Message, "Invalid License File", MessageBoxButtons.OK);
            }

            // Process the parsed lines into one output text block
            for (int pos = 0; pos < keepThese.Count; pos++)
            {
                cleanFile        += keepThese[pos] + Environment.NewLine;
                cleanedFile.Text += cleanFile;
                cleanFile         = "";
            }
            DisplayStatus("File parsed.");
        }