コード例 #1
0
 /// <summary>
 /// The async implementation of <see cref="PostStatusWithPic"/>
 /// </summary>
 public static void PostStatusWithPicAsync(AsyncCallback<StatusInfo> callback, UpdateStatusWithPicInfo updateStatusWithPicInfo)
 {
     // Validates arguments
     ValidateArgument(updateStatusWithPicInfo, "updateStatusWithPicInfo");
     ValidateArgument(updateStatusWithPicInfo.Status, "updateStatusWithPicInfo.Status");
     ValidateArgument(updateStatusWithPicInfo.Pic, "updateStatusWithPicInfo.Pic");
     FileInfo picInfo = new FileInfo(updateStatusWithPicInfo.Pic);
     if (picInfo.Length > 5 * 1021 * 1024) // 5MB limit
     {
         throw new AMicroblogException(LocalErrorCode.ArgumentInvalid, "Pic file too large to post.");
     }
     var uri = APIUri.UpdateStatusWithPic;
     var requester = new OAuthMultiPartHttpPost(uri);
     requester.PartFields.Add(new MultiPartField() { Name = "status", Value = RFC3986Encoder.UrlEncode(updateStatusWithPicInfo.Status) });
     requester.PartFields.Add(new MultiPartField() { Name = "pic", FilePath = updateStatusWithPicInfo.Pic });
     if (updateStatusWithPicInfo.Latitude.HasValue && updateStatusWithPicInfo.Longitude.HasValue)
     {
         requester.PartFields.Add(new MultiPartField() { Name = "lat", FilePath = updateStatusWithPicInfo.Latitude.Value.ToString(InvariantCulture) });
         requester.PartFields.Add(new MultiPartField() { Name = "long", FilePath = updateStatusWithPicInfo.Longitude.Value.ToString(InvariantCulture) });
     }
     requester.RequestAsync(delegate(AsyncCallResult<string> result)
     {
         ProcessAsyncCallbackResponse(result, callback);
     });
 }
コード例 #2
0
 /// <summary>
 /// The async implementation of <see cref="UpdateProfileImage"/>
 /// </summary>
 public static void UpdateProfileImageAsync(AsyncCallback<UserInfo> callback, string imageFileLocation)
 {
     // Validates arguments
     ValidateArgument(imageFileLocation, "imageFileLocation");
     FileInfo picInfo = new FileInfo(imageFileLocation);
     if (picInfo.Length > 700 * 1024) // 700KB limit
     {
         throw new AMicroblogException(LocalErrorCode.ArgumentInvalid, "Profile imgae file too large to upload.");
     }
     var requester = new OAuthMultiPartHttpPost(APIUri.UpdateProfileImage);
     requester.PartFields.Add(new MultiPartField() { Name = "image", FilePath = imageFileLocation });
     requester.RequestAsync(delegate(AsyncCallResult<string> result)
     {
         ProcessAsyncCallbackResponse(result, callback);
     });
 }