public void TestAddNew() { if (Globals.prefs == null) { Globals.prefs = JabRefPreferences.getInstance(); } ParserResult result; using (var parser = new BibtexParser(new StreamReader(@"C:\Users\Peter\Desktop\bibtest.bib"))) { result = parser.Parse(); } var db = result.Database; BibtexEntry entry = new BibtexEntry(); entry.setType(BibtexEntryType.ARTICLE.Instance); db.insertEntry(entry); db.setCiteKeyForEntry(entry.getId(), "ABC"); foreach (var f in entry.getRequiredFields()) { string value = BibtexFields.isNumeric(f) ? "1300" : "Another Test"; entry.setField(f, value); } db.saveDatabase(File.Open(@"C:\Users\Peter\Desktop\bibtest.bib", FileMode.Open)); }
public void TestMethod1() { var parser = new BibtexParser(new StreamReader(@"../../bib/cvgip.bib")); var result = parser.Parse(); var db = result.Database; foreach (var entry in db.getEntries()) { Debug.WriteLine(entry.ToString()); } }
/** * Shortcut usage to create a Parser and read the input. * * @param in - * Reader to read from * @throws IOException */ public static ParserResult Parse(StreamReader inFile) { BibtexParser parser = new BibtexParser(inFile); return parser.Parse(); }
/** * Parses BibtexEntries from the given string and returns the collection of all entries found. * * @param bibtexString * * @return Returns null if an error occurred, returns an empty collection if no entries where found. */ public static ICollection<BibtexEntry> FromString(string bibtexString) { StringReader reader = new StringReader(bibtexString); BibtexParser parser = new BibtexParser(reader); try { return parser.Parse().Database.getEntries(); } catch (Exception){ return null; } }
private void importBibTeXToolStripMenuItem_Click(object sender, EventArgs e) { openFileDialog1.Filter = "BibTeX Files|*.bib"; if (openFileDialog1.ShowDialog() != DialogResult.OK) return; BibtexParser parser = new BibtexParser(new StreamReader(new FileStream(openFileDialog1.FileName, FileMode.Open))); try { var result = parser.Parse(); foreach (var entry in result.Database.getEntries()) AddBibTeXEntry(entry); } catch (Exception ex) { MessageBox.Show(string.Format("The following error occurred when parsing the BibTeX file: {0}", ex.Message)); } }
private void importBibTexFromClipBoardToolStripMenuItem_Click(object sender, EventArgs e) { if (Clipboard.GetDataObject().GetDataPresent(DataFormats.Text)) { BibtexParser parser = new BibtexParser(new StringReader(Clipboard.GetDataObject().GetData(DataFormats.Text).ToString())); var result = parser.Parse(); db = result.Database; foreach (var entry in db.getEntries()) AddBibTeXEntry(entry); } }