Exemplo n.º 1
0
        /// <summary>
        /// Synchronizely get the query set count from the server by executing the $count=value query
        /// </summary>
        /// <param name="context">The context</param>
        /// <returns>The server side count of the query set</returns>
        internal long GetQuerySetCount(DataServiceContext context)
        {
            Debug.Assert(null != context, "context is null");
            Version requestVersion = this.QueryComponents(context.Model).Version;

            if (requestVersion == null || requestVersion.Major < 2)
            {
                // minimum DSV for $count is V2.
                requestVersion = Util.DataServiceVersion2;
            }

            QueryResult               response       = null;
            QueryComponents           qc             = this.QueryComponents(context.Model);
            Uri                       requestUri     = qc.Uri;
            DataServiceRequest <long> serviceRequest = new DataServiceRequest <long>(requestUri, qc, null);

            HeaderCollection headers = new HeaderCollection();

            // Validate and set the request DSV header
            headers.SetRequestVersion(requestVersion, context.MaxProtocolVersionAsVersion);
            context.Format.SetRequestAcceptHeaderForCount(headers);

            string httpMethod = XmlConstants.HttpMethodGet;
            ODataRequestMessageWrapper request = context.CreateODataRequestMessage(
                context.CreateRequestArgsAndFireBuildingRequest(httpMethod, requestUri, headers, context.HttpStack, null /*descriptor*/),
                new string[] { XmlConstants.HttpRequestAccept } /*headersToReset*/,
                null /*descriptor*/);

            response = new QueryResult(this, Util.ExecuteMethodName, serviceRequest, request, new RequestInfo(context), null, null);
            response.AllowDirectNetworkStreamReading = context.AllowDirectNetworkStreamReading;

            IODataResponseMessage responseMessage = null;

            try
            {
                responseMessage = response.ExecuteQuery();
                if (HttpStatusCode.NoContent != response.StatusCode)
                {
                    StreamReader sr = new StreamReader(response.GetResponseStream());
                    long         r  = -1;

                    try
                    {
                        r = XmlConvert.ToInt64(sr.ReadToEnd());
                    }
                    finally
                    {
                        sr.Close();
                    }

                    return(r);
                }
                else
                {
                    throw new DataServiceQueryException(Strings.DataServiceRequest_FailGetCount, response.Failure);
                }
            }
            catch (InvalidOperationException ex)
            {
                QueryOperationResponse operationResponse = null;
                operationResponse = response.GetResponse <long>(MaterializeAtom.EmptyResults);
                if (null != operationResponse)
                {
                    operationResponse.Error = ex;
                    throw new DataServiceQueryException(Strings.DataServiceException_GeneralError, ex, operationResponse);
                }

                throw;
            }
            finally
            {
                WebUtil.DisposeMessage(responseMessage);
            }
        }
Exemplo n.º 2
0
 public DataServiceQueryException(string message, Exception innerException, QueryOperationResponse response) : base(message, innerException)
 {
     this.response = response;
 }
Exemplo n.º 3
0
 /// <summary>Constructor</summary>
 /// <param name="queryOperationResponse">The response for the Load operation. null when the operation didn't succeed.</param>
 /// <param name="error"><see cref="Exception"/> which represents the error if the Load operation failed. null if the operation
 /// didn't fail.</param>
 /// <remarks>This constructor doesn't allow creation of canceled event args.</remarks>
 internal LoadCompletedEventArgs(QueryOperationResponse queryOperationResponse, Exception error)
     : this(queryOperationResponse, error, false)
 {
 }
Exemplo n.º 4
0
        private IEnumerable <OperationResponse> HandleBatchResponse(ODataBatchReader batchReader)
        {
            if (this.batchMessageReader == null)
            {
                goto Label_056D;
            }
            bool iteratorVariable0 = false;
            bool iteratorVariable1 = false;
            int  index             = 0;
            int  iteratorVariable3 = 0;

            this.entryIndex = 0;
            Label_PostSwitchInIterator :;
            while (batchReader.Read())
            {
                Exception iteratorVariable4;
                switch (batchReader.State)
                {
                case ODataBatchReaderState.Operation:
                {
                    iteratorVariable4 = this.ProcessCurrentOperationResponse(batchReader);
                    if (iteratorVariable1)
                    {
                        break;
                    }
                    QueryOperationResponse iteratorVariable5 = null;
                    try
                    {
                        if (iteratorVariable4 == null)
                        {
                            DataServiceRequest query   = this.Queries[index];
                            MaterializeAtom    results = DataServiceRequest.Materialize(this.RequestInfo.GetDeserializationInfo(null), query.QueryComponents(this.RequestInfo.MaxProtocolVersion), null, this.currentOperationResponse.GetHeader("Content-Type"), this.currentOperationResponse.CreateResponseMessage(), query.PayloadKind);
                            iteratorVariable5 = QueryOperationResponse.GetInstance(query.ElementType, this.currentOperationResponse.Headers, query, results);
                        }
                    }
                    catch (ArgumentException exception)
                    {
                        iteratorVariable4 = exception;
                    }
                    catch (FormatException exception2)
                    {
                        iteratorVariable4 = exception2;
                    }
                    catch (InvalidOperationException exception3)
                    {
                        iteratorVariable4 = exception3;
                    }
                    if (iteratorVariable5 == null)
                    {
                        if (this.Queries == null)
                        {
                            throw iteratorVariable4;
                        }
                        DataServiceRequest request2 = this.Queries[index];
                        if (this.RequestInfo.IgnoreResourceNotFoundException && (this.currentOperationResponse.StatusCode == HttpStatusCode.NotFound))
                        {
                            iteratorVariable5 = QueryOperationResponse.GetInstance(request2.ElementType, this.currentOperationResponse.Headers, request2, MaterializeAtom.EmptyResults);
                        }
                        else
                        {
                            iteratorVariable5       = QueryOperationResponse.GetInstance(request2.ElementType, this.currentOperationResponse.Headers, request2, MaterializeAtom.EmptyResults);
                            iteratorVariable5.Error = iteratorVariable4;
                        }
                    }
                    iteratorVariable5.StatusCode = (int)this.currentOperationResponse.StatusCode;
                    index++;
                    yield return(iteratorVariable5);

                    goto Label_PostSwitchInIterator;
                }

                case ODataBatchReaderState.ChangesetStart:
                {
                    if ((this.IsBatch && iteratorVariable0) || (iteratorVariable3 != 0))
                    {
                        System.Data.Services.Client.Error.ThrowBatchUnexpectedContent(InternalError.UnexpectedBeginChangeSet);
                    }
                    iteratorVariable1 = true;
                    continue;
                }

                case ODataBatchReaderState.ChangesetEnd:
                {
                    iteratorVariable0 = true;
                    iteratorVariable3 = 0;
                    iteratorVariable1 = false;
                    continue;
                }

                default:
                    goto Label_0491;
                }
                this.entryIndex = this.ValidateContentID(this.currentOperationResponse.Headers);
                try
                {
                    Descriptor descriptor = this.ChangedEntries[this.entryIndex];
                    iteratorVariable3 += this.SaveResultProcessed(descriptor);
                    if (iteratorVariable4 != null)
                    {
                        throw iteratorVariable4;
                    }
                    this.HandleOperationResponseHeaders(this.currentOperationResponse.StatusCode, this.currentOperationResponse.Headers);
                    this.HandleOperationResponse(descriptor, this.currentOperationResponse.Headers);
                }
                catch (Exception exception4)
                {
                    this.ChangedEntries[this.entryIndex].SaveError = exception4;
                    iteratorVariable4 = exception4;
                    if (!CommonUtil.IsCatchableExceptionType(exception4))
                    {
                        throw;
                    }
                }
                ChangeOperationResponse iteratorVariable6 = new ChangeOperationResponse(this.currentOperationResponse.Headers, this.ChangedEntries[this.entryIndex])
                {
                    StatusCode = (int)this.currentOperationResponse.StatusCode
                };
                if (iteratorVariable4 != null)
                {
                    iteratorVariable6.Error = iteratorVariable4;
                }
                iteratorVariable3++;
                this.entryIndex++;
                yield return(iteratorVariable6);

                goto Label_PostSwitchInIterator;
Label_0491:
                System.Data.Services.Client.Error.ThrowBatchExpectedResponse(InternalError.UnexpectedBatchState);
            }
            if (((this.Queries == null) && ((!iteratorVariable0 || (0 < index)) || (this.ChangedEntries.Any <Descriptor>(o => (o.ContentGeneratedForSave && (o.SaveResultWasProcessed == 0))) && (!this.IsBatch || (this.ChangedEntries.FirstOrDefault <Descriptor>(o => (o.SaveError != null)) == null))))) || ((this.Queries != null) && (index != this.Queries.Length)))
            {
                throw System.Data.Services.Client.Error.InvalidOperation(System.Data.Services.Client.Strings.Batch_IncompleteResponseCount);
            }
Label_056D:
            yield break;
        }
 internal LoadCompletedEventArgs(QueryOperationResponse queryOperationResponse, Exception error)
     : base(error, false, null)
 {
     this.queryOperationResponse = queryOperationResponse;
 }