Exemplo n.º 1
0
        public void AddUserInformation(User user)
        {
            string serializedUser = ObjectSerializer.SerializeUser(user);
            string listId         = KeysDictionary.UserInformation(user.Username);

            redis.Add(listId, serializedUser);
        }
Exemplo n.º 2
0
        public void AddCommentOnPost(CommentOnPost c)
        {
            string postKey           = KeysDictionary.PostKey(c.Post.Id);
            string serializedComment = ObjectSerializer.SerializeComment(c);

            redis.PushItemToList(postKey, serializedComment);
        }
Exemplo n.º 3
0
        public void AddVisitedPlace(string username, Place place)
        {
            string serializedPlace = ObjectSerializer.SerializePlace(place);
            string listId          = KeysDictionary.PlacesVisitedKey(username);

            redis.PushItemToList(listId, serializedPlace);
        }
Exemplo n.º 4
0
        public string CreatePlaceId()
        {
            string placeIdKey = KeysDictionary.PlaceIdKey();
            long   id         = redis.Incr(placeIdKey);

            return(id.ToString());
        }
Exemplo n.º 5
0
        public string GetNextCommentId()
        {
            string commentId = KeysDictionary.CommentIdKey();
            long   id        = redis.Incr(commentId);

            return(id.ToString());
        }
Exemplo n.º 6
0
        public void EditUserInformation(User user)
        {
            string serializedUser = ObjectSerializer.SerializeUser(user);
            string userKey        = KeysDictionary.UserInformation(user.Username);

            redis.Remove(userKey);
            redis.Add(userKey, serializedUser);
        }
Exemplo n.º 7
0
        public void AddUserPost(Post post)
        {
            string serializedPost = ObjectSerializer.SerializeRating(post);
            string username       = post.User.Username;
            string listId         = KeysDictionary.UserPosts(username);

            redis.PushItemToList(listId, serializedPost);
        }
Exemplo n.º 8
0
        public void AddPlacePost(Post post)
        {
            string serializedPost = ObjectSerializer.SerializeRating(post);
            string placeId        = post.Place.Id;
            string listId         = KeysDictionary.PlacePosts(placeId);

            redis.PushItemToList(listId, serializedPost);
        }
Exemplo n.º 9
0
        public User GetUser(string username)
        {
            string listId         = KeysDictionary.UserInformation(username);
            string serializedUser = redis.Get <string>(listId);

            User user = ObjectDeserializer.DeserializeUser(serializedUser);

            return(user);
        }
Exemplo n.º 10
0
 public void StoreUserInformation(List <User> users)
 {
     foreach (var user in users)
     {
         string listId         = KeysDictionary.UserInformation(user.Username);
         string serializedUser = ObjectSerializer.SerializeUser(user);
         redis.PushItemToList(listId, serializedUser);
     }
 }
Exemplo n.º 11
0
        public void AddVisitor(Post post)
        {
            string placeId        = post.Place.Id;
            User   user           = post.User;
            string serializedUser = ObjectSerializer.SerializeUser(user);
            string listId         = KeysDictionary.PlaceRecentVisitors(placeId);

            redis.PushItemToList(listId, serializedUser);
        }
Exemplo n.º 12
0
        public void StorePlacesVisited(string username, List <Place> places)
        {
            string listId = KeysDictionary.PlacesVisitedKey(username);

            foreach (var place in places)
            {
                string serializedPlace = ObjectSerializer.SerializePlace(place);
                redis.PushItemToList(listId, serializedPlace);
            }
        }
Exemplo n.º 13
0
        public void StoreUserPosts(string username, List <Post> posts)
        {
            string listId = KeysDictionary.UserPosts(username);

            foreach (var post in posts)
            {
                string serializedPost = ObjectSerializer.SerializeRating(post);
                redis.PushItemToList(listId, serializedPost);
            }
        }
Exemplo n.º 14
0
        public void AddPostPicturesToGallery(Post post)
        {
            string placeId = post.Place.Id;
            string listId  = KeysDictionary.PlaceGallery(placeId);

            foreach (var picture in post.Pictures)
            {
                string serializedPicture = ObjectSerializer.SerializePicture(picture);
                redis.PushItemToList(listId, serializedPicture);
            }
        }
Exemplo n.º 15
0
        public List <Post> GetNewsFeed(string username)
        {
            List <Post> posts  = new List <Post>();
            string      listId = KeysDictionary.UserNewsFeed(username);


            foreach (string postString in redis.GetRangeFromList(listId, 0, NewsFeedLength - 1))
            {
                Post post = ObjectDeserializer.DeserializeRating(postString);
                posts.Add(post);
            }

            return(posts);
        }
Exemplo n.º 16
0
        public string GetOldestPostId(string username)
        {
            string listId = KeysDictionary.UserNewsFeed(username);
            string obj    = redis.GetItemFromList(listId, 0);
            Post   p      = ObjectDeserializer.DeserializeRating(obj);

            if (p != null)
            {
                return(p.Id);
            }
            else
            {
                return(Int32.MaxValue.ToString());
            }
        }
Exemplo n.º 17
0
        public List <Picture> GetPlaceGallery(string placeId)
        {
            string listId    = KeysDictionary.PlaceGallery(placeId);
            int    listCount = (int)redis.GetListCount(listId);

            List <Picture> pictures = new List <Picture>();

            foreach (string placeString in redis.GetRangeFromList(listId, 0, listCount - 1))
            {
                Picture picture = ObjectDeserializer.DeserializePicture(placeString);
                pictures.Add(picture);
            }

            return(pictures);
        }
Exemplo n.º 18
0
        public List <Place> GetRecentVisitedPlaces(string username, int numberOfPlaces)
        {
            List <Place> places = new List <Place>();
            string       listId = KeysDictionary.PlacesVisitedKey(username);

            int listCount  = (int)redis.GetListCount(listId);
            int startIndex = listCount - numberOfPlaces;

            foreach (string placeString in redis.GetRangeFromList(listId, startIndex, listCount - 1))
            {
                Place place = ObjectDeserializer.DeserializePlace(placeString);
                places.Add(place);
            }

            return(places);
        }
Exemplo n.º 19
0
        public List <Post> GetRecentPlacePosts(string placeId, int numberOfPosts)
        {
            List <Post> posts  = new List <Post>();
            string      listId = KeysDictionary.PlacePosts(placeId);

            int listCount  = (int)redis.GetListCount(listId);
            int startIndex = listCount - numberOfPosts;

            foreach (string postString in redis.GetRangeFromList(listId, startIndex, listCount - 1))
            {
                Post post = ObjectDeserializer.DeserializeRating(postString);
                posts.Add(post);
            }

            return(posts);
        }
Exemplo n.º 20
0
        //deprecated
        public List <User> GetRecentVisitors(string placeId, int numberOfVisitors)
        {
            List <User> users  = new List <User>();
            string      listId = KeysDictionary.PlaceRecentVisitors(placeId);

            int listCount  = (int)redis.GetListCount(listId);
            int startIndex = listCount - numberOfVisitors;

            foreach (string userString in redis.GetRangeFromList(listId, startIndex, listCount - 1))
            {
                User user = ObjectDeserializer.DeserializeUser(userString);
                users.Add(user);
            }

            return(users);
        }
Exemplo n.º 21
0
        public List <CommentOnPost> GetCommentsLastN(string postId, int n)
        {
            string postKey    = KeysDictionary.PostKey(postId);
            int    listCount  = (int)redis.GetListCount(postId);
            int    startIndex = listCount - n;

            List <CommentOnPost> result = new List <CommentOnPost>();
            List <string>        list   = redis.GetRangeFromList(postKey, startIndex, n);

            foreach (string s in list)
            {
                result.Add(ObjectDeserializer.DeserializeComment(s));
            }

            return(result);
        }
Exemplo n.º 22
0
        public void AddPostToNewsFeed(string friendUsername, Post post)
        {
            string serializedPost = ObjectSerializer.SerializeRating(post);
            string username       = post.User.Username;
            string listId         = KeysDictionary.UserNewsFeed(friendUsername);

            redis.PushItemToList(listId, serializedPost);

            int listCount  = (int)redis.GetListCount(listId);
            int startIndex = listCount - NewsFeedLength;

            if (startIndex < 0)
            {
                startIndex = 0;
            }

            redis.TrimList(listId, startIndex, listCount);
        }
Exemplo n.º 23
0
        public void StoreToUserNewsFeed(string username, List <Post> posts)
        {
            string listId = KeysDictionary.UserNewsFeed(username);

            foreach (var post in posts)
            {
                string serializedPost = ObjectSerializer.SerializeRating(post);
                redis.PushItemToList(listId, serializedPost);
            }

            int listCount  = (int)redis.GetListCount(listId);
            int startIndex = listCount - NewsFeedLength;

            if (startIndex < 0)
            {
                startIndex = 0;
            }

            redis.TrimList(listId, startIndex, listCount);
        }