internal IAsyncResult BeginSend(System.Uri requestUri, WebClientAsyncResult asyncResult, bool callWriteAsyncRequest)
 {
     if (readResponseAsyncCallback == null)
     {
         lock (InternalSyncObject)
         {
             if (readResponseAsyncCallback == null)
             {
                 getRequestStreamAsyncCallback = new AsyncCallback(WebClientProtocol.GetRequestStreamAsyncCallback);
                 getResponseAsyncCallback = new AsyncCallback(WebClientProtocol.GetResponseAsyncCallback);
                 readResponseAsyncCallback = new AsyncCallback(WebClientProtocol.ReadResponseAsyncCallback);
             }
         }
     }
     WebRequest webRequest = this.GetWebRequest(requestUri);
     asyncResult.Request = webRequest;
     this.InitializeAsyncRequest(webRequest, asyncResult.InternalAsyncState);
     if (callWriteAsyncRequest)
     {
         webRequest.BeginGetRequestStream(getRequestStreamAsyncCallback, asyncResult);
     }
     else
     {
         webRequest.BeginGetResponse(getResponseAsyncCallback, asyncResult);
     }
     if (!asyncResult.IsCompleted)
     {
         asyncResult.CombineCompletedSynchronously(false);
     }
     return asyncResult;
 }
Esempio n. 2
0
        protected void CancelAsync(object userState)
        {
            WebClientAsyncResult result = (WebClientAsyncResult)mappings [userState];

            if (result == null)
            {
                return;
            }

            mappings.Remove(userState);
            result.Abort();
        }
Esempio n. 3
0
        /// <include file='doc\ClientProtocol.uex' path='docs/doc[@for="ClientProtocol.CancelInvokeAsync"]/*' />
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        protected void CancelAsync(object userState)
        {
            if (userState == null)
            {
                userState = NullToken;
            }
            WebClientAsyncResult result = OperationCompleted(userState, new object[] { null }, null, true);

            if (result != null)
            {
                result.Abort();
            }
        }
        /// <include file='doc\HttpClientProtocol.uex' path='docs/doc[@for="HttpSimpleClientProtocol.InvokeAsync1"]/*' />
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        protected void InvokeAsync(string methodName, string requestUrl, object[] parameters, SendOrPostCallback callback, object userState)
        {
            if (userState == null)
            {
                userState = NullToken;
            }
            AsyncOperation       asyncOp     = AsyncOperationManager.CreateOperation(new UserToken(callback, userState));
            WebClientAsyncResult asyncResult = new WebClientAsyncResult(this, null, null, new AsyncCallback(InvokeAsyncCallback), asyncOp);

            try {
                AsyncInvokes.Add(userState, asyncResult);
            }
            catch (Exception e) {
                if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException)
                {
                    throw;
                }
                if (Tracing.On)
                {
                    Tracing.ExceptionCatch(TraceEventType.Error, this, "InvokeAsync", e);
                }
                Exception exception = new ArgumentException(Res.GetString(Res.AsyncDuplicateUserState), e);
                InvokeCompletedEventArgs eventArgs = new InvokeCompletedEventArgs(new object[] { null }, exception, false, userState);
                asyncOp.PostOperationCompleted(callback, eventArgs);
                return;
            }
            try {
                HttpClientMethod    method      = GetClientMethod(methodName);
                MimeParameterWriter paramWriter = GetParameterWriter(method);
                Uri requestUri = new Uri(requestUrl);
                if (paramWriter != null)
                {
                    paramWriter.RequestEncoding = RequestEncoding;
                    requestUrl = paramWriter.GetRequestUrl(requestUri.AbsoluteUri, parameters);
                    requestUri = new Uri(requestUrl, true);
                }
                asyncResult.InternalAsyncState = new InvokeAsyncState(method, paramWriter, parameters);
                BeginSend(requestUri, asyncResult, paramWriter.UsesWriteRequest);
            }
            catch (Exception e) {
                if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException)
                {
                    throw;
                }
                if (Tracing.On)
                {
                    Tracing.ExceptionCatch(TraceEventType.Error, this, "InvokeAsync", e);
                }
                OperationCompleted(userState, new object[] { null }, e, false);
            }
        }
Esempio n. 5
0
        protected void InvokeAsync(string methodName, object[] parameters, SendOrPostCallback callback, object userState)
        {
            if (userState == null)
            {
                userState = this.NullToken;
            }
            SoapHttpClientProtocol.InvokeAsyncState invokeAsyncState = new SoapHttpClientProtocol.InvokeAsyncState(methodName, parameters);
            AsyncOperation       operation   = AsyncOperationManager.CreateOperation((object)new UserToken(callback, userState));
            WebClientAsyncResult asyncResult = new WebClientAsyncResult((WebClientProtocol)this, (object)invokeAsyncState, (WebRequest)null, new AsyncCallback(this.InvokeAsyncCallback), (object)operation);

            try
            {
                this.AsyncInvokes.Add(userState, (object)asyncResult);
            }
            catch (Exception ex)
            {
                if (ex is ThreadAbortException || ex is StackOverflowException || ex is OutOfMemoryException)
                {
                    throw;
                }
                else
                {
                    if (Tracing.On)
                    {
                        Tracing.ExceptionCatch(TraceEventType.Warning, (object)this, "InvokeAsync", ex);
                    }
                    InvokeCompletedEventArgs completedEventArgs = new InvokeCompletedEventArgs(new object[1], (Exception) new ArgumentException(System.Web.Services.Res.GetString("AsyncDuplicateUserState"), ex), false, userState);
                    operation.PostOperationCompleted(callback, (object)completedEventArgs);
                    return;
                }
            }
            try
            {
                this.BeginSend(this.Uri, asyncResult, true);
            }
            catch (Exception ex)
            {
                if (ex is ThreadAbortException || ex is StackOverflowException || ex is OutOfMemoryException)
                {
                    throw;
                }
                else
                {
                    if (Tracing.On)
                    {
                        Tracing.ExceptionCatch(TraceEventType.Warning, (object)this, "InvokeAsync", ex);
                    }
                    this.OperationCompleted(userState, new object[1], ex, false);
                }
            }
        }
Esempio n. 6
0
        internal WebClientAsyncResult OperationCompleted(object userState, object[] parameters, Exception e, bool canceled)
        {
            WebClientAsyncResult result = (WebClientAsyncResult)base.AsyncInvokes[userState];

            if (result != null)
            {
                AsyncOperation           asyncState        = (AsyncOperation)result.AsyncState;
                UserToken                userSuppliedState = (UserToken)asyncState.UserSuppliedState;
                InvokeCompletedEventArgs arg = new InvokeCompletedEventArgs(parameters, e, canceled, userState);
                base.AsyncInvokes.Remove(userState);
                asyncState.PostOperationCompleted(userSuppliedState.Callback, arg);
            }
            return(result);
        }
Esempio n. 7
0
        protected void CancelAsync(object userState)
        {
            if (userState == null)
            {
                userState = base.NullToken;
            }
            object[]             parameters = new object[1];
            WebClientAsyncResult result     = this.OperationCompleted(userState, parameters, null, true);

            if (result != null)
            {
                result.Abort();
            }
        }
Esempio n. 8
0
        private void InvokeAsyncCallback(IAsyncResult result)
        {
            object[]             parameters  = null;
            Exception            e           = null;
            WebClientAsyncResult asyncResult = (WebClientAsyncResult)result;

            if (asyncResult.Request != null)
            {
                object internalAsyncState = null;
                Stream responseStream     = null;
                try
                {
                    WebResponse      response = base.EndSend(asyncResult, ref internalAsyncState, ref responseStream);
                    InvokeAsyncState state    = (InvokeAsyncState)internalAsyncState;
                    parameters = this.ReadResponse(state.Message, response, responseStream, true);
                }
                catch (XmlException exception2)
                {
                    if (Tracing.On)
                    {
                        Tracing.ExceptionCatch(TraceEventType.Warning, this, "InvokeAsyncCallback", exception2);
                    }
                    e = new InvalidOperationException(System.Web.Services.Res.GetString("WebResponseBadXml"), exception2);
                }
                catch (Exception exception3)
                {
                    if (((exception3 is ThreadAbortException) || (exception3 is StackOverflowException)) || (exception3 is OutOfMemoryException))
                    {
                        throw;
                    }
                    if (Tracing.On)
                    {
                        Tracing.ExceptionCatch(TraceEventType.Warning, this, "InvokeAsyncCallback", exception3);
                    }
                    e = exception3;
                }
                finally
                {
                    if (responseStream != null)
                    {
                        responseStream.Close();
                    }
                }
            }
            AsyncOperation asyncState        = (AsyncOperation)result.AsyncState;
            UserToken      userSuppliedState = (UserToken)asyncState.UserSuppliedState;

            base.OperationCompleted(userSuppliedState.UserState, parameters, e, false);
        }
 static private void ReadAsyncResponse(WebClientAsyncResult client)
 {
     if (client.Response.ContentLength == 0)
     {
         client.Complete();
         return;
     }
     try {
         client.ResponseStream = client.Response.GetResponseStream();
         ReadAsyncResponseStream(client);
     }
     catch (Exception e) {
         ProcessAsyncException(client, e);
     }
 }
 protected IAsyncResult BeginInvoke(string methodName, string requestUrl, object[] parameters, AsyncCallback callback, object asyncState)
 {
     HttpClientMethod clientMethod = this.GetClientMethod(methodName);
     MimeParameterWriter parameterWriter = this.GetParameterWriter(clientMethod);
     Uri requestUri = new Uri(requestUrl);
     if (parameterWriter != null)
     {
         parameterWriter.RequestEncoding = base.RequestEncoding;
         requestUrl = parameterWriter.GetRequestUrl(requestUri.AbsoluteUri, parameters);
         requestUri = new Uri(requestUrl, true);
     }
     InvokeAsyncState internalAsyncState = new InvokeAsyncState(clientMethod, parameterWriter, parameters);
     WebClientAsyncResult asyncResult = new WebClientAsyncResult(this, internalAsyncState, null, callback, asyncState);
     return base.BeginSend(requestUri, asyncResult, parameterWriter.UsesWriteRequest);
 }
Esempio n. 11
0
        internal WebClientAsyncResult OperationCompleted(object userState, object[] parameters, Exception e, bool canceled)
        {
            Debug.Assert(userState != null, "We should not call OperationCompleted with null user token.");
            WebClientAsyncResult result = (WebClientAsyncResult)AsyncInvokes[userState];

            if (result != null)
            {
                AsyncOperation           asyncOp   = (AsyncOperation)result.AsyncState;
                UserToken                token     = (UserToken)asyncOp.UserSuppliedState;
                InvokeCompletedEventArgs eventArgs = new InvokeCompletedEventArgs(parameters, e, canceled, userState);
                AsyncInvokes.Remove(userState);
                asyncOp.PostOperationCompleted(token.Callback, eventArgs);
            }
            return(result);
        }
Esempio n. 12
0
        private void InvokeAsyncCallback(IAsyncResult result)
        {
            object[]             parameters        = (object[])null;
            Exception            e                 = (Exception)null;
            WebClientAsyncResult clientAsyncResult = (WebClientAsyncResult)result;

            if (clientAsyncResult.Request != null)
            {
                object internalAsyncState = (object)null;
                Stream responseStream     = (Stream)null;
                try
                {
                    WebResponse response = this.EndSend((IAsyncResult)clientAsyncResult, ref internalAsyncState, ref responseStream);
                    parameters = this.ReadResponse(((SoapHttpClientProtocol.InvokeAsyncState)internalAsyncState).Message, response, responseStream, true);
                }
                catch (XmlException ex)
                {
                    if (Tracing.On)
                    {
                        Tracing.ExceptionCatch(TraceEventType.Warning, (object)this, "InvokeAsyncCallback", (Exception)ex);
                    }
                    e = (Exception) new InvalidOperationException(System.Web.Services.Res.GetString("WebResponseBadXml"), (Exception)ex);
                }
                catch (Exception ex)
                {
                    if (ex is ThreadAbortException || ex is StackOverflowException || ex is OutOfMemoryException)
                    {
                        throw;
                    }
                    else
                    {
                        if (Tracing.On)
                        {
                            Tracing.ExceptionCatch(TraceEventType.Warning, (object)this, "InvokeAsyncCallback", ex);
                        }
                        e = ex;
                    }
                }
                finally
                {
                    if (responseStream != null)
                    {
                        responseStream.Close();
                    }
                }
            }
            this.OperationCompleted(((UserToken)((AsyncOperation)result.AsyncState).UserSuppliedState).UserState, parameters, e, false);
        }
Esempio n. 13
0
        protected void InvokeAsync(string methodName, object[] parameters, SendOrPostCallback callback, object userState)
        {
            if (userState == null)
            {
                userState = base.NullToken;
            }
            InvokeAsyncState     internalAsyncState = new InvokeAsyncState(methodName, parameters);
            AsyncOperation       userAsyncState     = AsyncOperationManager.CreateOperation(new UserToken(callback, userState));
            WebClientAsyncResult result             = new WebClientAsyncResult(this, internalAsyncState, null, new AsyncCallback(this.InvokeAsyncCallback), userAsyncState);

            try
            {
                base.AsyncInvokes.Add(userState, result);
            }
            catch (Exception exception)
            {
                if (((exception is ThreadAbortException) || (exception is StackOverflowException)) || (exception is OutOfMemoryException))
                {
                    throw;
                }
                if (Tracing.On)
                {
                    Tracing.ExceptionCatch(TraceEventType.Warning, this, "InvokeAsync", exception);
                }
                Exception exception2         = new ArgumentException(System.Web.Services.Res.GetString("AsyncDuplicateUserState"), exception);
                object[]  results            = new object[1];
                InvokeCompletedEventArgs arg = new InvokeCompletedEventArgs(results, exception2, false, userState);
                userAsyncState.PostOperationCompleted(callback, arg);
                return;
            }
            try
            {
                base.BeginSend(base.Uri, result, true);
            }
            catch (Exception exception3)
            {
                if (((exception3 is ThreadAbortException) || (exception3 is StackOverflowException)) || (exception3 is OutOfMemoryException))
                {
                    throw;
                }
                if (Tracing.On)
                {
                    Tracing.ExceptionCatch(TraceEventType.Warning, this, "InvokeAsync", exception3);
                }
                object[] objArray2 = new object[1];
                base.OperationCompleted(userState, objArray2, exception3, false);
            }
        }
        /// <include file='doc\HttpClientProtocol.uex' path='docs/doc[@for="HttpSimpleClientProtocol.BeginInvoke"]/*' />
        /// <devdoc>
        ///    <para>
        ///       Starts an asynchronous invocation of a method of a HTTP web service.
        ///    </para>
        /// </devdoc>
        protected IAsyncResult BeginInvoke(string methodName, string requestUrl, object[] parameters, AsyncCallback callback, object asyncState)
        {
            HttpClientMethod    method      = GetClientMethod(methodName);
            MimeParameterWriter paramWriter = GetParameterWriter(method);
            Uri requestUri = new Uri(requestUrl);

            if (paramWriter != null)
            {
                paramWriter.RequestEncoding = RequestEncoding;
                requestUrl = paramWriter.GetRequestUrl(requestUri.AbsoluteUri, parameters);
                requestUri = new Uri(requestUrl, true);
            }
            InvokeAsyncState     invokeState = new InvokeAsyncState(method, paramWriter, parameters);
            WebClientAsyncResult asyncResult = new WebClientAsyncResult(this, invokeState, null, callback, asyncState);

            return(BeginSend(requestUri, asyncResult, paramWriter.UsesWriteRequest));
        }
        private void InvokeAsyncCallback(IAsyncResult result)
        {
            object[]  parameters = null;
            Exception exception  = null;

            WebClientAsyncResult asyncResult = (WebClientAsyncResult)result;

            if (asyncResult.Request != null)
            {
                object o = null;
                Stream responseStream = null;
                try {
                    WebResponse      response    = EndSend(asyncResult, ref o, ref responseStream);
                    InvokeAsyncState invokeState = (InvokeAsyncState)o;
                    parameters = ReadResponse(invokeState.Message, response, responseStream, true);
                }
                catch (XmlException e) {
                    if (Tracing.On)
                    {
                        Tracing.ExceptionCatch(TraceEventType.Warning, this, "InvokeAsyncCallback", e);
                    }
                    exception = new InvalidOperationException(Res.GetString(Res.WebResponseBadXml), e);
                }
                catch (Exception e) {
                    if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException)
                    {
                        throw;
                    }
                    if (Tracing.On)
                    {
                        Tracing.ExceptionCatch(TraceEventType.Warning, this, "InvokeAsyncCallback", e);
                    }
                    exception = e;
                }
                finally {
                    if (responseStream != null)
                    {
                        responseStream.Close();
                    }
                }
            }
            AsyncOperation asyncOp = (AsyncOperation)result.AsyncState;
            UserToken      token   = (UserToken)asyncOp.UserSuppliedState;

            OperationCompleted(token.UserState, parameters, exception, false);
        }
Esempio n. 16
0
        static private void GetResponseAsyncCallback(IAsyncResult asyncResult)
        {
            WebClientAsyncResult client = (WebClientAsyncResult)asyncResult.AsyncState;

            client.CombineCompletedSynchronously(asyncResult.CompletedSynchronously);
            try {
                client.Response = client.ClientProtocol.GetWebResponse(client.Request, asyncResult);
            }
            catch (Exception e) {
                ProcessAsyncException(client, e);
                if (client.Response == null)
                {
                    return;
                }
            }

            ReadAsyncResponse(client);
        }
Esempio n. 17
0
        internal WebResponse EndSend(IAsyncResult asyncResult, ref object internalAsyncState, ref Stream responseStream)
        {
            if (asyncResult == null)
            {
                throw new ArgumentNullException(Res.GetString("WebNullAsyncResultInEnd"));
            }
            WebClientAsyncResult result = (WebClientAsyncResult)asyncResult;

            if (result.EndSendCalled)
            {
                throw new InvalidOperationException(Res.GetString("CanTCallTheEndMethodOfAnAsyncCallMoreThan"));
            }
            result.EndSendCalled = true;
            WebResponse response = result.WaitForResponse();

            internalAsyncState = result.InternalAsyncState;
            responseStream     = result.ResponseBufferedStream;
            return(response);
        }
Esempio n. 18
0
 static private void ReadAsyncResponse(WebClientAsyncResult client)
 {
     if (client.Response.ContentLength == 0)
     {
         client.Complete();
         return;
     }
     try {
         client.ResponseStream = client.Response.GetResponseStream();
         ReadAsyncResponseStream(client);
     }
     catch (Exception e) {
         if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException)
         {
             throw;
         }
         ProcessAsyncException(client, e, "ReadAsyncResponse");
     }
 }
Esempio n. 19
0
        static private void GetRequestStreamAsyncCallback(IAsyncResult asyncResult)
        {
            WebClientAsyncResult client = (WebClientAsyncResult)asyncResult.AsyncState;

            client.CombineCompletedSynchronously(asyncResult.CompletedSynchronously);
            try {
                Stream requestStream = client.Request.EndGetRequestStream(asyncResult);
                try {
                    client.ClientProtocol.AsyncBufferedSerialize(client.Request, requestStream, client.InternalAsyncState);
                }
                finally {
                    requestStream.Close();
                }
                client.Request.BeginGetResponse(getResponseAsyncCallback, client);
            }
            catch (Exception e) {
                ProcessAsyncException(client, e);
            }
        }
Esempio n. 20
0
        private static void ReadAsyncResponseStream(WebClientAsyncResult client)
        {
            IAsyncResult result;

            do
            {
                byte[] buffer        = client.Buffer;
                long   contentLength = client.Response.ContentLength;
                if (buffer == null)
                {
                    buffer = client.Buffer = new byte[(contentLength == -1L) ? ((int)0x400L) : ((int)contentLength)];
                }
                else if ((contentLength != -1L) && (contentLength > buffer.Length))
                {
                    buffer = client.Buffer = new byte[contentLength];
                }
                result = client.ResponseStream.BeginRead(buffer, 0, buffer.Length, readResponseAsyncCallback, client);
            }while (result.CompletedSynchronously && !ProcessAsyncResponseStreamResult(client, result));
        }
        /// <include file='doc\SoapClientProtocol.uex' path='docs/doc[@for="SoapClientProtocol.InvokeAsync1"]/*' />
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        protected void InvokeAsync(string methodName, object[] parameters, SendOrPostCallback callback, object userState)
        {
            if (userState == null)
            {
                userState = NullToken;
            }
            InvokeAsyncState     invokeState = new InvokeAsyncState(methodName, parameters);
            AsyncOperation       asyncOp     = AsyncOperationManager.CreateOperation(new UserToken(callback, userState));
            WebClientAsyncResult asyncResult = new WebClientAsyncResult(this, invokeState, null, new AsyncCallback(InvokeAsyncCallback), asyncOp);

            try {
                AsyncInvokes.Add(userState, asyncResult);
            }
            catch (Exception e) {
                if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException)
                {
                    throw;
                }
                if (Tracing.On)
                {
                    Tracing.ExceptionCatch(TraceEventType.Warning, this, "InvokeAsync", e);
                }
                Exception exception = new ArgumentException(Res.GetString(Res.AsyncDuplicateUserState), e);
                InvokeCompletedEventArgs eventArgs = new InvokeCompletedEventArgs(new object[] { null }, exception, false, userState);
                asyncOp.PostOperationCompleted(callback, eventArgs);
                return;
            }
            try {
                BeginSend(Uri, asyncResult, true);
            }
            catch (Exception e) {
                if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException)
                {
                    throw;
                }
                if (Tracing.On)
                {
                    Tracing.ExceptionCatch(TraceEventType.Warning, this, "InvokeAsync", e);
                }
                OperationCompleted(userState, new object[] { null }, e, false);
            }
        }
Esempio n. 22
0
        static private void ReadResponseAsyncCallback(IAsyncResult asyncResult)
        {
            WebClientAsyncResult client = (WebClientAsyncResult)asyncResult.AsyncState;

            client.CombineCompletedSynchronously(asyncResult.CompletedSynchronously);
            if (asyncResult.CompletedSynchronously)
            {
                return;
            }
            try {
                bool complete = ProcessAsyncResponseStreamResult(client, asyncResult);
                if (!complete)
                {
                    ReadAsyncResponseStream(client);
                }
            }
            catch (Exception e) {
                ProcessAsyncException(client, e);
            }
        }
Esempio n. 23
0
        private static void ProcessAsyncException(WebClientAsyncResult client, Exception e, string method)
        {
            if (Tracing.On)
            {
                Tracing.ExceptionCatch(TraceEventType.Error, typeof(WebClientProtocol), method, e);
            }
            WebException exception = e as WebException;

            if ((exception != null) && (exception.Response != null))
            {
                client.Response = exception.Response;
            }
            else
            {
                if (client.IsCompleted)
                {
                    throw new InvalidOperationException(Res.GetString("ThereWasAnErrorDuringAsyncProcessing"), e);
                }
                client.Complete(e);
            }
        }
Esempio n. 24
0
        static private void GetResponseAsyncCallback(IAsyncResult asyncResult)
        {
            WebClientAsyncResult client = (WebClientAsyncResult)asyncResult.AsyncState;

            client.CombineCompletedSynchronously(asyncResult.CompletedSynchronously);
            try {
                client.Response = client.ClientProtocol.GetWebResponse(client.Request, asyncResult);
            }
            catch (Exception e) {
                if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException)
                {
                    throw;
                }
                ProcessAsyncException(client, e, "GetResponseAsyncCallback");
                if (client.Response == null)
                {
                    return;
                }
            }

            ReadAsyncResponse(client);
        }
Esempio n. 25
0
        static private void GetRequestStreamAsyncCallback(IAsyncResult asyncResult)
        {
            WebClientAsyncResult client = (WebClientAsyncResult)asyncResult.AsyncState;

            client.CombineCompletedSynchronously(asyncResult.CompletedSynchronously);
            bool processingRequest = true;

            try {
                Stream requestStream = client.Request.EndGetRequestStream(asyncResult);
                processingRequest = false;
                try {
                    client.ClientProtocol.AsyncBufferedSerialize(client.Request, requestStream, client.InternalAsyncState);
                }
                finally {
                    requestStream.Close();
                }
                client.Request.BeginGetResponse(getResponseAsyncCallback, client);
            }
            catch (Exception e) {
                if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException)
                {
                    throw;
                }
                ProcessAsyncException(client, e, "GetRequestStreamAsyncCallback");
                if (processingRequest)
                {
                    WebException we = e as WebException;
                    if (we != null && we.Response != null)
                    {
                        // ProcessAsyncExcption doesn't call client.Complete() if there's a response,
                        // because it expects us to read the response. However, in certain cases
                        // (e.g. 502 errors), the exception thrown from Request can have a response.
                        // We don't process it, so call Complete() now.
                        client.Complete(e);
                    }
                }
            }
        }
Esempio n. 26
0
        private static void GetRequestStreamAsyncCallback(IAsyncResult asyncResult)
        {
            WebClientAsyncResult asyncState = (WebClientAsyncResult)asyncResult.AsyncState;

            asyncState.CombineCompletedSynchronously(asyncResult.CompletedSynchronously);
            bool flag = true;

            try
            {
                Stream requestStream = asyncState.Request.EndGetRequestStream(asyncResult);
                flag = false;
                try
                {
                    asyncState.ClientProtocol.AsyncBufferedSerialize(asyncState.Request, requestStream, asyncState.InternalAsyncState);
                }
                finally
                {
                    requestStream.Close();
                }
                asyncState.Request.BeginGetResponse(getResponseAsyncCallback, asyncState);
            }
            catch (Exception exception)
            {
                if (((exception is ThreadAbortException) || (exception is StackOverflowException)) || (exception is OutOfMemoryException))
                {
                    throw;
                }
                ProcessAsyncException(asyncState, exception, "GetRequestStreamAsyncCallback");
                if (flag)
                {
                    WebException exception2 = exception as WebException;
                    if ((exception2 != null) && (exception2.Response != null))
                    {
                        asyncState.Complete(exception);
                    }
                }
            }
        }
Esempio n. 27
0
        private static void GetResponseAsyncCallback(IAsyncResult asyncResult)
        {
            WebClientAsyncResult asyncState = (WebClientAsyncResult)asyncResult.AsyncState;

            asyncState.CombineCompletedSynchronously(asyncResult.CompletedSynchronously);
            try
            {
                asyncState.Response = asyncState.ClientProtocol.GetWebResponse(asyncState.Request, asyncResult);
            }
            catch (Exception exception)
            {
                if (((exception is ThreadAbortException) || (exception is StackOverflowException)) || (exception is OutOfMemoryException))
                {
                    throw;
                }
                ProcessAsyncException(asyncState, exception, "GetResponseAsyncCallback");
                if (asyncState.Response == null)
                {
                    return;
                }
            }
            ReadAsyncResponse(asyncState);
        }
Esempio n. 28
0
 private static void ReadAsyncResponse(WebClientAsyncResult client)
 {
     if (client.Response.ContentLength == 0L)
     {
         client.Complete();
     }
     else
     {
         try
         {
             client.ResponseStream = client.Response.GetResponseStream();
             ReadAsyncResponseStream(client);
         }
         catch (Exception exception)
         {
             if (((exception is ThreadAbortException) || (exception is StackOverflowException)) || (exception is OutOfMemoryException))
             {
                 throw;
             }
             ProcessAsyncException(client, exception, "ReadAsyncResponse");
         }
     }
 }
Esempio n. 29
0
        static private void ProcessAsyncException(WebClientAsyncResult client, Exception e)
        {
            WebException webException = e as WebException;

            if (webException != null && webException.Response != null)
            {
                client.Response = webException.Response;
            }
            else
            {
                // If we've already completed the call then the exception must have come
                // out of the user callback in which case we need to rethrow it here
                // so that it bubbles up to the AppDomain unhandled exception event.
                if (client.IsCompleted)
                {
                    throw new InvalidOperationException(Res.GetString(Res.ThereWasAnErrorDuringAsyncProcessing), e);
                }
                else
                {
                    client.Complete(e);
                }
            }
        }
Esempio n. 30
0
        static private void ReadAsyncResponseStream(WebClientAsyncResult client)
        {
            IAsyncResult asyncResult;

            do
            {
                byte[] buffer        = client.Buffer;
                long   contentLength = client.Response.ContentLength;
                if (buffer == null)
                {
                    buffer = client.Buffer = new byte[(contentLength == -1) ? 1024 : contentLength];
                }
                else if (contentLength != -1 && contentLength > buffer.Length)
                {
                    buffer = client.Buffer = new byte[contentLength];
                }
                asyncResult = client.ResponseStream.BeginRead(buffer, 0, buffer.Length, readResponseAsyncCallback, client);
                if (!asyncResult.CompletedSynchronously)
                {
                    return;
                }
            }while (!ProcessAsyncResponseStreamResult(client, asyncResult));
        }
Esempio n. 31
0
        static private void ReadResponseAsyncCallback(IAsyncResult asyncResult)
        {
            WebClientAsyncResult client = (WebClientAsyncResult)asyncResult.AsyncState;

            client.CombineCompletedSynchronously(asyncResult.CompletedSynchronously);
            if (asyncResult.CompletedSynchronously)
            {
                return;
            }
            try {
                bool complete = ProcessAsyncResponseStreamResult(client, asyncResult);
                if (!complete)
                {
                    ReadAsyncResponseStream(client);
                }
            }
            catch (Exception e) {
                if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException)
                {
                    throw;
                }
                ProcessAsyncException(client, e, "ReadResponseAsyncCallback");
            }
        }
Esempio n. 32
0
        private static void ReadResponseAsyncCallback(IAsyncResult asyncResult)
        {
            WebClientAsyncResult asyncState = (WebClientAsyncResult)asyncResult.AsyncState;

            asyncState.CombineCompletedSynchronously(asyncResult.CompletedSynchronously);
            if (!asyncResult.CompletedSynchronously)
            {
                try
                {
                    if (!ProcessAsyncResponseStreamResult(asyncState, asyncResult))
                    {
                        ReadAsyncResponseStream(asyncState);
                    }
                }
                catch (Exception exception)
                {
                    if (((exception is ThreadAbortException) || (exception is StackOverflowException)) || (exception is OutOfMemoryException))
                    {
                        throw;
                    }
                    ProcessAsyncException(asyncState, exception, "ReadResponseAsyncCallback");
                }
            }
        }
        private void OK_Click(object sender, System.EventArgs e)
        {
            if (pendingAsyncResult != null)
            {
                connectionCancelled = true;
                pendingAsyncResult.Abort();
                pendingAsyncResult = null;
            }

            if (GameEngine.Current == null || dataGrid1.DataSource == null ||
                this.BindingContext[dataGrid1.DataSource, "Table"] == null ||
                this.BindingContext[dataGrid1.DataSource, "Table"].Count == 0)
            {
                this.Hide();
                return;
            }

            DataRowView drv = (DataRowView)(this.BindingContext[dataGrid1.DataSource,"Table"].Current);
            SpeciesService service = new SpeciesService();
            service.Url = GameConfig.WebRoot + "/Species/AddSpecies.asmx";
            service.Timeout = 60000;

            byte [] speciesAssemblyBytes = null;

            try
            {
                if (reintroduce)
                {
                    speciesAssemblyBytes = service.ReintroduceSpecies((string)drv["Name"], Assembly.GetExecutingAssembly().GetName().Version.ToString(), GameEngine.Current.CurrentVector.State.StateGuid);
                }
                else
                {
                    speciesAssemblyBytes = service.GetSpeciesAssembly((string)drv["Name"], Assembly.GetExecutingAssembly().GetName().Version.ToString());
                }
            }
            catch(WebException)
            {
                MessageBox.Show(this, "The connection to the server timed out.  Please try again later.");
            }

            if (speciesAssemblyBytes == null)
            {
                MessageBox.Show("Error retrieving species from server.");
            }
            else
            {
                dataSet.Tables["Table"].Rows.Remove(drv.Row);

                // Save it to a temp file
                string tempFile = PrivateAssemblyCache.GetSafeTempFileName();
                using (Stream fileStream = File.OpenWrite(tempFile))
                {
                    fileStream.Write(speciesAssemblyBytes, 0, (int) speciesAssemblyBytes.Length);
                    fileStream.Close();
                }

                try
                {
                    GameEngine.Current.AddNewOrganism(tempFile, Point.Empty, reintroduce);
                    File.Delete(tempFile);
                }
                catch (TargetInvocationException exception)
                {
                    Exception innerException = exception;
                    while (innerException.InnerException != null)
                    {
                        innerException = innerException.InnerException;
                    }

                    MessageBox.Show(innerException.Message, "Error Loading Assembly", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }
                catch (GameEngineException exception)
                {
                    MessageBox.Show(exception.Message, "Error Loading Assembly", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }

                this.Hide();
            }
        }
 /// <include file='doc\SoapClientProtocol.uex' path='docs/doc[@for="SoapHttpClientProtocol.BeginInvoke"]/*' />
 /// <devdoc>
 ///    <para>
 ///       Starts an asynchronous invocation of a method of a SOAP web
 ///       service.
 ///    </para>
 /// </devdoc>
 protected IAsyncResult BeginInvoke(string methodName, object[] parameters, AsyncCallback callback, object asyncState) {
     InvokeAsyncState invokeState = new InvokeAsyncState(methodName, parameters);
     WebClientAsyncResult asyncResult = new WebClientAsyncResult(this, invokeState, null, callback, asyncState);
     return BeginSend(Uri, asyncResult, true);
 }
 /// <include file='doc\SoapClientProtocol.uex' path='docs/doc[@for="SoapClientProtocol.InvokeAsync1"]/*' />
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 protected void InvokeAsync(string methodName, object[] parameters, SendOrPostCallback callback, object userState) {
     if (userState == null)
         userState = NullToken;
     InvokeAsyncState invokeState = new InvokeAsyncState(methodName, parameters);
     AsyncOperation asyncOp = AsyncOperationManager.CreateOperation(new UserToken(callback, userState));
     WebClientAsyncResult asyncResult = new WebClientAsyncResult(this, invokeState, null, new AsyncCallback(InvokeAsyncCallback), asyncOp);
     try {
         AsyncInvokes.Add(userState, asyncResult);
     }
     catch (Exception e) {
         if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException)
             throw;
         if (Tracing.On) Tracing.ExceptionCatch(TraceEventType.Warning, this, "InvokeAsync", e);
         Exception exception = new ArgumentException(Res.GetString(Res.AsyncDuplicateUserState), e);
         InvokeCompletedEventArgs eventArgs = new InvokeCompletedEventArgs(new object[] { null }, exception, false, userState);
         asyncOp.PostOperationCompleted(callback, eventArgs);
         return;
     }
     try {
         BeginSend(Uri, asyncResult, true);
     } 
     catch (Exception e) {
         if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException)
             throw;
         if (Tracing.On) Tracing.ExceptionCatch(TraceEventType.Warning, this, "InvokeAsync", e);
         OperationCompleted(userState, new object[] { null }, e, false);
     }
 }
Esempio n. 36
0
		internal void RegisterMapping (object userState, WebClientAsyncResult result)
		{
		}
        private void ServerList_Click(object sender, EventArgs e)
        {
            this.retrievingData.Visible = true;

            service = new SpeciesService();
            service.Timeout = 10000;
            service.Url = GameConfig.WebRoot + "/Species/AddSpecies.asmx";

            try
            {
                if (reintroduce)
                {
                    pendingAsyncResult = (WebClientAsyncResult) service.BeginGetExtinctSpecies(Assembly.GetExecutingAssembly().GetName().Version.ToString(), "", new AsyncCallback(ExtinctSpeciesCallback), null);
                }
                else
                {
                    pendingAsyncResult = (WebClientAsyncResult) service.BeginGetAllSpecies(Assembly.GetExecutingAssembly().GetName().Version.ToString(), "", new AsyncCallback(AllSpeciesCallback), null);
                }
            }
            catch(WebException)
            {
                MessageBox.Show(this, "The connection to the server timed out.  Please try again later.");
            }
        }
Esempio n. 38
0
		void PasswordContinue_Clicked (object sender, EventArgs a)
		{
			notebook.Page = 5;
			SettingsHandler.Settings.Key = entry_password.Text;
			war = (WebClientAsyncResult) d.BeginGetSerial (entry_email.Text, entry_password.Text, new AsyncCallback (GetSerialDone), null); 
		}
Esempio n. 39
0
		void UploadDone (IAsyncResult iar)
		{
			try {
				int result = d.EndSubmit (iar);
				war = null;
				if (result < 0)
					state = State.SubmitError;
				else {
					state = State.Done;
					serial = result;
				}
			} catch (Exception e) {
				state = State.NetworkError;
				Console.WriteLine ("Upload: " + e);
			}
			if (tn != null)
				tn.WakeupMain ();
		}
Esempio n. 40
0
		void VersionChecked (IAsyncResult iar)
		{
			try {
				int ver = d.EndCheckVersion (iar);
				war = null;
				if (ver != 0)
					state = State.VersionError;
				else
					state = State.GetSerial;
			} catch (Exception e) {
				Console.WriteLine ("Version: " + e);
				state = State.NetworkError;
			}
			if (tn != null)
				tn.WakeupMain ();
		}
Esempio n. 41
0
		ConfigWizard (Browser browser)
		{
			tn = new ThreadNotify (new ReadyEvent (UpdateNotebookPage));
			Glade.XML ui = new Glade.XML (null, "browser.glade", "window_config_wizard", null);
			ui.Autoconnect (this);
			//notebook.ShowTabs = false;
			parent = browser;
			window_config_wizard.TransientFor = browser.window1;

			d = new Contributions ();
			if (Environment.GetEnvironmentVariable ("MONODOCTESTING") == null)
				d.Url = "http://www.go-mono.com/docs/server.asmx";
			notebook.Page = 8;
			
			war = (WebClientAsyncResult) d.BeginCheckVersion (1, new AsyncCallback (VersionChecked), null);
		}
        void ExtinctSpeciesCallback(IAsyncResult asyncResult)
        {
            try
            {
                pendingAsyncResult = null;
                dataSet = service.EndGetExtinctSpecies(asyncResult);
                cacheDate = DateTime.Now;
                retrievingData.Visible = false;
            }
            catch
            {
                if (!connectionCancelled)
                {
                    retrievingData.Text = "There was a problem getting species list from server.";
                }
                return;
            }

            this.Invalidate();
        }
        private void Cancel_Click(object sender, System.EventArgs e)
        {
            if (pendingAsyncResult != null)
            {
                connectionCancelled = true;
                pendingAsyncResult.Abort();
                pendingAsyncResult = null;
            }

            this.Hide();
        }
Esempio n. 44
0
		internal void RegisterMapping (object userState, WebClientAsyncResult result)
		{
			if (userState == null)
				userState = typeof (string);
			
			mappings [userState] = result;
		}
Esempio n. 45
0
		Upload (Browser browser)
		{
			tn = new ThreadNotify (new ReadyEvent (Update));
			Glade.XML ui = new Glade.XML (null, "browser.glade", "upload_dialog", null);
			ui.Autoconnect (this);
			d = new Contributions ();
			if (Environment.GetEnvironmentVariable ("MONODOCTESTING") == null)
				d.Url = "http://www.go-mono.com/docs/server.asmx";
			
			status.Text = "Checking Server version";
			war = (WebClientAsyncResult) d.BeginCheckVersion (1, new AsyncCallback (VersionChecked), null);
		}
Esempio n. 46
0
		void GetStatusDone (IAsyncResult iar)
		{
			try {
				status = d.EndGetStatus (iar);
				war = null;

				if (status == null)
					state = State.GetStatusError;
				else
					state = State.Done;

			} catch (Exception e) {
				state = State.NetworkError;
				Console.WriteLine ("Error getting status: " + e);
			}
			if (tn != null)
				tn.WakeupMain ();
		}	
Esempio n. 47
0
		void Update ()
		{
			Console.WriteLine ("In Update: " + state);
			switch (state){
			case State.NetworkError:
				status.Text = "A network error ocurred";
				cancel.Label = "Close";
				return;
			case State.VersionError:
				status.Text = "Server has a different version, upgrade your MonoDoc";
				cancel.Label = "Close";
				return;
			case State.GetSerial:
				war = (WebClientAsyncResult) d.BeginGetSerial (
					SettingsHandler.Settings.Email, SettingsHandler.Settings.Key,
					new AsyncCallback (GetSerialDone), null);
				return;
			case State.SerialError:
				status.Text = "Error obtaining serial number from server for this account";
				cancel.Label = "Close";
				return;
			case State.SubmitError:
				status.Text = "There was a problem with the documentation uploaded";
				cancel.Label = "Close";
				return;
				
			case State.PrepareUpload:
				GlobalChangeset cs = EditingUtils.GetChangesFrom (serial);
				if (cs == null){
					status.Text = "No new contributions";
					cancel.Label = "Close";
					return;
				}
				
				CopyXmlNodeWriter w = new CopyXmlNodeWriter ();
				GlobalChangeset.serializer.Serialize (w, cs);
				Console.WriteLine ("Uploading...");
				status.Text = String.Format ("Uploading {0} contributions", cs.Count);
				XmlDocument dd = (XmlDocument) w.Document;
				war = (WebClientAsyncResult) d.BeginSubmit (
					SettingsHandler.Settings.Email, SettingsHandler.Settings.Key,
					((XmlDocument) w.Document).DocumentElement,
					new AsyncCallback (UploadDone), null);
				return;
			case State.Done:
				status.Text = "All contributions uploaded";
				cancel.Label = "Close";
				SettingsHandler.Settings.SerialNumber = serial;
				SettingsHandler.Save ();
				return;
			}
		}
 protected void InvokeAsync(string methodName, string requestUrl, object[] parameters, SendOrPostCallback callback, object userState)
 {
     if (userState == null)
     {
         userState = base.NullToken;
     }
     AsyncOperation userAsyncState = AsyncOperationManager.CreateOperation(new UserToken(callback, userState));
     WebClientAsyncResult result = new WebClientAsyncResult(this, null, null, new AsyncCallback(this.InvokeAsyncCallback), userAsyncState);
     try
     {
         base.AsyncInvokes.Add(userState, result);
     }
     catch (Exception exception)
     {
         if (((exception is ThreadAbortException) || (exception is StackOverflowException)) || (exception is OutOfMemoryException))
         {
             throw;
         }
         if (Tracing.On)
         {
             Tracing.ExceptionCatch(TraceEventType.Error, this, "InvokeAsync", exception);
         }
         Exception exception2 = new ArgumentException(Res.GetString("AsyncDuplicateUserState"), exception);
         object[] results = new object[1];
         InvokeCompletedEventArgs arg = new InvokeCompletedEventArgs(results, exception2, false, userState);
         userAsyncState.PostOperationCompleted(callback, arg);
         return;
     }
     try
     {
         HttpClientMethod clientMethod = this.GetClientMethod(methodName);
         MimeParameterWriter parameterWriter = this.GetParameterWriter(clientMethod);
         Uri requestUri = new Uri(requestUrl);
         if (parameterWriter != null)
         {
             parameterWriter.RequestEncoding = base.RequestEncoding;
             requestUrl = parameterWriter.GetRequestUrl(requestUri.AbsoluteUri, parameters);
             requestUri = new Uri(requestUrl, true);
         }
         result.InternalAsyncState = new InvokeAsyncState(clientMethod, parameterWriter, parameters);
         base.BeginSend(requestUri, result, parameterWriter.UsesWriteRequest);
     }
     catch (Exception exception3)
     {
         if (((exception3 is ThreadAbortException) || (exception3 is StackOverflowException)) || (exception3 is OutOfMemoryException))
         {
             throw;
         }
         if (Tracing.On)
         {
             Tracing.ExceptionCatch(TraceEventType.Error, this, "InvokeAsync", exception3);
         }
         object[] objArray2 = new object[1];
         base.OperationCompleted(userState, objArray2, exception3, false);
     }
 }
Esempio n. 49
0
		void GetSerialDone (IAsyncResult iar)
		{
			try {
				serial = d.EndGetSerial (iar);
				war = null;
				if (serial < 0)
					state = State.SerialError;
				else
					state = State.PrepareUpload;
			} catch (Exception e) {
				Console.WriteLine ("Serial: " + e);
				state = State.NetworkError;
			}
			if (tn != null)
				tn.WakeupMain ();
		}
Esempio n. 50
0
        /// <summary>
        ///  Callback method used by the reporting service methods to enable
        ///  Async reporting.
        /// </summary>
        /// <param name="asyncResult">The results of the method.</param>
        private void ReportServiceCallback(IAsyncResult asyncResult)
        {
            try
            {
                var resultCode = _reportingService.EndReportPopulation(asyncResult);

                switch (resultCode)
                {
                    case ReturnCode.NodeTimedOut:
                        _timedOut = true;
                        break;
                    case ReturnCode.NodeCorrupted:
                        _nodeCorrupted = true;
                        break;
                    case ReturnCode.OrganismBlacklisted:
                        _organismBlacklisted = true;
                        break;
                    default:
                        if (resultCode != 0)
                        {
                        }
                        break;
                }

                if (_led != null)
                {
                    _led.LedState = LedStates.Idle;
                }
            }
            catch (SoapException e)
            {
                ErrorLog.LogHandledException(e);
                if (_led != null)
                {
                    _led.LedState = LedStates.Failed;
                }
            }
            catch (Exception e)
            {
                ErrorLog.LogHandledException(e);

                if (_led != null)
                {
                    _led.LedState = LedStates.Failed;
                }
            }
            finally
            {
                _pendingAsyncResult = null;
            }
        }
Esempio n. 51
0
		void Cancel_Clicked (object sender, EventArgs a)
		{
			if (war != null)
				war.Abort ();
			war = null;
			state = State.Done;

			upload_dialog.Destroy ();
			upload_dialog = null;
			tn = null;
		}
        /// <devdoc>
        ///    <para>
        ///     Starts async request processing including async retrieval of the request stream and response.
        ///     Derived classes can use BeginSend
        ///     to help implement their own higher level async methods like BeginInvoke. Derived
        ///     classes can add custom behavior by overriding GetWebRequest, GetWebResponse,
        ///     InitializeAsyncRequest and WriteAsyncRequest methods.
        ///    </para>
        /// </devdoc>
        internal IAsyncResult BeginSend(Uri requestUri, WebClientAsyncResult asyncResult, bool callWriteAsyncRequest) {
            if (readResponseAsyncCallback == null) {
                lock (InternalSyncObject) {
                    if (readResponseAsyncCallback == null) {
                        getRequestStreamAsyncCallback = new AsyncCallback(GetRequestStreamAsyncCallback);
                        getResponseAsyncCallback = new AsyncCallback(GetResponseAsyncCallback);
                        readResponseAsyncCallback = new AsyncCallback(ReadResponseAsyncCallback);
                    }
                }
            }
            Debug.Assert(asyncResult.Request == null, "calling GetWebRequest twice for the same WebClientAsyncResult");
            WebRequest request = GetWebRequest(requestUri);
            asyncResult.Request = request;
            InitializeAsyncRequest(request, asyncResult.InternalAsyncState);
            if (callWriteAsyncRequest)
                request.BeginGetRequestStream(getRequestStreamAsyncCallback, asyncResult);
            else
                request.BeginGetResponse(getResponseAsyncCallback, asyncResult);

            if (!asyncResult.IsCompleted)
                asyncResult.CombineCompletedSynchronously(false);
            return asyncResult;
        }
Esempio n. 53
0
		//
		// Request the user registration.
		//
		void OnPage2_Clicked (object sender, EventArgs a)
		{
			notebook.Page = 2;
			SettingsHandler.Settings.Email = entry_email.Text;
			war = (WebClientAsyncResult) d.BeginRegister (entry_email.Text, new AsyncCallback (RegisterDone), null);
		}
 static private void ProcessAsyncException(WebClientAsyncResult client, Exception e, string method) {
     if (Tracing.On) Tracing.ExceptionCatch(TraceEventType.Error, typeof(WebClientProtocol), method, e);
     WebException webException = e as WebException;
     if (webException != null && webException.Response != null) {
         client.Response = webException.Response;
     }
     else {
         // If we've already completed the call then the exception must have come
         // out of the user callback in which case we need to rethrow it here
         // so that it bubbles up to the AppDomain unhandled exception event.
         if (client.IsCompleted)
             throw new InvalidOperationException(Res.GetString(Res.ThereWasAnErrorDuringAsyncProcessing), e);
         else
             client.Complete(e);
     }
 }
Esempio n. 55
0
		ContributionStatus (string email, string key)
		{
			tn = new ThreadNotify (new ReadyEvent (Update));
			
			d = new Contributions ();
			if (Environment.GetEnvironmentVariable ("MONODOCTESTING") == null)
				d.Url = "http://www.go-mono.com/docs/server.asmx";
				
			war = (WebClientAsyncResult) d.BeginGetStatus (email, key, new AsyncCallback (GetStatusDone), null);
			contributoremail = email;
		}
 static private void ReadAsyncResponse(WebClientAsyncResult client) {
     if (client.Response.ContentLength == 0) {
         client.Complete();
         return;
     }
     try {
         client.ResponseStream = client.Response.GetResponseStream();
         ReadAsyncResponseStream(client);
     }
     catch (Exception e) {
         if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException) {
             throw;
         }
         ProcessAsyncException(client, e, "ReadAsyncResponse");
     }
 }
 /// <include file='doc\HttpClientProtocol.uex' path='docs/doc[@for="HttpSimpleClientProtocol.InvokeAsync1"]/*' />
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 protected void InvokeAsync(string methodName, string requestUrl, object[] parameters, SendOrPostCallback callback, object userState) {
     if (userState == null)
         userState = NullToken;
     AsyncOperation asyncOp = AsyncOperationManager.CreateOperation(new UserToken(callback, userState));
     WebClientAsyncResult asyncResult = new WebClientAsyncResult(this, null, null, new AsyncCallback(InvokeAsyncCallback), asyncOp);
     try {
         AsyncInvokes.Add(userState, asyncResult);
     }
     catch (Exception e) {
         if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException)
             throw;
         if (Tracing.On) Tracing.ExceptionCatch(TraceEventType.Error, this, "InvokeAsync", e);
         Exception exception = new ArgumentException(Res.GetString(Res.AsyncDuplicateUserState), e);
         InvokeCompletedEventArgs eventArgs = new InvokeCompletedEventArgs(new object[] { null }, exception, false, userState);
         asyncOp.PostOperationCompleted(callback, eventArgs);
         return;
     }
     try {
         HttpClientMethod method = GetClientMethod(methodName);
         MimeParameterWriter paramWriter = GetParameterWriter(method);
         Uri requestUri = new Uri(requestUrl);            
         if (paramWriter != null) {
             paramWriter.RequestEncoding = RequestEncoding;
             requestUrl = paramWriter.GetRequestUrl(requestUri.AbsoluteUri, parameters);
             requestUri = new Uri(requestUrl, true);
         }
         asyncResult.InternalAsyncState = new InvokeAsyncState(method, paramWriter, parameters);
         BeginSend(requestUri, asyncResult, paramWriter.UsesWriteRequest);
     } 
     catch (Exception e) {
         if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException)
             throw;
         if (Tracing.On) Tracing.ExceptionCatch(TraceEventType.Error, this, "InvokeAsync", e);
         OperationCompleted(userState, new object[] { null }, e, false);
     }
 }
 static private void ReadAsyncResponseStream(WebClientAsyncResult client) {
     IAsyncResult asyncResult;
     do {
         byte[] buffer = client.Buffer;
         long contentLength = client.Response.ContentLength;
         if (buffer == null)
             buffer = client.Buffer = new byte[(contentLength == -1) ? 1024 : contentLength];
         else if (contentLength != -1 && contentLength > buffer.Length)
             buffer = client.Buffer = new byte[contentLength];
         asyncResult = client.ResponseStream.BeginRead(buffer, 0, buffer.Length, readResponseAsyncCallback, client);
         if (!asyncResult.CompletedSynchronously)
             return;
     }
     while (!ProcessAsyncResponseStreamResult(client, asyncResult));
 }
        static private bool ProcessAsyncResponseStreamResult(WebClientAsyncResult client, IAsyncResult asyncResult) {
            bool complete;
            int bytesRead = client.ResponseStream.EndRead(asyncResult);
            long contentLength = client.Response.ContentLength;
            if (contentLength > 0 && bytesRead == contentLength) {
                // the non-chunked response finished in a single read
                client.ResponseBufferedStream = new MemoryStream(client.Buffer);
                complete = true;
            }
            else if (bytesRead > 0) {
                if (client.ResponseBufferedStream == null) {
                    int capacity = (int)((contentLength == -1) ? client.Buffer.Length : contentLength);
                    client.ResponseBufferedStream = new MemoryStream(capacity);
                }
                client.ResponseBufferedStream.Write(client.Buffer, 0, bytesRead);
                complete = false;
            }
            else
                complete = true;

            if (complete)
                client.Complete();
            return complete;
        }
Esempio n. 60
0
 protected void InvokeAsync(string methodName, object[] parameters, SendOrPostCallback callback, object userState)
 {
   if (userState == null)
     userState = this.NullToken;
   SoapHttpClientProtocol.InvokeAsyncState invokeAsyncState = new SoapHttpClientProtocol.InvokeAsyncState(methodName, parameters);
   AsyncOperation operation = AsyncOperationManager.CreateOperation((object) new UserToken(callback, userState));
   WebClientAsyncResult asyncResult = new WebClientAsyncResult((WebClientProtocol) this, (object) invokeAsyncState, (WebRequest) null, new AsyncCallback(this.InvokeAsyncCallback), (object) operation);
   try
   {
     this.AsyncInvokes.Add(userState, (object) asyncResult);
   }
   catch (Exception ex)
   {
     if (ex is ThreadAbortException || ex is StackOverflowException || ex is OutOfMemoryException)
     {
       throw;
     }
     else
     {
       if (Tracing.On)
         Tracing.ExceptionCatch(TraceEventType.Warning, (object) this, "InvokeAsync", ex);
       InvokeCompletedEventArgs completedEventArgs = new InvokeCompletedEventArgs(new object[1], (Exception) new ArgumentException(System.Web.Services.Res.GetString("AsyncDuplicateUserState"), ex), false, userState);
       operation.PostOperationCompleted(callback, (object) completedEventArgs);
       return;
     }
   }
   try
   {
     this.BeginSend(this.Uri, asyncResult, true);
   }
   catch (Exception ex)
   {
     if (ex is ThreadAbortException || ex is StackOverflowException || ex is OutOfMemoryException)
     {
       throw;
     }
     else
     {
       if (Tracing.On)
         Tracing.ExceptionCatch(TraceEventType.Warning, (object) this, "InvokeAsync", ex);
       this.OperationCompleted(userState, new object[1], ex, false);
     }
   }
 }