Exemple #1
0
 private void HandleProgressChanged(ProgressItem item)
 {
     //System.Console.WriteLine ("Changed value = {0}", item.Value);
     progress_dialog.Fraction = (photo_index - 1.0 + item.Value) / (double) selection.Count;
 }
Exemple #2
0
        private void Upload()
        {
            progress_item = new ProgressItem ();
            progress_item.Changed += HandleProgressChanged;
            fr.Connection.OnUploadProgress += HandleFlickrProgress;

            System.Collections.ArrayList ids = new System.Collections.ArrayList ();
            IBrowsableItem [] photos = selection.Items;
            Array.Sort (photos, new DateComparer ());

            for (int index = 0; index < photos.Length; index++) {
                try {
                    IBrowsableItem photo = photos [index];
                    progress_dialog.Message = System.String.Format (
                                                Catalog.GetString ("Uploading picture \"{0}\""), photo.Name);

                    progress_dialog.Fraction = photo_index / (double)selection.Count;
                    photo_index++;
                    progress_dialog.ProgressText = System.String.Format (
                        Catalog.GetString ("{0} of {1}"), photo_index,
                        selection.Count);

                    info = new FileInfo (photo.DefaultVersionUri.LocalPath);
                    FilterSet stack = new FilterSet ();
                    if (scale)
                        stack.Add (new ResizeFilter ((uint)size));

                    string id = fr.Upload (photo, stack, is_public, is_family, is_friend);
                    ids.Add (id);

                    if (App.Instance.Database != null && photo is FSpot.Photo)
                        App.Instance.Database.Exports.Create ((photo as FSpot.Photo).Id,
                                          (photo as FSpot.Photo).DefaultVersionId,
                                          ExportStore.FlickrExportType,
                                          auth.User.UserId + ":" + auth.User.Username + ":" + current_service.Name + ":" + id);

                } catch (System.Exception e) {
                    progress_dialog.Message = String.Format (Catalog.GetString ("Error Uploading To {0}: {1}"),
                                         current_service.Name,
                                         e.Message);
                    progress_dialog.ProgressText = Catalog.GetString ("Error");
                    System.Console.WriteLine (e);

                    if (progress_dialog.PerformRetrySkip ()) {
                        index--;
                        photo_index--;
                    }
                }
            }
            progress_dialog.Message = Catalog.GetString ("Done Sending Photos");
            progress_dialog.Fraction = 1.0;
            progress_dialog.ProgressText = Catalog.GetString ("Upload Complete");
            progress_dialog.ButtonLabel = Gtk.Stock.Ok;

            if (open && ids.Count != 0) {
                string view_url;
                if (current_service.Name == "Zooomr.com")
                    view_url = string.Format ("http://www.{0}/photos/{1}/", current_service.Name, auth.User.Username);
                else {
                    view_url = string.Format ("http://www.{0}/tools/uploader_edit.gne?ids", current_service.Name);
                    bool first = true;

                    foreach (string id in ids) {
                        view_url = view_url + (first ? "=" : ",") + id;
                        first = false;
                    }
                }

                GtkBeans.Global.ShowUri (Dialog.Screen, view_url);
            }
        }
	public HttpWebResponse Submit (Uri uri, FSpot.ProgressItem progress_item) 
	{
		this.Progress = progress_item;
		Request = (HttpWebRequest) WebRequest.Create (uri);
		CookieCollection cookie_collection = Cookies.GetCookies (uri);

		if (uri.UserInfo != null && uri.UserInfo != String.Empty) {
			NetworkCredential cred = new NetworkCredential ();
			cred.GetCredential (uri, "basic");
			CredentialCache credcache = new CredentialCache();
			credcache.Add(uri, "basic", cred);
			
			Request.PreAuthenticate = true;
			Request.Credentials = credcache;	
		}

		Request.ServicePoint.Expect100Continue = expect_continue;

		Request.CookieContainer = new CookieContainer ();
		foreach (Cookie c in cookie_collection) {
			if (SuppressCookiePath) 
				Request.CookieContainer.Add (new Cookie (c.Name, c.Value));
			else
				Request.CookieContainer.Add (c);
		}

		Request.Method = "POST";
		Request.Headers["Accept-Charset"] = "utf-8;";
		
		//Request.UserAgent = "F-Spot Gallery Remote Client";
		Request.UserAgent = "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7) Gecko/20040626 Firefox/0.9.1";

		Request.Proxy = WebProxy.GetDefaultProxy ();

		if (multipart) {
			GenerateBoundary ();
			Request.ContentType = "multipart/form-data; boundary=" + boundary;
			Request.Timeout = Request.Timeout * 3;

			long length = 0;
			for (int i = 0; i < Items.Count; i++) {
				FormItem item = (FormItem)Items[i];
				
				length += MultipartLength (item);
			}
			length += end_boundary.Length + 2;
			
			//Request.Headers["My-Content-Length"] = length.ToString ();
			if (Buffer == false) {
				Request.ContentLength = length;	
				Request.AllowWriteStreamBuffering = false;
			}
		} else {
			Request.ContentType = "application/x-www-form-urlencoded";
		}
		
		stream_writer = new StreamWriter (Request.GetRequestStream ());
		
		first_item = true;
		for (int i = 0; i < Items.Count; i++) {
			FormItem item = (FormItem)Items[i];
			
			Write (item);
		}
		
		if (multipart)
			stream_writer.Write (end_boundary + "\r\n");
		
		stream_writer.Flush ();
		stream_writer.Close ();

		HttpWebResponse response; 

		try {
			response = (HttpWebResponse) Request.GetResponse ();
			
			//Console.WriteLine ("found {0} cookies", response.Cookies.Count);
			
			foreach (Cookie c in response.Cookies) {
				Cookies.Add (c);
			}
		} catch (WebException e) {
			if (e.Status == WebExceptionStatus.ProtocolError 
			    && ((HttpWebResponse)e.Response).StatusCode == HttpStatusCode.ExpectationFailed && expect_continue) {
				e.Response.Close ();
				expect_continue = false;
				return Submit (uri, progress_item);
			}
			
			throw new WebException (Mono.Unix.Catalog.GetString ("Unhandled exception"), e);
		}

		return response;
	}
        private void Upload()
        {
            progress_item                   = new ProgressItem();
            progress_item.Changed          += HandleProgressChanged;
            fr.Connection.OnUploadProgress += HandleFlickrProgress;

            System.Collections.ArrayList ids = new System.Collections.ArrayList();
            for (int index = 0; index < selection.Items.Length; index++)
            {
                try {
                    IBrowsableItem photo = selection.Items [index];
                    progress_dialog.Message = System.String.Format(
                        Catalog.GetString("Uploading picture \"{0}\""), photo.Name);

                    progress_dialog.Fraction = photo_index / (double)selection.Count;
                    photo_index++;
                    progress_dialog.ProgressText = System.String.Format(
                        Catalog.GetString("{0} of {1}"), photo_index,
                        selection.Count);

                    info = new FileInfo(photo.DefaultVersionUri.LocalPath);
                    FilterSet stack = new Filters.FilterSet();
                    if (scale)
                    {
                        stack.Add(new ResizeFilter((uint)size));
                    }

                    string id = fr.Upload(photo, stack, is_public, is_family, is_friend);
                    ids.Add(id);

                    if (Core.Database != null && photo is Photo)
                    {
                        Core.Database.Exports.Create((photo as Photo).Id,
                                                     (photo as Photo).DefaultVersionId,
                                                     ExportStore.FlickrExportType,
                                                     auth.User.UserId + ":" + auth.User.Username + ":" + current_service.Name + ":" + id);
                    }

                    progress_dialog.Message      = Catalog.GetString("Done Sending Photos");
                    progress_dialog.Fraction     = 1.0;
                    progress_dialog.ProgressText = Catalog.GetString("Upload Complete");
                    progress_dialog.ButtonLabel  = Gtk.Stock.Ok;
                } catch (System.Exception e) {
                    progress_dialog.Message = String.Format(Catalog.GetString("Error Uploading To {0}: {1}"),
                                                            current_service.Name,
                                                            e.Message);
                    progress_dialog.ProgressText = Catalog.GetString("Error");
                    System.Console.WriteLine(e);

                    if (progress_dialog.PerformRetrySkip())
                    {
                        index--;
                    }
                }
            }

            if (open && ids.Count != 0)
            {
                string view_url = string.Format("http://www.{0}/tools/uploader_edit.gne?ids", current_service.Name);
                bool   first    = true;

                foreach (string id in ids)
                {
                    view_url = view_url + (first ? "=" : ",") + id;
                    first    = false;
                }

                GnomeUtil.UrlShow(progress_dialog, view_url);
            }
        }
 private void HandleProgressChanged(ProgressItem item)
 {
     //System.Console.WriteLine ("Changed value = {0}", item.Value);
     progress_dialog.Fraction = (photo_index - 1.0 + item.Value) / (double)selection.Count;
 }
    public HttpWebResponse Submit(Uri uri, FSpot.ProgressItem progress_item)
    {
        this.Progress = progress_item;
        Request       = (HttpWebRequest)WebRequest.Create(uri);
        CookieCollection cookie_collection = Cookies.GetCookies(uri);

        if (uri.UserInfo != null && uri.UserInfo != String.Empty)
        {
            NetworkCredential cred = new NetworkCredential();
            cred.GetCredential(uri, "basic");
            CredentialCache credcache = new CredentialCache();
            credcache.Add(uri, "basic", cred);

            Request.PreAuthenticate = true;
            Request.Credentials     = credcache;
        }

        Request.ServicePoint.Expect100Continue = expect_continue;

        Request.CookieContainer = new CookieContainer();
        foreach (Cookie c in cookie_collection)
        {
            if (SuppressCookiePath)
            {
                Request.CookieContainer.Add(new Cookie(c.Name, c.Value));
            }
            else
            {
                Request.CookieContainer.Add(c);
            }
        }

        Request.Method = "POST";
        Request.Headers["Accept-Charset"] = "utf-8;";

        //Request.UserAgent = "F-Spot Gallery Remote Client";
        Request.UserAgent = "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7) Gecko/20040626 Firefox/0.9.1";

        Request.Proxy = WebProxy.GetDefaultProxy();

        if (multipart)
        {
            GenerateBoundary();
            Request.ContentType = "multipart/form-data; boundary=" + boundary;
            Request.Timeout     = Request.Timeout * 3;

            long length = 0;
            for (int i = 0; i < Items.Count; i++)
            {
                FormItem item = (FormItem)Items[i];

                length += MultipartLength(item);
            }
            length += end_boundary.Length + 2;

            //Request.Headers["My-Content-Length"] = length.ToString ();
            if (Buffer == false)
            {
                Request.ContentLength             = length;
                Request.AllowWriteStreamBuffering = false;
            }
        }
        else
        {
            Request.ContentType = "application/x-www-form-urlencoded";
        }

        stream_writer = new StreamWriter(Request.GetRequestStream());

        first_item = true;
        for (int i = 0; i < Items.Count; i++)
        {
            FormItem item = (FormItem)Items[i];

            Write(item);
        }

        if (multipart)
        {
            stream_writer.Write(end_boundary + "\r\n");
        }

        stream_writer.Flush();
        stream_writer.Close();

        HttpWebResponse response;

        try {
            response = (HttpWebResponse)Request.GetResponse();

            //Console.WriteLine ("found {0} cookies", response.Cookies.Count);

            foreach (Cookie c in response.Cookies)
            {
                Cookies.Add(c);
            }
        } catch (WebException e) {
            if (e.Status == WebExceptionStatus.ProtocolError &&
                ((HttpWebResponse)e.Response).StatusCode == HttpStatusCode.ExpectationFailed && expect_continue)
            {
                e.Response.Close();
                expect_continue = false;
                return(Submit(uri, progress_item));
            }

            throw new WebException(Mono.Unix.Catalog.GetString("Unhandled exception"), e);
        }

        return(response);
    }
 public HttpWebResponse Submit(string url, FSpot.ProgressItem item)
 {
     return(Submit(new Uri(url), item));
 }