Esempio n. 1
0
        /// <summary>
        /// Get a BsonValue and GUID for the object referenced by a Reference or Owning field.
        /// The GUID will be returned by adding it to a list passed in by reference, so that
        /// ReferenceCollection, OwningSequence, and similar fields will be easy to process.
        /// Note that we guarantee that a GUID will always be added to the list, even if this function
        /// returns null for the object's data. That way Select(hvo => GetCustomReferencedObject(hvo, flid, ref myGuidList))
        /// will always return the same number of items as the number of GUIDs in myGuidList.
        /// </summary>
        /// <returns>The custom referenced object's data converted to a BsonValue.</returns>
        /// <param name="hvo">Hvo of referenced object.</param>
        /// <param name="flid">Flid of referring field (required to get correct writing system for an StText).</param>
        /// <param name="listConverters">Dictionary of ConvertLcmToMongoOptionList instances, keyed by list code</param>
        /// <param name="referencedObjectGuids">List to which referenced object's GUID will be added.</param>
        private BsonValue GetCustomReferencedObject(int hvo, int flid,
                                                    IDictionary <string, ConvertLcmToMongoOptionList> listConverters,
                                                    ref List <Guid> referencedObjectGuids)
        {
            ISilDataAccessManaged data = (ISilDataAccessManaged)cache.DomainDataByFlid;

            if (hvo == 0 || !data.get_IsValidObject(hvo))
            {
                referencedObjectGuids.Add(Guid.Empty);
                return(null);
            }
            ICmObject referencedObject = cache.GetAtomicPropObject(hvo);

            if (referencedObject == null)
            {
                referencedObjectGuids.Add(Guid.Empty);
                return(null);
            }
            referencedObjectGuids.Add(referencedObject.Guid);
            if (referencedObject is IStText)
            {
                return(ConvertUtilities.GetCustomStTextValues((IStText)referencedObject, flid,
                                                              servLoc.WritingSystemManager, LcmMetaData, cache.DefaultUserWs));
            }
            else if (referencedObject is ICmPossibility)
            {
                //return GetCustomListValues((ICmPossibility)referencedObject, flid);
                string listCode = GetParentListCode(flid);
                return(new BsonString(listConverters[listCode].LfItemKeyString((ICmPossibility)referencedObject, _wsEn)));
            }
            else
            {
                return(null);
            }
        }