Created
January 31, 2012 19:33
-
-
Save mauricio/1712438 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private Result<T> HandleHttpResult<T> (BasicFuture<Result<T>> future, Action<Result<T>> action, Func<HttpResult> httpResultGenerator) | |
| { | |
| Result<T> result = null; | |
| try { | |
| HttpResult httpResult = httpResultGenerator (); | |
| result = this.parser.ParseResponse<T> ((HttpStatusCode)httpResult.Code, httpResult.ContentType, httpResult.Content, typeof(T)); | |
| } catch (WebException e) { | |
| Console.WriteLine (e); | |
| if (e.Response != null && e.Response.GetResponseStream () != null) { | |
| string data = IOUtils.ReadAll (e.Response.GetResponseStream ()); | |
| Console.WriteLine (data); | |
| } | |
| result = new Result<T> (default(T), 500, e.Message, e); | |
| } catch (Exception e) { | |
| Console.WriteLine (e); | |
| result = new Result<T> (default(T), 500, e.Message, e); | |
| } | |
| future.SetResult (result); | |
| if (action != null) { | |
| action (result); | |
| } | |
| return result; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public Future<Result<Batch>> UploadFile (string path, long folderId = -1, Action<Result<Batch>> action = null) | |
| { | |
| IDictionary<string,string> parameters = new Dictionary<string,string> (); | |
| if (folderId > 0) { | |
| parameters ["folder_id"] = folderId.ToString (); | |
| } | |
| return this.HandleHttpResult<Batch> ( action, delegate { | |
| return HttpHelper.HttpUploadFile ( | |
| this.Credential, | |
| String.Format ("{0}/{1}", this.client.BaseUrl, UPLOAD), | |
| path, | |
| "uploaded_data", | |
| ContentTypeRegistry.ContentTypeOf (path), | |
| parameters); | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment