コード例 #1
0
 public void UpdateChatPhoto(long chatId, byte[] photoData, Rect thumbnailRect, Action <BackendResult <ChatInfoWithMessageId, ResultCode> > callback)
 {
     this.GetChatUploadServer(chatId, (Action <BackendResult <UploadServerAddress, ResultCode> >)(getUplResp =>
     {
         if (getUplResp.ResultCode != ResultCode.Succeeded)
         {
             callback(new BackendResult <ChatInfoWithMessageId, ResultCode>(getUplResp.ResultCode));
         }
         else
         {
             string uploadUrl = getUplResp.ResultData.upload_url;
             // ISSUE: explicit reference operation
             if (((Rect)@thumbnailRect).Width != 0.0)
             {
                 // ISSUE: explicit reference operation
                 // ISSUE: explicit reference operation
                 // ISSUE: explicit reference operation
                 string str = string.Format("&_square_crop={0},{1},{2}&_full={0},{1},{2},{2}", (int)((Rect)@thumbnailRect).X, (int)((Rect)@thumbnailRect).Y, (int)((Rect)@thumbnailRect).Width);
                 uploadUrl += str;
             }
             MemoryStream memoryStream = new MemoryStream(photoData);
             JsonWebRequest.Upload(uploadUrl, (Stream)memoryStream, "photo", "image", (Action <JsonResponseData>)(jsonResult =>
             {
                 if (!jsonResult.IsSucceeded)
                 {
                     callback(new BackendResult <ChatInfoWithMessageId, ResultCode>(ResultCode.UnknownError));
                 }
                 else
                 {
                     this.SetChatPhoto(JsonConvert.DeserializeObject <UploadResponseData>(jsonResult.JsonString), callback);
                 }
             }), "MyImage.jpg", null, null);
         }
     }));
 }
コード例 #2
0
 public void SaveProfilePhoto(long ownerId, Rect thumbnailRect, byte[] photoData, Action <BackendResult <ProfilePhoto, ResultCode> > callback)
 {
     ProfilesService.GetPhotoUploadServer(ownerId, (Action <BackendResult <VKClient.Audio.Base.UploadServerAddress, ResultCode> >)(res =>
     {
         if (res.ResultCode != ResultCode.Succeeded)
         {
             callback(new BackendResult <ProfilePhoto, ResultCode>(res.ResultCode));
         }
         else
         {
             string uploadUrl = res.ResultData.upload_url;
             // ISSUE: explicit reference operation
             if (((Rect)@thumbnailRect).Width != 0.0)
             {
                 // ISSUE: explicit reference operation
                 // ISSUE: explicit reference operation
                 // ISSUE: explicit reference operation
                 string str = string.Format("&_square_crop={0},{1},{2}&_full={0},{1},{2},{2}", (int)((Rect)@thumbnailRect).X, (int)((Rect)@thumbnailRect).Y, (int)((Rect)@thumbnailRect).Width);
                 uploadUrl += str;
             }
             MemoryStream memoryStream = new MemoryStream(photoData);
             JsonWebRequest.Upload(uploadUrl, (Stream)memoryStream, "photo", "image", (Action <JsonResponseData>)(jsonResult =>
             {
                 if (!jsonResult.IsSucceeded)
                 {
                     callback(new BackendResult <ProfilePhoto, ResultCode>(ResultCode.UnknownError));
                 }
                 else
                 {
                     ProfilesService.SaveProfilePhoto(JsonConvert.DeserializeObject <UploadPhotoResponseData>(jsonResult.JsonString), ownerId, callback);
                 }
             }), "MyImage.jpg", null, null);
         }
     }));
 }
コード例 #3
0
 public void UploadGraffitiDocument(string fileName, string fileExtension, Stream stream, Action <BackendResult <Doc, ResultCode> > callback, Action <double> progressCallback = null, Cancellation cancellation = null)
 {
     DocumentsService.GetDocumentUploadServer(0, "graffiti", (Action <BackendResult <VKClient.Audio.Base.UploadServerAddress, ResultCode> >)(uploadUrlResponse =>
     {
         if (uploadUrlResponse.ResultCode == ResultCode.Succeeded)
         {
             string uploadUrl                  = uploadUrlResponse.ResultData.upload_url;
             string str                        = fileName.EndsWith(fileExtension) ? fileName : fileName + fileExtension;
             Stream data                       = stream;
             string paramName                  = "file";
             string uploadContentType          = "file";
             string fileName1                  = str;
             Action <double> progressCallback1 = progressCallback;
             Cancellation c                    = cancellation;
             JsonWebRequest.Upload(uploadUrl, data, paramName, uploadContentType, (Action <JsonResponseData>)(jsonResult =>
             {
                 if (jsonResult.IsSucceeded)
                 {
                     UploadDocResponseData uploadData = JsonConvert.DeserializeObject <UploadDocResponseData>(jsonResult.JsonString);
                     if (string.IsNullOrEmpty(uploadData.error))
                     {
                         DocumentsService.SaveDocument(uploadData, callback);
                     }
                     else
                     {
                         callback(new BackendResult <Doc, ResultCode>(ResultCode.UnknownError));
                     }
                 }
                 else
                 {
                     callback(new BackendResult <Doc, ResultCode>(ResultCode.UnknownError));
                 }
             }), fileName1, progressCallback1, c);
         }
         else
         {
             callback(new BackendResult <Doc, ResultCode>(uploadUrlResponse.ResultCode));
         }
     }));
 }
コード例 #4
0
 public void UploadPhoto(byte[] photoData, Action <BackendResult <Photo, ResultCode> > callback, Action <double> progressCallback = null, Cancellation c = null)
 {
     this.GetPhotoUploadServer((Action <BackendResult <UploadServerAddress, ResultCode> >)(getUplResp =>
     {
         if (getUplResp.ResultCode != ResultCode.Succeeded)
         {
             callback(new BackendResult <Photo, ResultCode>(getUplResp.ResultCode));
         }
         else
         {
             JsonWebRequest.Upload(getUplResp.ResultData.upload_url, (Stream) new MemoryStream(photoData), "photo", "image", (Action <JsonResponseData>)(jsonResult =>
             {
                 if (!jsonResult.IsSucceeded)
                 {
                     callback(new BackendResult <Photo, ResultCode>(ResultCode.UnknownError));
                 }
                 else
                 {
                     this.SavePhoto(JsonConvert.DeserializeObject <UploadResponseData>(jsonResult.JsonString), callback);
                 }
             }), "MyImage.jpg", progressCallback, c);
         }
     }));
 }