Exemple #1
0
        protected IEnumerable <Complaint> DoFetchComplaints(CommentID commentID)
        {
            var qryComplaints = Queries.FindComplaints <ComplaintRow>(commentID.G_Comment);
            var complaints    = ForComment(commentID.G_Volume).LoadEnumerable(qryComplaints);

            return(complaints.Select(c => rowToComplaint(commentID, c)));
        }
Exemple #2
0
        protected virtual IEnumerable <Comment> DoFetchResponses(CommentID commentId, int offset = 0, int limit = 1) // todo доделать
        {
            var qryResponses = Queries.FindResponses <CommentRow>(commentId);
            var responses    = ForComment(commentId.G_Volume).LoadEnumerable(qryResponses);

            return(responses.Where(r => r.In_Use || (!r.In_Use && r.ResponseCount > 0)).Select(GraphCommentFetchStrategy.RowToComment));
        }
Exemple #3
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));
        }
Exemple #4
0
        /// <summary>
        /// Justify moderated comment
        /// </summary>
        /// <param name="commentID">Existing Comment ID</param>
        public GraphChangeStatus Justify(CommentID commentID)
        {
            if (commentID.IsZero)
            {
                return(GraphChangeStatus.NotFound);
            }

            try
            {
                var ctxComment = ForComment(commentID.G_Volume);

                var comment = getCommentRow(commentID, ctxComment);
                if (comment == null)
                {
                    return(GraphChangeStatus.NotFound);
                }

                var qry = Queries.CancelComplaintsByComment(commentID.G_Comment);
                ctxComment.ExecuteWithoutFetch(qry);

                comment.ComplaintCount = 0;
                ctxComment.Update(comment, filter: "ComplaintCount".OnlyTheseFields());
                return(GraphChangeStatus.Updated);
            }
            catch (Exception ex)
            {
                Log(MessageType.Error, "Justify", ex.ToMessageWithType(), ex);
                throw new GraphException(StringConsts.GS_JUSTIFY_COMMENT_ERROR.Args(commentID.G_Comment), ex);
            }
        }
Exemple #5
0
 public static Query DeleteResponses(CommentID commentId)
 {
     return(new Query("Graph.Server.Data.Scripts.Rating.DeleteResponses")
     {
         new Query.Param("pParent", commentId.G_Comment),
         new Query.Param("pVolume", commentId.G_Volume)
     });
 }
Exemple #6
0
 public static Query <TRow> FindResponses <TRow>(CommentID commentId) where TRow : Row
 {
     return(new Query <TRow>("Graph.Server.Data.Scripts.Rating.FindResponses")
     {
         new Query.Param("pComment", commentId.G_Comment),
         new Query.Param("pVolume", commentId.G_Volume)
     });
 }
Exemple #7
0
        private Comment DoGetComment(CommentID commentId)
        {
            var qry = Queries.FindCommentByGDID <CommentRow>(commentId.G_Comment);
            var row = ForComment(commentId.G_Volume).LoadRow(qry);

            if (row == null)
            {
                throw new GraphException("Comment not found, CommendID = {0}".Args(commentId));
            }
            return(GraphCommentFetchStrategy.RowToComment(row));
        }
Exemple #8
0
        private CommentRow getCommentRow(CommentID commentId, CRUDOperations?ctxComment = null)
        {
            if (commentId.IsZero)
            {
                return(null);
            }
            var ctx        = ctxComment ?? ForComment(commentId.G_Volume);
            var qryComment = Queries.FindCommentByGDID <CommentRow>(commentId.G_Comment);

            return(ctx.LoadRow(qryComment));
        }
Exemple #9
0
        /// <summary>
        /// Updates existing rating by ID
        /// </summary>
        public GraphChangeStatus Update(CommentID commentId, RatingValue value, string content, byte[] data)
        {
            if (commentId.IsZero)
            {
                return(GraphChangeStatus.NotFound);
            }

            try
            {
                // Taking comment row
                var currentDateTime = App.TimeSource.UTCNow;
                var ctxComment      = ForComment(commentId.G_Volume); // CRUD context for comment
                var comment         = getCommentRow(commentId, ctxComment);
                if (comment == null)
                {
                    return(GraphChangeStatus.NotFound);
                }

                var targetNode = DoGetNode(comment.G_TargetNode);
                if ((currentDateTime - comment.Create_Date) > GraphHost.EditCommentSpan(targetNode, comment.Dimension))
                {
                    return(GraphChangeStatus.NotFound);
                }

                var ctxNode = ForNode(comment.G_TargetNode); // CRUD context for target node

                // Updating fields
                var filter = "Message,Data";
                comment.Message = content;
                comment.Data    = data;

                // if comment is root and rating value is not RatingValue.Undefined
                // Update rating
                if (comment.IsRoot && value != RatingValue.Undefined)
                {
                    // Update NodeRating
                    var nodeRating = getNodeRating(comment.G_TargetNode, comment.Dimension, ctxNode);
                    nodeRating.UpdateRating((RatingValue)comment.Rating, -1);
                    nodeRating.UpdateRating(value, 1);
                    ctxNode.Update(nodeRating, filter: "Last_Change_Date,Cnt,Rating1,Rating2,Rating3,Rating4,Rating5".OnlyTheseFields());

                    // Update rating value of comment
                    comment.Rating = (byte)value;
                    filter         = "Rating," + filter;
                }
                var resComment = ctxComment.Update(comment, filter: filter.OnlyTheseFields());
                return(resComment == 0 ? GraphChangeStatus.NotFound : GraphChangeStatus.Updated);
            }
            catch (Exception ex)
            {
                Log(MessageType.Error, "GraphCommentSystem.Update", ex.ToMessageWithType(), ex);
                throw new GraphException(StringConsts.GS_UPDATE_RATING_ERROR.Args(commentId.G_Comment), ex);
            }
        }
Exemple #10
0
        /// <summary>
        /// Delete comment
        /// </summary>
        /// <param name="commentId">Existing Comment ID</param>
        public GraphChangeStatus DeleteComment(CommentID commentId)
        {
            if (commentId.IsZero)
            {
                return(GraphChangeStatus.NotFound);
            }

            try
            {
                //1. Try get comment row
                var ctxComment = ForComment(commentId.G_Volume); // CRUD context for comment
                var comment    = getCommentRow(commentId);
                if (comment == null)
                {
                    return(GraphChangeStatus.NotFound);
                }

                var ctxNode = ForNode(comment.G_TargetNode); // CRUD context for target node

                //2. Delete comment
                comment.In_Use = false;

                if (comment.IsRoot) // Only Root comments has ratings and counts in comments of target node
                {
                    //3. If comment has rating value, decrease value of that rating from target rating node
                    var nodeRating = getNodeRating(comment.G_TargetNode, comment.Dimension, ctxNode);
                    nodeRating.UpdateCount(-1);                               // Update count of comments
                    nodeRating.UpdateRating((RatingValue)comment.Rating, -1); // Update ratings (if RatingValue.Undefined - nothing happens)
                    nodeRating.Last_Change_Date = App.TimeSource.UTCNow;
                    ctxNode.Update(nodeRating, filter: "Last_Change_Date,Cnt,Rating1,Rating2,Rating3,Rating4,Rating5".OnlyTheseFields());
                }
                // Update parent "ResponseCount" , if comment is not root
                else if (comment.G_Parent.HasValue)
                {
                    var parentCommendID = new CommentID(comment.G_CommentVolume, comment.G_Parent.Value);
                    var ctxParent       = ForComment(parentCommendID.G_Volume);
                    var parent          = getCommentRow(parentCommendID, ctxParent);
                    if (parent != null && parent.ResponseCount > 0)
                    {
                        parent.UpdateResponseCount(-1);
                        ctxParent.Update(parent, filter: "ResponseCount".OnlyTheseFields());
                    }
                }

                var res = ctxComment.Update(comment);
                return(res > 0 ? GraphChangeStatus.Deleted : GraphChangeStatus.NotFound);
            }
            catch (Exception ex)
            {
                Log(MessageType.Error, "DeleteComment", ex.ToMessageWithType(), ex);
                throw new GraphException(StringConsts.GS_DELETE_COMMENT_ERROR.Args(commentId.G_Comment), ex);
            }
        }
Exemple #11
0
 public IEnumerable <Complaint> FetchComplaints(CommentID commentID)
 {
     try
     {
         return(DoFetchComplaints(commentID).ToArray());
     }
     catch (Exception ex)
     {
         Log(MessageType.Error, "FetchComplaints", ex.ToMessageWithType(), ex);
         throw new GraphException(StringConsts.GS_FETCH_COMPLAINTS_ERROR.Args(commentID.G_Comment), ex);
     }
 }
Exemple #12
0
 public Comment GetComment(CommentID commentId)
 {
     try
     {
         return(DoGetComment(commentId));
     }
     catch (Exception ex)
     {
         Log(MessageType.Error, "GetComment", ex.ToMessageWithType(), ex);
         throw new GraphException(StringConsts.GS_GET_COMMENT_ERROR.Args(commentId.G_Comment), ex);
     }
 }
Exemple #13
0
 public IEnumerable <Comment> FetchResponses(CommentID commentId)
 {
     try
     {
         return(DoFetchResponses(commentId).ToArray());
     }
     catch (Exception ex)
     {
         Log(MessageType.Error, "DoFetchResponses", ex.ToMessageWithType(), ex);
         throw new GraphException(StringConsts.GS_FETCH_RESPONSE_ERROR.Args(commentId.G_Comment), ex);
     }
 }
        /// <summary>
        /// Возвращает коллекцию параметров.
        /// </summary>
        public override Dictionary <string, string> GetParameters()
        {
            var parameters = base.GetParameters();

            parameters["owner_id"]   = OwnerID.ToString();
            parameters["comment_id"] = CommentID.ToString();
            if (Reason != VKReason.Spam)
            {
                parameters["reason"] = ((byte)Reason).ToString();
            }

            return(parameters);
        }
Exemple #15
0
        /// <summary>
        /// Post this message to the server
        /// </summary>
        private void PostMessage()
        {
            CIX.FolderCollection.NotifyMessagePostStarted(this);
            PostPending = false;
            try
            {
                Folder      folder      = Topic;
                PostMessage postMessage = new PostMessage
                {
                    Body       = Body.FixQuotes(),
                    Forum      = folder.ParentFolder.Name,
                    Topic      = folder.Name,
                    WrapColumn = "0",
                    MarkRead   = "1",
                    MsgID      = CommentID.ToString(CultureInfo.InvariantCulture)
                };

                HttpWebRequest postUrl        = APIRequest.Post("forums/post", APIRequest.APIFormat.XML, postMessage);
                string         responseString = APIRequest.ReadResponseString(postUrl);

                int newRemoteID;
                if (int.TryParse(responseString, out newRemoteID))
                {
                    RemoteID = newRemoteID;
                    Date     = DateTime.UtcNow.UTCToGMTBST();
                    lock (CIX.DBLock)
                    {
                        CIX.DB.Update(this);
                    }
                    if (CommentID == 0)
                    {
                        LogFile.WriteLine("Posted new thread \"{0}\" as message {1}", Body.FirstLine(), RemoteID);
                    }
                    else
                    {
                        LogFile.WriteLine("Posted new reply to message {0} as message {1}", CommentID, RemoteID);
                    }
                    CIX.FolderCollection.NotifyMessageChanged(this);
                }
                else
                {
                    LogFile.WriteLine("Failed to post message {0} : {1}", ID, responseString);
                }
            }
            catch (Exception e)
            {
                CIX.ReportServerExceptions("CIXMessage.PostMessage", e);
            }
            CIX.FolderCollection.NotifyMessagePostCompleted(this);
        }
Exemple #16
0
        private Complaint rowToComplaint(CommentID commentID, ComplaintRow row)
        {
            if (row == null)
            {
                return(default(Complaint));
            }

            return(new Complaint(new CommentID(commentID.G_Volume, row.G_Comment),
                                 row.GDID,
                                 GetNode(row.G_AuthorNode),
                                 row.Kind,
                                 row.Message,
                                 row.Create_Date,
                                 row.In_Use));
        }
Exemple #17
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);
            }
        }
Exemple #18
0
    public void PushToDatabase(string com, int ID)
    {
        //create new class to push into db
        MarkerCommentClass commentClass = new MarkerCommentClass(com, date, userFirstName, userLastName, location, localId);

        //the url for this has been modified, to take the ID as the key
        RestClient.Put(databaseURL + "/" + location + "/" + ID + ".json?auth=" + idToken, commentClass);

        //increment ID and push it back into DB
        ID++;
        CommentID commentID = new CommentID(ID);

        RestClient.Put(databaseURL + "/" + "IDCounter" + "/" + location + ".json?auth=" + idToken, commentID);

        message          += "\n Comment made successfully!";
        ConfirmationPopup = true;
    }
        public virtual string GetProperty(string strPropertyName, string strFormat, System.Globalization.CultureInfo formatProvider, DotNetNuke.Entities.Users.UserInfo accessingUser, DotNetNuke.Services.Tokens.Scope accessLevel, ref bool propertyNotFound)
        {
            switch (strPropertyName.ToLower())
            {
            case "commentid": // Int
                return(CommentID.ToString(strFormat, formatProvider));

            case "componentid": // Int
                return(ComponentId.ToString(strFormat, formatProvider));

            case "itemtype": // Int
                return(ItemType.ToString(strFormat, formatProvider));

            case "itemid": // Int
                return(ItemId.ToString(strFormat, formatProvider));

            case "parentid": // Int
                if (ParentId == null)
                {
                    return("");
                }
                ;
                return(((int)ParentId).ToString(strFormat, formatProvider));

            case "message": // NVarCharMax
                return(PropertyAccess.FormatString(Message, strFormat));

            case "approved": // Bit
                if (Approved == null)
                {
                    return("");
                }
                ;
                return(Approved.ToString());

            default:
                propertyNotFound = true;
                break;
            }

            return(Null.NullString);
        }
Exemple #20
0
        /// <summary>
        /// Возвращает коллекцию параметров.
        /// </summary>
        public override Dictionary <string, string> GetParameters()
        {
            var parameters = base.GetParameters();

            if (OwnerID != 0)
            {
                parameters["owner_id"] = OwnerID.ToString();
            }
            parameters["comment_id"] = CommentID.ToString();
            if (!string.IsNullOrWhiteSpace(Message))
            {
                parameters["message"] = Message;
            }
            if (Attachments != null && Attachments.Count != 0)
            {
                parameters["attachments"] = string.Join(",", Attachments);
            }

            return(parameters);
        }
Exemple #21
0
        /// <summary>
        /// Updates likes/dislikes
        /// </summary>
        public GraphChangeStatus Like(CommentID messageId, int deltaLike, int deltaDislike)
        {
            if (messageId.IsZero)
            {
                return(GraphChangeStatus.NotFound);
            }

            try
            {
                var ctxRating = ForComment(messageId.G_Volume);
                var qry       = Queries.UpdateLike(messageId.G_Volume, messageId.G_Comment, deltaLike, deltaDislike);
                var res       = ctxRating.ExecuteWithoutFetch(qry);
                return(res == 0 ? GraphChangeStatus.NotFound : GraphChangeStatus.Updated);
            }
            catch (Exception ex)
            {
                Log(MessageType.Error, "Like", ex.ToMessageWithType(), ex);
                throw new GraphException(StringConsts.GS_SET_LIKE_ERROR.Args(messageId.G_Comment), ex);
            }
        }
Exemple #22
0
        public GraphChangeStatus Complain(CommentID commentId, GDID gAuthorNode, string kind, string message)
        {
            if (commentId.IsZero)
            {
                return(GraphChangeStatus.NotFound);
            }

            try
            {
                var comment = getCommentRow(commentId);
                if (comment == null)
                {
                    return(GraphChangeStatus.NotFound);
                }

                var ctx          = ForComment(commentId.G_Volume);
                var complaintRow = new ComplaintRow(true)
                {
                    G_Comment    = commentId.G_Comment,
                    G_AuthorNode = gAuthorNode,
                    Kind         = kind,
                    Message      = message,
                    Create_Date  = App.TimeSource.UTCNow,
                    In_Use       = true
                };
                ctx.Insert(complaintRow);

                comment.ComplaintCount++;
                ctx.Update(comment, filter: "ComplaintCount".OnlyTheseFields());

                return(GraphChangeStatus.Updated);
            }
            catch (Exception ex)
            {
                Log(MessageType.Error, "Complain", ex.ToMessageWithType(), ex);
                throw new GraphException(StringConsts.GS_COMPLAINT_ERROR.Args(commentId.G_Comment), ex);
            }
        }
Exemple #23
0
 public override void DeleteComment(GraphNode gAuthorNode, CommentID gComment)
 {
     //throw new NotImplementedException();
 }
Exemple #24
0
 public GraphChangeStatus Complain(CommentID commentId, GDID gAuthorNode, string kind, string message)
 {
     return(Comments.Complain(commentId, gAuthorNode, kind, message));
 }
Exemple #25
0
 public GraphChangeStatus Justify(CommentID commentID)
 {
     return(Comments.Justify(commentID));
 }
Exemple #26
0
 /// <summary>
 /// Make response on target commentary
 /// </summary>
 /// <param name="gAuthorNode">Author</param>
 /// <param name="parent">Parent commentary</param>
 /// <param name="content">Content of commentary</param>
 /// <param name="data">Byte Array</param>
 /// <returns>New Comment</returns>
 public Comment Respond(GDID gAuthorNode, CommentID parent, string content, byte[] data)
 {
     return(Comments.Respond(gAuthorNode, parent, content, data));
 }
Exemple #27
0
 public GraphChangeStatus Update(CommentID commentId, RatingValue value, string content, byte[] data)
 {
     return(Comments.Update(commentId, value, content, data));
 }
Exemple #28
0
 public Comment GetComment(CommentID commentId)
 {
     return(Comments.GetComment(commentId));
 }
Exemple #29
0
 /// <summary>
 /// Delete comment
 /// </summary>
 /// <param name="commentId">Existing Comment ID</param>
 public GraphChangeStatus DeleteComment(CommentID commentId)
 {
     return(Comments.DeleteComment(commentId));
 }
Exemple #30
0
 public GraphChangeStatus Like(CommentID commentId, int deltaLike, int deltaDislike)
 {
     return(Comments.Like(commentId, deltaLike, deltaDislike));
 }