public void Action_WithOneModifiedEntry_ShouldCountOneModified() { // Setup var lfProj = _lfProj; sutFdoToMongo.Run(lfProj); Guid entryGuid = Guid.Parse(TestEntryGuidStr); LfLexEntry entry = _conn.GetLfLexEntryByGuid(entryGuid); FdoCache cache = lfProj.FieldWorksProject.Cache; string vernacularWS = cache.LanguageProject.DefaultVernacularWritingSystem.Id; string changedLexeme = "modified lexeme for this test"; entry.Lexeme = LfMultiText.FromSingleStringMapping(vernacularWS, changedLexeme); entry.AuthorInfo = new LfAuthorInfo(); entry.AuthorInfo.ModifiedDate = DateTime.UtcNow; _conn.UpdateMockLfLexEntry(entry); // Exercise sutMongoToFdo.Run(lfProj); // Verify Assert.That(_counts.Added, Is.EqualTo(0)); Assert.That(_counts.Modified, Is.EqualTo(1)); Assert.That(_counts.Deleted, Is.EqualTo(0)); Assert.That(LfMergeBridgeServices.FormatCommitMessageForLfMerge(_counts.Added, _counts.Modified, _counts.Deleted), Is.EqualTo("Language Forge: 1 entry modified")); }
public void Action_WithOneNewEntry_ShouldCountOneAdded() { // Setup var lfProj = _lfProj; LfLexEntry newEntry = new LfLexEntry(); newEntry.Guid = Guid.NewGuid(); FdoCache cache = lfProj.FieldWorksProject.Cache; string vernacularWS = cache.LanguageProject.DefaultVernacularWritingSystem.Id; string newLexeme = "new lexeme for this test"; newEntry.Lexeme = LfMultiText.FromSingleStringMapping(vernacularWS, newLexeme); newEntry.AuthorInfo = new LfAuthorInfo(); newEntry.AuthorInfo.CreatedDate = DateTime.UtcNow; newEntry.AuthorInfo.ModifiedDate = newEntry.AuthorInfo.CreatedDate; _conn.UpdateMockLfLexEntry(newEntry); // Exercise sutMongoToFdo.Run(lfProj); // Verify Assert.That(_counts.Added, Is.EqualTo(1)); Assert.That(_counts.Modified, Is.EqualTo(0)); Assert.That(_counts.Deleted, Is.EqualTo(0)); Assert.That(LfMergeBridgeServices.FormatCommitMessageForLfMerge(_counts.Added, _counts.Modified, _counts.Deleted), Is.EqualTo("Language Forge: 1 entry added")); }
public void Action_RunTwiceWithOneNewEntryEachTime_ShouldCountTwoAddedInTotal() { // Setup var lfProj = _lfProj; LfLexEntry newEntry = new LfLexEntry(); newEntry.Guid = Guid.NewGuid(); LcmCache cache = lfProj.FieldWorksProject.Cache; string vernacularWS = cache.LanguageProject.DefaultVernacularWritingSystem.Id; string newLexeme = "new lexeme for this test"; newEntry.Lexeme = LfMultiText.FromSingleStringMapping(vernacularWS, newLexeme); newEntry.AuthorInfo = new LfAuthorInfo(); newEntry.AuthorInfo.CreatedDate = DateTime.UtcNow; newEntry.AuthorInfo.ModifiedDate = newEntry.AuthorInfo.CreatedDate; _conn.UpdateMockLfLexEntry(newEntry); // Exercise SutMongoToLcm.Run(lfProj); // Verify Assert.That(_counts.Added, Is.EqualTo(1)); Assert.That(_counts.Modified, Is.EqualTo(0)); Assert.That(_counts.Deleted, Is.EqualTo(0)); Assert.That(LfMergeBridgeServices.FormatCommitMessageForLfMerge(_counts.Added, _counts.Modified, _counts.Deleted), Is.EqualTo("Language Forge: 1 entry added")); // Setup second run newEntry = new LfLexEntry(); newEntry.Guid = Guid.NewGuid(); newLexeme = "second new lexeme for this test"; newEntry.Lexeme = LfMultiText.FromSingleStringMapping(vernacularWS, newLexeme); newEntry.AuthorInfo = new LfAuthorInfo(); newEntry.AuthorInfo.CreatedDate = DateTime.UtcNow; newEntry.AuthorInfo.ModifiedDate = newEntry.AuthorInfo.CreatedDate; _conn.UpdateMockLfLexEntry(newEntry); // Exercise SutMongoToLcm.Run(lfProj); // Verify Assert.That(_counts.Added, Is.EqualTo(1)); // Modified and Deleted shouldn't have changed, but check Added first // since that's the main point of this test Assert.That(_counts.Modified, Is.EqualTo(0)); Assert.That(_counts.Deleted, Is.EqualTo(0)); Assert.That(LfMergeBridgeServices.FormatCommitMessageForLfMerge(_counts.Added, _counts.Modified, _counts.Deleted), Is.EqualTo("Language Forge: 1 entry added")); }
public void SynchronizeAction_LFDataChangedLDEntryDeleted_LFWins() { // Setup TestEnvironment.CopyFwProjectTo(modifiedTestProjectCode, _lDSettings.WebWorkDirectory); Directory.Move(Path.Combine(_lDSettings.WebWorkDirectory, modifiedTestProjectCode), LanguageDepotMock.ProjectFolderPath); _lfProject.IsInitialClone = true; _transferFdoToMongo.Run(_lfProject); IEnumerable <LfLexEntry> originalMongoData = _mongoConnection.GetLfLexEntries(); LfLexEntry lfEntry = originalMongoData.First(e => e.Guid == _testDeletedEntryGuid); DateTime originalLfDateModified = lfEntry.DateModified; Assert.That(lfEntry.Senses.Count, Is.EqualTo(1)); const string lfCreatedGloss = "new English gloss - added in LF"; const string fwChangedGloss = "English gloss - changed in FW"; // LF adds a gloss to the entry that LD is deleting lfEntry.Senses[0].Gloss = LfMultiText.FromSingleStringMapping("en", lfCreatedGloss); lfEntry.AuthorInfo.ModifiedDate = DateTime.UtcNow; _mongoConnection.UpdateRecord(_lfProject, lfEntry); _lDProject = new LanguageDepotMock(testProjectCode, _lDSettings); var lDcache = _lDProject.FieldWorksProject.Cache; Assert.That(() => lDcache.ServiceLocator.GetObject(_testDeletedEntryGuid), Throws.InstanceOf <KeyNotFoundException>()); var lDFdoEntry = lDcache.ServiceLocator.GetObject(_testEntryGuid) as ILexEntry; Assert.That(lDFdoEntry.SensesOS[0].Gloss.AnalysisDefaultWritingSystem.Text, Is.EqualTo(fwChangedGloss)); DateTime originalLdDateModified = lDFdoEntry.DateModified; // Exercise var sutSynchronize = new SynchronizeAction(_env.Settings, _env.Logger); var timeBeforeRun = DateTime.UtcNow; sutSynchronize.Run(_lfProject); // Verify modified LF entry wins Assert.That(GetGlossFromMongoDb(_testDeletedEntryGuid, originalNumOfFdoEntries + 1, 0), Is.EqualTo(lfCreatedGloss)); Assert.That(GetGlossFromMongoDb(_testEntryGuid, originalNumOfFdoEntries + 1, 0), Is.EqualTo(fwChangedGloss)); Assert.That(GetGlossFromLanguageDepot(_testDeletedEntryGuid, 1), Is.EqualTo(lfCreatedGloss)); LfLexEntry updatedLfEntry = _mongoConnection.GetLfLexEntries().First(e => e.Guid == _testEntryGuid); DateTime updatedLfDateModified = updatedLfEntry.DateModified; Assert.That(updatedLfDateModified, Is.GreaterThan(originalLfDateModified)); Assert.That(updatedLfDateModified, Is.GreaterThan(originalLdDateModified)); Assert.That(_mongoConnection.GetLastSyncedDate(_lfProject), Is.GreaterThanOrEqualTo(timeBeforeRun)); }
public void Action_RunTwiceWithTheSameEntryModifiedEachTime_ShouldCountTwoModifiedInTotal() { // Setup var lfProj = _lfProj; sutFdoToMongo.Run(lfProj); Guid entryGuid = Guid.Parse(TestEntryGuidStr); LfLexEntry entry = _conn.GetLfLexEntryByGuid(entryGuid); FdoCache cache = lfProj.FieldWorksProject.Cache; string vernacularWS = cache.LanguageProject.DefaultVernacularWritingSystem.Id; string changedLexeme = "modified lexeme for this test"; entry.Lexeme = LfMultiText.FromSingleStringMapping(vernacularWS, changedLexeme); entry.AuthorInfo = new LfAuthorInfo(); entry.AuthorInfo.ModifiedDate = DateTime.UtcNow; _conn.UpdateMockLfLexEntry(entry); // Exercise sutMongoToFdo.Run(lfProj); // Verify Assert.That(_counts.Added, Is.EqualTo(0)); Assert.That(_counts.Modified, Is.EqualTo(1)); Assert.That(_counts.Deleted, Is.EqualTo(0)); Assert.That(LfMergeBridgeServices.FormatCommitMessageForLfMerge(_counts.Added, _counts.Modified, _counts.Deleted), Is.EqualTo("Language Forge: 1 entry modified")); // Setup second run string changedLexeme2 = "second modified lexeme for this test"; entry.Lexeme = LfMultiText.FromSingleStringMapping(vernacularWS, changedLexeme2); entry.AuthorInfo = new LfAuthorInfo(); entry.AuthorInfo.ModifiedDate = DateTime.UtcNow; _conn.UpdateMockLfLexEntry(entry); // Exercise second run sutMongoToFdo.Run(lfProj); // Verify second run Assert.That(_counts.Modified, Is.EqualTo(1)); // Added and Deleted shouldn't have changed, but check Modified first // since that's the main point of this test Assert.That(_counts.Added, Is.EqualTo(0)); Assert.That(_counts.Deleted, Is.EqualTo(0)); Assert.That(LfMergeBridgeServices.FormatCommitMessageForLfMerge(_counts.Added, _counts.Modified, _counts.Deleted), Is.EqualTo("Language Forge: 1 entry modified")); }
public void SynchronizeAction_LFDataChangedLDOtherDataChanged_ModifiedDateUpdated() { //Setup TestEnvironment.CopyFwProjectTo(modifiedTestProjectCode, _lDSettings.WebWorkDirectory); Directory.Move(Path.Combine(_lDSettings.WebWorkDirectory, modifiedTestProjectCode), LanguageDepotMock.ProjectFolderPath); _lfProject.IsInitialClone = true; _transferFdoToMongo.Run(_lfProject); var lfEntry = _mongoConnection.GetLfLexEntries().First(e => e.Guid == _testEntryGuid); var originalLfDateModified = lfEntry.DateModified; var originalLfAuthorInfoModifiedDate = lfEntry.AuthorInfo.ModifiedDate; lfEntry.Note = LfMultiText.FromSingleStringMapping("en", "A note from LF"); lfEntry.AuthorInfo.ModifiedDate = DateTime.UtcNow; _mongoConnection.UpdateRecord(_lfProject, lfEntry); var fwChangedGloss = lfEntry.Senses[0].Gloss["en"].Value + " - changed in FW"; _lDProject = new LanguageDepotMock(testProjectCode, _lDSettings); var lDcache = _lDProject.FieldWorksProject.Cache; var lDFdoEntry = lDcache.ServiceLocator.GetObject(_testEntryGuid) as ILexEntry; Assert.That(lDFdoEntry.SensesOS[0].Gloss.AnalysisDefaultWritingSystem.Text, Is.EqualTo(fwChangedGloss)); // Exercise var sutSynchronize = new SynchronizeAction(_env.Settings, _env.Logger); var timeBeforeRun = DateTime.UtcNow; sutSynchronize.Run(_lfProject); // Verify Assert.That(GetGlossFromMongoDb(_testEntryGuid), Is.EqualTo(fwChangedGloss)); var updatedLfEntry = _mongoConnection.GetLfLexEntries().First(e => e.Guid == _testEntryGuid); // LF and LD changed the same entry but different fields, so we want to see the // DateModified change so that LF will re-process the entry. Assert.That(updatedLfEntry.DateModified, Is.GreaterThan(originalLfDateModified)); // The FDO modified date (AuthorInfo.ModifiedDate in LF) should be updated. Assert.That(updatedLfEntry.AuthorInfo.ModifiedDate, Is.GreaterThan(originalLfAuthorInfoModifiedDate)); Assert.That(_mongoConnection.GetLastSyncedDate(_lfProject), Is.GreaterThanOrEqualTo(timeBeforeRun)); }
/// <summary> /// Convert FDO lex entry to LF lex entry. /// </summary> /// <returns>LF entry /// <param name="fdoEntry">Fdo entry.</param> private LfLexEntry FdoLexEntryToLfLexEntry(ILexEntry fdoEntry) { if (fdoEntry == null) { return(null); } ILgWritingSystem AnalysisWritingSystem = ServiceLocator.LanguageProject.DefaultAnalysisWritingSystem; ILgWritingSystem VernacularWritingSystem = ServiceLocator.LanguageProject.DefaultVernacularWritingSystem; var lfEntry = new LfLexEntry(); IMoForm fdoLexeme = fdoEntry.LexemeFormOA; if (fdoLexeme == null) { lfEntry.Lexeme = null; } else { lfEntry.Lexeme = ToMultiText(fdoLexeme.Form); } // Other fields of fdoLexeme (AllomorphEnvironments, LiftResidue, MorphTypeRA, etc.) not mapped // Fields below in alphabetical order by ILexSense property, except for Lexeme foreach (IMoForm allomorph in fdoEntry.AlternateFormsOS) { // Do nothing; LanguageForge doesn't currently handle allomorphs, so we don't convert them } lfEntry.EntryBibliography = ToMultiText(fdoEntry.Bibliography); // TODO: Consider whether to use fdoEntry.CitationFormWithAffixType instead // (which would produce "-s" instead of "s" for the English plural suffix, for instance) lfEntry.CitationForm = ToMultiText(fdoEntry.CitationForm); lfEntry.Note = ToMultiText(fdoEntry.Comment); // DateModified and DateCreated can be confusing, because LF and FDO are doing two different // things with them. In FDO, there is just one DateModified and one DateCreated; simple. But // in LF, there is an AuthorInfo record as well, which contains its own ModifiedDate and CreatedDate // fields. (Note the word order: there's LfEntry.DateCreated, and LfEntry.AuthorInfo.CreatedDate). // The conversion we have chosen to use is: AuthorInfo will correspond to FDO. So FDO.DateCreated // becomes AuthorInfo.CreatedDate, and FDO.DateModified becomes AuthorInfo.ModifiedDate. The two // fields on the LF entry will instead refer to when the *Mongo record* was created or modified, // and the LfEntry.DateCreated and LfEntry.DateModified fields will never be put into FDO. var now = DateTime.UtcNow; if (LfProject.IsInitialClone) { lfEntry.DateCreated = now; } // LanguageForge needs this modified to know there is changed data lfEntry.DateModified = now; if (lfEntry.AuthorInfo == null) { lfEntry.AuthorInfo = new LfAuthorInfo(); } lfEntry.AuthorInfo.CreatedByUserRef = null; lfEntry.AuthorInfo.CreatedDate = fdoEntry.DateCreated.ToUniversalTime(); lfEntry.AuthorInfo.ModifiedByUserRef = null; lfEntry.AuthorInfo.ModifiedDate = fdoEntry.DateModified.ToUniversalTime(); #if DBVERSION_7000068 ILexEtymology fdoEtymology = fdoEntry.EtymologyOA; #else // TODO: Once LF's data model is updated from a single etymology to an array, // convert all of them instead of just the first. E.g., // foreach (ILexEtymology fdoEtymology in fdoEntry.EtymologyOS) { ... } ILexEtymology fdoEtymology = null; if (fdoEntry.EtymologyOS.Count > 0) { fdoEtymology = fdoEntry.EtymologyOS.First(); } #endif if (fdoEtymology != null) { lfEntry.Etymology = ToMultiText(fdoEtymology.Form); lfEntry.EtymologyComment = ToMultiText(fdoEtymology.Comment); lfEntry.EtymologyGloss = ToMultiText(fdoEtymology.Gloss); #if DBVERSION_7000068 lfEntry.EtymologySource = LfMultiText.FromSingleStringMapping(AnalysisWritingSystem.Id, fdoEtymology.Source); #else lfEntry.EtymologySource = ToMultiText(fdoEtymology.LanguageNotes); #endif // fdoEtymology.LiftResidue not mapped } lfEntry.Guid = fdoEntry.Guid; if (fdoEntry.LIFTid == null) { lfEntry.LiftId = null; } else { lfEntry.LiftId = fdoEntry.LIFTid.Normalize(System.Text.NormalizationForm.FormC); // Because LIFT files on disk are NFC and we need to make sure LiftIDs match those on disk } lfEntry.LiteralMeaning = ToMultiText(fdoEntry.LiteralMeaning); if (fdoEntry.PrimaryMorphType != null) { lfEntry.MorphologyType = fdoEntry.PrimaryMorphType.NameHierarchyString; } // TODO: Once LF's data model is updated from a single pronunciation to an array of pronunciations, convert all of them instead of just the first. E.g., //foreach (ILexPronunciation fdoPronunciation in fdoEntry.PronunciationsOS) { ... } if (fdoEntry.PronunciationsOS.Count > 0) { ILexPronunciation fdoPronunciation = fdoEntry.PronunciationsOS.First(); lfEntry.Pronunciation = ToMultiText(fdoPronunciation.Form); lfEntry.CvPattern = LfMultiText.FromSingleITsString(fdoPronunciation.CVPattern, ServiceLocator.WritingSystemFactory); lfEntry.Tone = LfMultiText.FromSingleITsString(fdoPronunciation.Tone, ServiceLocator.WritingSystemFactory); // TODO: Map fdoPronunciation.MediaFilesOS properly (converting video to sound files if necessary) lfEntry.Location = ToStringField(LocationListCode, fdoPronunciation.LocationRA); } lfEntry.EntryRestrictions = ToMultiText(fdoEntry.Restrictions); if (lfEntry.Senses == null) // Shouldn't happen, but let's be careful { lfEntry.Senses = new List <LfSense>(); } lfEntry.Senses.AddRange(fdoEntry.SensesOS.Select(FdoSenseToLfSense)); lfEntry.SummaryDefinition = ToMultiText(fdoEntry.SummaryDefinition); BsonDocument customFieldsAndGuids = _convertCustomField.GetCustomFieldsForThisCmObject(fdoEntry, "entry", ListConverters); BsonDocument customFieldsBson = customFieldsAndGuids["customFields"].AsBsonDocument; BsonDocument customFieldGuids = customFieldsAndGuids["customFieldGuids"].AsBsonDocument; lfEntry.CustomFields = customFieldsBson; lfEntry.CustomFieldGuids = customFieldGuids; return(lfEntry); /* Fields not mapped because it doesn't make sense to map them (e.g., Hvo, backreferences, etc): * fdoEntry.ComplexFormEntries; * fdoEntry.ComplexFormEntryRefs; * fdoEntry.ComplexFormsNotSubentries; * fdoEntry.EntryRefsOS; * fdoEntry.HasMoreThanOneSense; * fdoEntry.HeadWord; // Read-only virtual property * fdoEntry.IsMorphTypesMixed; // Read-only property * fdoEntry.LexEntryReferences; * fdoEntry.MainEntriesOrSensesRS; * fdoEntry.MinimalLexReferences; * fdoEntry.MorphoSyntaxAnalysesOC; * fdoEntry.MorphTypes; * fdoEntry.NumberOfSensesForEntry; * fdoEntry.PicturesOfSenses; * */ /* Fields that would make sense to map, but that we don't because LF doesn't handle them (e.g., allomorphs): * fdoEntry.AllAllomorphs; // LF doesn't handle allomorphs, so skip all allomorph-related fields * fdoEntry.AlternateFormsOS; * fdoEntry.CitationFormWithAffixType; // Citation form already mapped * fdoEntry.DoNotPublishInRC; * fdoEntry.DoNotShowMainEntryInRC; * fdoEntry.DoNotUseForParsing; * fdoEntry.HomographForm; * fdoEntry.HomographFormKey; * fdoEntry.HomographNumber; * fdoEntry.ImportResidue; * fdoEntry.LiftResidue; * fdoEntry.PronunciationsOS * fdoEntry.PublishAsMinorEntry; * fdoEntry.PublishIn; * fdoEntry.ShowMainEntryIn; * fdoEntry.Subentries; * fdoEntry.VariantEntryRefs; * fdoEntry.VariantFormEntries; * fdoEntry.VisibleComplexFormBackRefs; * fdoEntry.VisibleComplexFormEntries; * fdoEntry.VisibleVariantEntryRefs; * */ }
/// <summary> /// Gets the data for one custom field, and any relevant GUIDs. /// </summary> /// <param name="hvo">Hvo of object we're getting the field for.</param> /// <param name="flid">Flid for this field.</param> /// <param name="fieldSourceType">Either "entry", "senses" or "examples". Could also be "allomorphs", eventually.</param> /// <param name="bsonForThisField">Output of a BsonDocument with the following structure: <br /> /// { fieldName: { "value": BsonValue, "guid": "some-guid-as-a-string" } } <br /> /// -OR- <br /> /// { fieldName: { "value": BsonValue, "guid": ["guid1", "guid2", "guid3"] } } <br /> /// The format of the fieldName key will be "customField_FOO_field_name_with_underscores", /// where FOO is one of "entry", "senses", or "examples". <br /> /// The type of the "guid" value (array or string) will determine whether there is a single GUID, /// or a list of GUIDs that happens to contain only one entry. /// If there is no "guid" key, that field has no need for a GUID. (E.g., a number). /// </param> /// <param name="listConverters">Dictionary of ConvertLcmToMongoOptionList instances, keyed by list code</param> private BsonDocument GetCustomFieldData(int hvo, int flid, string fieldSourceType, IDictionary <string, ConvertLcmToMongoOptionList> listConverters) { BsonValue fieldValue = null; BsonValue fieldGuid = null; // Might be a single value, might be a list (as a BsonArray) ISilDataAccessManaged data = (ISilDataAccessManaged)cache.DomainDataByFlid; CellarPropertyType LcmFieldType = (CellarPropertyType)LcmMetaData.GetFieldType(flid); var dataGuids = new List <Guid>(); // Valid field types in Lcm are GenDate, Integer, String, OwningAtomic, ReferenceAtomic, and ReferenceCollection, so that's all we implement. switch (LcmFieldType) { case CellarPropertyType.GenDate: GenDate genDate = data.get_GenDateProp(hvo, flid); string genDateStr = genDate.ToLongString(); // LF wants single-string fields in the format { "ws": { "value": "contents" } } fieldValue = String.IsNullOrEmpty(genDateStr) ? null : LfMultiText.FromSingleStringMapping( MagicStrings.LanguageCodeForGenDateFields, genDateStr).AsBsonDocument(); break; // When parsing, will use GenDate.TryParse(str, out genDate) case CellarPropertyType.Integer: fieldValue = new BsonInt32(data.get_IntProp(hvo, flid)); if (fieldValue.AsInt32 == default(Int32)) { fieldValue = null; // Suppress int fields with 0 in them, to save Mongo DB space } else { // LF wants single-string fields in the format { "ws": { "value": "contents" } } fieldValue = LfMultiText.FromSingleStringMapping( MagicStrings.LanguageCodeForIntFields, fieldValue.AsInt32.ToString()).AsBsonDocument(); } break; case CellarPropertyType.OwningAtomic: case CellarPropertyType.ReferenceAtomic: int ownedHvo = data.get_ObjectProp(hvo, flid); fieldValue = GetCustomReferencedObject(ownedHvo, flid, listConverters, ref dataGuids); if (fieldValue != null && LcmFieldType == CellarPropertyType.ReferenceAtomic) { // Single CmPossiblity reference - LF expects format like { "value": "key of possibility" } fieldValue = new BsonDocument("value", fieldValue); } fieldGuid = new BsonString(dataGuids.FirstOrDefault().ToString()); break; case CellarPropertyType.MultiUnicode: ITsMultiString tss = data.get_MultiStringProp(hvo, flid); if (tss != null && tss.StringCount > 0) { fieldValue = LfMultiText.FromMultiITsString(tss, servLoc.WritingSystemManager).AsBsonDocument(); } break; case CellarPropertyType.OwningCollection: case CellarPropertyType.OwningSequence: case CellarPropertyType.ReferenceCollection: case CellarPropertyType.ReferenceSequence: int[] listHvos = data.VecProp(hvo, flid); var innerValues = new BsonArray(listHvos.Select(listHvo => GetCustomReferencedObject(listHvo, flid, listConverters, ref dataGuids)).Where(x => x != null)); if (innerValues.Count == 0) { fieldValue = null; } else { fieldValue = new BsonDocument("values", innerValues); fieldGuid = new BsonArray(dataGuids.Select(guid => guid.ToString())); } break; case CellarPropertyType.String: ITsString iTsValue = data.get_StringProp(hvo, flid); if (iTsValue == null || String.IsNullOrEmpty(iTsValue.Text)) { fieldValue = null; } else { fieldValue = LfMultiText.FromSingleITsString(iTsValue, servLoc.WritingSystemManager).AsBsonDocument(); } break; default: fieldValue = null; if (logger != null) { logger.Warning("Lcm CellarPropertyType.{0} not recognized for LF custom field", LcmFieldType.ToString()); } break; } if (fieldValue == null) { return(null); } else { var result = new BsonDocument(); result.Add("value", fieldValue ?? BsonNull.Value); // BsonValues aren't allowed to have C# nulls; they have their own null representation if (fieldGuid is BsonArray) { result.Add("guid", fieldGuid, ((BsonArray)fieldGuid).Count > 0); } else { result.Add("guid", fieldGuid, fieldGuid != null); } return(result); } }