예제 #1
0
        public Stream OpenWrite(Uri address, string method) {
            if(Logging.On)Logging.Enter(Logging.Web, this, "OpenWrite", address +", "+method);
            if (address == null) 
                throw new ArgumentNullException("address");
            if (method == null) {
                method = MapToDefaultMethod(address);
            }
            WebRequest request = null;
            ClearWebClientState();
            try {
                m_Method = method;
                request = m_WebRequest = GetWebRequest(GetUri(address));
                WebClientWriteStream webClientWriteStream =
                    new WebClientWriteStream(request.GetRequestStream(), request, this);
                if(Logging.On)Logging.Exit(Logging.Web, this, "OpenWrite", webClientWriteStream);
                return webClientWriteStream;
            } catch (Exception e) {
                if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException) {
                    throw;
                }

                if (!(e is WebException || e is SecurityException)) {
                    e = new WebException(SR.GetString(SR.net_webclient), e);
                }

                AbortRequest(request);
                throw e;
            }
            catch {
                Exception e = new WebException(SR.GetString(SR.net_webclient), new Exception(SR.GetString(SR.net_nonClsCompliantException)));

                AbortRequest(request);
                throw e;
            }
            finally {
                CompleteWebClientState();
            }
        }
 private void OpenWriteAsyncCallback(IAsyncResult result)
 {
     LazyAsyncResult result2 = (LazyAsyncResult) result;
     AsyncOperation asyncState = (AsyncOperation) result2.AsyncState;
     WebRequest asyncObject = (WebRequest) result2.AsyncObject;
     WebClientWriteStream stream = null;
     Exception exception = null;
     try
     {
         stream = new WebClientWriteStream(asyncObject.EndGetRequestStream(result), asyncObject, this);
     }
     catch (Exception exception2)
     {
         if (((exception2 is ThreadAbortException) || (exception2 is StackOverflowException)) || (exception2 is OutOfMemoryException))
         {
             throw;
         }
         exception = exception2;
         if (!(exception2 is WebException) && !(exception2 is SecurityException))
         {
             exception = new WebException(SR.GetString("net_webclient"), exception2);
         }
     }
     OpenWriteCompletedEventArgs eventArgs = new OpenWriteCompletedEventArgs(stream, exception, this.m_Cancelled, asyncState.UserSuppliedState);
     this.InvokeOperationCompleted(asyncState, this.openWriteOperationCompleted, eventArgs);
 }
예제 #3
0
        private void OpenWriteAsyncCallback(IAsyncResult result) {
            LazyAsyncResult lazyAsyncResult = (LazyAsyncResult) result;
            AsyncOperation asyncOp = (AsyncOperation) lazyAsyncResult.AsyncState;
            WebRequest request = (WebRequest) lazyAsyncResult.AsyncObject;
            WebClientWriteStream stream = null;
            Exception exception = null;

            try {
                stream =
                    new WebClientWriteStream(request.EndGetRequestStream(result), request, this);
            } catch (Exception e) {
                if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException) {
                    throw;
                }
                exception = e;
                if (!(e is WebException || e is SecurityException)) {
                    exception = new WebException(SR.GetString(SR.net_webclient), e);
                }
            }
            catch {
                exception = new WebException(SR.GetString(SR.net_webclient), new Exception(SR.GetString(SR.net_nonClsCompliantException)));
            }

            OpenWriteCompletedEventArgs eventArgs =
                new OpenWriteCompletedEventArgs(stream, exception, m_Cancelled, asyncOp.UserSuppliedState);
            InvokeOperationCompleted(asyncOp, openWriteOperationCompleted, eventArgs);
        }
 public Stream OpenWrite(Uri address, string method)
 {
     Stream stream2;
     if (Logging.On)
     {
         Logging.Enter(Logging.Web, this, "OpenWrite", address + ", " + method);
     }
     if (address == null)
     {
         throw new ArgumentNullException("address");
     }
     if (method == null)
     {
         method = this.MapToDefaultMethod(address);
     }
     WebRequest request = null;
     this.ClearWebClientState();
     try
     {
         this.m_Method = method;
         request = this.m_WebRequest = this.GetWebRequest(this.GetUri(address));
         WebClientWriteStream retObject = new WebClientWriteStream(request.GetRequestStream(), request, this);
         if (Logging.On)
         {
             Logging.Exit(Logging.Web, this, "OpenWrite", retObject);
         }
         stream2 = retObject;
     }
     catch (Exception exception)
     {
         if (((exception is ThreadAbortException) || (exception is StackOverflowException)) || (exception is OutOfMemoryException))
         {
             throw;
         }
         if (!(exception is WebException) && !(exception is SecurityException))
         {
             exception = new WebException(SR.GetString("net_webclient"), exception);
         }
         AbortRequest(request);
         throw exception;
     }
     finally
     {
         this.CompleteWebClientState();
     }
     return stream2;
 }