예제 #1
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 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();
     }
 }