Ejemplo n.º 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));
        }
Ejemplo n.º 2
0
        public static void RefreshComments(this IBacicInterface intFace, IHTMLDiv commentDiv)
        {
            commentDiv.Clear();

            Action refresh = async delegate
            {
                var comments = await intFace.GetAllViewComments(Native.document.location.hash);
                if (comments != null)
                {
                    for (var r = 0; r < comments.Rows.Count; r++)
                    {
                        var row = (global::Abstractatech.Comments.Schema.CommentCommentTableRow)comments.Rows[r];
                        var container = new CommentRow();
                        container.name.innerText = row.Name;
                        container.email.innerText = row.Email;
                        container.time.innerText = row.Timestamp.ToString("dd.MM.yyyy HH:mm:ss");
                        container.content.style.whiteSpace = IStyle.WhiteSpaceEnum.pre;
                        container.content.innerText = row.Comment;

                        container.AttachTo(commentDiv);
                    }
                }
            };
            refresh();
        }
Ejemplo n.º 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));
        }