Exemplo n.º 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 = ConvertFdoToMongoTsStrings.TextFromTsString(poss.Abbreviation.BestAnalysisVernacularAlternative, _wsf);

            if (item.Abbreviation != abbreviation)
            {
                modified = true;
            }
            item.Abbreviation = abbreviation;
            if (setKey)
            {
                string key = FindAppropriateKey(ConvertFdoToMongoTsStrings.TextFromTsString(poss.Abbreviation.get_String(_wsForKeys), _wsf));
                if (item.Key != key)
                {
                    modified = true;
                }
                item.Key = key;
            }
            string value = ConvertFdoToMongoTsStrings.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);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Make an LfParagraph object from an FDO StTxtPara.
        /// </summary>
        /// <returns>The LFParagraph.</returns>
        /// <param name="fdoPara">FDO StTxtPara object to convert.</param>
        public static LfParagraph FdoParaToLfPara(IStTxtPara fdoPara, ILgWritingSystemFactory wsf)
        {
            var lfPara = new LfParagraph();

            lfPara.Guid      = fdoPara.Guid;
            lfPara.StyleName = fdoPara.StyleName;
            lfPara.Content   = ConvertFdoToMongoTsStrings.TextFromTsString(fdoPara.Contents, wsf);
            return(lfPara);
        }
Exemplo n.º 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 FDO, 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 = fdoMetaData.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 = ConvertFdoToMongoTsStrings.TextFromTsString(parentList.Name.BestAnalysisVernacularAlternative, servLoc.WritingSystemFactory);
                    }
                    if (!String.IsNullOrEmpty(result) && result != MagicStrings.UnknownString)
                    {
                        GuidToListCode[parentListGuid] = result;
                        return(result);
                    }
                    if (parentList.Abbreviation != null)
                    {
                        result = ConvertFdoToMongoTsStrings.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
        }
Exemplo n.º 4
0
        public string LfItemKeyString(ICmPossibility fdoOptionListItem, int ws)
        {
            string result;

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

            if (_lfOptionList != null)
            {
                if (_lfOptionListItemKeyByGuid.TryGetValue(fdoOptionListItem.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}': " +
                              "FDO option list item '{2}' had GUID {3} but no LF option list item was found",
                              _lfOptionList.Name, _lfOptionList.Code,
                              fdoOptionListItem.AbbrAndName, fdoOptionListItem.Guid
                              );
                return(null);
            }

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