Beispiel #1
0
        public void StatsTrackEvents(List <AppEventBase> appEvents, Action <BackendResult <VKClient.Common.Backend.DataObjects.ResponseWithId, ResultCode> > callback)
        {
            List <AppEventBase> appEventBaseList1 = new List <AppEventBase>();
            List <AppEventBase> appEventBaseList2 = new List <AppEventBase>();

            foreach (AppEventBase appEvent in appEvents)
            {
                if (appEvent is AppEventAdImpression)
                {
                    appEventBaseList2.Add(appEvent);
                }
                else
                {
                    appEventBaseList1.Add(appEvent);
                }
            }
            string format1 = "API.stats.trackEvents({{events:\"{0}\"}});";
            string format2 = "API.adsint.registerAdEvents({{events:\"{0}\"}});";
            string code    = "";

            if (appEventBaseList2.Count > 0)
            {
                code += string.Format(format2, JsonConvert.SerializeObject(appEventBaseList2).Replace("\"", "\\\""));
            }
            if (appEventBaseList1.Count > 0)
            {
                code += string.Format(format1, JsonConvert.SerializeObject(appEventBaseList1).Replace("\"", "\\\""));
            }
            VKRequestsDispatcher.Execute <VKClient.Common.Backend.DataObjects.ResponseWithId>(code, callback, (Func <string, VKClient.Common.Backend.DataObjects.ResponseWithId>)(jsonStr => new VKClient.Common.Backend.DataObjects.ResponseWithId()), false, true, new CancellationToken?());
        }
Beispiel #2
0
 public void GetVideoData(long ownerId, Action <BackendResult <VideosData, ResultCode> > callback)
 {
     VKRequestsDispatcher.Execute <VideosData>(string.Format("var oid = {0};\r\nvar added = API.video.get({{\"owner_id\":oid, \"extended\":1}});\r\nvar uploaded = API.video.get({{\"owner_id\":oid, \"album_id\":-1}}).count;\r\nvar albums = API.video.getAlbums({{\"owner_id\":oid}}).count;\r\n\r\nreturn  {{\"AddedVideos\":added, \"UploadedVideosCount\":uploaded, \"VideoAlbumsCount\":albums}};", ownerId), callback, (Func <string, VideosData>)(jsonStr =>
     {
         jsonStr = VKRequestsDispatcher.FixFalseArray(jsonStr, "AddedVideos", true);
         return(JsonConvert.DeserializeObject <GenericRoot <VideosData> >(jsonStr).response);
     }), false, true, new CancellationToken?());
 }
Beispiel #3
0
 public void SearchVideo(string query, int offset, int count, Action <BackendResult <VideoSearchResponse, ResultCode> > callback)
 {
     VKRequestsDispatcher.Execute <VideoSearchResponse>(string.Format("var q = \"{0}\";\r\n                                var offset = {1};\r\n                                var count = {2};\r\n                                var videos = API.video.search({{\"q\": q, \"search_own\": 1, \"offset\": offset, \"count\": count}});\r\n                                var myVideos = [];\r\n                                var globalVideos = [];\r\n                                var i = 0;\r\n                                var items = videos.items;\r\n                                while (i < items.length) {{\r\n                                    var video = items[i];\r\n                                    if (video.owner_id == {3}) {{\r\n                                        myVideos.push(video);\r\n                                    }} else {{\r\n                                        globalVideos.push(video);\r\n                                    }}\r\n                                    i = i + 1;\r\n                                }}\r\n\r\n                                return  {{\"MyVideos\": myVideos, \"GlobalVideos\": globalVideos, \"TotalCount\": videos.count}};", query, offset, count, AppGlobalStateManager.Current.LoggedInUserId), callback, (Func <string, VideoSearchResponse>)(jsonStr =>
     {
         jsonStr = VKRequestsDispatcher.FixFalseArray(jsonStr, "MyVideos", true);
         jsonStr = VKRequestsDispatcher.FixFalseArray(jsonStr, "GlobalVideos", true);
         return(JsonConvert.DeserializeObject <GenericRoot <VideoSearchResponse> >(jsonStr).response);
     }), false, true, new CancellationToken?());
 }
Beispiel #4
0
        public void GetCommunityInvitations(int offset, int count, Action <BackendResult <CommunityInvitationsList, ResultCode> > callback)
        {
            string code = string.Format("\r\n\r\nvar inviters=[];\r\nvar invitations=API.groups.getInvites({{count:{0},offset:{1},\"fields\":\"members_count\"}});\r\n\r\nif (invitations.items.length>0)\r\n    inviters=API.users.get({{user_ids:[email protected]_by,fields:\"sex\"}});\r\n\r\nreturn\r\n{{\r\n    \"count\":invitations.count,\r\n    \"invitations\":invitations.items,\r\n    \"inviters\":inviters\r\n}};\r\n\r\n                ", count, offset);
            Action <BackendResult <CommunityInvitationsList, ResultCode> > callback1 = callback;
            int num1 = 0;
            int num2 = 1;
            CancellationToken?cancellationToken = new CancellationToken?();

            VKRequestsDispatcher.Execute <CommunityInvitationsList>(code, callback1, (Func <string, CommunityInvitationsList>)(jsonStr => JsonConvert.DeserializeObject <GenericRoot <CommunityInvitationsList> >(jsonStr).response), num1 != 0, num2 != 0, cancellationToken);
        }
Beispiel #5
0
        public void SetPushSettings(string deviceId, string key, string value, string key2, string value2, Action <BackendResult <VKClient.Common.Backend.DataObjects.ResponseWithId, ResultCode> > callback)
        {
            string format = "API.account.setPushSettings({{\"device_id\":\"{0}\", \"key\":\"{1}\", \"value\":\"{2}\"}});";
            string code   = string.Format(format, deviceId, key, value);

            if (!string.IsNullOrWhiteSpace(key2) && !string.IsNullOrWhiteSpace(value2))
            {
                code = code + Environment.NewLine + string.Format(format, deviceId, key2, value2);
            }
            VKRequestsDispatcher.Execute <VKClient.Common.Backend.DataObjects.ResponseWithId>(code, callback, (Func <string, VKClient.Common.Backend.DataObjects.ResponseWithId>)(jsonStr => new VKClient.Common.Backend.DataObjects.ResponseWithId()), false, true, new CancellationToken?());
        }
Beispiel #6
0
        public void WallSubscriptionsUnsubscribe(List <long> ownerIds, Action <BackendResult <ResponseWithId, ResultCode> > callback)
        {
            string format = "API.wall.unsubscribe({{\"owner_id\":{0} }});";
            string code   = "";

            foreach (long ownerId in ownerIds)
            {
                code = code + string.Format(format, ownerId) + Environment.NewLine;
            }
            VKRequestsDispatcher.Execute <ResponseWithId>(code, callback, (Func <string, ResponseWithId>)(jsonStr => new ResponseWithId()), false, true, new CancellationToken?());
        }
Beispiel #7
0
        public void UnbanUsers(List <long> user_ids, Action <BackendResult <VKClient.Common.Backend.DataObjects.ResponseWithId, ResultCode> > callback)
        {
            string format = "API.account.unbanUser({{\"user_id\":{0}}});";
            string code   = "";

            foreach (long userId in user_ids)
            {
                code = code + string.Format(format, userId) + Environment.NewLine;
            }
            VKRequestsDispatcher.Execute <VKClient.Common.Backend.DataObjects.ResponseWithId>(code, callback, (Func <string, VKClient.Common.Backend.DataObjects.ResponseWithId>)(jsonStr => new VKClient.Common.Backend.DataObjects.ResponseWithId()), false, true, new CancellationToken?());
        }
Beispiel #8
0
        public void GetProfileBasicInfo(long userId, Action <BackendResult <UserData, ResultCode> > callback)
        {
            string code = string.Format("var u = {0};\r\nvar full = API.users.get({{\"user_ids\":u, \"fields\":\"uid,first_name,last_name,photo_max,online, online_mobile,can_write_private_message,last_seen, can_post,activity,counters,wall_comments,sex\"}});\r\nvar friend_state = API.friends.areFriends({{\"user_ids\":u}})[0];\r\nreturn {{\"User\": full[0], \"friend\": friend_state}};", userId);
            Dictionary <string, string> dictionary = new Dictionary <string, string>();
            Action <BackendResult <UserData, ResultCode> > callback1 = callback;
            // ISSUE: variable of the null type

            int num1 = 0;
            int num2 = 1;
            CancellationToken?cancellationToken = new CancellationToken?();

            VKRequestsDispatcher.Execute <UserData>(code, callback1, null, num1 != 0, num2 != 0, cancellationToken);
        }
Beispiel #9
0
        private void GetAlbumPhotosImpl(long userOrGroupId, bool isGroup, string albumId, int offset, int count, Action <BackendResult <PhotosListWithCount, ResultCode> > callback)
        {
            Dictionary <string, string> parameters = new Dictionary <string, string>();

            parameters["owner_id"] = isGroup ? (-userOrGroupId).ToString() : userOrGroupId.ToString();
            parameters["album_id"] = albumId;
            parameters["offset"]   = offset.ToString();
            parameters["count"]    = count.ToString();
            parameters["extended"] = 1.ToString();
            parameters["rev"]      = 1.ToString();
            long result;

            if (long.TryParse(albumId, out result))
            {
                VKRequestsDispatcher.Execute <PhotosListWithCount>(string.Format("var photos = API.photos.get({{\"owner_id\":{0}, \"album_id\":{1}, \"offset\":{2}, \"count\":{3}, \"extended\":1, \"rev\":1}});\r\n                      var albums  = API.photos.getAlbums({{\"owner_id\":{0}, \"album_ids\":{1}}});\r\n                      var thumbId = [email protected]_id[0];\r\n                      var ownerPlusThumb = {0} + \"_\" + thumbId;\r\n                      var p= API.photos.getById({{\"photos\":ownerPlusThumb}});\r\n                      return {{\"Album\": albums.items[0], \"Photos\":photos, \"Thumb\": p[0]}};", parameters["owner_id"], result, offset, count), callback, (Func <string, PhotosListWithCount>)(jsonStr =>
                {
                    PhotosService.AlbumAndPhotosData response = JsonConvert.DeserializeObject <GenericRoot <PhotosService.AlbumAndPhotosData> >(jsonStr).response;
                    PhotosListWithCount photosListWithCount   = new PhotosListWithCount()
                    {
                        album       = response.Album,
                        photosCount = response.Photos.count,
                        response    = response.Photos.items
                    };
                    if (photosListWithCount.album != null && response.Thumb != null)
                    {
                        this.UpdateThumbSrc(new List <Album>()
                        {
                            photosListWithCount.album
                        }, new List <Photo>()
                        {
                            response.Thumb
                        });
                    }
                    return(photosListWithCount);
                }), false, true, new CancellationToken?());
            }
            else
            {
                VKRequestsDispatcher.DispatchRequestToVK <PhotosListWithCount>("photos.get", parameters, callback, (Func <string, PhotosListWithCount>)(jsonStr =>
                {
                    VKList <Photo> response = JsonConvert.DeserializeObject <GenericRoot <VKList <Photo> > >(jsonStr).response;
                    return(new PhotosListWithCount()
                    {
                        photosCount = response.count,
                        response = response.items
                    });
                }), false, true, new CancellationToken?(), null);
            }
        }
Beispiel #10
0
        public void AddRemoveToAlbums(long videoId, long ownerId, long targetId, List <long> addToAlbumsIds, List <long> removeFromAlbumsIds, Action <BackendResult <ResponseWithId, ResultCode> > callback)
        {
            string format = "API.video.{0}({{video_id:{1},target_id:{2},album_ids:\"{3}\",owner_id:{4}}});";
            string code   = "";

            if (!addToAlbumsIds.IsNullOrEmpty())
            {
                code = code + string.Format(format, "addToAlbum", videoId, targetId, addToAlbumsIds.GetCommaSeparated(), ownerId) + Environment.NewLine;
            }
            if (!removeFromAlbumsIds.IsNullOrEmpty())
            {
                code += string.Format(format, "removeFromAlbum", videoId, targetId, removeFromAlbumsIds.GetCommaSeparated(), ownerId);
            }
            VKRequestsDispatcher.Execute <ResponseWithId>(code, callback, (Func <string, ResponseWithId>)(jsonStr => new ResponseWithId()), false, true, new CancellationToken?());
        }
Beispiel #11
0
        public void GetWallForManyUsers(List <WallService.WallRequestData> requestData, Action <BackendResult <List <WallData>, ResultCode> > callback)
        {
            StringBuilder stringBuilder1 = new StringBuilder().AppendFormat("var users =  API.users.get({{\"user_ids\":\"{0}\", \"fields\":\"wall_default\"}});", new object[1]
            {
                requestData.Select <WallService.WallRequestData, long>((Func <WallService.WallRequestData, long>)(r => r.UserId)).ToList <long>().GetCommaSeparated()
            }).Append(Environment.NewLine);

            for (int index = 0; index < requestData.Count; ++index)
            {
                WallService.WallRequestData wallRequestData = requestData[index];
                stringBuilder1 = stringBuilder1.AppendFormat("var wall{3} = API.wall.get({{\"owner_id\":{0}, \"offset\":{1}, \"count\":{2}, \"extended\":1, \"filter\":users[{3}].wall_default}});", wallRequestData.UserId, wallRequestData.Offset, wallRequestData.Count, index).AppendFormat(Environment.NewLine);
            }
            StringBuilder stringBuilder2 = stringBuilder1.Append("return {");

            for (int index = 0; index < requestData.Count; ++index)
            {
                if (index > 0)
                {
                    stringBuilder2 = stringBuilder2.Append(", ");
                }
                stringBuilder2 = stringBuilder2.AppendFormat("\"Wall{0}\":wall{0} ", new object[1]
                {
                    index
                });
            }
            VKRequestsDispatcher.Execute <List <WallData> >(stringBuilder2.Append("};").ToString(), callback, (Func <string, List <WallData> >)(jsonStr =>
            {
                List <WallData> wallDataList1 = new List <WallData>();
                jsonStr = VKRequestsDispatcher.FixFalseArray(jsonStr, "wall", false);
                jsonStr = VKRequestsDispatcher.FixFalseArray(jsonStr, "profiles", false);
                jsonStr = VKRequestsDispatcher.FixFalseArray(jsonStr, "groups", false);
                for (int index = 0; index < requestData.Count; ++index)
                {
                    jsonStr = VKRequestsDispatcher.FixFalseArray(jsonStr, "Wall" + index, true);
                }
                List <int> resultCounts;
                jsonStr = VKRequestsDispatcher.GetArrayCountsAndRemove(jsonStr, "wall", out resultCounts);
                GenericRoot <Dictionary <string, WallData> > genericRoot = JsonConvert.DeserializeObject <GenericRoot <Dictionary <string, WallData> > >(jsonStr);
                List <WallData> wallDataList2 = new List <WallData>();
                foreach (KeyValuePair <string, WallData> keyValuePair in genericRoot.response)
                {
                    wallDataList2.Add(keyValuePair.Value);
                }
                return(wallDataList2);
            }), false, true, new CancellationToken?());
        }
        public void DeleteAudios(List <long> list)
        {
            string format         = "API.audio.delete({{ \"audio_id\":{0}, \"owner_id\":{1} }});";
            long   loggedInUserId = AppGlobalStateManager.Current.LoggedInUserId;
            string str            = "";

            foreach (long num in list)
            {
                str = str + string.Format(format, num, loggedInUserId) + Environment.NewLine;
            }

            Action <BackendResult <VKClient.Common.Backend.DataObjects.ResponseWithId, ResultCode> > action = (Action <BackendResult <VKClient.Common.Backend.DataObjects.ResponseWithId, ResultCode> >)(res => { });

            CancellationToken?cancellationToken = new CancellationToken?();
            Action <BackendResult <VKClient.Common.Backend.DataObjects.ResponseWithId, ResultCode> > callback = (Action <BackendResult <VKClient.Common.Backend.DataObjects.ResponseWithId, ResultCode> >)(res => { });

            VKRequestsDispatcher.Execute <VKClient.Common.Backend.DataObjects.ResponseWithId>(str, callback, (Func <string, VKClient.Common.Backend.DataObjects.ResponseWithId>)(jsonStr => new VKClient.Common.Backend.DataObjects.ResponseWithId()), false, true, cancellationToken);
        }
Beispiel #13
0
        public void GetTopicComments(long gid, long tid, int offset, int count, Action <BackendResult <CommentsInfo, ResultCode> > callback)
        {
            Dictionary <string, string> dictionary = new Dictionary <string, string>();
            string index1 = "group_id";
            string str1   = gid.ToString();

            dictionary[index1] = str1;
            string index2 = "topic_id";
            string str2   = tid.ToString();

            dictionary[index2] = str2;
            string index3 = "offset";
            string str3   = offset.ToString();

            dictionary[index3] = str3;
            string index4 = "count";
            string str4   = count.ToString();

            dictionary[index4] = str4;
            string index5 = "extended";
            string str5   = "1";

            dictionary[index5] = str5;
            string index6 = "need_likes";
            string str6   = "1";

            dictionary[index6] = str6;
            VKRequestsDispatcher.Execute <CommentsInfo>(string.Format("var cm = API.board.getComments({{\"group_id\":{0}, \"topic_id\":{1}, \"offset\":{2}, \"count\":{3}, \"extended\":1, \"need_likes\":1, \"allow_group_comments\":1  }});\r\nvar g = API.groups.getById({{\"group_id\":{0}}})[0];\r\nreturn {{CommentsResponse:cm, Group:g}};", gid, tid, offset, count), callback, (Func <string, CommentsInfo>)(jsonStr =>
            {
                GroupsService.TopicCommentsResponse response = JsonConvert.DeserializeObject <GenericRoot <GroupsService.TopicCommentsResponse> >(jsonStr).response;
                CommentsResponse commentsResponse            = response.CommentsResponse;
                GroupsService.Current.AddCachedGroup(response.Group);
                return(new CommentsInfo()
                {
                    comments = commentsResponse.items,
                    poll = commentsResponse.poll,
                    profiles = commentsResponse.profiles,
                    groups = commentsResponse.groups,
                    TotalCommentsCount = commentsResponse.count
                });
            }), false, true, new CancellationToken?());
        }
Beispiel #14
0
 public void GetSettingsProfileInfo(Action <BackendResult <ProfileInfo, ResultCode> > callback)
 {
     VKRequestsDispatcher.Execute <ProfileInfo>("var pi = API.account.getProfileInfo();\r\nvar u = API.users.get({\"fields\":\"photo_max\"});\r\nvar partner;\r\nif (pi.relation_partner + \"\"!=\"\")\r\n{\r\n    partner = API.users.get({\"user_ids\":pi.relation_partner.id, \"fields\":\"photo_max,first_name_gen,last_name_gen,sex\"});\r\n    return {\"User\":u[0], \"ProfileInfo\":pi, \"Partner\":partner[0]};\r\n}\r\nvar relation_requests;\r\nif (pi.relation_requests + \"\"!=\"\")\r\n{\r\n    relation_requests = API.users.get({\"user_ids\":[email protected], \"fields\":\"sex\"});\r\n}\r\n\r\nreturn {\"User\":u[0], \"ProfileInfo\":pi, \"RelationRequests\":relation_requests};", callback, (Func <string, ProfileInfo>)(jsonStr =>
     {
         GetProfileInfoResponse response = JsonConvert.DeserializeObject <GenericRoot <GetProfileInfoResponse> >(jsonStr).response;
         response.ProfileInfo.photo_max  = response.User.photo_max;
         if (response.partner != null && response.ProfileInfo.relation_partner != null)
         {
             response.ProfileInfo.relation_partner.photo_max      = response.partner.photo_max;
             response.ProfileInfo.relation_partner.first_name_gen = response.partner.first_name_gen;
             response.ProfileInfo.relation_partner.last_name_gen  = response.partner.last_name_gen;
             response.ProfileInfo.relation_partner.sex            = response.partner.sex;
         }
         if (response.RelationRequests != null)
         {
             response.ProfileInfo.relation_requests = response.RelationRequests;
         }
         return(response.ProfileInfo);
     }), false, true, new CancellationToken?());
 }
Beispiel #15
0
 public void GetComments(long ownerId, long vid, int knownCommentsCount, int offset, int count, StatisticsActionSource actionSource, string context, Action <BackendResult <VideoLikesCommentsData, ResultCode> > callback)
 {
     VKRequestsDispatcher.Execute <VideoLikesCommentsData>(string.Format("\r\nvar ownerId={0};\r\nvar vid  = {1};\r\nvar countToRead = {4};\r\nvar vidStr= ownerId + \"_\" + vid;\r\n\r\nvar knownCommentsCount = {2};\r\nvar offset = {3};\r\n\r\nvar albums = API.video.getAlbumsByVideo({{\"owner_id\":ownerId, \"video_id\":vid}});\r\n\r\nvar likesAll = API.likes.getList({{ \"type\": \"video\", \"owner_id\":ownerId, \"item_id\":vid, \"count\":10 }});\r\n\r\nvar repostsCount = API.likes.getList({{ \"type\": \"video\", \"owner_id\":ownerId, \"item_id\":vid, \"filter\": \"copies\"}}).count;\r\n\r\nvar comments;\r\n\r\nif (knownCommentsCount == -1)\r\n{{\r\n   comments = API.video.getComments({{\"video_id\":vid, \"owner_id\":ownerId, \"offset\":0, \"count\":countToRead, \"sort\":\"desc\", \"need_likes\":1, \"allow_group_comments\":1 }});\r\n}}\r\n\r\nelse\r\n{{\r\n   var calculatedOffset = knownCommentsCount - offset - countToRead;\r\n   if (calculatedOffset < 0)\r\n{{\r\n    calculatedOffset = 0;\r\n}}\r\n   comments = API.video.getComments({{\"video_id\":vid, \"owner_id\":ownerId, \"offset\":calculatedOffset, \"count\":countToRead, \"sort\":\"asc\", \"need_likes\":1, \"allow_group_comments\":1}});\r\n\r\n}}\r\n\r\nvar users2 = API.getProfiles({{ \"user_ids\":[email protected]_to_user, \"fields\":\"first_name_dat,last_name_dat\"}});\r\n\r\n\r\nvar likesAllIds = likesAll.items;\r\nvar likesAllCount = likesAll.count;\r\n\r\nvar userLiked = API.likes.isLiked({{\"owner_id\":ownerId, \"type\":\"video\", \"item_id\":vid}});\r\n\r\nvar tags = API.video.getTags({{\"owner_id\":ownerId, \"video_id\":vid}});\r\n\r\n\r\nvar userOrGroupIds = likesAllIds;\r\n\r\n\r\n\r\nuserOrGroupIds = userOrGroupIds + [email protected]_id;\r\n\r\nvar userIds = [];\r\nvar groupIds = [];\r\n\r\nvar i = 0;\r\n\r\nif (ownerId < 0)\r\n{{\r\n     var negOwner = -ownerId;\r\n     groupIds = groupIds + negOwner;\r\n}}\r\nelse\r\n{{\r\n    userIds = userIds + ownerId;\r\n}}\r\n\r\nvar length = userOrGroupIds.length;\r\n\r\nwhile (i < length)\r\n{{\r\n    var id = parseInt(userOrGroupIds[i]);\r\n    \r\n    if (id > 0)\r\n    {{\r\n       if (userIds.length > 0)\r\n       {{\r\n          userIds = userIds + \",\";\r\n       }}\r\n       userIds = userIds + id;\r\n    }}\r\n    else if (id < 0)\r\n    {{\r\n        id = -id;\r\n        if (groupIds.length > 0)\r\n        {{\r\n            groupIds = groupIds + \",\";\r\n        }}\r\n        groupIds = groupIds + id;\r\n    }}\r\n     \r\n    i = i + 1;\r\n}}\r\n\r\nvar users  = API.users.get({{\"user_ids\":userIds, \"fields\":\"sex,photo_max,online,online_mobile,friend_status\" }});\r\nvar users3 =API.users.get({{\"user_ids\":userIds, \"fields\":\"first_name_dat,last_name_dat,friend_status\" }}); \r\nvar groups = API.groups.getById({{\"group_ids\":groupIds, \"fields\":\"members_count,photo_100\"}});\r\n\r\n\r\nvar videoRecommendations = API.video.getRecommendations({{count: 8, extended: 1, owner_id: ownerId, video_id: vid, source: \"{5}\", context: \"{6}\"}});\r\n\r\n// for test\r\n//var videoRecomList = API.video.get({{count: 8, extended: 1}});\r\n//var videoRecom = {{\r\n//items: videoRecomList.items,\r\n//count: videoRecomList.count,\r\n//context: \"-1324220032\"\r\n//}};\r\n\r\nreturn {{\"comments\":comments, \"LikesAllIds\":likesAllIds,  \"LikesAllCount\":likesAllCount, \"userLiked\":userLiked, \"Users\":users,\"Users2\":users2, \"Users3\": users3, \"Groups\":groups, \"Tags\":tags, \"RepostsCount\":repostsCount, \"Albums\":albums, \"VideoRecommendations\": videoRecommendations}};\r\n", ownerId, vid, knownCommentsCount, offset, count, actionSource, context), callback, (Func <string, VideoLikesCommentsData>)(jsonStr =>
     {
         jsonStr = VKRequestsDispatcher.FixFalseArray(jsonStr, "Users", false);
         jsonStr = VKRequestsDispatcher.FixFalseArray(jsonStr, "Users2", false);
         jsonStr = VKRequestsDispatcher.FixFalseArray(jsonStr, "Users3", false);
         jsonStr = VKRequestsDispatcher.FixFalseArray(jsonStr, "Groups", false);
         jsonStr = VKRequestsDispatcher.FixFalseArray(jsonStr, "comments", true);
         jsonStr = VKRequestsDispatcher.FixFalseArray(jsonStr, "Tags", false);
         jsonStr = VKRequestsDispatcher.FixFalseArray(jsonStr, "LikesAllIds", false);
         jsonStr = VKRequestsDispatcher.FixFalseArray(jsonStr, "Albums", false);
         jsonStr = VKRequestsDispatcher.FixFalseArray(jsonStr, "VideoRecommendations", true);
         VideoLikesCommentsData response = JsonConvert.DeserializeObject <GenericRoot <VideoLikesCommentsData> >(jsonStr).response;
         GroupsService.Current.AddCachedGroups((IEnumerable <Group>)response.Groups);
         if (knownCommentsCount < 0)
         {
             response.Comments.Reverse();
         }
         response.Users2.AddRange((IEnumerable <User>)response.Users3);
         return(response);
     }), false, true, new CancellationToken?());
 }
Beispiel #16
0
 public void GetWallSubscriptionsGroups(int offset, int count, Action <BackendResult <VKList <Group>, ResultCode> > callback)
 {
     VKRequestsDispatcher.Execute <VKList <Group> >(string.Format("var subscriptions = API.wall.getSubscriptions({{\"offset\":{0}, \"count\":{1}, \"type\":2}});\r\nvar groups = [];\r\nif (subscriptions.items.length > 0)\r\n{{\r\n   var groupIds = [];\r\n   var i= 0;\r\n\r\n   while (i < subscriptions.items.length)\r\n   {{\r\n       groupIds.push(-subscriptions.items[i]);\r\n       i = i + 1;\r\n   }}\r\n\r\n   groups = API.groups.getById({{\"group_ids\":groupIds}});\r\n}}\r\nreturn {{\"items\": groups, \"count\":subscriptions.count}};", offset, count), callback, null, false, true, new CancellationToken?());
 }
Beispiel #17
0
 public void GetUsers(List <long> userIds, Action <BackendResult <List <User>, ResultCode> > callback)
 {
     if (userIds == null || userIds.Count == 0)
     {
         callback(new BackendResult <List <User>, ResultCode>()
         {
             ResultCode = ResultCode.Succeeded,
             ResultData = new List <User>()
         });
     }
     else
     {
         List <User> resultData = new List <User>();
         bool        flag       = true;
         foreach (long userId in userIds)
         {
             DateTime now = DateTime.Now;
             if (this.GetCachedUser(userId) != null)
             {
                 resultData.Add(this._usersCache[userId]);
             }
             else
             {
                 flag = false;
                 break;
             }
         }
         if (flag)
         {
             Logger.Instance.Info("Returning {0} users from cache", resultData.Count);
             callback(new BackendResult <List <User>, ResultCode>(ResultCode.Succeeded, resultData));
         }
         else
         {
             string allUserIds = userIds.GetCommaSeparated();
             if (this._callbacksToExecute.ContainsKey(allUserIds))
             {
                 this._callbacksToExecute[allUserIds].Add(callback);
             }
             else
             {
                 this._callbacksToExecute.Add(allUserIds, new List <Action <BackendResult <List <User>, ResultCode> > >()
                 {
                     callback
                 });
                 Dictionary <string, string> dictionary = new Dictionary <string, string>()
                 {
                     {
                         "user_ids",
                         allUserIds
                     },
                     {
                         "fields",
                         "uid,first_name,last_name,online,online_mobile,photo_max,sex,photo_medium,friend_status"
                     }
                 };
                 VKRequestsDispatcher.Execute <UsersAndGroups>(string.Format("\r\nvar userIds = \"{0}\";\r\nvar groupIds = \"{1}\";\r\n\r\nvar users = [];\r\nvar groups = [];\r\n\r\nif (userIds.length > 0)\r\n{{\r\n   users = API.users.get({{\"user_ids\":userIds, \"fields\":\"uid,first_name,last_name,online,online_mobile,photo_max,sex,photo_medium,friend_status,first_name_dat\" }});\r\n}}\r\n\r\nif (groupIds.length > 0)\r\n{{\r\n   groups = API.groups.getById({{\"group_ids\":groupIds, \"fields\":\"photo_200,is_messages_blocked\"}});\r\n}}\r\n\r\nreturn {{\"users\":users, \"groups\":groups}};", userIds.Where <long>((Func <long, bool>)(uid => uid > 0L)).ToList <long>().GetCommaSeparated(), userIds.Where <long>((Func <long, bool>)(uid =>
                 {
                     if (uid < 0L)
                     {
                         return(uid > -2000000000L);
                     }
                     return(false);
                 })).Select <long, long>((Func <long, long>)(uid => - uid)).ToList <long>().GetCommaSeparated()), (Action <BackendResult <UsersAndGroups, ResultCode> >)(res =>
                 {
                     if (res.ResultCode == ResultCode.Succeeded)
                     {
                         foreach (VKClient.Common.Backend.DataObjects.Group group in res.ResultData.groups)
                         {
                             User user = new User();
                             user.InitFromGroup(group);
                             res.ResultData.users.Add(user);
                         }
                         foreach (User user in res.ResultData.users)
                         {
                             this.SetCachedUser(user);
                         }
                     }
                     BackendResult <List <User>, ResultCode> backendResult = new BackendResult <List <User>, ResultCode>();
                     backendResult.ResultCode = res.ResultCode;
                     if (res.ResultData != null)
                     {
                         backendResult.ResultData = res.ResultData.users;
                     }
                     foreach (Action <BackendResult <List <User>, ResultCode> > action in this._callbacksToExecute[allUserIds])
                     {
                         action(backendResult);
                     }
                     this._callbacksToExecute.Remove(allUserIds);
                 }), null, false, true, new CancellationToken?());
             }
         }
     }
 }
Beispiel #18
0
 public void DeleteProfilePhoto(Action <BackendResult <User, ResultCode> > callback)
 {
     VKRequestsDispatcher.Execute <User>("var ph = API.photos.get({album_id:-6, rev:1, count:1}).items[0];\r\nAPI.photos.delete({owner_id:ph.owner_id, photo_id:ph.id});\r\nreturn API.users.get({fields:\"photo_max\"})[0];", callback, null, false, true, new CancellationToken?());
 }
Beispiel #19
0
 public void EditPoll(long ownerId, long pollId, string question, List <string> addAnswers, Dictionary <string, string> editAnswers, List <long> deleteAnswers, Action <BackendResult <Poll, ResultCode> > callback)
 {
     VKRequestsDispatcher.Execute <Poll>(string.Format("API.polls.edit({{\"owner_id\":{0}, \"poll_id\":{1}, \"question\":\"{2}\" {3} {4} {5}}});\r\nreturn API.polls.getById({{\"owner_id\":{0}, \"poll_id\":{1}}});", ownerId, pollId, question, (addAnswers.Any <string>() ? ", \"add_answers\":\"[" + addAnswers.Select <string, string>((Func <string, string>)(a => "\\\"" + a + "\\\"")).ToList <string>().GetCommaSeparated(",") + "]\"" : ""), (editAnswers.Any <KeyValuePair <string, string> >() ? ", \"edit_answers\":\"" + JsonConvert.SerializeObject(editAnswers).Replace("\"", "\\\"") + "\"" : ""), (deleteAnswers.Any <long>() ? ", \"delete_answers\":\"[" + deleteAnswers.GetCommaSeparated() + "]\"" : "")), callback, null, false, true, new CancellationToken?());
 }
Beispiel #20
0
 public void GetAddToAlbumInfo(long targetId, long ownerId, long videoId, Action <BackendResult <GetAddToAlbumInfoResponse, ResultCode> > callback)
 {
     VKRequestsDispatcher.Execute <GetAddToAlbumInfoResponse>(string.Format("var target_id = {0};\r\n\r\nvar owner_id = {1};\r\n\r\nvar video_id = {2};\r\n\r\nvar groups = API.groups.get({{extended:1, filter:\"moder\", \"fields\":\"can_upload_video\"}});\r\n\r\nvar albums = API.video.getAlbums({{need_system:1, extended:1, owner_id:target_id}});\r\n\r\nvar albumsByVideo = API.video.getAlbumsByVideo({{target_id:target_id, owner_id:owner_id, video_id:video_id}});\r\n\r\nreturn {{ AlbumsByVideo:albumsByVideo, Albums:albums, Groups:groups}};", targetId, ownerId, videoId), callback, null, false, true, new CancellationToken?());
 }
Beispiel #21
0
 public void Join(long gid, bool notSure, Action <BackendResult <OwnCounters, ResultCode> > callback, string source = null)
 {
     VKRequestsDispatcher.Execute <OwnCounters>(string.Format("var gid = {0};\r\n\r\nAPI.groups.join({{\"group_id\": gid, \"not_sure\": {1}{2}}});\r\n\r\nreturn API.getCounters();", gid, notSure ? "1" : "0", !string.IsNullOrEmpty(source) ? string.Format(", \"source\": \"{0}\"", source) : ""), callback, new Func <string, OwnCounters>(CountersDeserializerHelper.Deserialize), false, true, new CancellationToken?());
 }
Beispiel #22
0
 public void GetVideoDataExt(long ownerId, Action <BackendResult <GetVideosDataExtResponse, ResultCode> > callback)
 {
     VKRequestsDispatcher.Execute <GetVideosDataExtResponse>(string.Format("var oid = {0};\r\nvar added = API.video.get({{\"owner_id\":oid, \"extended\":1}});\r\nvar uploaded = API.video.get({{\"owner_id\":oid, \"album_id\":-1, extended:1}});\r\nvar albums = API.video.getAlbums({{\"owner_id\":oid, extended:1}});\r\nvar group;\r\nvar user;\r\nif (oid >0)\r\n{{\r\n   user = API.users.get ({{user_ids:oid, fields:\"photo_max\"}})[0];\r\n}}\r\nif (oid < 0)\r\n{{\r\n   group = API.groups.getById({{group_id:-oid, fields:\"members_count,can_upload_video\"}})[0];\r\n}}\r\n\r\nreturn  {{\"AddedVideos\":added, \"UploadedVideos\":uploaded, \"Albums\":albums, \"User\":user, \"Group\":group}};", ownerId), callback, null, false, true, new CancellationToken?());
 }
Beispiel #23
0
 public void GetSettingsAccountInfo(Action <BackendResult <SettingsAccountInfo, ResultCode> > callback)
 {
     VKRequestsDispatcher.Execute <SettingsAccountInfo>("var account = API.account.getInfo();\r\n\r\nvar newsBanned = API.newsfeed.getBanned();\r\n\r\nvar pi = API.account.getProfileInfo();\r\n\r\nreturn {\"Account\": account, \"NewsBanned\":newsBanned, \"ProfileInfo\":pi};", callback, null, false, true, new CancellationToken?());
 }
Beispiel #24
0
 public void Leave(long gid, Action <BackendResult <OwnCounters, ResultCode> > callback)
 {
     VKRequestsDispatcher.Execute <OwnCounters>(string.Format("var gid = {0};\r\n\r\nAPI.groups.leave({{\"group_id\": gid}});\r\n\r\nreturn API.getCounters();", gid), callback, new Func <string, OwnCounters>(CountersDeserializerHelper.Deserialize), false, true, new CancellationToken?());
 }
Beispiel #25
0
 public void GetWallSubscriptionsProfiles(int offset, int count, Action <BackendResult <VKList <User>, ResultCode> > callback)
 {
     VKRequestsDispatcher.Execute <VKList <User> >(string.Format("var subscriptions = API.wall.getSubscriptions({{\"offset\":{0}, \"count\":{1}, \"type\":1}});\r\nvar users = [];\r\nif (subscriptions.items.length > 0)\r\n{{\r\n     users = API.users.get({{\"user_ids\":subscriptions.items, \"fields\":\"photo_max, online, online_mobile\"}});\r\n}}\r\nreturn {{\"items\": users, \"count\":subscriptions.count}};", offset, count), callback, null, false, true, new CancellationToken?());
 }