Пример #1
0
        public Comment RowToComment(CommentRow row)
        {
            if (row == null)
            {
                return(default(Comment));
            }
            var commentID        = new CommentID(row.G_CommentVolume, row.GDID);
            var parentID         = row.G_Parent.HasValue ? new CommentID(row.G_CommentVolume, row.G_Parent.Value) : (CommentID?)null;
            var authorNode       = m_GraphSystemService.GetNode(row.G_AuthorNode);
            var targetNode       = m_GraphSystemService.GetNode(row.G_TargetNode);
            var editableTimespan = GraphHost.EditCommentSpan(targetNode, row.Dimension);
            var lifeTime         = App.TimeSource.UTCNow - row.Create_Date;

            return(new Comment(commentID,
                               parentID,
                               authorNode,
                               targetNode,
                               row.Create_Date,
                               row.Dimension,
                               GSPublicationState.ToPublicationState(row.PublicationState),
                               row.IsRoot ? (RatingValue)row.Rating : RatingValue.Undefined,
                               row.Message,
                               row.Data,
                               row.Like,
                               row.Dislike,
                               row.ComplaintCount,
                               row.ResponseCount,
                               row.In_Use,
                               editableTimespan > lifeTime));
        }
Пример #2
0
        /// <summary>
        /// Make response to target commentary
        /// </summary>
        /// <param name="gAuthorNode">Author</param>
        /// <param name="parentId">Parent commentary</param>
        /// <param name="content">Content of commentary</param>
        /// <param name="data">Byte Array</param>
        /// <returns>New CommentID</returns>
        public Comment Respond(GDID gAuthorNode, CommentID parentId, string content, byte[] data)
        {
            try
            {
                if (parentId.IsZero)
                {
                    throw new GraphException(StringConsts.GS_RESPONSE_BAD_PARENT_ID_ERROR);
                }

                var currentDateTime = App.TimeSource.UTCNow;

                // Get parent comment
                var parent = getCommentRow(parentId);

                if (parent == null)
                {
                    throw new GraphException(StringConsts.GS_COMMENT_NOT_FOUND.Args(parentId.G_Comment));
                }
                if (!parent.IsRoot)
                {
                    throw new GraphException(StringConsts.GS_PARENT_ID_NOT_ROOT.Args(parentId.G_Comment));
                }

                var authorNode    = GetNode(gAuthorNode);
                var parentComment = GraphCommentFetchStrategy.RowToComment(parent);

                if (!GraphHost.CanCreateCommentResponse(parentComment, authorNode, currentDateTime))
                {
                    throw new GraphException(StringConsts.GS_CAN_NOT_CREATE_RESPONSE_ERROR.Args(authorNode, parentComment.TargetNode));
                }

                // Create new comment
                return(DoCreate(parentComment.TargetNode,
                                authorNode,
                                parentId,
                                parent.Dimension,
                                content,
                                data,
                                GSPublicationState.ToPublicationState(parent.PublicationState),
                                RatingValue.Undefined,
                                App.TimeSource.UTCNow));
            }
            catch (Exception ex)
            {
                Log(MessageType.Error, "GraphCommentSystem.Response", ex.ToMessageWithType(), ex);
                throw new GraphException(StringConsts.GS_RESPONSE_COMMENT_ERROR.Args(parentId.G_Comment), ex);
            }
        }
Пример #3
0
        /// <summary>
        /// Creating new comment
        /// </summary>
        /// <param name="targetNode">Target node</param>
        /// <param name="authorNode">Author node, who made comment</param>
        /// <param name="parentID">Parent comment id</param>
        /// <param name="dimension">Scope of comment</param>
        /// <param name="content">Content</param>
        /// <param name="data">Byte array of data</param>
        /// <param name="publicationState">State of publication</param>
        /// <param name="value">star 1-2-3-4-5</param>
        /// <param name="creationTime">Time of current action</param>
        /// <returns>ID</returns>
        protected virtual Comment DoCreate(GraphNode targetNode,
                                           GraphNode authorNode,
                                           CommentID?parentID,
                                           string dimension,
                                           string content,
                                           byte[] data,
                                           PublicationState publicationState,
                                           RatingValue value,
                                           DateTime?creationTime)
        {
            // Create comment and, if need, volume
            var ctxNode = ForNode(targetNode.GDID); // get shard context for target node
            var volume  = parentID.HasValue         // if we have parentID, we need to place response comment in same volume as parent
        ? getVolume(targetNode.GDID, parentID.Value.G_Volume, ctxNode)
        : getEmptyVolume(targetNode.GDID, dimension, ctxNode);

            if (volume == null)
            {
                throw new GraphException(StringConsts.GS_RESPONSE_VOLUME_MISSING_ERROR);
            }

            var comment = new CommentRow(true)
            {
                G_CommentVolume = volume.G_CommentVolume,
                G_Parent        = parentID.HasValue ? parentID.Value.G_Comment : (GDID?)null,
                G_AuthorNode    = authorNode.GDID,
                G_TargetNode    = targetNode.GDID,
                Create_Date     = creationTime ?? App.TimeSource.UTCNow,
                Dimension       = dimension,

                Message          = content,
                Data             = data,
                PublicationState = GSPublicationState.ToDomainString(publicationState),
                Rating           = (byte)value,

                Like           = 0,
                Dislike        = 0,
                ComplaintCount = 0,
                ResponseCount  = 0,

                IsRoot = !parentID.HasValue,
                In_Use = true
            };

            ForComment(volume.G_CommentVolume).Insert(comment);

            // Update ratings , if comment is root
            if (comment.IsRoot)
            {
                var nodeRating = getNodeRating(targetNode.GDID, dimension, ctxNode);
                nodeRating.UpdateCount(1);                           // Update count of commentaries (only root commentaries counts)
                nodeRating.UpdateRating(value, 1);                   //Update ratings
                nodeRating.Last_Change_Date = App.TimeSource.UTCNow; // update change time
                ctxNode.Update(nodeRating, filter: "Last_Change_Date,Cnt,Rating1,Rating2,Rating3,Rating4,Rating5".OnlyTheseFields());
            }
            // Update parent ResponseCount, if comment is not root
            else if (parentID.HasValue)
            {
                var ctxParent = ForComment(parentID.Value.G_Volume);
                var parent    = getCommentRow(parentID.Value, ctxParent);
                if (parent != null)
                {
                    parent.UpdateResponseCount(1);
                    ctxParent.Update(parent, filter: "ResponseCount".OnlyTheseFields());
                }
            }

            // Update count of commentaries in volume
            volume.Count++;
            ctxNode.Update(volume, filter: "Count".OnlyTheseFields());
            return(Comment.MakeNew(new CommentID(comment.G_CommentVolume, comment.GDID),
                                   parentID,
                                   authorNode,
                                   targetNode,
                                   comment.Create_Date,
                                   comment.Dimension,
                                   GSPublicationState.ToPublicationState(comment.PublicationState),
                                   (RatingValue)comment.Rating,
                                   comment.Message,
                                   comment.Data));
        }