Exemplo n.º 1
0
        /// <summary>
        /// 获得所有广播及发给该用户的feed的个数
        /// (除了该用户自己发的)
        /// </summary>
        /// <param name="receiverId"></param>
        /// <param name="sortByKey"></param>
        /// <param name="isAscending"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public IEnumerable <Message> FindBroadcastAndMyFeeds(Guid receiverId, string sortByKey, bool isAscending, int pageIndex, int pageSize)
        {
            QueryObject <Message> queryObject = new QueryObject <Message>(FeedService.EntityRepository);
            //发给自己的
            Dictionary <string, object> queryDic1 = new Dictionary <string, object>();

            queryDic1.Add("ReceiverId", receiverId);
            Dictionary <string, object> subQueryDic1 = new Dictionary <string, object>();

            subQueryDic1.Add("$ne", receiverId.ToString());
            queryDic1.Add("MessageFrom", subQueryDic1);
            queryObject.AppendQuery(queryDic1, QueryLogic.And);
            //广播
            Dictionary <string, object> queryDic2 = new Dictionary <string, object>();

            queryDic2.Add("IsBroadcast", true);
            Dictionary <string, object> subQueryDic2 = new Dictionary <string, object>();

            subQueryDic2.Add("$ne", receiverId.ToString());
            queryDic2.Add("MessageFrom", subQueryDic2);
            queryObject.AppendQuery(queryDic2, QueryLogic.Or);

            List <Message> myMessages = new List <Message>();

            myMessages = FeedService.EntityRepository.Find(queryObject, sortByKey, isAscending, pageIndex, pageSize).ToList();
            return(myMessages);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 通过自己的id,找到我的所有好友id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static List <Guid> FindMyFriends(Guid id)
        {
            QueryObject <FriendRelationshipEntity> queryObject = new QueryObject <FriendRelationshipEntity>(friendRelationshipEntityRepository);
            Dictionary <string, object>            queryDic1   = new Dictionary <string, object>();

            queryDic1.Add("Volunteer1Id", id);
            Dictionary <string, object> queryDic2 = new Dictionary <string, object>();

            queryDic2.Add("Volunteer2Id", id);
            queryObject.AppendQuery(queryDic1, QueryLogic.Or);
            queryObject.AppendQuery(queryDic2, QueryLogic.Or);
            var         friendRelationshipEntities = friendRelationshipEntityRepository.Find(queryObject);
            List <Guid> result = new List <Guid>();

            foreach (FriendRelationshipEntity friendRelationshipEntity in friendRelationshipEntities)
            {
                if (friendRelationshipEntity.Volunteer1Id == id)
                {
                    result.Add(friendRelationshipEntity.Volunteer2Id);
                    continue;
                }
                if (friendRelationshipEntity.Volunteer2Id == id)
                {
                    result.Add(friendRelationshipEntity.Volunteer1Id);
                }
            }
            return(result);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 获得所有广播及发给该用户的feed的个数
        /// (除了该用户自己发的)
        /// </summary>
        /// <param name="receiverId"></param>
        /// <returns></returns>
        public long FindBroadcastAndMyFeedCount(Guid receiverId)
        {
            QueryObject <Message> queryObject = new QueryObject <Message>(FeedService.EntityRepository);
            //发给自己的
            Dictionary <string, object> queryDic1 = new Dictionary <string, object>();

            queryDic1.Add("ReceiverId", receiverId);
            Dictionary <string, object> subQueryDic1 = new Dictionary <string, object>();

            subQueryDic1.Add("$ne", receiverId.ToString());
            queryDic1.Add("MessageFrom", subQueryDic1);
            queryObject.AppendQuery(queryDic1, QueryLogic.And);
            //广播
            Dictionary <string, object> queryDic2 = new Dictionary <string, object>();

            queryDic2.Add("IsBroadcast", true);
            Dictionary <string, object> subQueryDic2 = new Dictionary <string, object>();

            subQueryDic2.Add("$ne", receiverId.ToString());
            queryDic2.Add("MessageFrom", subQueryDic2);
            queryObject.AppendQuery(queryDic2, QueryLogic.Or);

            long result = FeedService.EntityRepository.FindCountOfResult(queryObject);

            return(result);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 用于生成查找activity的queryObject
        /// </summary>
        /// <param name="filterSource">形式为:aaa+bbb+ccc+tags:ddd,eee</param>
        /// <returns></returns>
        private QueryObject <House> generateHouseFilter(string filterSource)
        {
            QueryObject <House> queryObject = new QueryObject <House>(EntityRepository);

            //过滤filterSource
            if (filterSource != null & filterSource != "")
            {
                //从url中获取的filterSource
                //需要将"%3A"替换为":"
                //"%2C"替换为","
                string filterResult = filterSource.Replace("%3A", ":").Replace("%2C", ",");
                //用'+'分割,前半部分未被标记的为name,用tag:标记的为tag
                string[]      strings = filterSource.Split('+');
                List <string> names   = new List <string>();
                List <string> tags    = new List <string>();
                //将filterSource中的filter信息读出来
                foreach (string str in strings)
                {
                    //tag
                    if (str.IndexOf("tags:") == 0)
                    {
                        string[] tagsString = str.Substring("tags:".Length).Split(',');
                        foreach (string tag in tagsString)
                        {
                            tags.Add(tag);
                        }
                    }
                    //name
                    else
                    {
                        names.Add(str);
                    }
                }
                //构建Name query
                //currentlly now suitable at leat not usful for house
                if (names.Any())
                {
                    QueryObject <House> nameQueryObject = new QueryObject <House>(EntityRepository);
                    foreach (string name in names)
                    {
                        nameQueryObject.AppendQuery(QueryOperator.Like, "Name", name, QueryLogic.Or);
                    }
                    queryObject.AppendQuery(nameQueryObject, QueryLogic.And);
                }
                //构建Tag query
                if (tags.Any())
                {
                    Dictionary <string, object> queryDict    = new Dictionary <string, object>();
                    Dictionary <string, object> subQueryDict = new Dictionary <string, object>();
                    subQueryDict.Add("$all", tags);
                    queryDict.Add("Tags", subQueryDict);
                    queryObject.AppendQuery(queryDict, QueryLogic.And);
                }
            }
            return(queryObject);
        }
        /// <summary>
        /// 搜索用户(like用户名或昵称)
        /// </summary>
        /// <param name="query"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public IEnumerable <OldHouseUser> GetUserByNickNameOrUserName(string query, int pageIndex, int pageSize)
        {
            QueryObject <OldHouseUser> queryObject = new QueryObject <OldHouseUser>(MyUserManager.UserRepository);

            queryObject.AppendQuery(QueryOperator.Like, "NickName", query, QueryLogic.Or);
            queryObject.AppendQuery(QueryOperator.Like, "UserName", query, QueryLogic.Or);
            var result = MyUserManager.UserRepository.Find(queryObject, pageIndex, pageSize);

            return(result);
        }
        /// <summary>
        /// 获得搜索到用户的个数(like用户名或昵称)
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public long GetUserCountByNickNameOrUserName(string query)
        {
            QueryObject <OldHouseUser> queryObject = new QueryObject <OldHouseUser>(MyUserManager.UserRepository);

            queryObject.AppendQuery(QueryOperator.Like, "NickName", query, QueryLogic.Or);
            queryObject.AppendQuery(QueryOperator.Like, "UserName", query, QueryLogic.Or);
            var result = MyUserManager.UserRepository.FindCountOfResult(queryObject);

            return(result);
        }
Exemplo n.º 7
0
        //获得发给该用户的已读或未读message
        public IEnumerable <Message> FindMyReadOrNotReadMessage(Guid receiverId, string messageFrom, bool hasRead, string sortByKey, bool isAscending, int pageIndex, int pageSize)
        {
            QueryObject <Message>       queryObject = new QueryObject <Message>(EntityRepository);
            Dictionary <string, object> queryDic    = new Dictionary <string, object>();

            queryDic.Add("ReceiverId", receiverId);
            if (messageFrom != null && messageFrom != "")
            {
                queryDic.Add("MessageFrom", messageFrom);
            }
            queryDic.Add("HasDeleted", false);
            if (hasRead == true)
            {
                queryDic.Add("HasRead", true);
            }
            else
            {
                queryDic.Add("HasRead", false);
            }
            queryObject.AppendQuery(queryDic, QueryLogic.And);
            List <Message> myMessages = new List <Message>();

            myMessages = EntityRepository.Find(queryObject, sortByKey, isAscending, pageIndex, pageSize).ToList();
            return(myMessages);
        }
        public static bool ToggleLike <T>(this EntityService <T> entityService, Guid targetId, Guid userId,
                                          LikeRateFavService lrfService) where T : Entity
        {
            var result = lrfService.ToggleLike(userId, targetId);

            if (result)
            {
                //fave times+1, make sure your entity has this field
                Dictionary <string, object> queryDict = new Dictionary <string, object>();
                queryDict.Add("_id", targetId);
                QueryObject <T> query = new QueryObject <T>(entityService.EntityRepository);
                query.AppendQuery(queryDict, QueryLogic.And);
                ((MongoDBRepository <T>)entityService.EntityRepository).Update(query,
                                                                               Update.Inc("LikeTimes", 1));
            }
            else
            {
                //fave times+1, make sure your entity has this field
                Dictionary <string, object> queryDict = new Dictionary <string, object>();
                queryDict.Add("_id", targetId);
                QueryObject <T> query = new QueryObject <T>(entityService.EntityRepository);
                query.AppendQuery(queryDict, QueryLogic.And);
                ((MongoDBRepository <T>)entityService.EntityRepository).Update(query,
                                                                               Update.Inc("LikeTimes", -1));
            }
            return(result);
        }
Exemplo n.º 9
0
        /// <summary>
        /// stop following the target
        /// </summary>
        /// <param name="targetId">target(followee) profile id</param>
        /// <param name="followerId">the follower Profile Id</param>
        public void UnFollow(Guid targetId, Guid followerId)
        {
            //不允许自己unfollow自己
            if (targetId == followerId)
            {
                throw new Exception("不允许自己unfollow自己");
            }
            Dictionary <string, object> queryDict = new Dictionary <string, object>();

            queryDict.Add("_id", followerId);
            QueryObject <T> query = new QueryObject <T>(EntityRepository);

            query.AppendQuery(queryDict, QueryLogic.And);
            ((MongoDBRepository <T>)EntityRepository).Update(query,
                                                             Update.Pull("FollowingIds", targetId));

            //decrease the followee's follower count
            Dictionary <string, object> queryDict2 = new Dictionary <string, object>();

            queryDict2.Add("_id", targetId);
            QueryObject <T> query2 = new QueryObject <T>(EntityRepository);

            query2.AppendQuery(queryDict2, QueryLogic.And);

            ((MongoDBRepository <T>)EntityRepository).Update(query2,
                                                             Update.Inc("FollowerCount", -1));

            //产生用户stop follow事件
            EventService.Publish("StopFollowingEvent", targetId, followerId);
        }
Exemplo n.º 10
0
        /// <summary>
        /// 检查eventQueue,如果不为空则处理event
        /// </summary>
        public static void CheckTheEventIdQueue()
        {
            while (true)
            {
                while (eventIdQueue.Any())
                {
                    Guid eventId = eventIdQueue.Dequeue();
                    //对每个event进行处理
                    Event oneEvent = eventRepository.FindOneById(eventId);
                    //subscriber.TriggerSender == oneEvent.Sender || subscriber.TriggerSender == null
                    QueryObject <Subscriber>    subQueryObject = new QueryObject <Subscriber>(subscriberRepository);
                    Dictionary <string, object> queryDict1     = new Dictionary <string, object>();
                    Dictionary <string, object> queryDict2     = new Dictionary <string, object>();
                    queryDict1.Add("TriggerSender", null);
                    queryDict2.Add("TriggerSender", oneEvent.Sender);
                    subQueryObject.AppendQuery(queryDict1, QueryLogic.And);
                    subQueryObject.AppendQuery(queryDict2, QueryLogic.Or);
                    //subscriber.TriggerEventTypes包含oneEvent.Type
                    QueryObject <Subscriber>    queryObject = new QueryObject <Subscriber>(subscriberRepository);
                    Dictionary <string, object> queryDict   = new Dictionary <string, object>();
                    queryDict.Add("TriggerEventTypes", oneEvent.Type);
                    queryObject.AppendQuery(queryDict, QueryLogic.And);
                    //以上二者结合
                    queryObject.AppendQuery(subQueryObject, QueryLogic.And);
                    IEnumerable <Subscriber> subscribers = subscriberRepository.Find(queryObject);
                    foreach (Subscriber subscriber in subscribers)
                    {
                        //每个subscriber调用handler处理event
                        foreach (IVolunteerEventHandler eventHandler in EventHandlerList)
                        {
                            if (subscriber.HandlerNames.Contains(eventHandler.Name))
                            {
                                eventHandler.HandleEvent(oneEvent);
                            }
                        }
                    }
                    //标记为已处理
                    oneEvent.hasHandled = true;
                    eventRepository.SaveOne(oneEvent);

                    Thread.Sleep(sleepTimeBetweenEvents);
                }
                Thread.Sleep(sleepTimeBetweenQueues);
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// 获得发送给指定用户id的feed
        /// 或者广播的feed
        /// </summary>
        /// <param name="feedService"></param>
        /// <param name="userId">用户id</param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public static IEnumerable <Message> FindFeedFor(this MessageService feedService, Guid userId, int pageIndex, int pageSize)
        {
            QueryObject <Message> queryObject = new QueryObject <Message>(feedService.EntityRepository);
            //指定用户id
            Dictionary <string, object> queryDic1 = new Dictionary <string, object>();

            queryDic1.Add("ReceiverId", userId);
            //广播
            Dictionary <string, object> queryDic2 = new Dictionary <string, object>();

            queryDic2.Add("IsBroadcast", true);
            queryObject.AppendQuery(queryDic1, QueryLogic.Or);
            queryObject.AppendQuery(queryDic2, QueryLogic.Or);
            List <Message> myMessages = new List <Message>();

            myMessages = feedService.EntityRepository.Find(queryObject, "Time", false, pageIndex, pageSize).ToList();
            return(myMessages);
        }
Exemplo n.º 12
0
        public virtual void Delete(Guid id)
        {
            QueryObject <T> query = new QueryObject <T>(EntityRepository);
            var             qdict = new Dictionary <string, object>();

            qdict.Add("_id", id);
            query.AppendQuery(qdict, QueryLogic.And);
            EntityRepository.Delete(query);
        }
Exemplo n.º 13
0
        /// <summary>
        /// 生成数据库查询query
        /// </summary>
        /// <param name="userQuery"></param>
        /// <returns></returns>
        private QueryObject <House> buildFilter(Dictionary <string, string> userQuery)
        {
            QueryObject <House> queryObject = new QueryObject <House>(EntityRepository);

            //精确查找city
            if (userQuery.ContainsKey("city"))
            {
                queryObject.AppendQuery(QueryOperator.Like, "City", userQuery["city"], QueryLogic.And);
            }
            //精确查找ownerId
            if (userQuery.ContainsKey("ownerid"))
            {
                queryObject.AppendQuery(QueryOperator.Equal, "OwnerId", new Guid(userQuery["ownerid"]), QueryLogic.And);
            }
            //地理位置查询
            if (userQuery.ContainsKey("location"))
            {
                queryObject.AppendQuery(QueryOperator.Near, "Location", userQuery["location"], QueryLogic.And);
            }
            //用户查找老房子的Name和Tag(用户的query用空格分隔)
            //模糊查找Name,精确查找Tag
            if (userQuery.ContainsKey("search"))
            {
                if (userQuery["search"] != "")
                {
                    QueryObject <House> userSearchQueryObject = new QueryObject <House>(EntityRepository);
                    string[]            userSearch            = userQuery["search"].Split(' ');
                    foreach (string query in userSearch)
                    {
                        //模糊查询Name
                        userSearchQueryObject.AppendQuery(QueryOperator.Like, "Name", query, QueryLogic.Or);
                        //精确查询Tag
                        Dictionary <string, object> queryDict = new Dictionary <string, object>();
                        queryDict.Add("Tags", query);
                        userSearchQueryObject.AppendQuery(queryDict, QueryLogic.Or);
                    }
                    queryObject.AppendQuery(userSearchQueryObject, QueryLogic.And);
                }
            }
            return(queryObject);
        }
Exemplo n.º 14
0
        /// <summary>
        /// 找到该用户Chenkin的数目
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public int FindChenkInCountByUser(Guid userId)
        {
            Dictionary <string, object> queryDict = new Dictionary <string, object>();

            queryDict.Add("User._id", userId);
            var queryObject = new QueryObject <BlogPostEntity>(CheckInService.EntityRepository);

            queryObject.AppendQuery(queryDict, QueryLogic.And);
            int result = (int)CheckInService.EntityRepository.FindCountOfResult(queryObject);

            return(result);
        }
Exemplo n.º 15
0
        /// <summary>
        /// 找到所有对targetId的BlogPost
        /// </summary>
        public IEnumerable <BlogPostEntity> FindAllBlogPost(Guid targetId, string sortByKey, bool isAscending, int pageIndex, int pageSize)
        {
            Dictionary <string, object> queryDict = new Dictionary <string, object>();

            queryDict.Add("TargetId", targetId);
            QueryObject <BlogPostEntity> queryObject = new QueryObject <BlogPostEntity>(blogPostRepository);

            queryObject.AppendQuery(queryDict, QueryLogic.And);
            IEnumerable <BlogPostEntity> result = blogPostRepository.Find(queryObject, sortByKey, isAscending, pageIndex, pageSize);

            return(result);
        }
Exemplo n.º 16
0
        /// <summary>
        /// 找到所有对targetId的BlogPost的个数
        /// </summary>
        public long FindAllBlogPostCount(Guid targetId)
        {
            Dictionary <string, object> queryDict = new Dictionary <string, object>();

            queryDict.Add("TargetId", targetId);
            QueryObject <BlogPostEntity> queryObject = new QueryObject <BlogPostEntity>(blogPostRepository);

            queryObject.AppendQuery(queryDict, QueryLogic.And);
            long result = blogPostRepository.FindCountOfResult(queryObject);

            return(result);
        }
Exemplo n.º 17
0
 /// <summary>
 /// 断绝好友关系(将两个人的好友信息从数据库中删除)
 /// </summary>
 /// <param name="volunteer1Id"></param>
 /// <param name="volunteer2Id"></param>
 /// <returns>成功返回true,失败返回false</returns>
 public static bool BreakOffFriendship(Guid volunteer1Id, Guid volunteer2Id)
 {
     if (CheckIfWeAreFriends(volunteer1Id, volunteer2Id))
     {
         QueryObject <FriendRelationshipEntity> queryObject = new QueryObject <FriendRelationshipEntity>(friendRelationshipEntityRepository);
         Dictionary <string, object>            queryDic1   = new Dictionary <string, object>();
         queryDic1.Add("Volunteer1Id", volunteer1Id);
         queryDic1.Add("Volunteer2Id", volunteer2Id);
         Dictionary <string, object> queryDic2 = new Dictionary <string, object>();
         queryDic2.Add("Volunteer1Id", volunteer2Id);
         queryDic2.Add("Volunteer2Id", volunteer1Id);
         queryObject.AppendQuery(queryDic1, QueryLogic.Or);
         queryObject.AppendQuery(queryDic2, QueryLogic.Or);
         friendRelationshipEntityRepository.Delete(queryObject);
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 18
0
        /// <summary>
        /// 找到该用户所有的Chenkin
        /// </summary>
        /// <param name="ownerId">the dicoverer is the house owner</param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public IEnumerable <CheckIn> FindChenkInByUser(Guid userId, int pageIndex, int pageSize)
        {
            Dictionary <string, object> queryDict = new Dictionary <string, object>();

            queryDict.Add("User._id", userId);
            var queryObject = new QueryObject <BlogPostEntity>(CheckInService.EntityRepository);

            queryObject.AppendQuery(queryDict, QueryLogic.And);
            var result = CheckInService.EntityRepository.Find(queryObject, "CreateTime", false, pageIndex, pageSize).Cast <CheckIn>();

            return(result);
        }
Exemplo n.º 19
0
        /// <summary>
        /// 找到所有对targetId的根评论
        /// </summary>
        public IEnumerable <CommentEntity> FindAllRootComments(Guid targetId, string sortByKey, bool isAscending, int pageIndex, int pageSize)
        {
            Dictionary <string, object> queryDict = new Dictionary <string, object>();

            queryDict.Add("TargetId", targetId);
            queryDict.Add("FatherId", Guid.Empty);
            QueryObject <CommentEntity> queryObject = new QueryObject <CommentEntity>(commentRepository);

            queryObject.AppendQuery(queryDict, QueryLogic.And);
            IEnumerable <CommentEntity> result = commentRepository.Find(queryObject, sortByKey, isAscending, pageIndex, pageSize);

            return(result);
        }
Exemplo n.º 20
0
        //获得所有发给该用户的message
        public IEnumerable <Message> FindMyMessages(Guid receiverId, string sortByKey, bool isAscending, int pageIndex, int pageSize)
        {
            QueryObject <Message>       queryObject = new QueryObject <Message>(EntityRepository);
            Dictionary <string, object> queryDic    = new Dictionary <string, object>();

            queryDic.Add("ReceiverId", receiverId);
            queryDic.Add("HasDeleted", false);
            queryObject.AppendQuery(queryDic, QueryLogic.And);
            List <Message> myMessages = new List <Message>();

            myMessages = EntityRepository.Find(queryObject, sortByKey, isAscending, pageIndex, pageSize).ToList();
            return(myMessages);
        }
Exemplo n.º 21
0
        /// <summary>
        /// 检查两个volunteer是否是好友
        /// </summary>
        /// <param name="volunteer1Id"></param>
        /// <param name="volunteer2Id"></param>
        /// <returns></returns>
        public static bool CheckIfWeAreFriends(Guid volunteer1Id, Guid volunteer2Id)
        {
            QueryObject <FriendRelationshipEntity> queryObject = new QueryObject <FriendRelationshipEntity>(friendRelationshipEntityRepository);
            Dictionary <string, object>            queryDic1   = new Dictionary <string, object>();

            queryDic1.Add("Volunteer1Id", volunteer1Id);
            queryDic1.Add("Volunteer2Id", volunteer2Id);
            Dictionary <string, object> queryDic2 = new Dictionary <string, object>();

            queryDic2.Add("Volunteer1Id", volunteer2Id);
            queryDic2.Add("Volunteer2Id", volunteer1Id);
            queryObject.AppendQuery(queryDic1, QueryLogic.Or);
            queryObject.AppendQuery(queryDic2, QueryLogic.Or);
            var result = friendRelationshipEntityRepository.Find(queryObject);

            if (result.Any())
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 22
0
        /// <summary>
        /// 获得所有发给该用户的feed的个数
        /// (不包括广播,除了该用户自己发的)
        /// </summary>
        /// <param name="receiverId"></param>
        /// <returns></returns>
        public long FindMyFeedCount(Guid receiverId)
        {
            QueryObject <Message>       queryObject = new QueryObject <Message>(FeedService.EntityRepository);
            Dictionary <string, object> queryDic    = new Dictionary <string, object>();

            queryDic.Add("ReceiverId", receiverId);
            Dictionary <string, object> subQueryDic = new Dictionary <string, object>();

            subQueryDic.Add("$ne", receiverId.ToString());
            queryDic.Add("MessageFrom", subQueryDic);
            queryObject.AppendQuery(queryDic, QueryLogic.And);
            long result = FeedService.EntityRepository.FindCountOfResult(queryObject);

            return(result);
        }
Exemplo n.º 23
0
        /// <summary>
        /// 找到该用户Chenkin被赞的数目
        /// </summary>
        /// <param name="ownerId"></param>
        /// <returns></returns>
        public int FindCheckinLikedCountByUser(Guid userId)
        {
            Dictionary <string, object> queryDict = new Dictionary <string, object>();

            queryDict.Add("User._id", userId);
            var queryObject = new QueryObject <BlogPostEntity>(CheckInService.EntityRepository);

            queryObject.AppendQuery(queryDict, QueryLogic.And);
            var checkins           = CheckInService.EntityRepository.FindAsQueryable(queryObject);
            int checkinsLikedCount = 0;

            foreach (var checkin in checkins)
            {
                checkinsLikedCount += LrfService.GetLRFCount(checkin.Id, LRFType.Like);
            }
            return(checkinsLikedCount);
        }
Exemplo n.º 24
0
        /// <summary>
        /// 将所有未handle过的event放到queue的结尾处
        /// 程序异常停止,重新启动时容错
        /// </summary>
        private static void addNotHandledEventToQueue()
        {
            Dictionary <string, object> queryDict = new Dictionary <string, object>();

            queryDict.Add("hasHandled", false);
            QueryObject <Event> queryObject = new QueryObject <Event>(eventRepository);

            queryObject.AppendQuery(queryDict, QueryLogic.And);
            IEnumerable <Event> notHandledEvents = eventRepository.Find(queryObject);

            if (notHandledEvents.Any())
            {
                foreach (Event notHandledEvent in notHandledEvents)
                {
                    eventIdQueue.Enqueue(notHandledEvent.Id);
                }
            }
        }
        /// <summary>
        /// 获得关注该用户的所有用户id
        /// </summary>
        /// <param name="followeeUserId">该用户id</param>
        /// <returns></returns>
        public IEnumerable <Guid> GetAllFollowerUserIds(Guid followeeUserId)
        {
            //找到该用户的profile的id
            Guid followeeProfileId = MyUserManager.FindByIdAsync(followeeUserId).Result.Profiles[OldHouseUserProfile.PROFILENBAME];

            QueryObject <OldHouseUserProfile> queryObject = new QueryObject <OldHouseUserProfile>(ProfileService.EntityRepository);
            Dictionary <string, object>       queryDict   = new Dictionary <string, object>();

            queryDict.Add("FollowingIds", followeeProfileId);
            queryObject.AppendQuery(queryDict, QueryLogic.And);
            List <Guid> userIds  = new List <Guid>();
            var         profiles = ProfileService.EntityRepository.Find(queryObject);

            foreach (var profile in profiles)
            {
                userIds.Add(profile.UserId);
            }
            return(userIds);
        }
Exemplo n.º 26
0
        /// <summary>
        /// you can call into the check in service directly
        /// </summary>
        /// <param name="houseId"></param>
        /// <param name="page"></param>
        /// <param name="pagesize"></param>
        /// <returns></returns>
        public IEnumerable <CheckIn> ListCheckInsFor(Guid houseId, int page, int pagesize)
        {
            //List<BlogPostEntity> source = new List<BlogPostEntity>();
            //List<BlogPostEntity> result = new List<BlogPostEntity>();
            ////先找到精华
            //Dictionary<string, object> queryDict1 = new Dictionary<string, object>();
            //queryDict1.Add("TargetId", houseId);
            //queryDict1.Add("IsEssence", true);
            //QueryObject<BlogPostEntity> queryObject1 = new QueryObject<BlogPostEntity>(CheckInService.EntityRepository);
            //queryObject1.AppendQuery(queryDict1, QueryLogic.And);
            //IEnumerable<BlogPostEntity> resultEssence = CheckInService.EntityRepository.Find(queryObject1, "ModifyTime", false);
            //source.AddRange(resultEssence);
            ////再找到非精华
            //Dictionary<string, object> queryDict2 = new Dictionary<string, object>();
            //queryDict2.Add("TargetId", houseId);
            //queryDict2.Add("IsEssence", false);
            //QueryObject<BlogPostEntity> queryObject2 = new QueryObject<BlogPostEntity>(CheckInService.EntityRepository);
            //queryObject2.AppendQuery(queryDict2, QueryLogic.And);
            //IEnumerable<BlogPostEntity> resultNotEssence = CheckInService.EntityRepository.Find(queryObject2, "ModifyTime", false);
            //source.AddRange(resultNotEssence);
            ////进行分页
            //if (page == 0 || pagesize == 0)
            //{
            //    return source;
            //}
            //result = source.Skip((page - 1) * pagesize).Take(pagesize).ToList();
            //return result;

            Dictionary <string, object> queryDict = new Dictionary <string, object>();

            queryDict.Add("TargetId", houseId);
            QueryObject <BlogPostEntity> queryObject = new QueryObject <BlogPostEntity>(CheckInService.EntityRepository);

            queryObject.AppendQuery(queryDict, QueryLogic.And);
            List <KeyValuePair <string, bool> > sorts = new List <KeyValuePair <string, bool> >();

            sorts.Add(new KeyValuePair <string, bool>("IsEssence", false));
            sorts.Add(new KeyValuePair <string, bool>("ModifyTime", false));
            var result = CheckInService.EntityRepository.Find(queryObject, sorts, page, pagesize).Cast <CheckIn>();

            return(result);
        }
        //rate
        /// <summary>
        /// rate the entity, make sure you have the RateTimes and Rating field in you entity, it will update the ratings in the entity
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="entityService"></param>
        /// <param name="targetId"></param>
        /// <param name="userId"></param>
        /// <param name="lrfService"></param>
        /// <param name="rating"></param>
        /// <returns></returns>
        public static float Rate <T>(this EntityService <T> entityService, Guid targetId, Guid userId,
                                     LikeRateFavService lrfService, float rating) where T : Entity
        {
            var doIRate = lrfService.DoILikeRateFav(userId, targetId, LRFType.Rate);
            //calc new rating
            Dictionary <string, object> queryDict = new Dictionary <string, object>();

            queryDict.Add("_id", targetId);
            QueryObject <T> query = new QueryObject <T>(entityService.EntityRepository);

            query.AppendQuery(queryDict, QueryLogic.And);

            var entity       = entityService.FindOneById(targetId);
            var oldRating    = (float)entity.GetType().GetProperty("Rating").GetValue(entity, null);
            var oldRateTimes = lrfService.GetLRFCount(targetId, LRFType.Rate);

            if (!doIRate)
            {
                //my first time rating
                var newRating = (oldRating * oldRateTimes + rating) / (oldRateTimes + 1);
                lrfService.Rate(userId, targetId, rating);
                ((MongoDBRepository <T>)entityService.EntityRepository).Update(query,
                                                                               Update.Set("Rating", newRating));
                return(newRating);
            }
            else
            {
                //get my old rating
                var myOldRating = lrfService.GetMyRatingFor(userId, targetId);
                //calc the new one
                var newRating = (oldRating * oldRateTimes - myOldRating + rating) / (oldRateTimes);
                lrfService.Rate(userId, targetId, rating);
                ((MongoDBRepository <T>)entityService.EntityRepository).Update(query,
                                                                               Update.Set("Rating", newRating));
                lrfService.Rate(userId, targetId, rating);
                return(newRating);
            }
        }
Exemplo n.º 28
0
        public virtual void AddComment(BasicUser user, Guid targetId, Guid fatherId, string content)
        {
            //先计算楼层
            Dictionary <string, object> queryDict = new Dictionary <string, object>();

            queryDict.Add("TargetId", targetId);
            QueryObject <CommentEntity> queryObject = new QueryObject <CommentEntity>(EntityRepository);

            queryObject.AppendQuery(queryDict, QueryLogic.And);
            int position = Convert.ToInt32(EntityRepository.FindCountOfResult(queryObject)) + 1;
            //加入数据库
            CommentEntity newComment = new CommentEntity(user, targetId, fatherId, content);

            newComment.Position = position;
            EntityRepository.SaveOne(newComment);
            //当存在father时
            //在father的children中加入该comment
            if (fatherId != Guid.Empty)
            {
                CommentEntity father = FindOneById(fatherId);
                father.ChildrenId.Add(newComment.Id);
                EntityRepository.SaveOne(father);
            }
        }
Exemplo n.º 29
0
        static void Main(string[] args)
        {
            initRepository();

            StreamWriter sw = null;

            #region 统计用户浏览老房子
            QueryObject <Event> findAllViewAHouseEvent = new QueryObject <Event>(EventDb);
            findAllViewAHouseEvent.AppendQuery(QueryOperator.Equal, "Type", "ViewAHouseEvent", QueryLogic.And);
            var allViewAHouseEvent = EventDb.Find(findAllViewAHouseEvent);
            //用来统计每个用户共浏览了多少次,key为用户id
            Dictionary <Guid, NameAndCount> userViewHouse = new Dictionary <Guid, NameAndCount>();
            //用来统计每个老房子被浏览了多少次,key为house id
            Dictionary <Guid, NameAndCount> houseHasViewed = new Dictionary <Guid, NameAndCount>();
            foreach (var viewAHouseEvent in allViewAHouseEvent)
            {
                #region userViewHouse
                Guid userId = (Guid)viewAHouseEvent.Sender;
                if (userViewHouse.ContainsKey(userId))
                {
                    userViewHouse[userId].Count++;
                }
                else
                {
                    string userName;
                    if (userId == Guid.Empty)
                    {
                        userName = "******";
                    }
                    else
                    {
                        userName = UserDb.FindOneById(userId).NickName;
                    }
                    userViewHouse.Add(userId, new NameAndCount(userName, 1));
                }
                #endregion

                #region houseHasViewed
                Guid houseId = (Guid)viewAHouseEvent.Subject;
                if (houseHasViewed.ContainsKey(houseId))
                {
                    houseHasViewed[houseId].Count++;
                }
                else
                {
                    string houseName;
                    if (HouseDb.FindOneById(houseId) == null)
                    {
                        houseName = "未知";
                    }
                    else
                    {
                        houseName = HouseDb.FindOneById(houseId).Name;
                    }
                    houseHasViewed.Add(houseId, new NameAndCount(houseName, 1));
                }
                #endregion
            }
            //统计用户浏览
            sw = new StreamWriter(@"C:\用户浏览老房子.csv", false, System.Text.Encoding.UTF8);
            sw.WriteLine("用户昵称,浏览次数");
            sw.WriteLine("总数," + allViewAHouseEvent.Count());
            foreach (KeyValuePair <Guid, NameAndCount> userViewHouseKeyValuePair in userViewHouse)
            {
                sw.WriteLine(userViewHouseKeyValuePair.Value.Name + "," + userViewHouseKeyValuePair.Value.Count);
            }
            sw.Dispose();
            //统计老房子被浏览
            sw = new StreamWriter(@"C:\老房子被浏览.csv", false, System.Text.Encoding.UTF8);
            sw.WriteLine("house名,浏览次数");
            sw.WriteLine("总数," + allViewAHouseEvent.Count());
            foreach (KeyValuePair <Guid, NameAndCount> houseHasViewedKeyValuePair in houseHasViewed)
            {
                sw.WriteLine(houseHasViewedKeyValuePair.Value.Name + "," + houseHasViewedKeyValuePair.Value.Count);
            }
            sw.Dispose();

            #endregion

            #region 统计用户like
            QueryObject <Event> findAllLikeEvent = new QueryObject <Event>(EventDb);
            findAllLikeEvent.AppendQuery(QueryOperator.Equal, "Type", "LikeEvent", QueryLogic.And);
            var allLikeEvent = EventDb.Find(findAllLikeEvent);
            //用来统计用户点赞次数
            Dictionary <Guid, NameAndCount> userLike = new Dictionary <Guid, NameAndCount>();
            foreach (var likeEvent in allLikeEvent)
            {
                Guid userId = (Guid)likeEvent.Sender;
                if (userLike.ContainsKey(userId))
                {
                    userLike[userId].Count++;
                }
                else
                {
                    string userName = UserDb.FindOneById(userId).NickName;
                    userLike.Add(userId, new NameAndCount(userName, 1));
                }
            }
            sw = new StreamWriter(@"C:\用户点赞次数.csv", false, System.Text.Encoding.UTF8);
            sw.WriteLine("用户昵称,点赞次数");
            sw.WriteLine("总数," + allLikeEvent.Count());
            foreach (KeyValuePair <Guid, NameAndCount> userLikeKeyValuePair in userLike)
            {
                sw.WriteLine(userLikeKeyValuePair.Value.Name + "," + userLikeKeyValuePair.Value.Count);
            }
            sw.Dispose();
            #endregion
        }
Exemplo n.º 30
0
        public void HandleEvent(Event oneEvent)
        {
            var    service  = HouseService.Instence;
            Guid   userId   = (Guid)oneEvent.Sender;
            var    likeUser = service.MyUserManager.FindByIdAsync(userId).Result;
            Guid   createEntityUserId;
            int    houseOrCheckin = service.CheckTheIdIsHouseOrCheckin((Guid)oneEvent.Subject);
            string myContent;
            string title;
            QueryObject <Message>       queryObject = new QueryObject <Message>(service.FeedService.EntityRepository);
            Dictionary <string, object> queryDic1   = new Dictionary <string, object>();
            Dictionary <string, object> queryDic2   = new Dictionary <string, object>();

            switch (houseOrCheckin)
            {
            case 0:
                House house = service.FindOneById((Guid)oneEvent.Subject);
                createEntityUserId = house.OwnerId;
                //该用户给house创建者发的feed
                title     = "我赞了您发现的老房子";
                myContent = "【" + likeUser.NickName + "(" + likeUser.UserName + ")】刚刚给你发现的【" + house.Name + "】点赞啦!";
                queryDic2.Add("Title", title);
                queryDic2.Add("Text", myContent);
                queryDic2.Add("ReceiverId", house.OwnerId);
                queryDic2.Add("MessageType", "Feed.TheEntityIsLikedByOther");
                //删除找到的feed
                queryObject.AppendQuery(queryDic1, QueryLogic.Or);
                queryObject.AppendQuery(queryDic2, QueryLogic.Or);
                //TODO BUG!!!胡斐然,,大爷的。。你把所有的feed都删了。。清空了
                //service.FeedService.EntityRepository.Delete(queryObject);
                break;

            case 1:
                var   checkIn  = service.CheckInService.FindOneById((Guid)oneEvent.Subject);
                House theHouse = service.FindOneById(checkIn.TargetId);
                createEntityUserId = checkIn.User.Id;
                //该用户给checkIn创建者发的feed
                title     = "我赞了您的签到";
                myContent = "【" + likeUser.NickName + "(" + likeUser.UserName + ")】刚刚赞了你!";
                queryDic2.Add("Title", title);
                queryDic2.Add("Text", myContent);
                queryDic2.Add("ReceiverId", checkIn.User.Id);
                queryDic2.Add("MessageType", "Feed.TheEntityIsLikedByOther");
                //删除找到的feed
                queryObject.AppendQuery(queryDic1, QueryLogic.Or);
                queryObject.AppendQuery(queryDic2, QueryLogic.Or);
                //TODO BUG!!!胡斐然,,大爷的。。你把所有的feed都删了。。清空了
                //service.FeedService.EntityRepository.Delete(queryObject);
                break;

            default:
                return;
            }
            //为house或者check in创建者扣5分
            var createEntityUser = service.MyUserManager.FindByIdAsync(createEntityUserId).Result;

            if (createEntityUser != null)
            {
                var profile = service.ProfileService.EntityRepository.FindOneById(createEntityUser.Profiles["OldHouseUserProfile"]);
                profile.MinusPoint(5);
                service.ProfileService.EntityRepository.SaveOne(profile);
            }
        }