コード例 #1
0
 public void UploadPhotoToAlbum(string aid, long optionalGroupId, byte[] photoData, Action <BackendResult <Photo, ResultCode> > callback)
 {
     this.GetPhotoUploadServerAlbum(aid, optionalGroupId, (Action <BackendResult <UploadServerAddress, ResultCode> >)(getUplResp =>
     {
         if (getUplResp.ResultCode != ResultCode.Succeeded)
         {
             callback(new BackendResult <Photo, ResultCode>(getUplResp.ResultCode));
         }
         else
         {
             string uploadUrl          = getUplResp.ResultData.upload_url;
             MemoryStream ms           = new MemoryStream(photoData);
             MemoryStream memoryStream = ms;
             string paramName          = "file1";
             string uploadContentType  = "image";
             Action <JsonResponseData> resultCallback = (Action <JsonResponseData>)(jsonResult =>
             {
                 ms.Close();
                 if (!jsonResult.IsSucceeded)
                 {
                     callback(new BackendResult <Photo, ResultCode>(ResultCode.UnknownError));
                 }
                 else
                 {
                     UploadPhotoResponseData uploadData = JsonConvert.DeserializeObject <UploadPhotoResponseData>(jsonResult.JsonString);
                     this.SavePhoto(uploadData.aid, optionalGroupId, uploadData, callback);
                 }
             });
             string fileName = "MyImage.jpg";
             // ISSUE: variable of the null type
             // ISSUE: variable of the null type
             JsonWebRequest.Upload(uploadUrl, (Stream)memoryStream, paramName, uploadContentType, resultCallback, fileName, null, null);
         }
     }));
 }
コード例 #2
0
        private static void SaveProfilePhoto(UploadPhotoResponseData responseData, long ownerId, Action <BackendResult <ProfilePhoto, ResultCode> > callback)
        {
            Action <BackendResult <ProfilePhoto, ResultCode> > callback1 = (Action <BackendResult <ProfilePhoto, ResultCode> >)(result =>
            {
                if (result.ResultCode == ResultCode.Succeeded && ownerId < 0L)
                {
                    BackendResult <ProfilePhoto, ResultCode> savePhotoResult = result;
                    Action <BackendResult <Group[], ResultCode> > callback2  = (Action <BackendResult <Group[], ResultCode> >)(getGroupResult =>
                    {
                        if (getGroupResult.ResultCode == ResultCode.Succeeded)
                        {
                            savePhotoResult.ResultData.photo_200 = ((IEnumerable <Group>)getGroupResult.ResultData).First <Group>().photo_200;
                            callback(savePhotoResult);
                        }
                        else
                        {
                            result.ResultCode = getGroupResult.ResultCode;
                            callback(result);
                        }
                    });
                    VKRequestsDispatcher.DispatchRequestToVK <Group[]>("groups.getById", new Dictionary <string, string>()
                    {
                        {
                            "group_id",
                            (-ownerId).ToString()
                        }
                    }, callback2, (Func <string, Group[]>)null, false, true, new CancellationToken?(), null);
                }
                else
                {
                    callback(result);
                }
            });

            VKRequestsDispatcher.DispatchRequestToVK <ProfilePhoto>("photos.saveOwnerPhoto", new Dictionary <string, string>()
            {
                {
                    "server",
                    responseData.server
                },
                {
                    "photo",
                    responseData.photo
                },
                {
                    "hash",
                    responseData.hash
                }
            }, callback1, null, false, true, new CancellationToken?(), null);
        }
コード例 #3
0
        public void SaveProfilePhoto(UploadPhotoResponseData responseData, Action <BackendResult <ProfilePhoto, ResultCode> > callback)
        {
            Dictionary <string, string> dictionary = new Dictionary <string, string>();

            dictionary["server"] = responseData.server;
            dictionary["photo"]  = responseData.photo;
            dictionary["hash"]   = responseData.hash;
            string methodName = "photos.saveOwnerPhoto";
            Dictionary <string, string> parameters = dictionary;
            Action <BackendResult <ProfilePhoto, ResultCode> > callback1 = callback;
            int num1 = 0;
            int num2 = 1;
            CancellationToken?cancellationToken = new CancellationToken?();

            // ISSUE: variable of the null type

            VKRequestsDispatcher.DispatchRequestToVK <ProfilePhoto>(methodName, parameters, callback1, (Func <string, ProfilePhoto>)(jsonStr => JsonConvert.DeserializeObject <VKRequestsDispatcher.GenericRoot <ProfilePhoto> >(jsonStr).response), num1 != 0, num2 != 0, cancellationToken, null);
        }
コード例 #4
0
        private void SaveWallPhoto(long userOrGroupId, bool isGroup, UploadPhotoResponseData uploadData, Action <BackendResult <Photo, ResultCode> > callback)
        {
            Dictionary <string, string> dictionary = new Dictionary <string, string>();

            dictionary["server"] = uploadData.server;
            dictionary["photo"]  = uploadData.photo;
            dictionary["hash"]   = uploadData.hash;
            if (userOrGroupId != 0L)
            {
                string index = isGroup ? "group_id" : "user_id";
                dictionary[index] = userOrGroupId.ToString();
            }
            string methodName = "photos.saveWallPhoto";
            Dictionary <string, string> parameters = dictionary;
            Action <BackendResult <Photo, ResultCode> > callback1 = callback;
            int num1 = 0;
            int num2 = 1;
            CancellationToken?cancellationToken = new CancellationToken?();

            // ISSUE: variable of the null type

            VKRequestsDispatcher.DispatchRequestToVK <Photo>(methodName, parameters, callback1, (Func <string, Photo>)(jsonStr => JsonConvert.DeserializeObject <VKRequestsDispatcher.GenericRoot <List <Photo> > >(jsonStr).response.First <Photo>()), num1 != 0, num2 != 0, cancellationToken, null);
        }
コード例 #5
0
        public void SavePhoto(string aid, long optionalGroupId, UploadPhotoResponseData uploadData, Action <BackendResult <Photo, ResultCode> > callback)
        {
            Dictionary <string, string> dictionary = new Dictionary <string, string>();

            dictionary["server"]      = uploadData.server;
            dictionary["photos_list"] = uploadData.photos_list;
            dictionary["hash"]        = uploadData.hash;
            dictionary["album_id"]    = aid;
            if (optionalGroupId != 0L)
            {
                dictionary["group_id"] = optionalGroupId.ToString();
            }
            string methodName = "photos.save";
            Dictionary <string, string> parameters = dictionary;
            Action <BackendResult <Photo, ResultCode> > callback1 = callback;
            int num1 = 0;
            int num2 = 1;
            CancellationToken?cancellationToken = new CancellationToken?();

            // ISSUE: variable of the null type

            VKRequestsDispatcher.DispatchRequestToVK <Photo>(methodName, parameters, callback1, (Func <string, Photo>)(jsonStr => JsonConvert.DeserializeObject <VKRequestsDispatcher.GenericRoot <List <Photo> > >(jsonStr).response.First <Photo>()), num1 != 0, num2 != 0, cancellationToken, null);
        }
コード例 #6
0
 public void SaveSettingsAccountInfo(Dictionary <string, string> parameters, Action <BackendResult <SaveProfileResponse, ResultCode> > callback, UploadPhotoResponseData newPhotoData = null)
 {
     if (parameters.Count == 0)
     {
         if (newPhotoData == null)
         {
             return;
         }
         UsersService.Instance.SaveProfilePhoto(newPhotoData, (Action <BackendResult <ProfilePhoto, ResultCode> >)(pres => callback(new BackendResult <SaveProfileResponse, ResultCode>(pres.ResultCode, new SaveProfileResponse()))));
     }
     else
     {
         VKRequestsDispatcher.DispatchRequestToVK <SaveProfileResponse>("account.saveProfileInfo", parameters, (Action <BackendResult <SaveProfileResponse, ResultCode> >)(res =>
         {
             if (res.ResultCode == ResultCode.Succeeded && newPhotoData != null)
             {
                 UsersService.Instance.SaveProfilePhoto(newPhotoData, (Action <BackendResult <ProfilePhoto, ResultCode> >)(pres => callback(res)));
             }
             else
             {
                 callback(res);
             }
         }), null, false, true, new CancellationToken?(), null);
     }
 }