//private void Page_Loaded(object sender, EventArgs e)
        //{

        //    // Grab SynchronizationContext while on UI Thread
        //    syncContext = SynchronizationContext.Current;



        //    // Create request
        //    HttpWebRequest request = WebRequest.Create("http://msite.com/myFeed") as HttpWebRequest;
        //    request.Method = "POST";
        //    request.Headers["x-custom-header"] = "value";


        //    // Make async call for request stream.  Callback will be called on a background thread.
        //    IAsyncResult asyncResult = request.BeginGetRequestStream(new AsyncCallback(RequestStreamCallback), request);

        //}

        //private void UploadBinaryFile(byte[] fileBits)
        //{
        //    string url = "http://chuckconway.com/gallery/photoupload.ashx";
        //    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri(url));
        //    request.ContentType = "application/octet-stream";
        //    request.Method = "POST";

        //    IAsyncResult asyncResult = request.BeginGetRequestStream(new AsyncCallback(RequestStreamCallback), request);

        //}


        //string chuck = "chuck";

        //  using(Stream requestStream = request.EndGetRequestStream(ar))
        //  {
        //     requestStream.Write(
        //  }



        //  StreamWriter streamWriter = new StreamWriter(requestStream);

        //  streamWriter.Write("<?xml version="1.0"?>"
        //                     + "<entry xmlns="http://www.w3.org/2005/Atom">"
        //                     + "<author>"
        //                    + "<name>Elizabeth Bennet</name>"
        //                     + "<email>[email protected]</email>"
        //                     + "</author>"
        //                    + "<title type="text">Entry 1</title>"
        //                    + "<content type="text">This is my entry</content>"
        //                    + "</entry>");


        //  streamWriter.Close();


        //// Make async call for response.  Callback will be called on a background thread.
        // request.BeginGetResponse(new AsyncCallback(ResponseCallback), request);

        //}

        //private void ResponseCallback(IAsyncResult ar)
        //{

        //    HttpWebRequest request = ar.AsyncState as HttpWebRequest;
        //    WebResponse response = request.EndGetResponse(ar);

        //    // Invoke onto UI thread
        //    syncContext.Post(ExtractResponse, response);

        //    // use response.  Could include reading response stream.

        //}

        //private void ExtractResponse(object state)
        //{
        //    HttpWebResponse response = state as HttpWebResponse;
        //    // use response.  Could include reading response stream.

        //}

        //private void OpenConnection()
        //{
        //    using (SocketClient client = new SocketClient("chuckconway.com", 80))
        //    {
        //        client.
        //    }

        //}

        //private void OnSocketConnectCompleted(object sender, SocketAsyncEventArgs e)
        //{
        //    byte[] response = new byte[1024];
        //    e.SetBuffer(response, 0, response.Length);
        //    e.Completed -= new EventHandler<SocketAsyncEventArgs>(OnSocketConnectCompleted);
        //    //e.Completed += new EventHandler<SocketAsyncEventArgs>(OnSocketReceive);
        //    Socket socket = (Socket)e.UserToken;
        //    socket.ReceiveAsync(e);
        //}

        /// <summary>
        /// Handles the Click event of the uploadButton control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        private void uploadButton_Click(object sender, RoutedEventArgs e)
        {
            //WebClient client = new WebClient();

            //string url = "http://chuckconway.com/gallery/photoupload.ashx";

            PhotoServiceSoapClient service = new PhotoServiceSoapClient();

            service.UploadCompleted += (service_UploadCompleted);

            //check for selected gallery, if none selected prompt the user to select a gallery.
            if (galleryListBox.SelectedItem != null && uploadListBox.Items.Count > 0)
            {
                CalculateProgressbar();

                foreach (object image in uploadListBox.Items)
                {
                    ClientImage clientImage = (ClientImage)image;

                    string extension = File.GetFileExtension(clientImage.ImageName);
                    byte[] bytes     = File.GetByteArrayFromStream(clientImage.FileInfo.OpenRead());

                    //Upload the photos
                    service.UploadAsync(userToken, bytes, clientImage.GalleryId, extension);
                }
            }
            else
            {
                //if there is no gallery selected then show the gallery error message
                //otherwise the problem must be no photos in the upload listbox
                uploadErrorMessage.Text = (galleryListBox.SelectedItem == null ? "Please select a gallery." : "Please choose a photo to upload.");
            }
        }
示例#2
0
        /// <summary>
        /// Handles the DoWork event of the worker control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.ComponentModel.DoWorkEventArgs"/> instance containing the event data.</param>
        void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            //PhotoServiceSoapClient service = new PhotoServiceSoapClient();
            List<ClientImage> images = (List<ClientImage>)e.Argument;

            foreach (ClientImage image in images)
            {
                PhotoServiceSoapClient service = new PhotoServiceSoapClient();

                service.Upload(Client.Default.token, image.PhotoBytes, image.GalleryId, ".jpg");
                //worker.ReportProgress(1, image.ImageName);

                if (service.State == CommunicationState.Closed || service.State == CommunicationState.Closing)
                {
                    service.Close();
                }
            }
        }
示例#3
0
        /// <summary>
        /// Handles the DoWork event of the worker control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.ComponentModel.DoWorkEventArgs"/> instance containing the event data.</param>
        void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            //PhotoServiceSoapClient service = new PhotoServiceSoapClient();
            List <ClientImage> images = (List <ClientImage>)e.Argument;

            foreach (ClientImage image in images)
            {
                PhotoServiceSoapClient service = new PhotoServiceSoapClient();

                service.Upload(Client.Default.token, image.PhotoBytes, image.GalleryId, ".jpg");
                //worker.ReportProgress(1, image.ImageName);

                if (service.State == CommunicationState.Closed || service.State == CommunicationState.Closing)
                {
                    service.Close();
                }
            }
        }
        //private void Page_Loaded(object sender, EventArgs e)
        //{
        //    // Grab SynchronizationContext while on UI Thread
        //    syncContext = SynchronizationContext.Current;
        //    // Create request
        //    HttpWebRequest request = WebRequest.Create("http://msite.com/myFeed") as HttpWebRequest;
        //    request.Method = "POST";
        //    request.Headers["x-custom-header"] = "value";
        //    // Make async call for request stream.  Callback will be called on a background thread.
        //    IAsyncResult asyncResult = request.BeginGetRequestStream(new AsyncCallback(RequestStreamCallback), request);
        //}
        //private void UploadBinaryFile(byte[] fileBits)
        //{
        //    string url = "http://chuckconway.com/gallery/photoupload.ashx";
        //    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri(url));
        //    request.ContentType = "application/octet-stream";
        //    request.Method = "POST";
        //    IAsyncResult asyncResult = request.BeginGetRequestStream(new AsyncCallback(RequestStreamCallback), request);
        //}
        //string chuck = "chuck";
        //  using(Stream requestStream = request.EndGetRequestStream(ar))
        //  {
        //     requestStream.Write(
        //  }
        //  StreamWriter streamWriter = new StreamWriter(requestStream);
        //  streamWriter.Write("<?xml version="1.0"?>"
        //                     + "<entry xmlns="http://www.w3.org/2005/Atom">"
        //                     + "<author>"
        //                    + "<name>Elizabeth Bennet</name>"
        //                     + "<email>[email protected]</email>"
        //                     + "</author>"
        //                    + "<title type="text">Entry 1</title>"
        //                    + "<content type="text">This is my entry</content>"
        //                    + "</entry>");
        //  streamWriter.Close();
        //// Make async call for response.  Callback will be called on a background thread.
        // request.BeginGetResponse(new AsyncCallback(ResponseCallback), request);
        //}
        //private void ResponseCallback(IAsyncResult ar)
        //{
        //    HttpWebRequest request = ar.AsyncState as HttpWebRequest;
        //    WebResponse response = request.EndGetResponse(ar);
        //    // Invoke onto UI thread
        //    syncContext.Post(ExtractResponse, response);
        //    // use response.  Could include reading response stream.
        //}
        //private void ExtractResponse(object state)
        //{
        //    HttpWebResponse response = state as HttpWebResponse;
        //    // use response.  Could include reading response stream.
        //}
        //private void OpenConnection()
        //{
        //    using (SocketClient client = new SocketClient("chuckconway.com", 80))
        //    {
        //        client.
        //    }
        //}
        //private void OnSocketConnectCompleted(object sender, SocketAsyncEventArgs e)
        //{
        //    byte[] response = new byte[1024];
        //    e.SetBuffer(response, 0, response.Length);
        //    e.Completed -= new EventHandler<SocketAsyncEventArgs>(OnSocketConnectCompleted);
        //    //e.Completed += new EventHandler<SocketAsyncEventArgs>(OnSocketReceive);
        //    Socket socket = (Socket)e.UserToken;
        //    socket.ReceiveAsync(e);
        //}
        /// <summary>
        /// Handles the Click event of the uploadButton control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        private void uploadButton_Click(object sender, RoutedEventArgs e)
        {
            //WebClient client = new WebClient();

            //string url = "http://chuckconway.com/gallery/photoupload.ashx";

            PhotoServiceSoapClient service = new PhotoServiceSoapClient();
            service.UploadCompleted += (service_UploadCompleted);

            //check for selected gallery, if none selected prompt the user to select a gallery.
            if (galleryListBox.SelectedItem != null && uploadListBox.Items.Count > 0)
            {
                CalculateProgressbar();

                foreach (object image in uploadListBox.Items)
                {
                    ClientImage clientImage = (ClientImage)image;

                    string extension = File.GetFileExtension(clientImage.ImageName);
                    byte[] bytes = File.GetByteArrayFromStream(clientImage.FileInfo.OpenRead());

                    //Upload the photos
                    service.UploadAsync(userToken, bytes, clientImage.GalleryId, extension);
                }
            }
            else
            {
                //if there is no gallery selected then show the gallery error message
                //otherwise the problem must be no photos in the upload listbox
                uploadErrorMessage.Text = (galleryListBox.SelectedItem == null ? "Please select a gallery." : "Please choose a photo to upload.");
            }
        }