Пример #1
0
        public void AddGlossaryItem(GlossaryItem glossaryItem)
        {
            _glossaryItems.Add(glossaryItem);

            if (glossaryItem.IsTermPreferred)
            {
                try
                {
                    _AbbreviationToTermDictionary.Add(glossaryItem.Abbreviation.ToUpper(), glossaryItem.Term);
                }
                catch (Exception ex)
                {
                    if (ex.GetType() == typeof(ArgumentException) && ex.Message.Contains("same key"))
                    {
                        throw new DuplicateNameException($"An preferred glossary item for '{glossaryItem.Abbreviation}' is already in the glossary. There can be only one primary term for an abbreviation. Consider marking IsTermPreferred to false.");
                    }
                    else
                    {
                        throw ex;
                    }
                }
            }
            if (glossaryItem.Abbreviation.IsNotNullOrEmptyString())
            {
                try
                {
                    _TermToAbbreviationDictionary.Add(glossaryItem.Term.ToUpper(), glossaryItem.Abbreviation);
                }
                catch (Exception ex)
                {
                    if (ex.GetType() == typeof(ArgumentException) && ex.Message.Contains("same key"))
                    {
                        throw new DuplicateNameException($"The term '{glossaryItem.Term}' already exists in the glossary. ");
                    }
                    else
                    {
                        throw ex;
                    }
                }
            }
        }
Пример #2
0
 public void RemoveGlossaryItem(GlossaryItem gi)
 {
     _glossaryItems.Remove(gi);
 }