Example #1
0
        private static bool ShouldIgnoreNode(XmlReader reader)
        {
            Debug.Assert(reader != null, "reader != null");

            switch (reader.NodeType)
            {
            case XmlNodeType.CDATA:
            case XmlNodeType.EntityReference:
            case XmlNodeType.EndEntity:
                Error.ThrowInternalError(InternalError.UnexpectedXmlNodeTypeWhenReading);
                break;

            case XmlNodeType.Text:
            case XmlNodeType.SignificantWhitespace:
                Error.ThrowInternalError(InternalError.UnexpectedXmlNodeTypeWhenReading);
                break;

            case XmlNodeType.Element:
            case XmlNodeType.EndElement:
                return(false);

            default:
                break;
            }

            return(true);
        }
Example #2
0
 private static void CompleteCheck(QueryResult pereq, InternalError errorcode)
 {
     if ((null == pereq) || (pereq.IsCompletedInternally && !pereq.IsAborted))
     {
         Error.ThrowInternalError(errorcode);
     }
 }
Example #3
0
 protected static void EqualRefCheck(PerRequest actual, PerRequest expected, InternalError errorcode)
 {
     if (!object.ReferenceEquals(actual, expected))
     {
         Error.ThrowInternalError(errorcode);
     }
 }
Example #4
0
 protected virtual void CompleteCheck(PerRequest value, InternalError errorcode)
 {
     if ((value == null) || value.RequestCompleted)
     {
         Error.ThrowInternalError(errorcode);
     }
 }
Example #5
0
        /// <summary>
        /// Checks whether the current node on the specified <paramref name="reader"/>
        /// should be ignored.
        /// </summary>
        /// <param name="reader">Reader to check.</param>
        /// <returns>true if the node should be ignored; false if it should be processed.</returns>
        /// <remarks>
        /// This method will throw an exception on unexpected content (CDATA, entity references,
        /// text); therefore it should not be used if mixed content is allowed.
        /// </remarks>
        private static bool ShouldIgnoreNode(XmlReader reader)
        {
            Debug.Assert(reader != null, "reader != null");

            switch (reader.NodeType)
            {
            case XmlNodeType.CDATA:
            case XmlNodeType.EntityReference:
            case XmlNodeType.EndEntity:
                Error.ThrowInternalError(InternalError.UnexpectedXmlNodeTypeWhenReading);
                break;

            case XmlNodeType.Text:
            case XmlNodeType.SignificantWhitespace:
                // throw Error.InvalidOperation(Strings.Deserialize_MixedContent(currentType.ElementTypeName));
                Error.ThrowInternalError(InternalError.UnexpectedXmlNodeTypeWhenReading);
                break;

            case XmlNodeType.Element:
            case XmlNodeType.EndElement:
                return(false);

            default:
                break;
            }

            return(true);
        }
Example #6
0
 internal static T NullCheck <T>(T value, InternalError errorcode) where T : class
 {
     if (object.ReferenceEquals(value, null))
     {
         Error.ThrowInternalError(errorcode);
     }
     return(value);
 }
 /// <summary>verify non-null and not completed</summary>
 /// <param name="pereq">async result</param>
 /// <param name="errorcode">error code if null or completed</param>
 private static void CompleteCheck(QueryResult pereq, InternalError errorcode)
 {
     if ((null == pereq) || (pereq.IsCompletedInternally && !pereq.IsAborted))
     {
         // if aborting, let the request throw its abort code
         Error.ThrowInternalError(errorcode);
     }
 }
Example #8
0
 /// <summary>verify non-null and not completed</summary>
 /// <param name="pereq">async result</param>
 /// <param name="errorcode">error code if null or completed</param>
 protected override void CompleteCheck(PerRequest pereq, InternalError errorcode)
 {
     if ((null == pereq) || ((pereq.RequestCompleted || this.IsCompletedInternally) && !(this.IsAborted || pereq.RequestAborted)))
     {
         // if aborting, let the request throw its abort code
         Error.ThrowInternalError(errorcode);
     }
 }
Example #9
0
        protected virtual void FinishCurrentChange(PerRequest pereq)
        {
            if (!pereq.RequestCompleted)
            {
                Error.ThrowInternalError(InternalError.SaveNextChangeIncomplete);
            }
            PerRequest perRequest = this.perRequest;

            if (perRequest != null)
            {
                EqualRefCheck(perRequest, pereq, InternalError.InvalidSaveNextChange);
            }
        }
Example #10
0
        protected void AsyncEndGetRequestStream(IAsyncResult asyncResult)
        {
            AsyncStateBag      asyncState = asyncResult.AsyncState as AsyncStateBag;
            PerRequest         request    = (asyncState == null) ? null : asyncState.PerRequest;
            DataServiceContext context    = (asyncState == null) ? null : asyncState.Context;

            try
            {
                this.CompleteCheck(request, InternalError.InvalidEndGetRequestCompleted);
                request.SetRequestCompletedSynchronously(asyncResult.CompletedSynchronously);
                EqualRefCheck(this.perRequest, request, InternalError.InvalidEndGetRequestStream);
                Stream stream = Util.NullCheck <Stream>(WebUtil.EndGetRequestStream(Util.NullCheck <ODataRequestMessageWrapper>(request.Request, InternalError.InvalidEndGetRequestStreamRequest), asyncResult, context), InternalError.InvalidEndGetRequestStreamStream);
                request.RequestStream = stream;
                ContentStream requestContentStream = request.RequestContentStream;
                Util.NullCheck <ContentStream>(requestContentStream, InternalError.InvalidEndGetRequestStreamContent);
                Util.NullCheck <Stream>(requestContentStream.Stream, InternalError.InvalidEndGetRequestStreamContent);
                if (requestContentStream.IsKnownMemoryStream)
                {
                    MemoryStream stream3  = requestContentStream.Stream as MemoryStream;
                    byte[]       buffer   = stream3.GetBuffer();
                    int          position = (int)stream3.Position;
                    int          num2     = ((int)stream3.Length) - position;
                    if ((buffer == null) || (num2 == 0))
                    {
                        Error.ThrowInternalError(InternalError.InvalidEndGetRequestStreamContentLength);
                    }
                }
                request.RequestContentBufferValidLength = -1;
                Stream stream1 = requestContentStream.Stream;
                asyncResult = InvokeAsync(new AsyncAction(stream1.BeginRead), request.RequestContentBuffer, 0, request.RequestContentBuffer.Length, new AsyncCallback(this.AsyncRequestContentEndRead), asyncState);
                request.SetRequestCompletedSynchronously(asyncResult.CompletedSynchronously);
            }
            catch (Exception exception)
            {
                if (this.HandleFailure(request, exception))
                {
                    throw;
                }
            }
            finally
            {
                this.HandleCompleted(request);
            }
        }
        private static void AsyncEndGetRequestStream(IAsyncResult asyncResult)
        {
            QueryAsyncResult state = asyncResult.AsyncState as QueryAsyncResult;

            try
            {
                int step = CompleteCheck(state, InternalError.InvalidEndGetRequestCompleted);
                state.CompletedSynchronously &= asyncResult.CompletedSynchronously; // BeginGetRequestStream

                HttpWebRequest httpWebRequest = Util.NullCheck(state.Request, InternalError.InvalidEndGetRequestStreamRequest);

                Stream stream = Util.NullCheck(httpWebRequest.EndGetRequestStream(asyncResult), InternalError.InvalidEndGetRequestStreamStream);
                state.requestStream = stream;

                MemoryStream memoryStream = Util.NullCheck(state.requestStreamContent, InternalError.InvalidEndGetRequestStreamContent);
                byte[]       buffer       = memoryStream.GetBuffer();
                int          bufferOffset = checked ((int)memoryStream.Position);
                int          bufferLength = checked ((int)memoryStream.Length) - bufferOffset;
                if ((null == buffer) || (0 == bufferLength))
                {
                    Error.ThrowInternalError(InternalError.InvalidEndGetRequestStreamContentLength);
                }

                // the following is useful in the debugging Immediate Window
                // string x = System.Text.Encoding.UTF8.GetString(buffer, bufferOffset, bufferLength);
                asyncResult = stream.BeginWrite(buffer, bufferOffset, bufferLength, QueryAsyncResult.AsyncEndWrite, state);

                bool reallyCompletedSynchronously = asyncResult.CompletedSynchronously && (step < state.asyncCompleteStep);
                state.CompletedSynchronously &= reallyCompletedSynchronously; // BeginWrite
            }
            catch (Exception e)
            {
                if (state.HandleFailure(e))
                {
                    throw;
                }
            }
            finally
            {
                state.HandleCompleted();
            }
        }
Example #12
0
 protected override void HandleCompleted(BaseAsyncResult.PerRequest pereq)
 {
     Error.ThrowInternalError(InternalError.InvalidHandleCompleted);
 }
Example #13
0
 /// <summary>Set the AsyncWait and invoke the user callback.</summary>
 /// <param name="pereq">the request object</param>
 /// <remarks>This method is not implemented for this class.</remarks>
 protected override void HandleCompleted(BaseAsyncResult.PerRequest pereq)
 {
     Debug.Assert(false, "This method should never be called from GetReadStreamResult.");
     Error.ThrowInternalError(InternalError.InvalidHandleCompleted);
 }