Ejemplo n.º 1
0
        /// <summary>
        /// Updates the source.
        /// </summary>
        /// <param name="table">The table.</param>
        public void UpdateSource(translationTextTable table = null)
        {
            List <BibTexEntryTag> _tags = new List <BibTexEntryTag>();

            foreach (var pair in Tags)
            {
                if (table != null)
                {
                    pair.Value.source = table.translate(pair.Value.Value, true);
                }
                _tags.Add(pair.Value);
            }

            Tags.Clear();
            foreach (var t in _tags)
            {
                AddTag(t.Key, t);
            }

            StringBuilder sb = new StringBuilder();

            sb.AppendLine("@" + type + "{" + Key + ",");

            Int32 c = 0;

            foreach (var pair in Tags)
            {
                String format = tagFormatOther;

                if (pair.Key == tagKey_Title)
                {
                    format = tagFormatTitle;
                }

                String line = "";

                if (table != null)
                {
                    line = String.Format(format, pair.Key, pair.Value.source);
                }
                else
                {
                    line = String.Format(format, pair.Key, pair.Value.Value);
                }

                sb.AppendLine(line);

                c++;
                if (c < Tags.Count)
                {
                    sb.Append(",");
                }
            }
            sb.AppendLine("}");

            source = sb.ToString();
        }
        /// <summary>
        /// Generates BibTex source
        /// </summary>
        /// <param name="table">The table.</param>
        /// <param name="log">The log.</param>
        /// <returns></returns>
        public String GetSource(translationTextTable table, ILogBuilder log = null)
        {
            StringBuilder sb = new StringBuilder();

            foreach (BibTexEntryModel emodel in this)
            {
                sb.AppendLine(emodel.GetEntry(table, log).GetSource(table));
            }

            return(sb.ToString());
        }
        /// <summary>
        /// Gets the data file object model
        /// </summary>
        /// <param name="filename">The filename, without extension</param>
        /// <param name="table">LaTeX translation table</param>
        /// <param name="log">The log.</param>
        /// <returns></returns>
        public BibTexDataFile GetDataFile(String filename, translationTextTable table, ILogBuilder log = null)
        {
            BibTexDataFile file = new BibTexDataFile();

            file.name = filename;
            foreach (BibTexEntryModel emodel in this)
            {
                file.UntypedEntries.Add(emodel.GetEntry(table, log));
            }
            return(file);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Gets BibTex source code
        /// </summary>
        /// <param name="table">The table.</param>
        /// <param name="log">The log.</param>
        /// <returns></returns>
        public String GetSource(translationTextTable table, ILogBuilder log = null)
        {
            StringBuilder sb = new StringBuilder();

            foreach (BibTexEntryBase entry in UntypedEntries)
            {
                sb.AppendLine(entry.GetSource(table));
            }

            return(sb.ToString());
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Processes the source.
 /// </summary>
 /// <param name="table">The table.</param>
 public void ProcessSource(translationTextTable table = null)
 {
     if (table == null)
     {
         return;
     }
     foreach (var pair in Tags)
     {
         pair.Value.Value = table.translate(pair.Value.source);
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Deploys the specified source.
        /// </summary>
        /// <param name="_source">The source.</param>
        /// <param name="_type">The type.</param>
        /// <param name="_key">The key.</param>
        /// <param name="processor">The processor.</param>
        public void Deploy(String _source, String _type, String _key, translationTextTable processor = null)
        {
            type   = _type;
            Key    = _key;
            source = _source;

            foreach (Match mch in _select_isSelectTags.Matches(source))
            {
                String source = mch.Groups[2].Value.Trim(sourceTrim.ToArray());

                BibTexEntryTag tmp = new BibTexEntryTag(mch.Groups[1].Value, source);
                tmp.source = source;
                AddTag(tmp.Key, tmp);
            }

            ProcessSource(processor);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Gets the bib tex code.
        /// </summary>
        /// <param name="processed">if set to <c>true</c> [processed].</param>
        /// <param name="processorTable">The processor table.</param>
        /// <param name="log">The log.</param>
        /// <returns></returns>
        public String GetBibTexCode(Boolean processed = false, translationTextTable processorTable = null, ILogBuilder log = null)
        {
            StringBuilder sb = new StringBuilder();

            if (processorTable == null)
            {
                processed = true;
            }
            if (processed == true)
            {
                processorTable = null;
            }

            foreach (var entry in UntypedEntries)
            {
                entry.UpdateSource(processorTable);
                sb.AppendLine(entry.source);
            }

            return(sb.ToString());
        }
        /// <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);
        }
Ejemplo n.º 9
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.");
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Saves data from the instance into BibTex file
        /// </summary>
        /// <param name="path">The path, to save the data into</param>
        /// <param name="processorTable">LaTeX entities translation table</param>
        /// <param name="log">The log.</param>
        public void Save(String path, translationTextTable processorTable = null, ILogBuilder log = null)
        {
            String source = GetSource(processorTable, log);

            File.WriteAllText(path, source);
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Gets BibTex source, using specified <c>translationTextTable</c> to convert UTF-8 strings into proper LaTeX symbols
 /// </summary>
 /// <param name="table">Table with pairs used to convert UTF-8 strings into proper LaTeX symbols</param>
 /// <param name="log">The log.</param>
 /// <returns>BibTex source code</returns>
 public String GetSource(translationTextTable table, ILogBuilder log = null)
 {
     return(GetEntry(table, log).GetSource(table));
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BibTexEntryBase"/> class.
 /// </summary>
 /// <param name="_source">The source.</param>
 /// <param name="_type">The type.</param>
 /// <param name="_key">The key.</param>
 /// <param name="processor">The processor.</param>
 public BibTexEntryBase(String _source, String _type, String _key, translationTextTable processor = null)
 {
     Deploy(_source, _type, _key, processor);
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Calls <see cref="UpdateSource(translationTextTable)"/> and returns reconstructed BibTex source (<see cref="source"/>)
 /// </summary>
 /// <param name="table">The LaTex entity translation table</param>
 /// <returns>BibTex source</returns>
 public String GetSource(translationTextTable table)
 {
     UpdateSource(table);
     return(source);
 }