/// <summary>
        /// Constructs object instance with data from the entry. To enable loging, use <see cref="BibTexEntryModel()"/> and <see cref="SetFromEntry(BibTexEntryBase, ILogBuilder)"/> instead
        /// </summary>
        /// <param name="entry">The entry.</param>
        public BibTexEntryModel(BibTexEntryBase entry)
        {
            EntryKey  = entry.Key;
            EntryType = entry.type;

            SetFromEntry(entry);
        }
 /// <summary>
 /// Sets object instance properties.
 /// </summary>
 /// <param name="entry">The entry.</param>
 /// <param name="log">The log - if null, log is off</param>
 public void SetFromEntry(BibTexEntryBase entry, ILogBuilder log = null)
 {
     SetDictionary();
     foreach (var tag in entry.Tags)
     {
         if (propDictionary.ContainsKey(tag.Key))
         {
             this.imbSetPropertyConvertSafe(propDictionary[tag.Key], tag.Value.Value);
         }
         else
         {
             if (log != null)
             {
                 log.log(entry.Key + "[" + tag.Key + "] - property not declared at [" + GetType().Name + "] - consider using your own class, derived from BibTexEntryModel");
             }
         }
     }
 }
        /// <summary>
        /// Gets untyped <see cref="BibTexEntryBase"/> object, consumed for BibTex format export
        /// </summary>
        /// <param name="log">The log.</param>
        /// <returns>BibTex entry with data from this object instance</returns>
        public BibTexEntryBase GetEntry(translationTextTable process = null, ILogBuilder log = null)
        {
            SetDictionary();

            BibTexEntryBase entry = new BibTexEntryBase();

            entry.type = EntryType;
            entry.Key  = EntryKey;

            foreach (var pair in propDictionary)
            {
                Object         vl  = this.imbGetPropertySafe(pair.Key, "");
                BibTexEntryTag tag = new BibTexEntryTag(pair.Key, vl.toStringSafe());

                entry.Tags.Add(tag.Key, tag);
            }

            entry.UpdateSource(process);

            return(entry);
        }
Esempio n. 4
0
        /// <summary>
        /// Loads Bibtex entries from the source code
        /// </summary>
        /// <param name="source">The BibTex string source code</param>
        /// <param name="log">The log.</param>
        public void LoadSource(String source, ILogBuilder log = null)
        {
            BibTexSourceProcessor processor      = new BibTexSourceProcessor();
            translationTextTable  processorTable = processor.latex;

            var sourceParts = _select_SplitEntries.Split(source);

            foreach (String entrySource in sourceParts)
            {
                Match mch = _select_keyAndTypeSelection.Match(entrySource);
                if (mch.Success)
                {
                    var lastType = mch.Groups[1].Value;
                    var lastKey  = mch.Groups[2].Value;
                    var bEB      = new BibTexEntryBase(entrySource, lastType, lastKey, processorTable);

                    UntypedEntries.Add(bEB);
                }
            }

            foreach (var bED in UntypedEntries)
            {
                foreach (BibTexEntryTag bEDt in bED.Tags.Values)
                {
                    if (!fields.Contains(bEDt.Key))
                    {
                        fields.Add(bEDt.Key);
                    }
                }
            }

            if (log != null)
            {
                log.log("BibTex segments [" + UntypedEntries.Count + "] ready for parsing.");
            }
        }