From f518d8d925ae9c6fa53c856df519d425f15d27c1 Mon Sep 17 00:00:00 2001 From: Robin Munn Date: Tue, 9 Jul 2024 10:56:08 +0700 Subject: [PATCH] Don't serialize comments to JSON when calling LfMergeBridge (#338) * Get ready to use new LfMergeBridge API Many parts of the LfMerge model have been transferred over to LfMergeBridge, so that the new API can reference the same data types that LfMerge does. * Register new model class location with Mongo The Mongo class registration needs to be told about the new namespace that some of our model classes live in, so that the auto-registration can do its job and they can be serialized to Mongo correctly. * Call LfMergeBridge without JSON serialization Now that the LfMergeBridge code is working, we can switch to calling it without serializing comments as JSON. This will save quite a bit of memory for large projects. * Remove no-longer-needed LfMergeBridge option We no longer need the `serializedCommentsFromLfMerge` option now that we pass the comments in as objects. * Use new LfMergeBridge API to write to ChorusNotes Similarly to what we did with the GetChorusNotes handler, the other direction (WriteToChorusNotes) can also skip serializing JSON. * Use LfMergeBridge NuGet package LfMergeBridge build in GitHub Actions now uploads nuget packages, so we can reference the latest LfMergeBridge package to use the new API. * Update LibChorus to go along with LfMergeBridge update The new LfMergeBridge package needs a higher version of LibChorus than we were referencing before. * Register new model class location for test double In addition to registering the Mongo serialization options for the real MongoConnection, we also need to do the same thing for the test double of the MongoConnection class, so that it can test real data correctly. --- src/LfMerge.Core.Tests/Lcm/LcmTestBase.cs | 2 +- src/LfMerge.Core.Tests/Lcm/RoundTripTests.cs | 1 + .../Lcm/TransferLcmToMongoActionTests.cs | 1 + .../Lcm/TransferMongoToLcmActionTests.cs | 1 + src/LfMerge.Core.Tests/TestDoubles.cs | 3 +- .../ConvertLcmToMongoComments.cs | 51 +++++------ .../ConvertLcmToMongoLexicon.cs | 1 + .../ConvertLcmToMongoOptionList.cs | 1 + .../ConvertMongoToLcmComments.cs | 87 +++++-------------- .../ConvertMongoToLcmLexicon.cs | 1 + .../ConvertMongoToLcmOptionList.cs | 1 + .../LanguageForge/Model/IHasNullableGuid.cs | 15 ---- .../LanguageForge/Model/LfAuthorInfo.cs | 16 ---- .../LanguageForge/Model/LfComment.cs | 43 --------- .../LanguageForge/Model/LfCommentRegarding.cs | 31 ------- .../LanguageForge/Model/LfCommentReply.cs | 34 -------- .../LanguageForge/Model/LfExample.cs | 1 + .../Model/LfInputSystemRecord.cs | 20 ----- .../LanguageForge/Model/LfLexEntry.cs | 1 + .../LanguageForge/Model/LfMultiParagraph.cs | 1 + .../LanguageForge/Model/LfOptionList.cs | 26 ------ .../LanguageForge/Model/LfOptionListItem.cs | 18 ---- .../LanguageForge/Model/LfParagraph.cs | 1 + .../LanguageForge/Model/LfPicture.cs | 1 + .../LanguageForge/Model/LfProject.cs | 23 ----- .../LanguageForge/Model/LfSense.cs | 1 + src/LfMerge.Core/LfMerge.Core.csproj | 10 +-- .../MongoConnector/IMongoConnection.cs | 1 + .../MongoConnector/MongoConnection.cs | 3 +- .../MongoConnector/MongoProjectRecord.cs | 2 +- src/LfMerge.Core/Reporting/ConversionError.cs | 1 + 31 files changed, 73 insertions(+), 326 deletions(-) delete mode 100644 src/LfMerge.Core/LanguageForge/Model/IHasNullableGuid.cs delete mode 100644 src/LfMerge.Core/LanguageForge/Model/LfAuthorInfo.cs delete mode 100644 src/LfMerge.Core/LanguageForge/Model/LfComment.cs delete mode 100644 src/LfMerge.Core/LanguageForge/Model/LfCommentRegarding.cs delete mode 100644 src/LfMerge.Core/LanguageForge/Model/LfCommentReply.cs delete mode 100644 src/LfMerge.Core/LanguageForge/Model/LfInputSystemRecord.cs delete mode 100644 src/LfMerge.Core/LanguageForge/Model/LfOptionList.cs delete mode 100644 src/LfMerge.Core/LanguageForge/Model/LfOptionListItem.cs delete mode 100644 src/LfMerge.Core/LanguageForge/Model/LfProject.cs diff --git a/src/LfMerge.Core.Tests/Lcm/LcmTestBase.cs b/src/LfMerge.Core.Tests/Lcm/LcmTestBase.cs index 5d999b09..3bc29340 100644 --- a/src/LfMerge.Core.Tests/Lcm/LcmTestBase.cs +++ b/src/LfMerge.Core.Tests/Lcm/LcmTestBase.cs @@ -6,7 +6,7 @@ using LfMerge.Core.Actions; using LfMerge.Core.DataConverters; using LfMerge.Core.FieldWorks; -using LfMerge.Core.LanguageForge.Model; +using LfMergeBridge.LfMergeModel; using LfMerge.Core.MongoConnector; using LfMerge.Core.Reporting; using LfMerge.Core.Settings; diff --git a/src/LfMerge.Core.Tests/Lcm/RoundTripTests.cs b/src/LfMerge.Core.Tests/Lcm/RoundTripTests.cs index 7902a85c..75a99f65 100644 --- a/src/LfMerge.Core.Tests/Lcm/RoundTripTests.cs +++ b/src/LfMerge.Core.Tests/Lcm/RoundTripTests.cs @@ -6,6 +6,7 @@ using System.Linq; using LfMerge.Core.DataConverters; using LfMerge.Core.LanguageForge.Model; +using LfMergeBridge.LfMergeModel; using MongoDB.Bson; using NUnit.Framework; using SIL.LCModel; diff --git a/src/LfMerge.Core.Tests/Lcm/TransferLcmToMongoActionTests.cs b/src/LfMerge.Core.Tests/Lcm/TransferLcmToMongoActionTests.cs index db54a05d..3a7d8b55 100644 --- a/src/LfMerge.Core.Tests/Lcm/TransferLcmToMongoActionTests.cs +++ b/src/LfMerge.Core.Tests/Lcm/TransferLcmToMongoActionTests.cs @@ -8,6 +8,7 @@ using LfMerge.Core.DataConverters; using LfMerge.Core.LanguageForge.Config; using LfMerge.Core.LanguageForge.Model; +using LfMergeBridge.LfMergeModel; using NUnit.Framework; using SIL.LCModel; diff --git a/src/LfMerge.Core.Tests/Lcm/TransferMongoToLcmActionTests.cs b/src/LfMerge.Core.Tests/Lcm/TransferMongoToLcmActionTests.cs index df306d5c..bec32938 100644 --- a/src/LfMerge.Core.Tests/Lcm/TransferMongoToLcmActionTests.cs +++ b/src/LfMerge.Core.Tests/Lcm/TransferMongoToLcmActionTests.cs @@ -3,6 +3,7 @@ using LfMerge.Core.Actions.Infrastructure; using LfMerge.Core.DataConverters; using LfMerge.Core.LanguageForge.Model; +using LfMergeBridge.LfMergeModel; using MongoDB.Bson; using NUnit.Framework; using System; diff --git a/src/LfMerge.Core.Tests/TestDoubles.cs b/src/LfMerge.Core.Tests/TestDoubles.cs index ff314905..01a9a079 100644 --- a/src/LfMerge.Core.Tests/TestDoubles.cs +++ b/src/LfMerge.Core.Tests/TestDoubles.cs @@ -7,6 +7,7 @@ using System.Linq; using System.Linq.Expressions; using Bugsnag.Payload; +using LfMergeBridge.LfMergeModel; using IniParser.Model; using LfMerge.Core.Actions; using LfMerge.Core.Actions.Infrastructure; @@ -107,7 +108,7 @@ public static void Initialize() ConventionRegistry.Register( "My Custom Conventions", pack, - t => t.FullName.StartsWith("LfMerge.")); + t => t.FullName.StartsWith("LfMerge.") || t.FullName.StartsWith("LfMergeBridge.LfMergeModel")); // Register class mappings before opening first connection new MongoRegistrarForLfConfig().RegisterClassMappings(); diff --git a/src/LfMerge.Core/DataConverters/ConvertLcmToMongoComments.cs b/src/LfMerge.Core/DataConverters/ConvertLcmToMongoComments.cs index 4bae34fa..b8e35015 100644 --- a/src/LfMerge.Core/DataConverters/ConvertLcmToMongoComments.cs +++ b/src/LfMerge.Core/DataConverters/ConvertLcmToMongoComments.cs @@ -7,7 +7,8 @@ using LfMerge.Core.Logging; using LfMerge.Core.MongoConnector; using LfMerge.Core.LanguageForge.Config; -using LfMerge.Core.LanguageForge.Model; +using LfMergeBridge; +using LfMergeBridge.LfMergeModel; using LfMerge.Core.Reporting; using Newtonsoft.Json; using SIL.LCModel; @@ -43,17 +44,13 @@ public List> RunConversion() var exceptions = new List>(); var fixedComments = new List(_conn.GetComments(_project)); string allCommentsJson = JsonConvert.SerializeObject(fixedComments); - // _logger.Debug("Doing Lcm->Mongo direction. The json for ALL comments from Mongo would be: {0}", allCommentsJson); - // _logger.Debug("Doing Lcm->Mongo direction. About to call LfMergeBridge with that JSON..."); string bridgeOutput; - if (CallLfMergeBridge(allCommentsJson, out bridgeOutput)) + GetChorusNotesResponse response = CallLfMergeBridge(fixedComments, out bridgeOutput); + if (response != null) { - string newCommentsStr = ConvertMongoToLcmComments.GetPrefixedStringFromLfMergeBridgeOutput(bridgeOutput, "New comments not yet in LF: "); - string newRepliesStr = ConvertMongoToLcmComments.GetPrefixedStringFromLfMergeBridgeOutput(bridgeOutput, "New replies on comments already in LF: "); - string newStatusChangesStr = ConvertMongoToLcmComments.GetPrefixedStringFromLfMergeBridgeOutput(bridgeOutput, "New status changes on comments already in LF: "); - List comments = JsonConvert.DeserializeObject>(newCommentsStr); - List>> replies = JsonConvert.DeserializeObject>>>(newRepliesStr); - List>> statusChanges = JsonConvert.DeserializeObject>>>(newStatusChangesStr); + List comments = response.LfComments; + List>> replies = response.LfReplies; + List>> statusChanges = response.LfStatusChanges; var entryErrorsByGuid = _entryConversionErrors.EntryErrors.ToDictionary(s => s.EntryGuid()); foreach (LfComment comment in comments) @@ -290,28 +287,26 @@ public ILexEntry OwningEntry(Guid guidOfUnknownLcmObject) } } - private bool CallLfMergeBridge(string bridgeInput, out string bridgeOutput) + private GetChorusNotesResponse CallLfMergeBridge(List comments, out string bridgeOutput) { // Call into LF Bridge to do the work. bridgeOutput = string.Empty; - using (var tmpFile = new SIL.IO.TempFile(bridgeInput)) + var bridgeInput = new LfMergeBridge.GetChorusNotesInput { LfComments = comments }; + var options = new Dictionary { - var options = new Dictionary - { - {"-p", _project.FwDataPath}, - {"serializedCommentsFromLfMerge", tmpFile.Path}, - }; - if (!LfMergeBridge.LfMergeBridge.Execute("Language_Forge_Get_Chorus_Notes", _progress, - options, out bridgeOutput)) - { - _logger.Error("Got an error from Language_Forge_Get_Chorus_Notes: {0}", bridgeOutput); - return false; - } - else - { - // _logger.Debug("Got the JSON from Language_Forge_Get_Chorus_Notes: {0}", bridgeOutput); - return true; - } + {"-p", _project.FwDataPath}, + }; + LfMergeBridge.LfMergeBridge.ExtraInputData.Add(options, bridgeInput); + if (!LfMergeBridge.LfMergeBridge.Execute("Language_Forge_Get_Chorus_Notes", _progress, + options, out bridgeOutput)) + { + _logger.Error("Got an error from Language_Forge_Get_Chorus_Notes: {0}", bridgeOutput); + return null; + } + else + { + var success = LfMergeBridge.LfMergeBridge.ExtraOutputData.TryGetValue(options, out var outputObject); + return outputObject as GetChorusNotesResponse; } } } diff --git a/src/LfMerge.Core/DataConverters/ConvertLcmToMongoLexicon.cs b/src/LfMerge.Core/DataConverters/ConvertLcmToMongoLexicon.cs index 33792518..413bdd9a 100644 --- a/src/LfMerge.Core/DataConverters/ConvertLcmToMongoLexicon.cs +++ b/src/LfMerge.Core/DataConverters/ConvertLcmToMongoLexicon.cs @@ -7,6 +7,7 @@ using LfMerge.Core.FieldWorks; using LfMerge.Core.LanguageForge.Config; using LfMerge.Core.LanguageForge.Model; +using LfMergeBridge.LfMergeModel; using LfMerge.Core.Logging; using LfMerge.Core.MongoConnector; using LfMerge.Core.Reporting; diff --git a/src/LfMerge.Core/DataConverters/ConvertLcmToMongoOptionList.cs b/src/LfMerge.Core/DataConverters/ConvertLcmToMongoOptionList.cs index 4196131d..ea9c6097 100644 --- a/src/LfMerge.Core/DataConverters/ConvertLcmToMongoOptionList.cs +++ b/src/LfMerge.Core/DataConverters/ConvertLcmToMongoOptionList.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Linq; using LfMerge.Core.LanguageForge.Model; +using LfMergeBridge.LfMergeModel; using LfMerge.Core.Logging; using SIL.LCModel; using SIL.LCModel.Core.KernelInterfaces; diff --git a/src/LfMerge.Core/DataConverters/ConvertMongoToLcmComments.cs b/src/LfMerge.Core/DataConverters/ConvertMongoToLcmComments.cs index ca2b0eaa..8f70fb4e 100644 --- a/src/LfMerge.Core/DataConverters/ConvertMongoToLcmComments.cs +++ b/src/LfMerge.Core/DataConverters/ConvertMongoToLcmComments.cs @@ -3,14 +3,14 @@ using System; using System.Collections.Generic; using System.Linq; -using LfMerge.Core.Actions.Infrastructure; using LfMerge.Core.Logging; using LfMerge.Core.MongoConnector; using LfMerge.Core.LanguageForge.Model; +using LfMergeBridge.LfMergeModel; using LfMerge.Core.Reporting; using MongoDB.Bson; -using Newtonsoft.Json; using SIL.Progress; +using LfMergeBridge; namespace LfMerge.Core.DataConverters { @@ -84,16 +84,15 @@ public List> RunConversion(Dictionary(exceptions.Select(s => s.CommentGuid().ToString())); - string unskippedCommentsJson = JsonConvert.SerializeObject(commentsWithIds.Where(s => !skippedCommentGuids.Contains(s.Key))); + var unskippedComments = commentsWithIds.Where(s => !skippedCommentGuids.Contains(s.Key)).ToList(); string bridgeOutput; - CallLfMergeBridge(unskippedCommentsJson, out bridgeOutput); - // LfMergeBridge returns two lists of IDs (comment IDs or reply IDs) that need to have their GUIDs updated in Mongo. - string commentGuidMappingsStr = GetPrefixedStringFromLfMergeBridgeOutput(bridgeOutput, "New comment ID->Guid mappings: "); - string replyGuidMappingsStr = GetPrefixedStringFromLfMergeBridgeOutput(bridgeOutput, "New reply ID->Guid mappings: "); - Dictionary commentIdToGuidMappings = ParseGuidMappings(commentGuidMappingsStr); - Dictionary uniqIdToGuidMappings = ParseGuidMappings(replyGuidMappingsStr); - _conn.SetCommentGuids(_project, commentIdToGuidMappings); - _conn.SetCommentReplyGuids(_project, uniqIdToGuidMappings); + var response = CallLfMergeBridge(unskippedComments, out bridgeOutput); + if (response != null) + { + // LfMergeBridge returns two lists of IDs (comment IDs or reply IDs) that need to have their GUIDs updated in Mongo. + _conn.SetCommentGuids(_project, response.CommentIdsThatNeedGuids); + _conn.SetCommentReplyGuids(_project, response.ReplyIdsThatNeedGuids); + } return exceptions; } @@ -102,72 +101,34 @@ private LfLexEntry GetLexEntry(ObjectId idOfEntry) return _conn.GetRecords(_project, MagicStrings.LfCollectionNameForLexicon, entry => entry.Id == idOfEntry).First(); } - private bool CallLfMergeBridge(string bridgeInput, out string bridgeOutput) + private WriteToChorusNotesResponse CallLfMergeBridge(List> lfComments, out string bridgeOutput) { bridgeOutput = string.Empty; - using (var tmpFile = new SIL.IO.TempFile(bridgeInput)) + var options = new Dictionary { - var options = new Dictionary - { - {"-p", _project.FwDataPath}, - {"serializedCommentsFromLfMerge", tmpFile.Path} - }; - try { + {"-p", _project.FwDataPath}, + }; + try { + var bridgeInput = new WriteToChorusNotesInput { LfComments = lfComments }; + LfMergeBridge.LfMergeBridge.ExtraInputData.Add(options, bridgeInput); if (!LfMergeBridge.LfMergeBridge.Execute("Language_Forge_Write_To_Chorus_Notes", _progress, options, out bridgeOutput)) { _logger.Error("Got an error from Language_Forge_Write_To_Chorus_Notes: {0}", bridgeOutput); - return false; + return null; } else { - // _logger.Debug("Good output from Language_Forge_Write_To_Chorus_Notes: {0}", bridgeOutput); - return true; - } - } - catch (NullReferenceException) - { - _logger.Debug("Got an exception. Before rethrowing it, here is what LfMergeBridge sent:"); - _logger.Debug("{0}", bridgeOutput); - throw; + var success = LfMergeBridge.LfMergeBridge.ExtraOutputData.TryGetValue(options, out var outputObject); + return outputObject as WriteToChorusNotesResponse; } } - } - - public static string GetPrefixedStringFromLfMergeBridgeOutput(string lfMergeBridgeOutput, string prefix) - { - if (string.IsNullOrEmpty(prefix) || string.IsNullOrEmpty(lfMergeBridgeOutput)) - { - return string.Empty; - } - string result = LfMergeBridgeServices.GetLineContaining(lfMergeBridgeOutput, prefix); - if (result.StartsWith(prefix)) + catch (NullReferenceException) { - return result.Substring(prefix.Length); - } - else - { - return string.Empty; // If the "prefix" wasn't actually a prefix, this wasn't the string we wanted. - } - } - - public Dictionary ParseGuidMappings(string input) - { - string[] parts = input.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); - var result = new Dictionary(); - foreach (string part in parts) - { - string[] kv = part.Split(new char[] { '=' }, StringSplitOptions.RemoveEmptyEntries); - if (kv.Length == 2) - { - Guid parsed; - if (Guid.TryParse(kv[1], out parsed)) - { - result[kv[0]] = parsed; - } - } + _logger.Debug("Got an exception. Before rethrowing it, here is what LfMergeBridge sent:"); + _logger.Debug("{0}", bridgeOutput); + throw; } - return result; } } } diff --git a/src/LfMerge.Core/DataConverters/ConvertMongoToLcmLexicon.cs b/src/LfMerge.Core/DataConverters/ConvertMongoToLcmLexicon.cs index 1ae0de38..2371695a 100644 --- a/src/LfMerge.Core/DataConverters/ConvertMongoToLcmLexicon.cs +++ b/src/LfMerge.Core/DataConverters/ConvertMongoToLcmLexicon.cs @@ -7,6 +7,7 @@ using LfMerge.Core.DataConverters.CanonicalSources; using LfMerge.Core.FieldWorks; using LfMerge.Core.LanguageForge.Model; +using LfMergeBridge.LfMergeModel; using LfMerge.Core.Logging; using LfMerge.Core.MongoConnector; using LfMerge.Core.Reporting; diff --git a/src/LfMerge.Core/DataConverters/ConvertMongoToLcmOptionList.cs b/src/LfMerge.Core/DataConverters/ConvertMongoToLcmOptionList.cs index 164bbce3..e33a4f96 100644 --- a/src/LfMerge.Core/DataConverters/ConvertMongoToLcmOptionList.cs +++ b/src/LfMerge.Core/DataConverters/ConvertMongoToLcmOptionList.cs @@ -5,6 +5,7 @@ using System.Linq; using LfMerge.Core.DataConverters.CanonicalSources; using LfMerge.Core.LanguageForge.Model; +using LfMergeBridge.LfMergeModel; using LfMerge.Core.Logging; using SIL.LCModel; diff --git a/src/LfMerge.Core/LanguageForge/Model/IHasNullableGuid.cs b/src/LfMerge.Core/LanguageForge/Model/IHasNullableGuid.cs deleted file mode 100644 index 383999a4..00000000 --- a/src/LfMerge.Core/LanguageForge/Model/IHasNullableGuid.cs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) 2016 SIL International -// This software is licensed under the MIT license (http://opensource.org/licenses/MIT) -using System; -//using MongoDB.Bson; -//using MongoDB.Bson.Serialization.Attributes; - -namespace LfMerge.Core.LanguageForge.Model -{ - public interface IHasNullableGuid - { -// [BsonRepresentation(BsonType.String)] - Guid? Guid { get; set; } - } -} - diff --git a/src/LfMerge.Core/LanguageForge/Model/LfAuthorInfo.cs b/src/LfMerge.Core/LanguageForge/Model/LfAuthorInfo.cs deleted file mode 100644 index 79f869b5..00000000 --- a/src/LfMerge.Core/LanguageForge/Model/LfAuthorInfo.cs +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (c) 2016 SIL International -// This software is licensed under the MIT license (http://opensource.org/licenses/MIT) -using System; -using MongoDB.Bson; - -namespace LfMerge.Core.LanguageForge.Model -{ - public class LfAuthorInfo : LfFieldBase - { - public ObjectId? CreatedByUserRef { get; set; } - public DateTime CreatedDate { get; set; } - public ObjectId? ModifiedByUserRef { get; set; } - public DateTime ModifiedDate { get; set; } - } -} - diff --git a/src/LfMerge.Core/LanguageForge/Model/LfComment.cs b/src/LfMerge.Core/LanguageForge/Model/LfComment.cs deleted file mode 100644 index e72d48cb..00000000 --- a/src/LfMerge.Core/LanguageForge/Model/LfComment.cs +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (c) 2016 SIL International -// This software is licensed under the MIT license (http://opensource.org/licenses/MIT) -using System; -using System.Collections.Generic; -using MongoDB.Bson; -using MongoDB.Bson.Serialization.Attributes; - -namespace LfMerge.Core.LanguageForge.Model -{ - public class LfComment : LfFieldBase, IHasNullableGuid - { - public ObjectId Id { get; set; } - [BsonRepresentation(BsonType.String)] - public Guid? Guid { get; set; } - public LfAuthorInfo AuthorInfo { get; set; } - public string AuthorNameAlternate { get; set; } // Used in sending comments to FW; should be null when serializing to Mongo - public LfCommentRegarding Regarding { get; set; } - public DateTime DateCreated { get; set; } - public DateTime DateModified { get; set; } - public string Content { get; set; } - public string Status { get; set; } - [BsonRepresentation(BsonType.String)] - public Guid? StatusGuid { get; set; } - public bool IsDeleted { get; set; } - public List Replies { get; set; } - public ObjectId EntryRef { get; set; } - public int Score { get; set; } - public string ContextGuid { get; set; } // not really a GUID - - public bool ShouldSerializeGuid() { return (Guid != null && Guid.Value != System.Guid.Empty); } - public bool ShouldSerializeDateCreated() { return true; } - public bool ShouldSerializeDateModified() { return true; } - public bool ShouldSerializeContent() { return ( ! String.IsNullOrEmpty(Content)); } - public bool ShouldSerializeAuthorNameAlternate() { return ( ! String.IsNullOrEmpty(AuthorNameAlternate)); } - public bool ShouldSerializeStatusGuid() { return (StatusGuid != null && StatusGuid.Value != System.Guid.Empty); } - public bool ShouldSerializeReplies() { return (Replies != null && Replies.Count > 0); } - - public LfComment() { - Replies = new List(); - } - } -} - diff --git a/src/LfMerge.Core/LanguageForge/Model/LfCommentRegarding.cs b/src/LfMerge.Core/LanguageForge/Model/LfCommentRegarding.cs deleted file mode 100644 index c12ad654..00000000 --- a/src/LfMerge.Core/LanguageForge/Model/LfCommentRegarding.cs +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (c) 2016 SIL International -// This software is licensed under the MIT license (http://opensource.org/licenses/MIT) -using System; -using System.Collections.Generic; -using MongoDB.Bson; -using MongoDB.Bson.Serialization.Attributes; - -namespace LfMerge.Core.LanguageForge.Model -{ - public class LfCommentRegarding : LfFieldBase - { - public string TargetGuid { get; set; } - public string Field { get; set; } - public string FieldNameForDisplay { get; set; } - public string FieldValue { get; set; } - public string InputSystem { get; set; } - public string InputSystemAbbreviation { get; set; } - public string Word { get; set; } - public string Meaning { get; set; } - - public bool ShouldSerializeEntryGuid() { return ( ! String.IsNullOrEmpty(TargetGuid)); } - public bool ShouldSerializeField() { return ( ! String.IsNullOrEmpty(Field)); } - public bool ShouldSerializeFieldNameForDisplay() { return ( ! String.IsNullOrEmpty(FieldNameForDisplay)); } - public bool ShouldSerializeFieldValue() { return ( ! String.IsNullOrEmpty(FieldValue)); } - public bool ShouldSerializeInputSystem() { return ( ! String.IsNullOrEmpty(InputSystem)); } - public bool ShouldSerializeInputSystemAbbreviation() { return ( ! String.IsNullOrEmpty(InputSystemAbbreviation)); } - public bool ShouldSerializeWord() { return ( ! String.IsNullOrEmpty(Word)); } - public bool ShouldSerializeMeaning() { return ( ! String.IsNullOrEmpty(Meaning)); } - } -} - diff --git a/src/LfMerge.Core/LanguageForge/Model/LfCommentReply.cs b/src/LfMerge.Core/LanguageForge/Model/LfCommentReply.cs deleted file mode 100644 index b3d15b42..00000000 --- a/src/LfMerge.Core/LanguageForge/Model/LfCommentReply.cs +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (c) 2016 SIL International -// This software is licensed under the MIT license (http://opensource.org/licenses/MIT) -using System; -using System.Collections.Generic; -using MongoDB.Bson; -using MongoDB.Bson.Serialization.Attributes; - -namespace LfMerge.Core.LanguageForge.Model -{ - [BsonIgnoreExtraElements] // WARNING: Beware of using FindOneAndReplace() with IgnoreExtraElements, as you can lose data - public class LfCommentReply : LfFieldBase, IHasNullableGuid - { - [BsonRepresentation(BsonType.String)] - public Guid? Guid { get; set; } - public LfAuthorInfo AuthorInfo { get; set; } - public string AuthorNameAlternate { get; set; } // Used in sending comments to FW; should be null when serializing to Mongo - public string Content { get; set; } - [BsonElement("id")] - public string UniqId { get; set; } // If we name this field "Id", the C# driver tries to map it to _id and always thinks it is null - public bool IsDeleted { get; set; } - - public bool ShouldSerializeGuid() { return (Guid != null && Guid.Value != System.Guid.Empty); } - public bool ShouldSerializeContent() { return ( ! String.IsNullOrEmpty(Content)); } - public bool ShouldSerializeAuthorNameAlternate() { return ( ! String.IsNullOrEmpty(AuthorNameAlternate)); } - public bool ShouldSerializeId() { return ( ! String.IsNullOrEmpty(UniqId)); } - // We almost always want to store the IsDeleted value, unless the reply is pretty much empty of any useful content. - public bool ShouldSerializeIsDeleted() { return IsDeleted || ShouldSerializeGuid() || ShouldSerializeContent() || ShouldSerializeId(); } - - public LfCommentReply() { - // Any lists, etc., should be populated in here - } - } -} - diff --git a/src/LfMerge.Core/LanguageForge/Model/LfExample.cs b/src/LfMerge.Core/LanguageForge/Model/LfExample.cs index f65abd29..0319fad1 100644 --- a/src/LfMerge.Core/LanguageForge/Model/LfExample.cs +++ b/src/LfMerge.Core/LanguageForge/Model/LfExample.cs @@ -3,6 +3,7 @@ using System; using MongoDB.Bson; using MongoDB.Bson.Serialization.Attributes; +using LfMergeBridge.LfMergeModel; namespace LfMerge.Core.LanguageForge.Model { diff --git a/src/LfMerge.Core/LanguageForge/Model/LfInputSystemRecord.cs b/src/LfMerge.Core/LanguageForge/Model/LfInputSystemRecord.cs deleted file mode 100644 index c53d636a..00000000 --- a/src/LfMerge.Core/LanguageForge/Model/LfInputSystemRecord.cs +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (c) 2016-2018 SIL International -// This software is licensed under the MIT license (http://opensource.org/licenses/MIT) -using MongoDB.Bson.Serialization.Attributes; - -namespace LfMerge.Core.LanguageForge.Model -{ - [BsonIgnoreExtraElements] - public class LfInputSystemRecord - { - public string Abbreviation { get; set; } - public string Tag { get; set; } - public string LanguageName { get; set; } - public bool IsRightToLeft { get; set; } - - // We'll store vernacular / analysis writing system info when - // importing LCM projects, but LF won't be using this information - public bool VernacularWS { get; set; } - public bool AnalysisWS { get; set; } - } -} diff --git a/src/LfMerge.Core/LanguageForge/Model/LfLexEntry.cs b/src/LfMerge.Core/LanguageForge/Model/LfLexEntry.cs index 41aa85b0..28fb02a6 100644 --- a/src/LfMerge.Core/LanguageForge/Model/LfLexEntry.cs +++ b/src/LfMerge.Core/LanguageForge/Model/LfLexEntry.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using MongoDB.Bson; using MongoDB.Bson.Serialization.Attributes; +using LfMergeBridge.LfMergeModel; namespace LfMerge.Core.LanguageForge.Model { diff --git a/src/LfMerge.Core/LanguageForge/Model/LfMultiParagraph.cs b/src/LfMerge.Core/LanguageForge/Model/LfMultiParagraph.cs index 77485c3c..be23a363 100644 --- a/src/LfMerge.Core/LanguageForge/Model/LfMultiParagraph.cs +++ b/src/LfMerge.Core/LanguageForge/Model/LfMultiParagraph.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using MongoDB.Bson; using MongoDB.Bson.Serialization.Attributes; +using LfMergeBridge.LfMergeModel; namespace LfMerge.Core.LanguageForge.Model { diff --git a/src/LfMerge.Core/LanguageForge/Model/LfOptionList.cs b/src/LfMerge.Core/LanguageForge/Model/LfOptionList.cs deleted file mode 100644 index 60206e64..00000000 --- a/src/LfMerge.Core/LanguageForge/Model/LfOptionList.cs +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (c) 2016 SIL International -// This software is licensed under the MIT license (http://opensource.org/licenses/MIT) -using MongoDB.Bson; -using System; -using System.Collections.Generic; - -namespace LfMerge.Core.LanguageForge.Model -{ - public class LfOptionList - { - public ObjectId Id { get; set; } - public string Name { get; set; } - public string Code { get; set; } - public DateTime DateCreated { get; set; } - public DateTime DateModified { get; set; } - public List Items { get; set; } - public string DefaultItemKey { get; set; } - public bool CanDelete { get; set; } - - public LfOptionList() - { - Items = new List(); - } - } -} - diff --git a/src/LfMerge.Core/LanguageForge/Model/LfOptionListItem.cs b/src/LfMerge.Core/LanguageForge/Model/LfOptionListItem.cs deleted file mode 100644 index dc64800d..00000000 --- a/src/LfMerge.Core/LanguageForge/Model/LfOptionListItem.cs +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (c) 2016 SIL International -// This software is licensed under the MIT license (http://opensource.org/licenses/MIT) -using MongoDB.Bson.Serialization.Attributes; -using MongoDB.Bson; -using System; - -namespace LfMerge.Core.LanguageForge.Model -{ - public class LfOptionListItem : IHasNullableGuid - { - [BsonRepresentation(BsonType.String)] - public Guid? Guid { get; set; } - public string Key { get; set; } - public string Value { get; set; } - public string Abbreviation { get; set; } - } -} - diff --git a/src/LfMerge.Core/LanguageForge/Model/LfParagraph.cs b/src/LfMerge.Core/LanguageForge/Model/LfParagraph.cs index f26a3a95..119e6be8 100644 --- a/src/LfMerge.Core/LanguageForge/Model/LfParagraph.cs +++ b/src/LfMerge.Core/LanguageForge/Model/LfParagraph.cs @@ -3,6 +3,7 @@ using System; using MongoDB.Bson; using MongoDB.Bson.Serialization.Attributes; +using LfMergeBridge.LfMergeModel; namespace LfMerge.Core.LanguageForge.Model { diff --git a/src/LfMerge.Core/LanguageForge/Model/LfPicture.cs b/src/LfMerge.Core/LanguageForge/Model/LfPicture.cs index 433be4ef..ea5d393e 100644 --- a/src/LfMerge.Core/LanguageForge/Model/LfPicture.cs +++ b/src/LfMerge.Core/LanguageForge/Model/LfPicture.cs @@ -3,6 +3,7 @@ using System; using MongoDB.Bson; using MongoDB.Bson.Serialization.Attributes; +using LfMergeBridge.LfMergeModel; namespace LfMerge.Core.LanguageForge.Model { diff --git a/src/LfMerge.Core/LanguageForge/Model/LfProject.cs b/src/LfMerge.Core/LanguageForge/Model/LfProject.cs deleted file mode 100644 index b5f1e0be..00000000 --- a/src/LfMerge.Core/LanguageForge/Model/LfProject.cs +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (c) 2016 SIL International -// This software is licensed under the MIT license (http://opensource.org/licenses/MIT) -using System.Collections.Generic; -using MongoDB.Bson.Serialization.Attributes; -using MongoDB.Bson; - -namespace LfMerge.Core.LanguageForge.Model -{ - [BsonIgnoreExtraElements] // WARNING: Beware of using FindOneAndReplace() with IgnoreExtraElements, as you can lose data - public class LfProject - { - public ObjectId Id { get; set; } - public string ProjectCode { get; set; } - public string ProjectName { get; set; } - public Dictionary InputSystems { get; set; } - - public LfProject() - { - InputSystems = new Dictionary(); - } - } -} - diff --git a/src/LfMerge.Core/LanguageForge/Model/LfSense.cs b/src/LfMerge.Core/LanguageForge/Model/LfSense.cs index ba9ed72b..a707ebd5 100644 --- a/src/LfMerge.Core/LanguageForge/Model/LfSense.cs +++ b/src/LfMerge.Core/LanguageForge/Model/LfSense.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using MongoDB.Bson; using MongoDB.Bson.Serialization.Attributes; +using LfMergeBridge.LfMergeModel; namespace LfMerge.Core.LanguageForge.Model { diff --git a/src/LfMerge.Core/LfMerge.Core.csproj b/src/LfMerge.Core/LfMerge.Core.csproj index e3272c3e..10420a79 100644 --- a/src/LfMerge.Core/LfMerge.Core.csproj +++ b/src/LfMerge.Core/LfMerge.Core.csproj @@ -37,14 +37,14 @@ See full changelog at https://github.com/sillsdev/LfMerge/blob/develop/CHANGELOG - - + + - - + + - + diff --git a/src/LfMerge.Core/MongoConnector/IMongoConnection.cs b/src/LfMerge.Core/MongoConnector/IMongoConnection.cs index 44914b38..2f8d27dc 100644 --- a/src/LfMerge.Core/MongoConnector/IMongoConnection.cs +++ b/src/LfMerge.Core/MongoConnector/IMongoConnection.cs @@ -7,6 +7,7 @@ using MongoDB.Driver; using LfMerge.Core.LanguageForge.Config; using LfMerge.Core.LanguageForge.Model; +using LfMergeBridge.LfMergeModel; namespace LfMerge.Core.MongoConnector { diff --git a/src/LfMerge.Core/MongoConnector/MongoConnection.cs b/src/LfMerge.Core/MongoConnector/MongoConnection.cs index a5bad235..6ef2b87a 100644 --- a/src/LfMerge.Core/MongoConnector/MongoConnection.cs +++ b/src/LfMerge.Core/MongoConnector/MongoConnection.cs @@ -17,6 +17,7 @@ using LfMerge.Core.LanguageForge.Model; using LfMerge.Core.Logging; using LfMerge.Core.Settings; +using LfMergeBridge.LfMergeModel; namespace LfMerge.Core.MongoConnector { @@ -62,7 +63,7 @@ public static void Initialize() ConventionRegistry.Register( "My Custom Conventions", pack, - t => t.FullName.StartsWith("LfMerge.")); + t => t.FullName.StartsWith("LfMerge.") || t.FullName.StartsWith("LfMergeBridge.LfMergeModel")); // Register class mappings before opening first connection new MongoRegistrarForLfConfig().RegisterClassMappings(); diff --git a/src/LfMerge.Core/MongoConnector/MongoProjectRecord.cs b/src/LfMerge.Core/MongoConnector/MongoProjectRecord.cs index 4f18aa6c..4def7ce7 100644 --- a/src/LfMerge.Core/MongoConnector/MongoProjectRecord.cs +++ b/src/LfMerge.Core/MongoConnector/MongoProjectRecord.cs @@ -4,7 +4,7 @@ using MongoDB.Bson; using MongoDB.Bson.Serialization.Attributes; using LfMerge.Core.LanguageForge.Config; -using LfMerge.Core.LanguageForge.Model; +using LfMergeBridge.LfMergeModel; using System; using System.Collections.Generic; diff --git a/src/LfMerge.Core/Reporting/ConversionError.cs b/src/LfMerge.Core/Reporting/ConversionError.cs index 5b120563..da6607a3 100644 --- a/src/LfMerge.Core/Reporting/ConversionError.cs +++ b/src/LfMerge.Core/Reporting/ConversionError.cs @@ -7,6 +7,7 @@ using LfMerge.Core.LanguageForge.Model; using SIL.LCModel; using LfMerge.Core.DataConverters; +using LfMergeBridge.LfMergeModel; namespace LfMerge.Core.Reporting {