コード例 #1
0
 public static async Task <T> RunAsync <T>(Task <T> task, bool logNotFoundException = true)
 {
     try
     {
         await task;
         return(task.Result);
     }
     catch (Exception ex)
     {
         if (!logNotFoundException && ex is RestServiceRequestException)
         {
             RestServiceRequestException restEx = (RestServiceRequestException)ex;
             if (restEx.StatusCode == HttpStatusCode.NotFound)
             {
                 return(default(T));
             }
         }
         Logger.Log(ex);
     }
     return(default(T));
 }
コード例 #2
0
        public async Task <string> ProcessStringResponse(HttpResponseMessage response)
        {
            if (response.StatusCode == HttpStatusCode.OK || response.StatusCode == HttpStatusCode.Created)
            {
                string result = await response.Content.ReadAsStringAsync();

                if (this.OnSuccessResponseReceived != null)
                {
                    this.OnSuccessResponseReceived(this, result);
                }
                return(result);
            }
            else
            {
                RestServiceRequestException ex = new RestServiceRequestException(response);
                if (this.OnFailureResponseReceived != null)
                {
                    this.OnFailureResponseReceived(this, ex);
                }
                throw ex;
            }
        }
コード例 #3
0
 private void RestAPIServices_OnFailureResponseReceived(object sender, RestServiceRequestException e)
 {
     Util.Logger.Log(string.Format("Rest API Failure Response: {0}", e.ToString()));
 }