public void RunConversion(Dictionary <MongoDB.Bson.ObjectId, Guid> entryObjectIdToGuidMappings)
        {
            var commentsWithIds = new List <KeyValuePair <string, LfComment> >();

            foreach (LfComment comment in _conn.GetComments(_project))
            {
                Guid guid;
                // LfMergeBridge wants lex entry GUIDs (passed along in comment.Regarding.TargetGuid), not Mongo ObjectIds like comment.EntryRef contains.
                if (comment.EntryRef != null && entryObjectIdToGuidMappings.TryGetValue(comment.EntryRef, out guid))
                {
                    comment.Regarding.TargetGuid = guid.ToString();
                }
                commentsWithIds.Add(new KeyValuePair <string, LfComment>(comment.Id.ToString(), comment));
            }
            string allCommentsJson = JsonConvert.SerializeObject(commentsWithIds);
            string bridgeOutput;

            CallLfMergeBridge(allCommentsJson, 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 <string, Guid> commentIdToGuidMappings = ParseGuidMappings(commentGuidMappingsStr);
            Dictionary <string, Guid> uniqIdToGuidMappings    = ParseGuidMappings(replyGuidMappingsStr);

            _conn.SetCommentGuids(_project, commentIdToGuidMappings);
            _conn.SetCommentReplyGuids(_project, uniqIdToGuidMappings);
        }
Exemple #2
0
        public void RunConversion(Dictionary <MongoDB.Bson.ObjectId, Guid> entryObjectIdToGuidMappings)
        {
            var commentsWithIds = new List <KeyValuePair <string, LfComment> >();

            foreach (var comment in _conn.GetComments(_project))
            {
                Guid guid;
                // LfMergeBridge wants lex entry GUIDs (passed along in comment.Regarding.TargetGuid), not Mongo ObjectIds like comment.EntryRef contains.
                if (comment.EntryRef != null &&
                    entryObjectIdToGuidMappings.TryGetValue(comment.EntryRef, out guid))
                {
                    comment.Regarding.TargetGuid = guid.ToString();

                    // LF-186
                    if (string.IsNullOrEmpty(comment.Regarding.Word))
                    {
                        var lexeme = GetLexEntry(comment.EntryRef).Lexeme.FirstNonEmptyString();
                        var field  = comment.Regarding.FieldNameForDisplay;
                        var ws     = comment.Regarding.InputSystemAbbreviation;
                        var value  = string.IsNullOrEmpty(comment.Regarding.FieldValue)
                                                        ? ""
                                                        : string.Format(" \"{0}\"", comment.Regarding.FieldValue);
                        comment.Regarding.Word = string.Format("{0} ({1} - {2}{3})", lexeme,
                                                               field, ws, value);
                    }
                }

                commentsWithIds.Add(new KeyValuePair <string, LfComment>(comment.Id.ToString(), comment));
            }
            string allCommentsJson = JsonConvert.SerializeObject(commentsWithIds);
            string bridgeOutput;

            CallLfMergeBridge(allCommentsJson, 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 <string, Guid> commentIdToGuidMappings = ParseGuidMappings(commentGuidMappingsStr);
            Dictionary <string, Guid> uniqIdToGuidMappings    = ParseGuidMappings(replyGuidMappingsStr);

            _conn.SetCommentGuids(_project, commentIdToGuidMappings);
            _conn.SetCommentReplyGuids(_project, uniqIdToGuidMappings);
        }