Exemplo n.º 1
0
        /// <summary>
        /// Parse the upload response
        /// </summary>
        /// <param name="response">XML</param>
        /// <returns>PhotobucketInfo object</returns>
        public static PhotobucketInfo FromUploadResponse(string response)
        {
            Log.Debug(response);
            PhotobucketInfo photobucketInfo = new PhotobucketInfo();

            try {
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(response);
                var nodes = doc.GetElementsByTagName("url");
                if (nodes.Count > 0)
                {
                    photobucketInfo.Original = nodes.Item(0)?.InnerText;
                }
                nodes = doc.GetElementsByTagName("browseurl");
                if (nodes.Count > 0)
                {
                    photobucketInfo.Page = nodes.Item(0)?.InnerText;
                }
                nodes = doc.GetElementsByTagName("thumb");
                if (nodes.Count > 0)
                {
                    photobucketInfo.Thumbnail = nodes.Item(0)?.InnerText;
                }
            } catch (Exception e) {
                Log.ErrorFormat("Could not parse Photobucket response due to error {0}, response was: {1}", e.Message, response);
            }
            return(photobucketInfo);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Upload the capture to Photobucket
        /// </summary>
        /// <param name="captureDetails"></param>
        /// <param name="surfaceToUpload">ISurface</param>
        /// <param name="uploadURL">out string for the url</param>
        /// <returns>true if the upload succeeded</returns>
        public bool Upload(ICaptureDetails captureDetails, ISurface surfaceToUpload, string albumPath, out string uploadURL)
        {
            SurfaceOutputSettings outputSettings = new SurfaceOutputSettings(config.OutputFileFormat, config.OutputFileJpegQuality, config.OutputFileAutoReduceColors);

            try {
                string          filename        = Path.GetFileName(FilenameHelper.GetFilename(config.OutputFileFormat, captureDetails));
                PhotobucketInfo photobucketInfo = null;

                // Run upload in the background
                new PleaseWaitForm().ShowAndWait("Photobucket plug-in", Language.GetString("photobucket", LangKey.communication_wait),
                                                 delegate() {
                    photobucketInfo = PhotobucketUtils.UploadToPhotobucket(surfaceToUpload, outputSettings, albumPath, captureDetails.Title, filename);
                }
                                                 );
                // This causes an exeption if the upload failed :)
                LOG.DebugFormat("Uploaded to Photobucket page: " + photobucketInfo.Page);
                uploadURL = null;
                try {
                    if (config.UsePageLink)
                    {
                        uploadURL = photobucketInfo.Page;
                        Clipboard.SetText(photobucketInfo.Page);
                    }
                    else
                    {
                        uploadURL = photobucketInfo.Original;
                        Clipboard.SetText(photobucketInfo.Original);
                    }
                } catch (Exception ex) {
                    LOG.Error("Can't write to clipboard: ", ex);
                }
                return(true);
            } catch (Exception e) {
                LOG.Error(e);
                MessageBox.Show(Language.GetString("photobucket", LangKey.upload_failure) + " " + e.Message);
            }
            uploadURL = null;
            return(false);
        }
Exemplo n.º 3
0
		/// <summary>
		/// Parse the upload response
		/// </summary>
		/// <param name="response">XML</param>
		/// <returns>PhotobucketInfo object</returns>
		public static PhotobucketInfo FromUploadResponse(string response) {
			LOG.Debug(response);
			PhotobucketInfo PhotobucketInfo = new PhotobucketInfo();
			try {
				XmlDocument doc = new XmlDocument();
				doc.LoadXml(response);
				XmlNodeList nodes;
				nodes = doc.GetElementsByTagName("url");
				if(nodes.Count > 0) {
					PhotobucketInfo.Original = nodes.Item(0).InnerText;
				}
				nodes = doc.GetElementsByTagName("browseurl");
				if(nodes.Count > 0) {
					PhotobucketInfo.Page = nodes.Item(0).InnerText;
				}
				nodes = doc.GetElementsByTagName("thumb");
				if(nodes.Count > 0) {
					PhotobucketInfo.Thumbnail = nodes.Item(0).InnerText;
				}
			} catch(Exception e) {
				LOG.ErrorFormat("Could not parse Photobucket response due to error {0}, response was: {1}", e.Message, response);
			}
			return PhotobucketInfo;
		}
Exemplo n.º 4
0
        /// <summary>
        /// Do the actual upload to Photobucket
        /// For more details on the available parameters, see: http://api.Photobucket.com/resources_anon
        /// </summary>
        /// <returns>PhotobucketResponse</returns>
        public static PhotobucketInfo UploadToPhotobucket(ISurface surfaceToUpload, SurfaceOutputSettings outputSettings, string albumPath, string title, string filename)
        {
            string responseString;

            if (string.IsNullOrEmpty(albumPath))
            {
                albumPath = "!";
            }

            OAuthSession oAuth = createSession(true);

            if (oAuth == null)
            {
                return(null);
            }
            IDictionary <string, object> signedParameters = new Dictionary <string, object>();

            // add album
            if (albumPath == null)
            {
                signedParameters.Add("id", config.Username);
            }
            else
            {
                signedParameters.Add("id", albumPath);
            }
            // add type
            signedParameters.Add("type", "image");
            // add title
            if (title != null)
            {
                signedParameters.Add("title", title);
            }
            // add filename
            if (filename != null)
            {
                signedParameters.Add("filename", filename);
            }
            IDictionary <string, object> unsignedParameters = new Dictionary <string, object>();

            // Add image
            unsignedParameters.Add("uploadfile", new SurfaceContainer(surfaceToUpload, outputSettings, filename));
            try {
                string apiUrl = "http://api.photobucket.com/album/!/upload";
                responseString = oAuth.MakeOAuthRequest(HTTPMethod.POST, apiUrl, apiUrl.Replace("api.photobucket.com", config.SubDomain), signedParameters, unsignedParameters, null);
            } catch (Exception ex) {
                LOG.Error("Error uploading to Photobucket.", ex);
                throw;
            } finally {
                if (!string.IsNullOrEmpty(oAuth.Token))
                {
                    config.Token = oAuth.Token;
                }
                if (!string.IsNullOrEmpty(oAuth.TokenSecret))
                {
                    config.TokenSecret = oAuth.TokenSecret;
                }
            }
            if (responseString == null)
            {
                return(null);
            }
            LOG.Info(responseString);
            PhotobucketInfo PhotobucketInfo = PhotobucketInfo.FromUploadResponse(responseString);

            LOG.Debug("Upload to Photobucket was finished");
            return(PhotobucketInfo);
        }