Пример #1
0
        // Returns true if the item passed in has been modified at all, false otherwise
        protected bool SetOptionListItemFromCmPossibility(LfOptionListItem item, ICmPossibility poss, bool setKey = false)
        {
            bool   modified     = false;
            string abbreviation = ConvertLcmToMongoTsStrings.TextFromTsString(poss.Abbreviation.BestAnalysisVernacularAlternative, _wsf);

            if (item.Abbreviation != abbreviation)
            {
                modified = true;
            }
            item.Abbreviation = abbreviation;
            if (setKey)
            {
                string key = FindAppropriateKey(ConvertLcmToMongoTsStrings.TextFromTsString(poss.Abbreviation.get_String(_wsForKeys), _wsf));
                if (item.Key != key)
                {
                    modified = true;
                }
                item.Key = key;
            }
            string value = ConvertLcmToMongoTsStrings.TextFromTsString(poss.Name.BestAnalysisVernacularAlternative, _wsf);

            if (item.Value != value)
            {
                modified = true;
            }
            item.Value = value;
            if (item.Guid != poss.Guid)
            {
                modified = true;
            }
            item.Guid = poss.Guid;
            return(modified);
        }
Пример #2
0
        /// <summary>
        /// Make an LfParagraph object from an LCM StTxtPara.
        /// </summary>
        /// <returns>The LFParagraph.</returns>
        /// <param name="lcmPara">LCM StTxtPara object to convert.</param>
        public static LfParagraph LcmParaToLfPara(IStTxtPara lcmPara, ILgWritingSystemFactory wsf)
        {
            var lfPara = new LfParagraph();

            lfPara.Guid      = lcmPara.Guid;
            lfPara.StyleName = lcmPara.StyleName;
            lfPara.Content   = ConvertLcmToMongoTsStrings.TextFromTsString(lcmPara.Contents, wsf);
            return(lfPara);
        }
Пример #3
0
        /// <summary>
        /// Get the list code of the parent
        /// </summary>
        /// <returns>The list code as used in LF (e.g., "sense-type" or "grammatical-info").
        /// For custom lists from Lcm, returns the user-given list name or abbreviation.</returns>
        /// <param name="flid">Flid.</param>
        private string GetParentListCode(int flid)
        {
            string result         = string.Empty;
            Guid   parentListGuid = LcmMetaData.GetFieldListRoot(flid);

            if (parentListGuid != Guid.Empty)
            {
                if (GuidToListCode.TryGetValue(parentListGuid, out result))
                {
                    return(result);
                }
                // If it wasn't in GuidToListCode, it's a custom field we haven't actually seen yet
                ICmPossibilityList parentList;
                if (servLoc.GetInstance <ICmPossibilityListRepository>().TryGetObject(parentListGuid, out parentList))
                {
                    if (parentList.Name != null)
                    {
                        result = ConvertLcmToMongoTsStrings.TextFromTsString(parentList.Name.BestAnalysisVernacularAlternative, servLoc.WritingSystemFactory);
                    }
                    if (!String.IsNullOrEmpty(result) && result != MagicStrings.UnknownString)
                    {
                        GuidToListCode[parentListGuid] = result;
                        return(result);
                    }
                    if (parentList.Abbreviation != null)
                    {
                        result = ConvertLcmToMongoTsStrings.TextFromTsString(parentList.Abbreviation.BestAnalysisVernacularAlternative, servLoc.WritingSystemFactory);
                    }
                    if (!String.IsNullOrEmpty(result) && result != MagicStrings.UnknownString)
                    {
                        GuidToListCode[parentListGuid] = result;

                        return(result);
                    }
                    result = String.Format("Custom List {0}", parentListGuid);
                    GuidToListCode[parentListGuid] = result;
                    return(result);
                }
            }
            return(result);            // If we reach here, result is still an empty string
        }
Пример #4
0
        public string LfItemKeyString(ICmPossibility lcmOptionListItem, int ws)
        {
            string result;

            if (lcmOptionListItem == null)
            {
                return(null);
            }

            if (_lfOptionList != null)
            {
                if (_lfOptionListItemKeyByGuid.TryGetValue(lcmOptionListItem.Guid, out result))
                {
                    return(result);
                }

                // We shouldn't get here, because the option list SHOULD be pre-populated.
                _logger.Error("Got an option list item without a corresponding LF option list item. " +
                              "In option list name '{0}', list code '{1}': " +
                              "LCM option list item '{2}' had GUID {3} but no LF option list item was found",
                              _lfOptionList.Name, _lfOptionList.Code,
                              lcmOptionListItem.AbbrAndName, lcmOptionListItem.Guid
                              );
                return(null);
            }

            if (lcmOptionListItem.Abbreviation == null || lcmOptionListItem.Abbreviation.get_String(ws) == null)
            {
                // Last-ditch effort
                char ORC = '\ufffc';
                return(lcmOptionListItem.AbbrevHierarchyString.Split(ORC).LastOrDefault());
            }
            else
            {
                return(ConvertLcmToMongoTsStrings.TextFromTsString(lcmOptionListItem.Abbreviation.get_String(ws), _wsf));
            }
        }