internal QueryOperationResponse <TElement> Execute <TElement>(DataServiceContext context, QueryComponents queryComponents) { QueryResult result = null; try { DataServiceRequest <TElement> serviceRequest = new DataServiceRequest <TElement>(queryComponents, this.Plan); result = serviceRequest.CreateResult(this, context, null, null); result.Execute(); return(result.ProcessResult <TElement>(context, this.Plan)); } catch (InvalidOperationException ex) { QueryOperationResponse operationResponse = result.GetResponse <TElement>(MaterializeAtom.EmptyResults); if (null != operationResponse) { if (context.IgnoreResourceNotFoundException) { DataServiceClientException cex = ex as DataServiceClientException; if (cex != null && cex.StatusCode == (int)HttpStatusCode.NotFound) { return((QueryOperationResponse <TElement>)operationResponse); } } operationResponse.Error = ex; throw new DataServiceQueryException(Strings.DataServiceException_GeneralError, ex, operationResponse); } throw; } }
/// <summary> /// Ends an asynchronous request to an Internet resource. /// </summary> /// <typeparam name="TElement">Element type of the result.</typeparam> /// <param name="source">Source object of async request.</param> /// <param name="context">The data service context.</param> /// <param name="method">async method name.</param> /// <param name="asyncResult">The asyncResult being ended.</param> /// <returns>The response - result of the request.</returns> internal static IEnumerable <TElement> EndExecute <TElement>(object source, DataServiceContext context, string method, IAsyncResult asyncResult) { QueryResult result = null; try { result = QueryResult.EndExecuteQuery <TElement>(source, method, asyncResult); return(result.ProcessResult <TElement>(result.ServiceRequest.Plan)); } catch (DataServiceQueryException ex) { Exception inEx = ex; while (inEx.InnerException != null) { inEx = inEx.InnerException; } DataServiceClientException serviceEx = inEx as DataServiceClientException; if (context.IgnoreResourceNotFoundException && serviceEx != null && serviceEx.StatusCode == (int)HttpStatusCode.NotFound) { QueryOperationResponse qor = new QueryOperationResponse <TElement>(ex.Response.HeaderCollection, ex.Response.Query, MaterializeAtom.EmptyResults); qor.StatusCode = (int)HttpStatusCode.NotFound; return((IEnumerable <TElement>)qor); } throw; } }
internal QueryOperationResponse <TElement> Execute <TElement>(DataServiceContext context, System.Data.Services.Client.QueryComponents queryComponents) { QueryResult result = null; QueryOperationResponse <TElement> response2; try { result = new DataServiceRequest <TElement>(queryComponents, this.Plan).CreateResult(this, context, null, null, "Execute"); result.ExecuteQuery(context); response2 = result.ProcessResult <TElement>(this.Plan); } catch (InvalidOperationException exception) { if (result != null) { QueryOperationResponse response = result.GetResponse <TElement>(MaterializeAtom.EmptyResults); if (response != null) { if (context.IgnoreResourceNotFoundException) { DataServiceClientException exception2 = exception as DataServiceClientException; if ((exception2 != null) && (exception2.StatusCode == 0x194)) { return((QueryOperationResponse <TElement>)response); } } response.Error = exception; throw new DataServiceQueryException(System.Data.Services.Client.Strings.DataServiceException_GeneralError, exception, response); } } throw; } return(response2); }
internal static IEnumerable <TElement> EndExecute <TElement>(object source, DataServiceContext context, string method, IAsyncResult asyncResult) { QueryResult result = null; try { result = QueryResult.EndExecuteQuery <TElement>(source, method, asyncResult); return(result.ProcessResult <TElement>(result.ServiceRequest.Plan)); } catch (DataServiceQueryException exception) { Exception innerException = exception; while (innerException.InnerException != null) { innerException = innerException.InnerException; } DataServiceClientException exception3 = innerException as DataServiceClientException; if ((!context.IgnoreResourceNotFoundException || (exception3 == null)) || (exception3.StatusCode != 0x194)) { throw; } QueryOperationResponse response = new QueryOperationResponse <TElement>(new Dictionary <string, string>(exception.Response.Headers), exception.Response.Query, MaterializeAtom.EmptyResults) { StatusCode = 0x194 }; return((IEnumerable <TElement>)response); } }
void Container_ReceivingResponse(object sender, ReceivingResponseEventArgs e) { if (e.ResponseMessage.StatusCode == (int)System.Net.HttpStatusCode.InternalServerError) { using (StreamReader reader = new StreamReader(e.ResponseMessage.GetStream())) { string contents = reader.ReadToEnd(); var ex = new DataServiceClientException(contents); if (this.Format.ODataFormat == ODataFormat.Atom) DataServiceExceptionAtomParser.Throw(ex); else if (this.Format.ODataFormat == ODataFormat.Json) DataServiceExceptionJsonParser.Throw(ex); else throw ex; } } else if (e.ResponseMessage.StatusCode == (int)System.Net.HttpStatusCode.Unauthorized) { var h = e.ResponseMessage.Headers.Where(kvp => kvp.Key == "WWW-Authenticate").Select(kvp => kvp.Value).FirstOrDefault(); } }
/// <summary> /// execute uri and materialize result /// </summary> /// <typeparam name="TElement">element type</typeparam> /// <param name="context">context</param> /// <param name="queryComponents">query components for request to execute</param> /// <returns>enumerable of results</returns> internal QueryOperationResponse <TElement> Execute <TElement>(DataServiceContext context, QueryComponents queryComponents) { QueryResult result = null; try { Uri requestUri = queryComponents.Uri; DataServiceRequest <TElement> serviceRequest = new DataServiceRequest <TElement>(requestUri, queryComponents, this.Plan); result = serviceRequest.CreateExecuteResult(this, context, null, null, Util.ExecuteMethodName); result.AllowDirectNetworkStreamReading = context.AllowDirectNetworkStreamReading; result.ExecuteQuery(); return(result.ProcessResult <TElement>(this.Plan)); } catch (InvalidOperationException ex) { if (result != null) { QueryOperationResponse operationResponse = result.GetResponse <TElement>(MaterializeAtom.EmptyResults); if (null != operationResponse) { if (context.IgnoreResourceNotFoundException) { DataServiceClientException cex = ex as DataServiceClientException; if (cex != null && cex.StatusCode == (int)HttpStatusCode.NotFound) { // don't throw return((QueryOperationResponse <TElement>)operationResponse); } } operationResponse.Error = ex; throw new DataServiceQueryException(Strings.DataServiceException_GeneralError, ex, operationResponse); } } throw; } }
private void HandleOperationException(InvalidOperationException e, HttpWebResponse response) { Func<Stream> getResponseStream = null; Descriptor descriptor = base.ChangedEntries[base.entryIndex]; Dictionary<string, string> headers = null; HttpStatusCode internalServerError = HttpStatusCode.InternalServerError; Version parsedResponseVersion = null; if (response != null) { headers = WebUtil.WrapResponseHeaders(response); base.HandleOperationResponseHeaders(response.StatusCode, headers); if (getResponseStream == null) { getResponseStream = () => WebUtil.GetResponseStream(response, (DataServiceContext) this.Source); } e = BaseSaveResult.HandleResponse(base.RequestInfo, response.StatusCode, response.Headers["DataServiceVersion"], getResponseStream, false, out parsedResponseVersion); internalServerError = response.StatusCode; } else { headers = new Dictionary<string, string>(StringComparer.Ordinal); headers.Add("Content-Type", "text/plain"); if (e.GetType() != typeof(DataServiceClientException)) { e = new DataServiceClientException(e.Message, e); } } this.cachedResponses.Add(new CachedResponse(descriptor, headers, internalServerError, parsedResponseVersion, null, e)); base.perRequest = null; this.CheckContinueOnError(); }
void ISafeSerializationData.CompleteDeserialization(object deserialized) { DataServiceClientException exception = (DataServiceClientException)deserialized; exception.state = this; }