Ejemplo n.º 1
0
        private static void GetResponseCallback(IAsyncResult asynchronousResult)
        {
            UploadState state = (UploadState)asynchronousResult.AsyncState;

            state.statusCB("Waiting For Response");

            // End the operation
            try
            {
                HttpWebResponse response       = (HttpWebResponse)state.request.EndGetResponse(asynchronousResult);
                Stream          streamResponse = response.GetResponseStream();
                StreamReader    streamRead     = new StreamReader(streamResponse);
                state.response = streamRead.ReadToEnd();
                // Close the stream object
                streamResponse.Close();
                streamRead.Close();
                response.Close();
            }
            catch (Exception e)
            {
                state.failureCB(e, "Result Retrieval Problem");
                return;
            }
            // Release the HttpWebResponse

            state.statusCB("Done");
            state.responseDoneCB();
        }
Ejemplo n.º 2
0
        public void sendFile(string uuid, string file_path, string title, string description, UploadState state)
        {
            state.statusCB("Encoding File");
            NameValueCollection upload_components = bundleFile(uuid, file_path, title, description);
            FileStream          encodedFileStream = File.OpenRead(upload_components.Get("packed_file"));

            // this is where we will send it
            string uri_pattern  = "https://{0}/pcpbridge/upload";
            string uri          = String.Format(uri_pattern, server);
            long   bufferLength = encodedFileStream.Length;

            // Create the request object
            HttpWebRequest bridgeSubmitRequest = (HttpWebRequest)WebRequest.Create(uri);

            bridgeSubmitRequest.ContentType   = "multipart/form-data; boundary=" + upload_components.Get("Boundary");
            bridgeSubmitRequest.Method        = "POST";
            bridgeSubmitRequest.KeepAlive     = true;
            bridgeSubmitRequest.Credentials   = System.Net.CredentialCache.DefaultCredentials;
            bridgeSubmitRequest.ContentLength = bufferLength;
            state.request    = bridgeSubmitRequest;
            state.filename   = upload_components.Get("packed_file");
            state.totalBytes = bufferLength;

            encodedFileStream.Close();
            bridgeSubmitRequest.BeginGetRequestStream(new AsyncCallback(postFile_GetRequestStreamCallback), state);
        }
Ejemplo n.º 3
0
        private void postFile_GetRequestStreamCallback(IAsyncResult asynchronousResult)
        {
            UploadState state = (UploadState)asynchronousResult.AsyncState;

            state.statusCB("Sending File");
            // End the operation
            try
            {
                Stream    postStream = state.request.EndGetRequestStream(asynchronousResult);
                const int BUFFER     = 4096;

                byte[]     buffer            = new byte[BUFFER];
                FileStream encodedFileStream = File.OpenRead(state.filename);
                int        bytes_read        = 0;
                long       total_read        = 0;
                bytes_read = encodedFileStream.Read(buffer, 0, BUFFER);
                while (bytes_read > 0)
                {
                    total_read += bytes_read;
                    postStream.Write(buffer, 0, bytes_read);
                    bytes_read = encodedFileStream.Read(buffer, 0, BUFFER);
                    state.progCB(((double)total_read / (double)state.totalBytes) * 100.0);
                }

                postStream.Close();
                encodedFileStream.Close();
                File.Delete(state.filename);
            }

            catch (Exception e)
            {
                state.failureCB(e, "Upload Problem");
                return;
            }
            state.uploadDoneCB();
            // Start the asynchronous operation to get the response
            state.request.BeginGetResponse(new AsyncCallback(GetResponseCallback), state);
        }
Ejemplo n.º 4
0
        public void sendFile(string uuid, string file_path, string title, string description, UploadState state)
        {
            state.statusCB("Encoding File");
            NameValueCollection upload_components = bundleFile(uuid, file_path, title, description);
            FileStream encodedFileStream = File.OpenRead(upload_components.Get("packed_file"));

            // this is where we will send it
            string uri_pattern = "https://{0}/pcpbridge/upload";
            string uri = String.Format(uri_pattern, server);
            long bufferLength = encodedFileStream.Length;

            // Create the request object
            HttpWebRequest bridgeSubmitRequest = (HttpWebRequest)WebRequest.Create(uri);
            bridgeSubmitRequest.ContentType = "multipart/form-data; boundary=" + upload_components.Get("Boundary");
            bridgeSubmitRequest.Method = "POST";
            bridgeSubmitRequest.KeepAlive = true;
            bridgeSubmitRequest.Credentials = System.Net.CredentialCache.DefaultCredentials;
            bridgeSubmitRequest.ContentLength = bufferLength;
            state.request = bridgeSubmitRequest;
            state.filename = upload_components.Get("packed_file");
            state.totalBytes = bufferLength;

            encodedFileStream.Close();
            bridgeSubmitRequest.BeginGetRequestStream(new AsyncCallback(postFile_GetRequestStreamCallback), state);
        }