Exemple #1
0
        private static GetUserPhotoResponse GetResultOrDefault(Func <object> serviceResponseFactory)
        {
            try
            {
                return((GetUserPhotoResponse)serviceResponseFactory());
            }
            catch (ServiceRequestException ex)
            {
                // 404 is a valid return code in the case of GetUserPhoto when the photo is
                // not found, so it is necessary to catch this exception here.
                WebException webException = ex.InnerException as WebException;
                if (webException != null)
                {
                    HttpWebResponse errorResponse = webException.Response as HttpWebResponse;
                    if (errorResponse != null && errorResponse.StatusCode == HttpStatusCode.NotFound)
                    {
                        return(GetUserPhotoRequest.GetNotFoundResponse());
                    }
                }

                throw;
            }
        }
        /// <summary>
        private static async Task <GetUserPhotoResponse> GetResultOrDefault(Func <Task <object> > serviceResponseFactory)
        {
            try
            {
                return((GetUserPhotoResponse) await serviceResponseFactory().ConfigureAwait(false));
            }
            catch (ServiceRequestException ex)
            {
                // 404 is a valid return code in the case of GetUserPhoto when the photo is
                // not found, so it is necessary to catch this exception here.
                EwsHttpClientException webException = ex.InnerException as EwsHttpClientException;
                if (webException != null)
                {
                    var errorResponse = webException.Response;
                    if (errorResponse != null && errorResponse.StatusCode == HttpStatusCode.NotFound)
                    {
                        return(GetUserPhotoRequest.GetNotFoundResponse());
                    }
                }

                throw;
            }
        }
Exemple #3
0
 /// <summary>
 /// Ends executing this async request.
 /// </summary>
 /// <param name="asyncResult">The async result</param>
 /// <returns>Service response collection.</returns>
 internal GetUserPhotoResponse EndExecute(IAsyncResult asyncResult)
 {
     return(GetUserPhotoRequest.GetResultOrDefault(() => this.EndInternalExecute(asyncResult)));
 }
Exemple #4
0
 /// <summary>
 /// Executes this request.
 /// </summary>
 /// <returns>Service response.</returns>
 internal GetUserPhotoResponse Execute()
 {
     return(GetUserPhotoRequest.GetResultOrDefault(this.InternalExecute));
 }
Exemple #5
0
 /// <summary>
 /// Executes this request.
 /// </summary>
 /// <returns>Service response.</returns>
 internal Task <GetUserPhotoResponse> Execute()
 {
     return(GetUserPhotoRequest.GetResultOrDefault(this.InternalExecuteAsync));
 }
 /// <summary>
 /// Executes this request.
 /// </summary>
 /// <returns>Service response.</returns>
 internal Task <GetUserPhotoResponse> Execute(CancellationToken token)
 {
     return(GetUserPhotoRequest.GetResultOrDefault(() => this.InternalExecuteAsync(token)));
 }