예제 #1
0
        private void btnDBFile_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.DefaultExt = "xml";
            ofd.Filter     = "XML files (*.xml)|*.xml";
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    _logger.Log(String.Format("Loading XML data file: {0}", ofd.FileName));
                    _db_loaded = true;
                    //run the reader.
                    XmlReaderSettings set = new XmlReaderSettings();
                    set.ValidationEventHandler += new ValidationEventHandler(this.ShowCompileErrors);
                    set.Schemas.Add(null, XmlReader.Create(Settings.Default.XMLSchemaFile));
                    set.ValidationType = ValidationType.Schema;

                    XmlReader reader = XmlReader.Create(ofd.FileName, set);

                    while (reader.Read())
                    {
                    }
                    reader.Close();
                    _db.Clear();
                    if (_db_loaded)
                    {
                        this.lvMessages.Items.Clear();
                        MessagesDB db = new MessagesDB();
                        db.Load(ofd.FileName);
                        foreach (SingleCategory cat in db.Categories)
                        {
                            foreach (SingleRecord record in cat.Records)
                            {
                                _db[record.Phrase] = record.Telegram;
                                string confirmed_phrase = record.Phrase + " confirmed";
                                _db[confirmed_phrase] = null;
                                //Update the Main screen
                                ListViewItem item = new ListViewItem();
                                item.Text = record.Phrase;
                                this.lvMessages.Items.Add(item);
                            }
                        }

                        LoadGrammer();
                        this.pboxVoiceStatus.Image = this.imageListVoiceStatus.Images[0];
                        _logger.Log(String.Format("XML data file loaded successfuly"));
                    }
                }
                catch (XmlException)
                {
                }
                catch (XmlSchemaException)
                {
                }
                catch (Exception)
                {
                }
            }
        }
예제 #2
0
        public void Load(string file_name)
        {
            FileStream    fs  = File.Open(file_name, FileMode.Open, FileAccess.Read);
            XmlSerializer ser = new XmlSerializer(typeof(MessagesDB));

            try
            {
                MessagesDB mdb = (MessagesDB)ser.Deserialize(fs);
                _categories = mdb._categories;
                _db_loaded  = true;
            }
            catch (Exception)
            {
                fs.Close();
                _db_loaded = false;
            }
            fs.Close();
        }
예제 #3
0
        private void btnDBFile_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.DefaultExt = "xml";
            ofd.Filter = "XML files (*.xml)|*.xml";
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    _logger.Log(String.Format("Loading XML data file: {0}", ofd.FileName));
                    _db_loaded = true;
                    //run the reader.
                    XmlReaderSettings set = new XmlReaderSettings();
                    set.ValidationEventHandler += new ValidationEventHandler(this.ShowCompileErrors);
                    set.Schemas.Add(null, XmlReader.Create(Settings.Default.XMLSchemaFile));
                    set.ValidationType = ValidationType.Schema;

                    XmlReader reader = XmlReader.Create(ofd.FileName, set);

                    while (reader.Read()) { }
                    reader.Close();
                    _db.Clear();
                    if (_db_loaded)
                    {
                        this.lvMessages.Items.Clear();
                        MessagesDB db = new MessagesDB();
                        db.Load(ofd.FileName);
                        foreach (SingleCategory cat in db.Categories)
                        {
                            foreach (SingleRecord record in cat.Records)
                            {
                                _db[record.Phrase] = record.Telegram;
                                string confirmed_phrase = record.Phrase + " confirmed";
                                _db[confirmed_phrase] = null;
                                //Update the Main screen
                                ListViewItem item = new ListViewItem();
                                item.Text = record.Phrase;
                                this.lvMessages.Items.Add(item);
                            }
                        }

                        LoadGrammer();
                        this.pboxVoiceStatus.Image = this.imageListVoiceStatus.Images[0];
                        _logger.Log(String.Format("XML data file loaded successfuly"));
                    }
                }
                catch (XmlException)
                {

                }
                catch (XmlSchemaException)
                {

                }
                catch (Exception)
                {

                }
            }
        }