public List <UserPhoto> GetUsesLike_Photo(List <PhotoInfo> photoInfo, string friendsId, string targetUserId) { int length = photoInfo.Count; int maincounter = 0; int beginpoint = 0; string owner_id = null; string item_id = null; string param = null; string request = null; int count = 0; int itemsCounter = 0; int loopCounter = 0; int idCounter = 0; string id = targetUserId; if (length % 25 != 0) { maincounter = length / 25 + 1; } else { maincounter = length / 25; } LikesData response = null; List <UserPhoto> finalResponse = new List <UserPhoto>(); for (int i = 0; i < maincounter; i++) { if (length - beginpoint > 25) { count = 25; beginpoint += 25; param = null; for (int z = 1; z < count + 1; z++) { if (z != 25) { param = ","; } else { param = ""; } owner_id = owner_id + String.Format("{0}{1}", photoInfo[itemsCounter].owner_id, param); item_id = item_id + String.Format("{0}{1}", photoInfo[itemsCounter].id, param); itemsCounter++; } request = "var count = 25;var owner_id = [" + owner_id + "];var item_id = [" + item_id + "];var i = 0,d=[],likeInfo=[];while (i<count){d = API.likes.getList({type:\"photo\",owner_id:owner_id[i],item_id:item_id[i],filter:\"likes\",extended:1});i = i + 1;likeInfo.push(d);}return likeInfo;"; response = LikeRequest(request); if (response.like == null) { break; } else { foreach (Like like in response.like) { foreach (User user in response.like[loopCounter].items) { if (friendsId == user.id) { finalResponse.Add(new UserPhoto(photoInfo[idCounter].owner_id, photoInfo[idCounter].id, photoInfo[idCounter].album_id));// Дичь с цыклом } else { continue; } } idCounter++; loopCounter++; } loopCounter = 0; } owner_id = null; item_id = null; } else { count = length - beginpoint; param = null; for (int z = 1; z < count + 1; i++) { z++; if (z != 25) { param = ","; } else { param = ""; } owner_id = owner_id + String.Format("{0}{1}", photoInfo[itemsCounter].owner_id, param); item_id = item_id + String.Format("{0}{1}", photoInfo[itemsCounter].id, param); itemsCounter++; } request = "var count = 25;var owner_id = [" + owner_id + "];var item_id = [" + item_id + "];var i = 0,d=[],likeInfo=[];while (i<count){d = API.likes.getList({type:\"photo\",owner_id:owner_id[i],item_id:item_id[i],filter:\"likes\",extended:1});i = i + 1;likeInfo.push(d);}return likeInfo;"; response = LikeRequest(request); try { foreach (Like like in response.like) // try catch for nullable { foreach (User user in response.like[loopCounter].items) { if (friendsId == user.id) { finalResponse.Add(new UserPhoto(photoInfo[idCounter].owner_id, photoInfo[idCounter].id, photoInfo[idCounter].album_id)); } else { continue; } } idCounter++; loopCounter++; } } catch (NullReferenceException) { finalResponse = null; } loopCounter = 0; owner_id = null; item_id = null; } } return(finalResponse); }
/**************************************************** OTHER METHODS ******************************************************/ /// <summary> /// <para>parses and returns the FeedData in the form of list</para> /// </summary> /// <param name="ParsedJson"></param> /// <returns></returns> private List <FeedData> ParseFeeds(dynamic ParsedJson) { // CREATE FEEDDATA LIST List <FeedData> Data = new List <FeedData>(); foreach (dynamic Post in ParsedJson.data) { // CREATE FEEDDATA OBJECT FeedData Feed = new FeedData(); // CREATE ATTRIBUTION OBJECT; if (Post.attribution == null) { Feed.Attribution = null; } else { AttributionData Attribution = new AttributionData(); Attribution.Website = Post.Attribution.website; Attribution.ItunesUrl = Post.Attribution.itunes_url; Attribution.Name = Post.Attribution.name; Feed.Attribution = Attribution; } // SET TAGS List <String> Tags = new List <String>(); foreach (dynamic Tag in Post.tags) { Tags.Add(Tag.ToString()); } Feed.Tags = Tags; // SET TYPE Feed.Type = Post.type; // SET LOCATION if (Post.location == null) { Feed.Location = null; } else { LocationData Location = new LocationData(); Location.Id = Post.location.id; Location.Latitude = Post.location.latitude; Location.Longitude = Post.location.longitude; Location.Name = Post.location.name; Feed.Location = Location; } // SET COMMENTS CommentData Comments = new CommentData(); Comments.Count = Post.comments.count; List <Comment> CommentData = new List <Comment>(); foreach (dynamic EachComment in Post.comments.data) { // CREATE COMMENT OBJECT Comment Comment = new Comment(); Comment.CreatedTime = new DateTime(long.Parse(EachComment.created_time.ToString())); Comment.Id = EachComment.id; Comment.Text = EachComment.text; // CREATE USER OBJECT User CommentedBy = new User(); CommentedBy.UserName = EachComment.from.username; CommentedBy.ProfilePicture = EachComment.from.profile_pciture; CommentedBy.Id = EachComment.from.id; CommentedBy.FullName = EachComment.from.full_name; // ASSOCIATE COMMENT WITH USER Comment.From = CommentedBy; // ADD COMMENT TO THE LIST CommentData.Add(Comment); } Comments.Data = CommentData; Feed.Comments = Comments; // SET FILTER Feed.Filter = Post.filter; // SET CREATED TIME Feed.CreatedTime = new DateTime(long.Parse(Post.created_time.ToString())); // SET LINK Feed.Link = Post.link; // SET LIKES LikesData Likes = new LikesData(); Likes.Count = Post.likes.count; List <User> LikedByUsers = new List <User>(); foreach (dynamic EachLike in Post.likes.data) { // CREATE USER OBJECT User LikedBy = new User(); LikedBy.UserName = EachLike.username; LikedBy.ProfilePicture = EachLike.profile_picture; LikedBy.Id = EachLike.id; LikedBy.FullName = EachLike.full_name; // ADD USER TO THE LIST LikedByUsers.Add(LikedBy); } Likes.Data = LikedByUsers; Feed.Likes = Likes; // SET VIDEO if (Feed.Type.Equals("video")) { VideosData VideoData = new VideosData(); LowResolutionVideo LRVideo = new LowResolutionVideo(); LRVideo.url = Post.videos.low_resolution.url; LRVideo.width = Post.videos.low_resolution.width; LRVideo.height = Post.videos.low_resolution.height; VideoData.LowResolution = LRVideo; StandardResolutionVideo SRVideo = new StandardResolutionVideo(); SRVideo.url = Post.videos.standard_resolution.url; SRVideo.width = Post.videos.standard_resolution.width; SRVideo.height = Post.videos.standard_resolution.height; VideoData.StandardResolution = SRVideo; Feed.Videos = VideoData; } else { Feed.Videos = null; } // SET IMAGES ImagesData Images = new ImagesData(); StandardResolutionImage SRImage = new StandardResolutionImage(); SRImage.url = Post.images.standard_resolution.url; SRImage.width = Post.images.standard_resolution.width; SRImage.height = Post.images.standard_resolution.height; Images.StandardResolution = SRImage; ThumbnailImage TImage = new ThumbnailImage(); TImage.url = Post.images.thumbnail.url; TImage.width = Post.images.thumbnail.width; TImage.height = Post.images.thumbnail.height; Images.Thumbnail = TImage; LowResolutionImage LRImage = new LowResolutionImage(); LRImage.url = Post.images.low_resolution.url; LRImage.width = Post.images.low_resolution.width; LRImage.height = Post.images.low_resolution.height; Images.LowResolution = LRImage; Feed.Images = Images; // SET CAPTIONS CaptionData Caption = new CaptionData(); if (Post.caption != null) { Caption.CreratedTime = new DateTime(long.Parse(Post.caption.created_time.ToString())); Caption.Text = Post.caption.text; Caption.Id = Post.caption.id; User CaptionedBy = new User(); CaptionedBy.UserName = Post.caption.from.username; CaptionedBy.ProfilePicture = Post.caption.from.profile_pciture; CaptionedBy.Id = Post.caption.from.id; CaptionedBy.FullName = Post.caption.from.full_name; Caption.From = CaptionedBy; } Feed.Caption = Caption; // SET TAGGED USER List <TaggedUser> UserInPhotos = new List <TaggedUser>(); if (Post.users_in_photo != null) { foreach (dynamic UserTag in Post.users_in_photo) { // CREATE TAGGED USER OBJECT TaggedUser TUser = new TaggedUser(); // SET USER User TaggedUser = new User(); TaggedUser.UserName = UserTag.user.username; TaggedUser.FullName = UserTag.user.full_name; TaggedUser.Id = UserTag.user.id; TaggedUser.ProfilePicture = UserTag.user.profile_picture; TUser.User = TaggedUser; // SET POSITION Position TagPosition = new Position(); TagPosition.x = float.Parse(UserTag.position.x.ToString()); TagPosition.y = float.Parse(UserTag.position.y.ToString()); TUser.Position = TagPosition; // ADD TO LIST UserInPhotos.Add(TUser); } } Feed.UsersInPhoto = UserInPhotos; // SET USER LIKE Feed.UserHasLiked = Post.user_has_liked; // SET ID Feed.Id = Post.id; // SET USER User FeedBy = new User(); FeedBy.UserName = Post.user.username; FeedBy.Website = Post.user.webste; FeedBy.ProfilePicture = Post.user.profile_picture; FeedBy.FullName = Post.user.full_name; FeedBy.Bio = Post.user.bio; FeedBy.Id = Post.user.id; Feed.User = FeedBy; // ADD FEED TO LIST Data.Add(Feed); } return(Data); }
public List <UserInfo> GetUsesLike_Wall(Dictionary <int, WallItems> wallitems, string targetUser) { int length = wallitems.Count; int maincounter = 0; int beginpoint = 0; string owner_id = null; string item_id = null; string param = null; string request = null; int count = 0; int itemsCounter = 1; int loopCounter = 0; int idCounter = 1; string id = targetUser; if (length % 25 != 0) { maincounter = length / 25 + 1; } else { maincounter = length / 25; } LikesData response = null; List <UserInfo> finalResponse = new List <UserInfo>(); for (int i = 0; i < maincounter; i++) { if (length - beginpoint > 25) { count = 25; beginpoint += 25; param = null; for (int z = 1; z < count + 1; z++) { if (z != 25) { param = ","; } else { param = ""; } owner_id = owner_id + String.Format("{0}{1}", wallitems[itemsCounter].owner_id, param); item_id = item_id + String.Format("{0}{1}", wallitems[itemsCounter].id, param); itemsCounter++; } request = "var count = 25;var owner_id = [" + owner_id + "];var item_id = [" + item_id + "];var i = 0,d=[],likeInfo=[];while (i<count){d = API.likes.getList({type:\"post\",owner_id:owner_id[i],item_id:item_id[i],filter:\"likes\",extended:1,count:0});i = i + 1;likeInfo.push(d);}return likeInfo;"; response = LikeRequest(request); if (response.like == null) { break; } else { foreach (Like like in response.like) { foreach (User user in response.like[loopCounter].items) { if (id == user.id) { finalResponse.Add(new UserInfo(wallitems[idCounter].owner_id, wallitems[idCounter].id));// Дичь с цыклом } else { continue; } } idCounter++; loopCounter++; } loopCounter = 0; } owner_id = null; item_id = null; } else { count = length - beginpoint; param = null; for (int z = 1; z < count + 1; i++) { z++; if (z != 25) { param = ","; } else { param = ""; } owner_id = owner_id + String.Format("{0}{1}", wallitems[itemsCounter].owner_id, param); item_id = item_id + String.Format("{0}{1}", wallitems[itemsCounter].id, param); itemsCounter++; } request = "var count = 2;var owner_id = [" + owner_id + "];var item_id = [" + item_id + "];var i = 0,d=[],likeInfo=[];while (i<count){d = API.likes.getList({type:\"post\",owner_id:owner_id[i],item_id:item_id[i],filter:\"likes\",extended:1,count:0});i = i + 1;likeInfo.push(d);}return likeInfo;"; response = LikeRequest(request); foreach (Like like in response.like) { foreach (User user in response.like[loopCounter].items) { if (id == user.id) { finalResponse.Add(new UserInfo(wallitems[idCounter].owner_id, wallitems[idCounter].id)); } else { continue; } } idCounter++; loopCounter++; } loopCounter = 1; owner_id = null; item_id = null; } } return(finalResponse); }