public IndexResult AddCommentIndex(CommentDTO comment) { var indexResult = new IndexResult(); if (comment.CommentID == null || comment.GeneralID == null) { return(new IndexResult()); } if (Exists <hOOt.Document>(comment.CommentID.Value, DocumentIndexTypeToken.Comment)) { if (_profile.Initialized) { _log.WarnFormat("CANNOT PROCESS 'CommentCreatedMessage' FOR COMMENT#{0} FOR ENTITY #{1} - '{2}'. COMMENT HAS ALREADY BEEN ADDED ON PROFILE INITIALIZATION OR ENTITY CREATION !!!", comment.CommentID.GetValueOrDefault(), comment.GeneralID.GetValueOrDefault(), comment.GeneralName); } else { _log.ErrorFormat("CANNOT PROCESS 'CommentCreatedMessage' FOR COMMENT#{0} FOR ENTITY #{1} - '{2}'. COMMENT HAS ALREADY BEEN ADDED !!!", comment.CommentID.GetValueOrDefault(), comment.GeneralID.GetValueOrDefault(), comment.GeneralName); } return(indexResult); } var entityIndex = _documentIndexProvider.GetOrCreateDocumentIndex(_pluginContext.AccountName, DocumentIndexTypeToken.Entity); var commentEntity = entityIndex.FindDocumentByName <EntityDocument>(EntityDocument.CreateName(comment.GeneralID)); if (commentEntity == null) { _log.Error(string.Format("CANNOT PROCESS 'CommentCreatedMessage' FOR COMMENT#{0} FOR ENTITY #{1} - '{2}'. ENTITY WAS NOT ADDED DURING PROFILE INITIALIZATION OR ENTITY CREATION !!!", comment.CommentID.GetValueOrDefault(), comment.GeneralID.GetValueOrDefault(), comment.GeneralName)); return(indexResult); } var commentIndex = _documentIndexProvider.GetOrCreateDocumentIndex(_pluginContext.AccountName, DocumentIndexTypeToken.Comment); var doc = _documentFactory.CreateComment(comment, commentEntity); if (doc == null) { return(indexResult); } indexResult = commentIndex.Index(doc, false); _log.Debug(string.Format("Added comment #{0} to #{1} - '{2}':{3}", comment.CommentID.GetValueOrDefault(), comment.GeneralID.GetValueOrDefault(), comment.GeneralName, indexResult.WordsAdded.Any() ? string.Format(" added words - {0};", string.Join(",", indexResult.WordsAdded.Keys)) : " NO WORDS ADDED;")); if (indexResult.DocNumber != -1) { int?projectId = null; if (commentEntity.ProjectId != null) { int projectIdValue; if (int.TryParse(commentEntity.ProjectId, out projectIdValue)) { projectId = projectIdValue == 0 ? null : (int?)projectIdValue; } } IDocumentIndex commentProjectIndex = _documentIndexProvider.GetOrCreateDocumentIndex(_pluginContext.AccountName, DocumentIndexTypeToken.CommentProject); commentProjectIndex.Index(indexResult.DocNumber, _documentIdFactory.EncodeProjectId(projectId)); int?squadId = null; if (commentEntity.SquadId != null) { int squadIdValue; if (int.TryParse(commentEntity.SquadId, out squadIdValue)) { squadId = squadIdValue == 0 ? null : (int?)squadIdValue; } } IDocumentIndex commentSquadIndex = _documentIndexProvider.GetOrCreateDocumentIndex(_pluginContext.AccountName, DocumentIndexTypeToken.CommentSquad); commentSquadIndex.Index(indexResult.DocNumber, _documentIdFactory.EncodeSquadId(squadId)); IDocumentIndex commentEntityTypeIndex = _documentIndexProvider.GetOrCreateDocumentIndex(_pluginContext.AccountName, DocumentIndexTypeToken.CommentEntityType); Maybe <string> maybeEntityTypeName = _entityTypeProvider.GetEntityTypeName(int.Parse(commentEntity.EntityTypeId)); string entityTypeName = maybeEntityTypeName.FailIfNothing(() => new ApplicationException("No entgity type name for {0}".Fmt(commentEntity.EntityTypeId))); commentEntityTypeIndex.Index(indexResult.DocNumber, entityTypeName); } return(indexResult); }