Example #1
0
        private BibtexFile convertParseNode(ParseNode node)
        {
            Nodes.BibtexFile parseFile = (Nodes.BibtexFile)node;

            BibtexFile bibtex = new BibtexFile();

            foreach (Entry entry in parseFile.Entries)
            {
                if (entry.Type == "String")
                {
                    bibtex.StringDefinitions.Add(entry.Tags.First().Key, entry.Tags.First().Value);
                }
                else
                {
                    BibtexEntry bibtexEntry = new BibtexEntry {
                        Key = entry.Key, Type = entry.Type
                    };

                    entry.Tags.ToList().ForEach(x => bibtexEntry.Tags.Add(x.Key, x.Value));

                    bibtex.Entries.Add(bibtexEntry);
                }
            }

            return(bibtex);
        }
        /// <summary>
        /// Constructs and initialises a styled Bibitem.
        /// </summary>
        /// <param name="auxEntry">The aux entry associated with the citation.</param>
        /// <param name="bibtexEntry">The bibtex entry associated to the citation key.</param>
        /// <param name="entryStyle">The style to apply to the Bibitem.</param>
        /// <exception cref="ArgumentNullException"></exception>
        /// /// <exception cref="ArgumentException">Thrown when the AuxEntry key and the BibtexEntry key do not match.</exception>
        public Bibitem(int index, AuxEntry auxEntry, BibtexEntry bibtexEntry, EntryStyle entryStyle)
        {
            if (auxEntry is null)
            {
                throw new ArgumentNullException(nameof(auxEntry));
            }
            if (bibtexEntry is null)
            {
                throw new ArgumentNullException(nameof(bibtexEntry));
            }
            if (entryStyle is null)
            {
                throw new ArgumentNullException(nameof(entryStyle));
            }
            if (!auxEntry.Key.Equals(bibtexEntry.CitationKey, StringComparison.OrdinalIgnoreCase))
            {
                throw new ArgumentException($"The AuxEntry Key '{auxEntry.Key}' must match the BibtexEntry CitationKey '{bibtexEntry.CitationKey}'!");
            }

            Index       = index;
            CitationKey = auxEntry.Key;
            Label       = bibtexEntry.GetStyledLabel(entryStyle, index);
            Detail      = bibtexEntry.ApplyStyle(entryStyle);
        }
Example #3
0
        private BibtexFile convertParseNode(ParseNode node)
        {
            Nodes.BibtexFile parseFile = (Nodes.BibtexFile) node;

            BibtexFile bibtex = new BibtexFile();

            foreach (Entry entry in parseFile.Entries)
            {
                if (entry.Type == "String")
                {
                    bibtex.StringDefinitions.Add(entry.Tags.First().Key, entry.Tags.First().Value);
                }
                else
                {
                    BibtexEntry bibtexEntry = new BibtexEntry { Key = entry.Key, Type = entry.Type };

                    entry.Tags.ToList().ForEach(x => bibtexEntry.Tags.Add(x.Key, x.Value));

                    bibtex.Entries.Add(bibtexEntry);
                }
            }

            return bibtex;
        }
Example #4
0
 public PostData(BibtexEntry entry)
 {
     Entry = entry;
 }
Example #5
0
        private void AddBibTeXEntry(BibtexEntry entry)
        {
            string title    = entry.getField("title");
            string subtitle = "";
            string author   = entry.getField("author");
            string editor   = entry.getField("editor");

            title  = TrimEntry(title);
            author = TrimEntry(author);
            editor = TrimEntry(editor);

            if (author == null)
            {
                Console.WriteLine("Warning: empty author field in entry {0}", entry.getId());
                author = "";
            }

            if (editor == null)
            {
                Console.WriteLine("Warning: empty editor field in entry {0}", entry.getId());
                editor = "";
            }

            string[] authors    = author.Split(new string[] { " and ", "," }, StringSplitOptions.RemoveEmptyEntries);
            string   new_author = "";

            foreach (string a in authors)
            {
                if (a.Length > 0 && new_author != "")
                {
                    new_author = new_author + ";" + TrimEntry(a);
                }
                else if (a.Length > 0)
                {
                    new_author = TrimEntry(a);
                }
            }

            if (editor == "")
            {
                editor = new_author;
            }
            if (new_author == "")
            {
                new_author = editor;
            }

            string booktitle            = entry.getField("booktitle");
            string edition              = entry.getField("edition");
            string isbn                 = entry.getField("isbn");
            string journalorseriestitle = entry.getType() == BibtexEntryType.getType("ARTICLE") ? entry.getField("journal") : entry.getField("series");
            string volume               = entry.getField("volume");
            string issue                = entry.getField("issue");
            string pages                = entry.getField("pages");
            string startpage            = "";
            string endpage              = "";

            if (pages != null)
            {
                string[] splittedPages = pages.Split(new string[] { "-", "--" }, StringSplitOptions.RemoveEmptyEntries);
                if (splittedPages.Length > 0)
                {
                    startpage = splittedPages[0].Trim();
                }
                if (splittedPages.Length > 1)
                {
                    endpage = splittedPages[1].Trim();
                }
            }


            string issn            = entry.getField("issn");
            string publisher       = entry.getField("publisher");
            string publicationdate = entry.getField("year");
            string abstract_txt    = entry.getField("abstract");
            string doi             = entry.getField("doi");
            string fulltexturl     = entry.getField("url");
            string notes           = entry.getField("notes");
            string publicationtype = "";
            string orgcode         = BibTex2eCitation.Properties.Settings.Default.DefaultOrgCode.ToString();

            if (entry.getType() == BibtexEntryType.getType("ARTICLE"))
            {
                publicationtype = "Journal Items";
            }
            else if (entry.getType() == BibtexEntryType.getType("BOOK"))
            {
                publicationtype = "Monographs/ Monograph Items";
            }
            else if (entry.getType() == BibtexEntryType.getType("PHDTHESIS"))
            {
                publicationtype = "Doctoral Thesis and Habilitation";
            }
            else if (entry.getType() == BibtexEntryType.getType("MASTERSTHESIS"))
            {
                publicationtype = "Master Thesis and Bachelor Thesis";
            }
            else if (entry.getType() == BibtexEntryType.getType("INPROCEEDINGS"))
            {
                publicationtype = "Conference Contributions";
            }
            string language = "English";

            dataGridView1.Rows.Add(new string[] { title, new_author, publicationdate, editor, publicationtype, "", orgcode, subtitle, booktitle, edition, "", "", isbn, journalorseriestitle, volume, issue, startpage, endpage, issn, publisher, "", "", abstract_txt, doi, fulltexturl, "", "", "", notes, "", language });
        }
Example #6
0
        void PostToDatabase(BibtexEntry entry)
        {
            PostData post = new PostData(entry);


            string tablePrefix = "wp_2a8dr8";

            try
            {
                string       sql = string.Format("SELECT ID from {0}_users where user_login='******'", tablePrefix);
                MySqlCommand cmd = new MySqlCommand(sql, conn);

                int userId = Convert.ToInt32(cmd.ExecuteScalar());

                /* check for a post with this citekey */
                cmd.CommandText = string.Format("select count(*) from {0}_posts where post_name='{1}'", tablePrefix, post.Key);
                int number = Convert.ToInt32(cmd.ExecuteScalar());

                if (number > 0)
                {
                    Debug.WriteLine("*** There is already an entry for " + entry.getCiteKey() + " ***");
                    return;
                }

                MySqlCommand postCmd = new MySqlCommand();
                postCmd.Connection = conn;
                if (number == 0)
                {
                    postCmd.CommandText = string.Format(
                        @"insert into {0}_posts (post_author, post_date, post_date_gmt, post_content, post_title, post_excerpt, post_status, comment_status, ping_status,
                        post_password, post_name, to_ping, pinged, post_modified, post_modified_gmt, post_content_filtered, post_parent, guid, menu_order, post_type, 
                        post_mime_type, comment_count) 
                        values (@post_author, @post_date, @post_date_gmt, @post_content, @post_title, @post_excerpt, @post_status, @comment_status, @ping_status,
                        @post_password, @post_name, @to_ping, @pinged, @post_modified, @post_modified_gmt, @post_content_filtered, @post_parent, @guid, @menu_order, @post_type, 
                        @post_mime_type, @comment_count)", tablePrefix);
                    postCmd.Prepare();

                    Dictionary <string, object> paramValues = new Dictionary <string, object>()
                    {
                        { "@post_author", userId },
                        { "@post_date", post.DateTime },
                        { "@post_date_gmt", post.DateTime },
                        { "@post_content", post.PostText },
                        { "@post_title", post.Title },
                        { "@post_excerpt", "" },
                        { "@post_status", "publish" },
                        { "@comment_status", "closed" },
                        { "@ping_status", "open" },
                        { "@post_password", "" },
                        { "@post_name", post.Key },
                        { "@to_ping", "" },
                        { "@pinged", "" },
                        { "@post_modified", DateTime.Now },
                        { "@post_modified_gmt", DateTime.Now },
                        { "@post_content_filtered", "" },
                        { "@post_parent", 0 },
                        { "@guid", entry.getCiteKey() },
                        { "@menu_order", 0 },
                        { "@post_type", "post" },
                        { "@post_mime_type", "" },
                        { "@comment_count", 0 }
                    };

                    foreach (var kvp in paramValues)
                    {
                        postCmd.Parameters.AddWithValue(kvp.Key, kvp.Value);
                    }
                }
                else
                {
                    postCmd.CommandText = string.Format(
                        @"update {0}_posts set post_content=@post_content, post_title=@post_title, post_date=@post_date,
                            post_date_gmt=@post_date_gmt
                            where post_name = '{1}'", tablePrefix, post.Key);
                    postCmd.Prepare();
                    Dictionary <string, object> paramValues = new Dictionary <string, object>()
                    {
                        { "@post_date", post.DateTime },
                        { "@post_date_gmt", post.DateTime },
                        { "@post_content", post.PostText },
                        { "@post_title", post.Title }
                    };
                    foreach (var kvp in paramValues)
                    {
                        postCmd.Parameters.AddWithValue(kvp.Key, kvp.Value);
                    }
                }

                postCmd.ExecuteNonQuery();

                AddCategoryToPost("Publications", post.Key);
            } catch (MySql.Data.MySqlClient.MySqlException ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }
Example #7
0
 private void ParseField(BibtexEntry entry)
 {
     string key = ParseTextToken().ToLower();
     // Util.pr("Field: _"+key+"_");
     SkipWhitespace();
     Consume('=');
     string content = ParseFieldContent(key);
     if (content.Length > 0) {
     if (entry.getField(key) == null)
         entry.setField(key, content);
     else {
         // The following hack enables the parser to deal with multiple
         // author or
         // editor lines, stringing them together instead of getting just
         // one of them.
         // Multiple author or editor lines are not allowed by the bibtex
         // format, but
         // at least one online database exports bibtex like that, making
         // it inconvenient
         // for users if JabRef didn't accept it.
         if (key.Equals("author") || key.Equals("editor"))
             entry.setField(key, entry.getField(key) + " and " + content);
     }
     }
 }
Example #8
0
        public BibtexEntry ParseEntry(BibtexEntryType tp)
        {
            string id = Util.createNeutralId();// createId(tp, _db);
            BibtexEntry result = new BibtexEntry(id, tp);
            SkipWhitespace();
            Consume('{', '(');
            SkipWhitespace();
            int c = Peek();
            if ((c != '\n') && (c != '\r'))
            SkipWhitespace();
            string key = null;
            bool doAgain = true;
            while (doAgain) {
            doAgain = false;
            try {
                if (key != null)
                    key = key + ParseKey();// parseTextToken(),
                else
                    key = ParseKey();
            } catch (NoLabelException ex) {
                // This exception will be thrown if the entry lacks a key
                // altogether, like in "@article{ author = { ...".
                // It will also be thrown if a key Contains =.
                c = (char) Peek();
                if (char.IsWhiteSpace((char)c) || (c == '{') || (c == '\"')) {
                    string fieldName = ex.Message.Trim().ToLower();
                    string cont = ParseFieldContent(fieldName);
                    result.setField(fieldName, cont);
                } else {
                    if (key != null)
                        key = key + ex.Message + "=";
                    else
                        key = ex.Message + "=";
                    doAgain = true;
                }
            }
            }

            if ((key != null) && key.Equals(""))
            key = null;

            result.setField(Globals.KEY_FIELD, key);
            SkipWhitespace();

            while (true) {
            c = Peek();
            if ((c == '}') || (c == ')')) {
                break;
            }

            if (c == ',')
                Consume(',');

            SkipWhitespace();

            c = Peek();
            if ((c == '}') || (c == ')')) {
                break;
            }
            ParseField(result);
            }

            Consume('}', ')');
            return result;
        }
Example #9
0
 public SaveException(string message, BibtexEntry entry)
     : base(message)
 {
     this.entry = entry;
 }
Example #10
0
 public SaveException(string message, int status)
     : base(message)
 {
     entry = null;
     this.status = status;
 }
Example #11
0
 //~ Constructors ///////////////////////////////////////////////////////////
 public SaveException(string message)
     : base(message)
 {
     entry = null;
 }