Ejemplo n.º 1
0
        private void buttonOk_Click(object sender, EventArgs e)
        {
            authenticate();

            string userName      = comboLogin.Text;
            string selectedAlbum = checkUploadToDropbox.Checked ? null : listAlbums.SelectedItem.ToString();

            disableItemsForRun();

            Thread thr = new Thread(new ThreadStart(delegate
            {
                FileInfo fileInfo     = new FileInfo(fileName);
                FileStream fileStream = fileInfo.OpenRead();

                PicasaEntry entry = null;

                try
                {
                    if (checkUploadToDropbox.Checked)
                    {
                        entry = (PicasaEntry)service.Insert(new Uri(DROPBOX_URL), fileStream, "image/jpeg", fileName);
                    }
                    else
                    {
                        if (selectedAlbum != null)
                        {
                            Uri postUri = new Uri(PicasaQuery.CreatePicasaUri(
                                                      userName, albumMap[selectedAlbum].Name));

                            entry = (PicasaEntry)service.Insert(postUri, fileStream, "image/jpeg", fileName);
                        }
                    }

                    if (entry != null)
                    {
                        entry.Title.Text           = name;
                        entry.Summary.Text         = textComment.Text;
                        entry.Media.Keywords.Value = "Mazio";
                    }

                    entry = (PicasaEntry)service.Update(entry);

                    string contentUrl = entry.Media.Content.Attributes["url"] as string;

                    Invoke(new MethodInvoker(delegate
                    {
                        uploadLog.Text = "Uploaded photo, URL is " + contentUrl + "\r\n";
                    }));
                }
                catch (GDataRequestException ex)
                {
                    Invoke(new MethodInvoker(delegate
                    {
                        uploadLog.Text = "Upload failed: " + ex.Message +
                                         "\r\nResponse: " + ex.ResponseString + "\r\n";
                    }));
                }
                catch (IOException ex)
                {
                    Invoke(new MethodInvoker(delegate
                    {
                        uploadLog.Text = "Upload failed: " + ex.Message +
                                         "\r\nResponse: " + ex.InnerException.Message + "\r\n";
                    }));
                }

                fileStream.Close();
                Invoke(new MethodInvoker(delegate
                {
                    done = true;
                    updateItems();
                    buttonOk.Enabled  = false;
                    buttonCancel.Text = "Close";
                }));
            }));

            thr.Start();
        }