예제 #1
0
        protected virtual GraphChangeStatus DoAddFriend(GDID gNode, GDID gFriendNode, bool?approve)
        {
            var node       = DoGetNode(gNode);
            var friendNode = DoGetNode(gFriendNode);

            if (!GraphHost.CanBeFriends(node.NodeType, friendNode.NodeType))
            {
                throw new GraphException(StringConsts.GS_FRIEND_DRIECTION_ERROR.Args(node.NodeType, friendNode.NodeType));
            }

            int countMe     = countFriends(gNode);
            int countFriend = countFriends(gFriendNode);

            if (countMe > SocialConsts.GS_MAX_FRIENDS_COUNT)
            {
                throw new GraphException(StringConsts.GS_MAX_FRIENDS_IN_NODE.Args(gNode));
            }
            if (countFriend > SocialConsts.GS_MAX_FRIENDS_COUNT)
            {
                throw new GraphException(StringConsts.GS_MAX_FRIENDS_IN_NODE.Args(gFriendNode));
            }


            GraphChangeStatus resultMe     = addFriend(gNode, gFriendNode, approve, FriendshipRequestDirection.I);
            GraphChangeStatus resultFriend = addFriend(gFriendNode, gNode, approve, FriendshipRequestDirection.Friend);

            return(resultMe == GraphChangeStatus.Added && resultFriend == GraphChangeStatus.Added ? GraphChangeStatus.Added : GraphChangeStatus.Updated);
        }
예제 #2
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));
        }
예제 #3
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);
            }
        }
예제 #4
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);
            }
        }
예제 #5
0
        protected virtual void DoSubscribe(GDID gRecipientNode, GDID gEmitterNode, byte[] parameters)
        {
            var emitter = DoGetNode(gEmitterNode);
            var gh      = DoGetNode(gRecipientNode);

            if (!GraphHost.CanBeSubscribed(gh.NodeType, emitter.NodeType))
            {
                throw new GraphException(StringConsts.GS_CAN_NOT_BE_SUSBCRIBED_ERROR.Args(gh.NodeType, emitter.NodeType));
            }
            var todo = Todo.MakeNew <EventSubscribeTodo>();

            todo.G_Owner      = gEmitterNode;
            todo.G_Subscriber = gRecipientNode;
            todo.Subs_Type    = gh.NodeType;
            todo.Parameters   = parameters;
            SocialGraphTodos.EnqueueSubscribtion(todo);
        }
예제 #6
0
        protected virtual IEnumerable <FriendConnection> DoGetFriendConnections(FriendQuery query, ICacheParams cacheParams = null)
        {
            var rows = ForNode(query.G_Node).LoadEnumerable(Queries.FindFriends <FriendRow>(query));

            foreach (var row in rows)
            {
                var friendNode = DoGetNode(row.G_Friend, cacheParams);
                foreach (var graphNode in GraphHost.FilterByOriginQuery(new[] { friendNode }, query.OriginQuery))
                {
                    yield return(new FriendConnection(graphNode,
                                                      row.Request_Date,
                                                      FriendStatus.Approved.Equals(GSFriendStatus.ToFriendStatus(row.Status))
              ? (DateTime?)row.Status_Date
              : null,
                                                      GSFriendshipRequestDirection.ToFriendshipRequestDirection(row.Direction),
                                                      GSFriendVisibility.ToFriendVisibility(row.Visibility),
                                                      row.Lists));
                }
            }
        }
예제 #7
0
        void IApplicationStarter.ApplicationStartAfterInit(IApplication application)
        {
            application.RegisterAppFinishNotifiable(this);

            var nDataSore = m_Config[SocialConsts.CONFIG_DATA_STORE_SECTION];

            if (!nDataSore.Exists)
            {
                throw new SocialException(StringConsts.GS_INIT_NOT_CONF_ERRROR.Args(this.GetType().Name, SocialConsts.CONFIG_DATA_STORE_SECTION));
            }
            m_DataStore = FactoryUtils.MakeAndConfigure <MDBDataStore>(nDataSore, args: new object[] { "GraphSystem", this });
            m_DataStore.Start();

            var nHost = m_Config[SocialConsts.CONFIG_GRAPH_HOST_SECTION];

            if (!nHost.Exists)
            {
                throw new SocialException(StringConsts.GS_INIT_NOT_CONF_ERRROR.Args(this.GetType().Name, SocialConsts.CONFIG_GRAPH_HOST_SECTION));
            }
            m_GraphHost = FactoryUtils.MakeAndConfigure <GraphHost>(nHost, args: new object[] { this, nHost });
        }
예제 #8
0
        /// <summary>
        /// Create new comment with rating
        /// </summary>
        /// <param name="gAuthorNode">GDID of autor node</param>
        /// <param name="gTargetNode">GDID of target node</param>
        /// <param name="dimension">Scope for rating</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="timeStamp">Time of current action</param>
        /// <returns>ID</returns>
        Comment IGraphCommentSystem.Create(GDID gAuthorNode,
                                           GDID gTargetNode,
                                           string dimension,
                                           string content,
                                           byte[] data,
                                           PublicationState publicationState,
                                           RatingValue value,
                                           DateTime?timeStamp)
        {
            try
            {
                // 1. Get nodes for creation new comment
                var authorNode      = DoGetNode(gAuthorNode);
                var targetNode      = DoGetNode(gTargetNode);
                var currentDateTime = timeStamp ?? App.TimeSource.UTCNow;

                if (!GraphHost.CanCreateComment(authorNode, targetNode, dimension, currentDateTime, value))
                {
                    throw new GraphException(StringConsts.GS_CAN_NOT_CREATE_COMMENT_ERROR.Args(authorNode, targetNode, value));
                }

                return(DoCreate(targetNode,
                                authorNode,
                                null, dimension,
                                content,
                                data,
                                publicationState,
                                value,
                                currentDateTime));
            }
            catch (Exception ex)
            {
                Log(MessageType.Error, "GraphCommentSystem.Create()", ex.ToMessageWithType(), ex);
                throw new GraphException(StringConsts.GS_CREATE_COMMENT_ERROR.Args(gTargetNode, gAuthorNode), ex);
            }
        }