示例#1
0
        //
        // Construction
        //
        public RuleDialog(Settings st)
        {
            Settings = st;

            InitializeComponent();

            InitializeOutputCombo();

            kaiListBoxStress.DisableEdit = false;

            iCurrentItem = -1;

            comboBox.Visible = false;
            textBox.Visible = false;
        }
示例#2
0
        public RuleDialog(Settings st, StRule stCurrentRule)
        {
            Settings = st;

            InitializeComponent();

            InitializeOutputCombo();

            kaiListBoxStress.DisableEdit = false;

            iCurrentItem = -1;

            comboBox.Visible = false;

            textBox.Visible = false;

            textBoxInput.Text = stCurrentRule.sInput;

            foreach (KeyValuePair<string, string> kvp in stCurrentRule.dictStressPositions)
            {
                kaiListBoxStress.Items.Add (new DataItem (kvp));
            }

            foreach (KeyValuePair<string, string> kvp in stCurrentRule.dictLeftContexts)
            {
                kaiListBoxLeftContext.Items.Add (new DataItem(kvp));
            }

            foreach (KeyValuePair<string, string> kvp in stCurrentRule.dictRightContexts)
            {
                kaiListBoxRightContext.Items.Add (new DataItem(kvp));
            }

            foreach (KeyValuePair<string, string> kvp in stCurrentRule.dictExceptions)
            {
                kaiListBoxExceptions.Items.Add (new DataItem(kvp));
            }

            foreach (KeyValuePair<string, string> kvp in stCurrentRule.dictOutputModifiers)
            {
                kaiListBoxOutputModifiers.Items.Add (new DataItem(kvp));
            }

            foreach (KeyValuePair<string, string> kvp in stCurrentRule.dictOutputSymbols)
            {
                comboBoxOut.Text = kvp.Value;
            }
        }
示例#3
0
        private void ReadSettings()
        {
            string sSettingsPath;
            try
            {
                sSettingsPath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
                sSettingsPath = Path.Combine(sSettingsPath, Application.CompanyName);
                sSettingsPath = Path.Combine(sSettingsPath, Application.ProductName);
                sSettingsPath = Path.Combine(sSettingsPath, "RuleSettings.xml");
            }
            catch (Exception ex)
            {
                string sText = string.Format ("Error accessing settings file: {0}", ex.Message);
                MessageBox.Show (sText,
                                 "RuleEditor",
                                 MessageBoxButtons.OK,
                                 MessageBoxIcon.Exclamation);
                return;
            }

            Console.WriteLine();
            try
            {
                XmlReaderSettings xmlSettings = new XmlReaderSettings();
                xmlSettings.ConformanceLevel = ConformanceLevel.Document;
                xmlSettings.IgnoreComments = true;
                xmlSettings.IgnoreWhitespace = true;

                XmlReader xmlReader = XmlReader.Create(sSettingsPath, xmlSettings);

                xmlReader.Read();

                while (!xmlReader.IsStartElement("Language"))
                {
                    xmlReader.Read();
                }

                Settings Settings = new Settings();
                while (xmlReader.IsStartElement("Language"))
                {
                    xmlReader.Read();

                    Settings.sLanguage = xmlReader.ReadString();

                    while (!xmlReader.EOF && !xmlReader.IsStartElement())
                    {
                        xmlReader.Read();
                    }

                    while (xmlReader.IsStartElement())
                    {
                        switch (xmlReader.LocalName)
                        {
                            case "Stress":
                            {
                                ReadAttributes (xmlReader, Settings.dictStressTypes);
                                break;
                            }
                            case "LeftContext":
                            {
                                ReadAttributes( xmlReader, Settings.dictLeftContexts);
                                break;
                            }
                            case "RightContext":
                            {
                                ReadAttributes (xmlReader, Settings.dictRightContexts);
                                break;
                            }
                            case "Exception":
                            {
                                ReadAttributes (xmlReader, Settings.dictExceptions);
                                break;
                            }
                            case "OutputSymbol":
                            {
                                ReadAttributes (xmlReader, Settings.dictOutputSymbols);
                                break;
                            }
                            case "Modifier":
                            {
                                ReadAttributes(xmlReader, Settings.dictOutputModifiers);
                                break;
                            }
                            default:
                            {
                                string sMsg = string.Format ("Unknown keyword: {0} in {1}",
                                                             xmlReader.LocalName,
                                                             sSettingsPath);
                                MessageBox.Show (sMsg,
                                                 "Rule Editor",
                                                 MessageBoxButtons.OK,
                                                 MessageBoxIcon.Exclamation);
                                KaiLibCS.MfcHelpers.LogError (sMsg);
                                continue;
                            }

                        }   // switch

                    }   // while (xmlReader.IsStartElement())

                    liSettings.Add(Settings);

                }   //  while (xmlReader.IsStartElement("Language"))

                xmlReader.Close();

            }
            catch (Exception ex)
            {
                string sText = string.Format ("Error reading settings: {0}", ex.Message);
                MessageBox.Show (sText,
                                 "RuleEditor",
                                 MessageBoxButtons.OK,
                                 MessageBoxIcon.Exclamation);
            }
        }