private void UploadBits(WebRequest request, Stream readStream, byte[] buffer, int chunkSize, byte[] header, byte[] footer, CompletionDelegate uploadCompletionDelegate, CompletionDelegate downloadCompletionDelegate, AsyncOperation asyncOp)
 {
     if (request.RequestUri.Scheme == Uri.UriSchemeFile)
     {
         header = (byte[]) (footer = null);
     }
     UploadBitsState state = new UploadBitsState(request, readStream, buffer, chunkSize, header, footer, uploadCompletionDelegate, downloadCompletionDelegate, asyncOp, this.m_Progress, this);
     if (state.Async)
     {
         request.BeginGetRequestStream(new AsyncCallback(WebClient.UploadBitsRequestCallback), state);
     }
     else
     {
         Stream requestStream = request.GetRequestStream();
         state.SetRequestStream(requestStream);
         while (!state.WriteBytes())
         {
         }
         state.Close();
     }
 }
Ejemplo n.º 2
0
        /// <devdoc>
        ///    <para>Takes a byte array or an open file stream and writes it to a server</para>
        /// </devdoc>

        private void UploadBits(WebRequest request, Stream readStream, byte[] buffer, byte [] header, byte [] footer, CompletionDelegate completionDelegate, AsyncOperation asyncOp) {
            if (request.RequestUri.Scheme == Uri.UriSchemeFile)
                header = footer = null;
            UploadBitsState state = new UploadBitsState(request, readStream, buffer, header, footer, completionDelegate, asyncOp, m_Progress, this);
            Stream writeStream;
            if (state.Async) {
                request.BeginGetRequestStream(new AsyncCallback(UploadBitsRequestCallback), state);
                return;
            } else {
                writeStream = request.GetRequestStream();
            }
            state.SetRequestStream(writeStream);
            while(!state.WriteBytes());
            state.Close();
        }
 private void StartDownloadAsync(UploadBitsState state)
 {
     try
     {
         this.DownloadBits(state.Request, null, state.DownloadCompletionDelegate, state.AsyncOp);
     }
     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);
         }
         state.DownloadCompletionDelegate(null, exception, state.AsyncOp);
     }
 }