protected void ExecuteUpload(IExecutePicasaUploaderWorkflowMessage message, ClientLoginAuthenticator picasaAuthenticator, PicasaEntry picasaEntry)
		{
			var cancellationTokenSource = new CancellationTokenSource();
			var cancellationToken = cancellationTokenSource.Token;

			var task = Task.Factory.StartNew(()=>{});
			task.ContinueWith((t) =>
				{
					if (!cancellationToken.IsCancellationRequested)
					{
						PicasaUploaderService.Uploaders.Add(message, new CancellableTask
						{
							Task = task,
							CancellationTokenSource = cancellationTokenSource
						});

						var resumableUploader = new ResumableUploader(message.Settings.Upload.ChunkSize);

						resumableUploader.AsyncOperationCompleted += OnResumableUploaderAsyncOperationCompleted;
						resumableUploader.AsyncOperationProgress += OnResumableUploaderAsyncOperationProgress;

						cancellationToken.Register(() => resumableUploader.CancelAsync(message));
						resumableUploader.InsertAsync(picasaAuthenticator, picasaEntry, message);
					}
					cancellationToken.ThrowIfCancellationRequested();
				}
				, cancellationToken);
		}
Example #2
0
 /// <summary>
 /// constructs a tag accessor for the passed in entry
 /// </summary>
 /// <param name="entry"></param>
 public TagAccessor(PicasaEntry entry)
 {
     this.entry = entry;
     if (!entry.IsTag)
     {
         throw new ArgumentException("Entry is not a tag", "entry");
     }
 }
 /// <summary>
 /// constructs a photo accessor for the passed in entry
 /// </summary>
 /// <param name="entry"></param>
 public PhotoAccessor(PicasaEntry entry)
 {
     this.entry = entry;
     if (entry.IsPhoto == false)
     {
         throw new ArgumentException("Entry is not a photo", "entry");
     }
 }
 /// <summary>
 /// constructs a photo accessor for the passed in entry
 /// </summary>
 /// <param name="entry"></param>
 public CommentAccessor(PicasaEntry entry)
 {
     this.entry = entry;
     if (entry.IsComment == false)
     {
         throw new ArgumentException("Entry is not a comment", "entry");
     }
 }
Example #5
0
 /// <summary>
 /// constructs a photo accessor for the passed in entry
 /// </summary>
 /// <param name="entry"></param>
 public AlbumAccessor(PicasaEntry entry)
 {
     this.entry = entry;
     if (!entry.IsAlbum)
     {
         throw new ArgumentException("Entry is not a album", "entry");
     }
 }
Example #6
0
 /// <summary>
 /// constructs a photo accessor for the passed in entry
 /// </summary>
 /// <param name="entry"></param>
 public AlbumAccessor(PicasaEntry entry)
 {
     this.entry = entry;
     if (!entry.IsAlbum)
     {
         throw new ArgumentException("Entry is not a album", "entry");
     }
 }
Example #7
0
 /// <summary>
 /// constructs a photo accessor for the passed in entry
 /// </summary>
 /// <param name="entry"></param>
 public CommentAccessor(PicasaEntry entry)
 {
     this.entry = entry;
     if (entry.IsComment == false)
     {
         throw new ArgumentException("Entry is not a comment", "entry");
     }
 }
Example #8
0
 /// <summary>
 /// constructs a tag accessor for the passed in entry
 /// </summary>
 /// <param name="entry"></param>
 public TagAccessor(PicasaEntry entry)
 {
     this.entry = entry;
     if (!entry.IsTag)
     {
         throw new ArgumentException("Entry is not a tag", "entry");
     }
 }
 /// <summary>
 /// constructs a photo accessor for the passed in entry
 /// </summary>
 /// <param name="entry"></param>
 public PhotoAccessor(PicasaEntry entry)
 {
     this.entry = entry;
     if (entry.IsPhoto == false)
     {
         throw new ArgumentException("Entry is not a photo", "entry");
     }
 }
Example #10
0
 public void MediaTest()
 {
     PicasaEntry target = new PicasaEntry(); // TODO: Initialize to an appropriate value
     MediaGroup expected = new MediaGroup();
     MediaGroup actual;
     target.Media = expected;
     actual = target.Media;
     Assert.AreEqual(expected, actual);
 }
Example #11
0
 public void WeightTest()
 {
     PicasaEntry entry = new PicasaEntry();
     entry.IsTag = true;
     TagAccessor target = new TagAccessor(entry); // TODO: Initialize to an appropriate value
     uint expected = 5; // TODO: Initialize to an appropriate value
     uint actual;
     target.Weight = expected;
     actual = target.Weight;
     Assert.AreEqual(expected, actual);
 }
 public PicasaWebPhoto(PicasaEntry photo, string albumName)
 {
     PhotoAccessor pa = new PhotoAccessor(photo);
     this.m_accessId = pa.Id;
     this.m_media = photo.Media;
     this.m_id = photo.Id.Uri.ToString();
     this.m_title = photo.Title.Text;
     this.m_albumName = albumName;
     this.m_height = pa.Height;
     this.m_width = pa.Width;
     this.m_uploaded = photo.Updated.ToShortDateString() + " " + photo.Updated.ToShortTimeString();
     this.m_location = (string)photo.Media.Content.Attributes["url"];
     pa = null;
 }
Example #13
0
        internal PicasaAlbumInfo(PicasaEntry album, PicasaService picasaService)
        {
            if (picasaService == null)
                throw new ArgumentNullException("picasaService", "picasaService is null.");
            if (album == null)
                throw new ArgumentNullException("album", "album is null.");

            _picasaService = picasaService;
            _album = album;

            NumPhotos = Int32.Parse(_album.GetPhotoExtensionValue(GPhotoNameTable.NumPhotos));
            RemainingPhotos = Int32.Parse(_album.GetPhotoExtensionValue(GPhotoNameTable.NumPhotosRemaining));
            Title = _album.Title.Text;
            if (_album.Media.Thumbnails != null && _album.Media.Thumbnails.Count > 0)
                AlbumCover = new Bitmap(_picasaService.Query(new Uri((string)_album.Media.Thumbnails[0].Attributes["url"])));
            Id = _album.GetPhotoExtensionValue(GPhotoNameTable.Id);
        }
Example #14
0
        public static WebControl BuildImageFromPicasaEntry(PicasaEntry entry)
        {
            WebControl link = new WebControl(HtmlTextWriterTag.A);
            link.Attributes.Add("href", (String)entry.Media.Thumbnails[1].Attributes["url"]/*(String) entry.Media.Content.Attributes["url"]*/);
            link.CssClass = "thickbox";

            Photo pa = new Photo();
            pa.AtomEntry = entry;

            Image image = new Image();
            image.AlternateText = pa.Title;

            image.ImageUrl = (String)entry.Media.Thumbnails[0].Attributes["url"];

            link.Controls.Add(image);

            return link;
        }
        private void Ok_Click(object sender, System.EventArgs e)
        {
            AlbumEntry entry = new AlbumEntry();
            AlbumAccessor acc = new AlbumAccessor(entry);
            entry.Title.Text = this.AlbumName.Text;
            entry.Summary.Text = this.AlbumDescription.Text;
            if (this.AlbumLocation.Text.Length > 0) 
            {
                acc.Location = this.AlbumLocation.Text;
            }
            if (this.AlbumKeywords.Text.Length > 0) 
            {
                entry.Media = new MediaGroup();
                MediaKeywords keywords = new MediaKeywords(this.AlbumKeywords.Text);
                entry.Media.Keywords = keywords;
            }
            acc.Access = this.AlbumPublic.Checked ? "public" : "private";
            acc.CommentingEnabled = this.AllowComments.Checked;

            this.newEntry = this.service.Insert(this.feed, entry); 
            this.Close();

        }
Example #16
0
 public void TagAccessorConstructorTest()
 {
     PicasaEntry entry = new PicasaEntry();
     entry.IsTag = true;
     TagAccessor target = new TagAccessor(entry);
     Assert.IsNotNull(target);
 }
Example #17
0
 public void ExifTest()
 {
     PicasaEntry target = new PicasaEntry(); // TODO: Initialize to an appropriate value
     ExifTags expected = new ExifTags();
     ExifTags actual;
     target.Exif = expected;
     actual = target.Exif;
     Assert.AreEqual(expected, actual);
 }
Example #18
0
 public void setPhotoExtensionTest()
 {
     PicasaEntry target = new PicasaEntry(); // TODO: Initialize to an appropriate value
     string extension = GPhotoNameTable.Photoid;
     string newValue = "theid";
     SimpleElement actual;
     actual = target.SetPhotoExtensionValue(extension, newValue);
     Assert.IsTrue(actual is GPhotoPhotoId);
     Assert.AreEqual(newValue, actual.Value);
 }
        public static object GetMinDateKey(PicasaEntry picasaEntry, Dictionary<object, List<object>> driveKeys)
        {
            var photo = new PhotoAccessor(picasaEntry);

            /*
            var value = photo.Timestamp;
            var time = DateTime.FromFileTimeUtc((long)value);
                
            var tmp = new DateTime(1970, 1, 1, 0, 0, 0);
            tmp = tmp.AddMilliseconds(value);
            
            return time;*/

            //Picasa API do not have video metadata.
            //Try to match video by size (size on google drive are the same as on picasa)

            //Make dictionary Size -> Keys from driveKeys
            var sizeToKeys = new Dictionary<string, List<object>>();
            foreach (var pair in driveKeys)
            {
                foreach (object googleObject in pair.Value)
                {
                    var googleFile = (File)googleObject;
                    long size = googleFile.FileSize.HasValue ? googleFile.FileSize.Value : 0;
                    var sizeKey = size.ToString() + "&&" + googleFile.OriginalFilename;
                    if (!sizeToKeys.ContainsKey(sizeKey))
                        sizeToKeys.Add(sizeKey, new List<object>());
                    sizeToKeys[sizeKey].Add(pair.Key);
                }
            }

            //Get key by size
            var photoKey = photo.Size.ToString() + "&&" + photo.PhotoTitle;

            if (sizeToKeys.ContainsKey(photoKey) && sizeToKeys[photoKey].Count == 1)
                return sizeToKeys[photoKey][0];

            return null;

        }
        private string GetPhotoExtensions(PicasaEntry photo)
        {
            StringBuilder info = new StringBuilder();

            foreach (var extension in photo.ExtensionElements)
            {
                info.AppendLine(extension.XmlName + " = " + photo.GetPhotoExtensionValue(extension.XmlName) + HTML_BREAK);
            }

            string output = info.ToString();

            return output;
        }
 public AlbumInfo(PicasaEntry album)
 {
     this.FeedUri = album.FeedUri;
     this.Title = album.Title.Text + " [" + album.GetPhotoExtensionValue(GPhotoNameTable.NumPhotos) + "]";
     this.Url = album.AlternateUri.Content;
 }
Example #22
0
 public void getPhotoExtensionValueTest()
 {
     PicasaEntry target = new PicasaEntry(); // TODO: Initialize to an appropriate value
     string extension = GPhotoNameTable.Photoid;
     string newValue = "theid";
     string actual = null; 
     target.SetPhotoExtensionValue(extension, newValue);
     actual = target.GetPhotoExtensionValue(extension);
     Assert.AreEqual(newValue, actual);
 }
Example #23
0
 public void LocationTest()
 {
     PicasaEntry target = new PicasaEntry(); // TODO: Initialize to an appropriate value
     GeoRssWhere expected = new GeoRssWhere(); 
     GeoRssWhere actual;
     target.Location = expected;
     actual = target.Location;
     Assert.AreEqual(expected, actual);
 }
        public static PicasaInfo RetrievePicasaInfo(PicasaEntry picasaEntry)
        {
            PhotoAccessor photoAccessor = new PhotoAccessor(picasaEntry);

            LOG.InfoFormat("Retrieving Picasa info for {0}", photoAccessor.Id);

            PicasaInfo picasaInfo = new PicasaInfo();

            picasaInfo.ID = photoAccessor.Id;
            picasaInfo.Title = picasaEntry.Title.Text;
            picasaInfo.Timestamp = picasaEntry.Updated;
            picasaInfo.Description = picasaEntry.Summary.Text;
            picasaInfo.SquareThumbnailUrl = picasaEntry.Media.Thumbnails[0].Url;
            picasaInfo.OriginalUrl = picasaEntry.Media.Content.Url;

            List<AtomLink> links = picasaEntry.Links.Where(r => r.Type.Equals("text/html", StringComparison.OrdinalIgnoreCase)).ToList();
            picasaInfo.WebUrl = string.Empty;
            if (links.Count > 0)
            {
                picasaInfo.WebUrl = links.First().HRef.ToString();
            }
            return picasaInfo;
        }
        private string GetPreviewUrl(PicasaEntry photo)
        {
            int originalWidth = int.Parse(photo.GetPhotoExtensionValue(GPhotoNameTable.Width));
            int originalHeight = int.Parse(photo.GetPhotoExtensionValue(GPhotoNameTable.Height));

            int size = originalWidth > originalHeight
                     ? Math.Min(this.previewWidth, originalWidth)
                     : Math.Min(this.previewHeight, originalHeight);

            string output = GetImageUrl(photo, size.ToString());

            return output;
        }
Example #26
0
 static public void saveImageFile(PicasaEntry entry, string filename, PicasaService service)
 {
     if (entry.Media != null &&
         entry.Media.Content != null)
     {
         Stream stream  = service.Query(new Uri(entry.Media.Content.Attributes["url"] as string));
         FileStream fs = new FileStream(filename, FileMode.OpenOrCreate);
         BinaryWriter w = new BinaryWriter(fs);
         byte []buffer = new byte[1024];
         int iRead=0;
         int iOffset = 0; 
         while ((iRead = stream.Read(buffer, 0, 1024)) > 0) 
         {
             w.Write(buffer, 0, iRead);
             iOffset += iRead;
         }
         w.Close();
         fs.Close();
     }    
 }
Example #27
0
 private void setSelection(PicasaEntry entry)
 {
     if (entry != null) 
     {
         this.Cursor = Cursors.WaitCursor;
         Stream stream  = this.picasaService.Query(new Uri(findLargestThumbnail(entry.Media.Thumbnails)));
         this.PhotoPreview.Image = new Bitmap(stream);
         this.PhotoInspector.SelectedObject = new PhotoAccessor(entry);
         this.Cursor = Cursors.Default;
     }
     else 
     {
         this.PhotoPreview.Image = null;
         this.PhotoInspector.SelectedObject = null; 
     }
 }
Example #28
0
 private void setSelection(PicasaEntry entry)
 {
     if (entry != null) 
     {
         this.Cursor = Cursors.WaitCursor;
         try
         {
             Stream stream = this.picasaService.Query(new Uri(findLargestThumbnail(entry.Media.Thumbnails)));
             this.PhotoPreview.Image = new Bitmap(stream);
         }
         catch
         {
             Icon error = new Icon(SystemIcons.Exclamation, 40, 40);
             this.PhotoPreview.Image = error.ToBitmap();
         }
         Photo photo = new Photo();
         photo.AtomEntry = entry;
         this.PhotoInspector.SelectedObject = photo;
         this.Cursor = Cursors.Default;
         this.DownloadPhoto.Enabled = true;
     }
     else 
     {
         this.PhotoPreview.Image = null;
         this.PhotoInspector.SelectedObject = null;
         this.DownloadPhoto.Enabled = false;
     }
 }
 private string GetPhotoCaption(PicasaEntry photo)
 {
     string output = HttpUtility.HtmlAttributeEncode(photo.Summary.Text).Replace(NEW_LINE, HTML_BREAK);
     return output;
 }
Example #30
0
        public void DoSaveImageFile(PicasaEntry entry, string filename)
        {
            if (entry.Media != null &&
                entry.Media.Content != null)
            {
                UserState ut = new UserState();
                ut.opType = UserState.OperationType.download;
                ut.filename = filename;
                this.states.Add(ut);

                this.picasaService.QueryStreamAync(new Uri(entry.Media.Content.Attributes["url"] as string), DateTime.MinValue, ut);
            }
        }
        private string GetPicasaUrl(PicasaEntry photo)
        {
            string url = photo.AlternateUri.ToString();
            string output;

            if (url.Contains(QUESTION_MARK))
            {
                output = url.Replace(QUESTION_MARK, NOREDIRECT + AMPERSAND);
            }
            else
            {
                int insertPosition = url.LastIndexOf(HASH);
                output = url.Insert(insertPosition, NOREDIRECT);
            }

            return output;
        }
        public static object GetPicasaKeyByDriveKey(PicasaEntry picasaEntry, Dictionary<object, List<object>> driveKeys)
        {
            //Make dictionary Size -> Keys from driveKeys
            var sizeToKeys = new Dictionary<string, List<object>>();
            foreach (var pair in driveKeys)
            {
                foreach (object googleObject in pair.Value)
                {
                    var googleFile = (File)googleObject;
                    long size = googleFile.FileSize.HasValue ? googleFile.FileSize.Value : 0;
                    var sizeKey = size.ToString() + "&&" + googleFile.OriginalFilename;
                    if (!sizeToKeys.ContainsKey(sizeKey))
                        sizeToKeys.Add(sizeKey, new List<object>());
                    sizeToKeys[sizeKey].Add(pair.Key);
                }
            }

            //Get key by size
            PhotoAccessor photo = new PhotoAccessor(picasaEntry);
            var photoKey = photo.Size.ToString() + "&&" + photo.PhotoTitle;

            if (sizeToKeys.ContainsKey(photoKey) && sizeToKeys[photoKey].Count == 1)
                return sizeToKeys[photoKey][0];
            return null;
        }
        private string GetImageUrl(PicasaEntry photo, string size)
        {
            string output;

            if (size == FULL_SIZE && photo.Media.Contents.Any(i => i.Type.StartsWith(CONTENT_VIDEO)))
            {
                output = this.GetPicasaUrl(photo);
            }
            else
            {
                string url = photo.Content.Src.ToString();
                int insertPosition = url.LastIndexOf(FORWARD_SLASH);
                output = url.Insert(insertPosition, SIZE_PREFIX + size);
            }

            return output;
        }
 private void setSelection(PicasaEntry entry)
 {
     if (entry != null) 
     {
         this.Cursor = Cursors.WaitCursor;
         MediaThumbnail thumb = entry.Media.Thumbnails[0];
         try
         {
             Stream stream = this.picasaService.Query(new Uri(thumb.Attributes["url"] as string));
             this.AlbumPicture.Image = new Bitmap(stream);
         }
         catch
         {
             Icon error = new Icon(SystemIcons.Exclamation, 40, 40);
             this.AlbumPicture.Image = error.ToBitmap();
         }
         this.AlbumInspector.SelectedObject = new AlbumAccessor(entry);
         this.Cursor = Cursors.Default;
     }
     else 
     {
         this.AlbumPicture.Image = null;
         this.AlbumInspector.SelectedObject = null; 
     }
 }