Exemplo n.º 1
0
        static void Main(string[] args)
        {
            DbUtils.OpenDbContext(db =>
            {
                // clear Db
                db.Database.ExecuteSqlCommand("DELETE FROM [Album]");
                //
                PicasaService service = new PicasaService("");
                var feed = default(PicasaFeed);
                // add albums
                {

                    AlbumQuery albumQuery = new AlbumQuery(PicasaQuery.CreatePicasaUri("109913968155621160630"));
                    feed = service.Query(albumQuery);
                    foreach (PicasaEntry entry in feed.Entries)
                    {
                        var apiAlbum = new AlbumAccessor(entry);
                        db.Albums.Add(new Album
                        {
                            ExternalId = apiAlbum.Id,
                            Name = apiAlbum.AlbumTitle,
                            CoverPath = entry.Media.Thumbnails[0].Url,
                            IsActive = false
                        });
                    }
                    db.SaveChanges();
                }
                // add images to albums
                {
                    foreach (var dbAlbum in db.Albums)
                    {
                        PhotoQuery photoQuery = new PhotoQuery(PicasaQuery.CreatePicasaUri("109913968155621160630", dbAlbum.ExternalId));
                        feed = service.Query(photoQuery);
                        foreach (PicasaEntry entry in feed.Entries)
                        {
                            dbAlbum.AlbumImages.Add(new AlbumImage
                            {
                                Name = entry.Title.Text,
                                Path = entry.Media.Contents[0].Url,
                                Thumbnail = entry.Media.Thumbnails[entry.Media.Thumbnails.Count - 1].Url,
                                Description = entry.Media.Description.Value
                            });
                        }
                    }
                    db.SaveChanges();
                }
            });
        }
		private void AuthenticatePicasaButton_Click(object sender, RoutedEventArgs e)
		{
		    authenticatePicasaButton.IsEnabled = false;
		    authenticatePicasaLabel.Content = "";
			try
			{
			    var query = new PhotoQuery(PicasaQuery.CreatePicasaUri(DataModel.Element.PicasaUsername));
			    query.NumberToRetrieve = 1;

			    var picasaService = new PicasaService(DataModel.Element.ApplicationName);
			    picasaService.setUserCredentials(DataModel.Element.GoogleUsername, DataModel.Element.GooglePassword);

			    var feed = picasaService.Query(query);

			    authenticatePicasaLabel.Content = "Authentication Successful";
			}
			catch (Exception exception)
			{
			    authenticatePicasaLabel.Content = "Authentication Failure";
			}
			finally
			{
                authenticatePicasaButton.IsEnabled = true;
			}
		}
Exemplo n.º 3
0
        public GoogleService(string username, string password)
        {
            // init the service
            this.username = username;
            service = new PicasaService(AppName);
            service.setUserCredentials(username, password);

            // cache albums
            AlbumQuery query = new AlbumQuery(PicasaQuery.CreatePicasaUri(username));
            PicasaFeed feed = service.Query(query);
            foreach (PicasaEntry entry in feed.Entries)
            {
                Album a = new Album();
                a.AtomEntry = entry;
                cache[a.Title] = a;
            }
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
        public static string GetAlbum(string album)
        {
            string retVal;
            try
            {
                var service = new PicasaService("exampleCo-exampleApp-1");

                string usr = Settings.GetSingleValue("Account") + "@gmail.com";
                string pwd = Settings.GetSingleValue("Password");

                service.setUserCredentials(usr, pwd);

                var query = new PhotoQuery(PicasaQuery.CreatePicasaUri(usr, album));
                PicasaFeed feed = service.Query(query);

                retVal = "<ul id=\"AlbumList\">";
                foreach (PicasaEntry entry in feed.Entries)
                {
                    var firstThumbUrl = entry.Media.Thumbnails[0].Attributes["url"] as string;
                    string thumGrp = "/s" + Settings.GetSingleValue("PicWidth") + "/";

                    if (firstThumbUrl != null) firstThumbUrl = firstThumbUrl.Replace("/s72/", thumGrp);

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

                    if (contentUrl != null) contentUrl = contentUrl.Substring(0, contentUrl.LastIndexOf("/"));

                    contentUrl += "/s640/" + entry.Title.Text;

                    retVal += string.Format(Img, firstThumbUrl, contentUrl);
                }
                retVal += "</ul>";
            }
            catch (Exception qex)
            {
                retVal = qex.Message;
            }
            return retVal;
        }
        /// <summary>
        /// Syncs a local folder to an online Picasa Web Album location
        /// </summary>
        /// <param name="sourceFolder">The source folder to sync.</param>
        /// <param name="albumNamePrefix">A prefix to prepend to the album name.</param>
        /// <param name="includeSubFolders">Indicated whether to sync all subfolders recursively.</param>
        /// <param name="session">The current authenticated Picasa session.</param>
        /// <param name="albumFeed">A feed listing all existing Picass Web Albums in the Picasa account.</param>
        private void SyncFolder(DirectoryInfo sourceFolder, string albumNamePrefix, AlbumAccessEnum targetAlbumAccess, bool includeSubFolders, PicasaService session, PicasaFeed albumFeed)
        {
            if (!sourceFolder.Exists)
            {
                throw new DirectoryNotFoundException(string.Format("Folder '{0}' cannot be located.", sourceFolder.FullName));
            }

            string targetAlbumName = GetTargetAlbumName(sourceFolder, albumNamePrefix);
            Dictionary<string, FileInfo> sourceFiles = GetSourceFiles(sourceFolder);
            bool excludeFolder = ShouldExcludeFolder(sourceFolder, sourceFiles);
            PicasaEntry existingAlbumEntry = albumFeed.Entries.FirstOrDefault(a => a.Title.Text == targetAlbumName) as PicasaEntry;

            if (excludeFolder)
            {
                if (existingAlbumEntry != null && !this.AddOnly)
                {
                    //album needs to be removed
                    WriteOutput(string.Format("Removing Album: {0} (excluded but already exists)", targetAlbumName));
                    existingAlbumEntry.Delete();
                    existingAlbumEntry.Summary.Text = ENTRY_DELETED_SUMMARY;
                    m_albumDeleteCount++;
                }
                else
                {
                    m_folderSkipCount++;
                }
            }
            else
            {
                WriteOutput(string.Format("Syncing Folder: {0} to Album: {1}", sourceFolder.FullName, targetAlbumName), true);

                try
                {
                    targetAlbumAccess = DetermineAlbumAccess(sourceFolder, targetAlbumAccess);

                    if (sourceFiles.Count > 0)
                    {
                        Album targetAlbum = new Album();
                        if (existingAlbumEntry != null)
                        {
                            targetAlbum.AtomEntry = existingAlbumEntry;
                            if (targetAlbum.Access != targetAlbumAccess.ToString().ToLower())
                            {
                                UpdateAlbumAccess(session, targetAlbum, targetAlbumAccess);
                            }
                        }
                        else
                        {
                            targetAlbum = CreateAlbum(session, albumFeed, targetAlbumName, targetAlbumAccess);
                        }

                        PhotoQuery existingAlbumPhotosQuery = new PhotoQuery(PicasaQuery.CreatePicasaUri(this.PicasaUsername, targetAlbum.Id));
                        PicasaFeed existingAlbumPhotosFeed = session.Query(existingAlbumPhotosQuery);

                        //sync folder files
                        DeleteFilesFromAlbum(sourceFiles, existingAlbumPhotosFeed);

                        foreach (KeyValuePair<string, FileInfo> file in sourceFiles.OrderBy(f => f.Value.LastWriteTime))
                        {
                            AddFileToAlbum(file.Value, targetAlbum, existingAlbumPhotosFeed, session);
                        }
                    }
                }
                catch (Exception ex)
                {
                    WriteOutput(string.Format("Skipping Folder: {0} (Error - {1})", sourceFolder.Name, ex.Message), true);
                }

                if (includeSubFolders)
                {
                    DirectoryInfo[] subfolders = sourceFolder.GetDirectories().OrderBy(d => d.CreationTime).ToArray();
                    if (subfolders.Length > 0)
                    {
                        foreach (DirectoryInfo folder in subfolders)
                        {
                            SyncFolder(folder, targetAlbumName, targetAlbumAccess, includeSubFolders, session, albumFeed);
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Syncs a local folder to an online Picasa Web Album location
        /// </summary>
        /// <param name="folderPath">The source folder to sync.</param>
        public void SyncFolder(string folderPath)
        {
            ResetCounters();
            PicasaService session = new PicasaService("PicasaWebSync");
            session.setUserCredentials(this.PicasaUsername, this.PicasaPassword);
            AlbumQuery query = new AlbumQuery(PicasaQuery.CreatePicasaUri(this.PicasaUsername));

            try
            {
                WriteOutput("[Connecting to Picasa web service]");
                //fetch all albums
                PicasaFeed albumFeed = session.Query(query);

                WriteOutput("[Starting sync]");

                folderPath = folderPath.TrimEnd(new char[] { '\\' });
                DirectoryInfo sourceFolder = new DirectoryInfo(folderPath);
                m_baseDirectoryName = sourceFolder.Name;

                SyncFolder(sourceFolder, null, this.AlbumAccess, this.IncludeSubFolders, session, albumFeed);
            }
            catch (GDataRequestException gdrex)
            {
                if (gdrex.ResponseString.Contains(GDATA_RESPONSE_BADAUTH))
                {
                    throw new AuthenticationException("Picasa error - username and/or password is incorrect!  Check the config file values.");
                }
                else
                {
                    throw new Exception(string.Format("Picasa error - {0}", gdrex.ResponseString));
                }
            }

            WriteOutput("[Done]");
            WriteOutput(string.Empty);
            WriteOutput("Summary:");
            WriteOutput(string.Format("  Folders skipped: {0}", m_folderSkipCount.ToString()));
            WriteOutput(string.Format("   Albums created: {0}", m_albumCreateCount.ToString()));
            WriteOutput(string.Format("   Albums updated: {0}", m_albumUpdateCount.ToString()));
            WriteOutput(string.Format("   Albums deleted: {0}", m_albumDeleteCount.ToString()));
            WriteOutput(string.Format("   Files uploaded: {0}", m_fileCreateCount.ToString()));
            WriteOutput(string.Format("    Files removed: {0}", m_fileDeleteCount.ToString()));
            WriteOutput(string.Format("    Files skipped: {0}", m_fileSkipCount.ToString()));
            WriteOutput(string.Format("   Errors occured: {0}", m_errorsCount.ToString()));
            WriteOutput(string.Format("     Elapsed time: {0}", (DateTime.Now - m_startTime).ToString()));
        }
Exemplo n.º 8
0
        public static PicasaEntry RetrievePicasaEntry(string id)
        {
            PicasaService service = new PicasaService(Picasa_APPLICATION_NAME);
            service.setUserCredentials(config.Username, config.Password);

            PhotoQuery photoQuery = new PhotoQuery(PicasaQuery.CreatePicasaUri(config.Username, string.Empty, id));
            photoQuery.NumberToRetrieve = 1;
            PicasaFeed picasaFeed = service.Query(photoQuery);

            if (picasaFeed.Entries.Count > 0)
            {
                return  (PicasaEntry)picasaFeed.Entries[0];
            }

            return null;
        }
    protected string GetAlbumsTable()
    {
        if (string.IsNullOrEmpty(Settings.GetSingleValue("Account"))) return string.Empty;

        var service = new PicasaService("exampleCo-exampleApp-1");

        string usr = Settings.GetSingleValue("Account") + "@gmail.com";
        string pwd = Settings.GetSingleValue("Password");

        service.setUserCredentials(usr, pwd);

        var sb = new StringBuilder("<table class=\"beTable\">");

        var query = new AlbumQuery(PicasaQuery.CreatePicasaUri(usr));
        PicasaFeed feed = service.Query(query);

        sb.Append(GetHeader());

        var cnt = 0;
        foreach (PicasaEntry entry in feed.Entries)
        {
            var ac = new AlbumAccessor(entry);
            const string cell = "<td>{0}</td>";

            sb.Append(cnt%2 == 0 ? "<tr>" : "<tr class=\"alt\">");

            // thumbnail
            string albumUri = ((Google.GData.Client.AtomEntry)(entry)).AlternateUri.ToString();
            string firstThumbUrl = entry.Media.Thumbnails[0].Attributes["url"] as string;
            string thumbAncr = string.Format("<a href=\"{2}\"><img src=\"{0}\" alt=\"{1}\" width=\"40\" /></a>",
                         firstThumbUrl, entry.Title.Text, albumUri);
            sb.Append(string.Format(cell, thumbAncr));

            // title
            sb.Append(string.Format(cell, ac.AlbumTitle));

            // description
            sb.Append(string.Format(cell, ac.AlbumSummary + "&nbsp;"));

            // number of photos
            sb.Append(string.Format(cell, ac.NumPhotos));

            // access
            sb.Append(string.Format(cell, ac.Access));

            // extension tag
            string feedUri = entry.FeedUri;
            const string showTag = "[PicasaShow:{0}]";
            const string albmTag = "[PicasaAlbum:{0}]";

            if (ac.Access.ToLower() == "protected")
            {
                sb.Append(string.Format(cell, "&nbsp;"));
                sb.Append(string.Format(cell, "&nbsp;"));
            }
            else
            {
                sb.Append(string.Format(cell, string.Format(showTag, ac.AlbumTitle)));
                sb.Append(string.Format(cell, string.Format(albmTag, ac.AlbumTitle)));
            }

            sb.Append("</tr>");
            cnt++;
        }

        return sb + "</table>";
    }
Exemplo n.º 10
0
        /////////////////////////////////////////////////////////////////////////////

        //////////////////////////////////////////////////////////////////////
        /// <summary>tries to insert a photo using MIME multipart</summary> 
        //////////////////////////////////////////////////////////////////////
        [Test] public void InsertMimePhotoTest()
        {
            Tracing.TraceMsg("Entering InsertMimePhotoTest");

            AlbumQuery query = new AlbumQuery();
            PicasaService service = new PicasaService("unittests");
           
            if (this.defaultPhotosUri != null)
            {
                if (this.userName != null)
                {
                    service.Credentials = new GDataCredentials(this.userName, this.passWord);
                }

                query.Uri = new Uri(this.defaultPhotosUri);

                PicasaFeed feed = service.Query(query);
                if (feed != null)
                {
                    
                    Assert.IsTrue(feed.Entries != null, "the albumfeed needs entries");
                    Assert.IsTrue(feed.Entries[0] != null, "the albumfeed needs at least ONE entry");

                    PicasaEntry album = feed.Entries[0] as PicasaEntry;

                    PhotoEntry newPhoto = new PhotoEntry();
                    newPhoto.Title.Text = "this is a title";
                    newPhoto.Summary.Text = "A lovely shot in the ocean";

                    newPhoto.MediaSource = new MediaFileSource(this.resourcePath + "testnet.jpg", "image/jpeg");

                    Uri postUri = new Uri(album.FeedUri.ToString());

                    PicasaEntry entry = service.Insert(postUri, newPhoto) as PicasaEntry;

                    Assert.IsTrue(entry.IsPhoto, "the new entry should be a photo entry");

                    entry.Title.Text = "This is a new Title";
                    entry.Summary.Text = "A lovely shot in the shade";
                    entry.MediaSource = new MediaFileSource(this.resourcePath + "testnet.jpg", "image/jpeg");
                    PicasaEntry updatedEntry = entry.Update() as PicasaEntry;
                    Assert.IsTrue(updatedEntry.IsPhoto, "the new entry should be a photo entry");
                    Assert.IsTrue(updatedEntry.Title.Text == "This is a new Title", "The titles should be identical");
                    Assert.IsTrue(updatedEntry.Summary.Text == "A lovely shot in the shade", "The summariesa should be identical");


                }
            }
        }
Exemplo n.º 11
0
        private static string GetSlideShow(string albumId)
        {
            string s;
            try
            {
                var service = new PicasaService("exampleCo-exampleApp-1");
                string usr = Settings.GetSingleValue("Account") + "@gmail.com";
                string pwd = Settings.GetSingleValue("Password");
                service.setUserCredentials(usr, pwd);

                var query = new AlbumQuery(PicasaQuery.CreatePicasaUri(usr));
                PicasaFeed feed = service.Query(query);

                string id = "";
                string key = "";

                foreach (PicasaEntry entry in feed.Entries)
                {
                    var ac = new AlbumAccessor(entry);

                    if (ac.Name == albumId)
                    {
                        id = ac.Id;
                        string feedUri = entry.FeedUri;
                        if (feedUri.Contains("authkey="))
                        {
                            string authKey = feedUri.Substring(feedUri.IndexOf("authkey=")).Substring(8);
                            key = authKey;
                        }
                    }
                }

                if (key.Length > 0) key = "authkey%3D" + key;

                string user = Settings.GetSingleValue("Account");

                string auto = "";
                if (bool.Parse(Settings.GetSingleValue("AutoPlay")) == false)
                {
                    auto = "&noautoplay=1";
                }

                string width = Settings.GetSingleValue("ShowWidth");
                string height = "96";

                if (int.Parse(width) > 0)
                {
                    height = (int.Parse(width) * 0.74).ToString();
                }
                s = string.Format(Tag, id, key, user, auto, width, height);
            }
            catch (Exception exp)
            {
                s = exp.Message;
            }
            return s;
        }
Exemplo n.º 12
0
        public static List<PicasaAlbum> GetAlbums()
        {
            Settings = ExtensionManager.GetSettings("Picasa2");
            if (string.IsNullOrEmpty(Settings.GetSingleValue("Account"))) return null;

            var service = new PicasaService("exampleCo-exampleApp-1");

            string usr = Settings.GetSingleValue("Account") + "@gmail.com";
            string pwd = Settings.GetSingleValue("Password");

            service.setUserCredentials(usr, pwd);

            var query = new AlbumQuery(PicasaQuery.CreatePicasaUri(usr));
            PicasaFeed feed = service.Query(query);

            var albums = new List<PicasaAlbum>();
            foreach (PicasaEntry entry in feed.Entries)
            {
                var ac = new AlbumAccessor(entry);

                // thumbnail
                string albumUri = ((Google.GData.Client.AtomEntry)(entry)).AlternateUri.ToString();
                string firstThumbUrl = entry.Media.Thumbnails[0].Attributes["url"] as string;
                albums.Add(new PicasaAlbum() { Accessor = ac, ThumbNailURl = firstThumbUrl, AlbumUri = albumUri });

            }
            return albums;
        }
Exemplo n.º 13
0
        /////////////////////////////////////////////////////////////////////////////

        
        //////////////////////////////////////////////////////////////////////
        /// <summary>runs an authentication test, inserts a new photo</summary> 
        //////////////////////////////////////////////////////////////////////
        [Test] public void InsertPhotoTest()
        {
            Tracing.TraceMsg("Entering InsertPhotoTest");

            AlbumQuery query = new AlbumQuery();
            PicasaService service = new PicasaService("unittests");
           
            if (this.defaultPhotosUri != null)
            {
                if (this.userName != null)
                {
                    service.Credentials = new GDataCredentials(this.userName, this.passWord);
                }

                query.Uri = new Uri(this.defaultPhotosUri);

                PicasaFeed feed = service.Query(query);
                if (feed != null)
                {
                    Assert.IsTrue(feed.Entries != null, "the albumfeed needs entries");
                    Assert.IsTrue(feed.Entries[0] != null, "the albumfeed needs at least ONE entry");
                    PicasaEntry album = feed.Entries[0] as PicasaEntry;
                    Assert.IsTrue(album != null, "should be an album there");
                    Assert.IsTrue(album.FeedUri != null, "the albumfeed needs a feed URI, no photo post on that one");
                    Uri postUri = new Uri(album.FeedUri.ToString());
                    FileStream fs = File.OpenRead("testnet.jpg");
                    PicasaEntry entry = service.Insert(postUri, fs, "image/jpeg", "testnet.jpg") as PicasaEntry;
                    Assert.IsTrue(entry.IsPhoto, "the new entry should be a photo entry");

                    entry.Title.Text = "This is a new Title";
                    entry.Summary.Text = "A lovely shot in the shade";
                    PicasaEntry updatedEntry = entry.Update() as PicasaEntry;
                    Assert.IsTrue(updatedEntry.IsPhoto, "the new entry should be a photo entry");
                    Assert.IsTrue(updatedEntry.Title.Text == "This is a new Title", "The titles should be identical");
                    Assert.IsTrue(updatedEntry.Summary.Text == "A lovely shot in the shade", "The summariesa should be identical");


                }
            }
        }
Exemplo n.º 14
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();
     }    
 }
Exemplo n.º 15
0
        public static List<PicasaPhoto> GetAlbumContent(string album)
        {
            List<PicasaPhoto> retVal = new List<PicasaPhoto>();
            try
            {
                var service = new PicasaService("exampleCo-exampleApp-1");

                string usr = Settings.GetSingleValue("Account") + "@gmail.com";
                string pwd = Settings.GetSingleValue("Password");

                service.setUserCredentials(usr, pwd);

                var query = new PhotoQuery(PicasaQuery.CreatePicasaUri(usr, album));
                PicasaFeed feed = service.Query(query);

                foreach (PicasaEntry entry in feed.Entries)
                {
                    var firstThumbUrl = entry.Media.Thumbnails[0].Attributes["url"] as string;
                    string thumGrp = "/s" + Settings.GetSingleValue("PicWidth") + "/";

                    if (firstThumbUrl != null) firstThumbUrl = firstThumbUrl.Replace("/s72/", thumGrp);

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

                    if (contentUrl != null) contentUrl = contentUrl.Substring(0, contentUrl.LastIndexOf("/"));

                    contentUrl += "/s640/" + entry.Title.Text;

                    retVal.Add(new PicasaPhoto() { Title = entry.Summary.Text, ImageSrc = contentUrl, Url = firstThumbUrl });
                }
            }
            catch
            {
                retVal = null;
            }
            return retVal;
        }
Exemplo n.º 16
0
        /////////////////////////////////////////////////////////////////////////////

        //////////////////////////////////////////////////////////////////////
        /// <summary>runs an authentication test, iterates all entries</summary> 
        //////////////////////////////////////////////////////////////////////
        [Test] public void QueryPhotosTest()
        {
            Tracing.TraceMsg("Entering PhotosQueryPhotosTest");

            PhotoQuery query = new PhotoQuery();
            PicasaService service = new PicasaService("unittests");
           
            if (this.defaultPhotosUri != null)
            {
                if (this.userName != null)
                {
                    service.Credentials = new GDataCredentials(this.userName, this.passWord);
                }

                GDataLoggingRequestFactory factory = (GDataLoggingRequestFactory) this.factory;
                factory.MethodOverride = true;
                service.RequestFactory = this.factory; 

                query.Uri = new Uri(this.defaultPhotosUri);
                PicasaFeed feed = service.Query(query);

                ObjectModelHelper.DumpAtomObject(feed,CreateDumpFileName("PhotoAuthTest")); 
     
                if (feed != null && feed.Entries.Count > 0)
                {
                    Tracing.TraceMsg("Found a Feed " + feed.ToString());
                    DisplayExtensions(feed);

                    foreach (PicasaEntry entry in feed.Entries)
                    {
                        Tracing.TraceMsg("Found an entry " + entry.ToString());
                        DisplayExtensions(entry);

                        GeoRssWhere w = entry.Location;
                        if (w != null)
                        {
                            Tracing.TraceMsg("Found an location " + w.Latitude + w.Longitude);
                        }

                        ExifTags tags = entry.Exif;
                        if (tags != null)
                        {
                            Tracing.TraceMsg("Found an exif block ");
                        }

                        MediaGroup group = entry.Media;
                        if (group != null)
                        {
                            Tracing.TraceMsg("Found a media Group");
                            if (group.Title != null)
                            {
                                Tracing.TraceMsg(group.Title.Value);
                            }
                            if (group.Keywords != null)
                            {
                                Tracing.TraceMsg(group.Keywords.Value);
                            }
                            if (group.Credit != null)
                            {
                                Tracing.TraceMsg(group.Credit.Value);
                            }
                            if (group.Description != null)
                            {
                                Tracing.TraceMsg(group.Description.Value);
                            }
                        }


                        PhotoAccessor photo = new PhotoAccessor(entry);

                        Assert.IsTrue(entry.IsPhoto, "this is a photo entry, it should have the kind set");
                        Assert.IsTrue(photo != null, "this is a photo entry, it should convert to PhotoEntry");

                        Assert.IsTrue(photo.AlbumId != null);
                        Assert.IsTrue(photo.Height > 0);
                        Assert.IsTrue(photo.Width > 0);
                    }
                }

                factory.MethodOverride = false;
            }
        }
        private void LoadAlbumBackground(object sender, DoWorkEventArgs e)
        {
            //albums = new List<PicasaEntry>();
              //albumIndex = -1;

              // Prepare for contact query
              string applicationName = "DigitalFrame";
              string username = settings.Username;
              string password = settings.Password;

              RequestSettings contactRequestSettings = new RequestSettings(applicationName, username, password);
              ContactsRequest contactRequest = new ContactsRequest(contactRequestSettings);

              // Request all groups of the auth user.
              //var allGroups = contactRequest.GetGroups();
              //foreach (var item in allGroups.Entries) {
              //  Debug.Write(item.Id + " - " + item.Title);
              //}

              // Get Family group entry.
              Group familyGroup;
              StringBuilder gs = new StringBuilder(GroupsQuery.CreateGroupsUri("default"));
              gs.Append("/");
              gs.Append("e"); // Family

              try {
            Feed<Group> gf = contactRequest.Get<Group>(new Uri(gs.ToString()));
            familyGroup = gf.Entries.First();
              }
              catch (AuthenticationException) {
            // We fail to get the group which means the login failed.
            return;
              }
              catch (GDataRequestException) {
            return;
              }

              // Get all contacts in Family group.
              ContactsQuery contactQuery = new ContactsQuery(ContactsQuery.CreateContactsUri("default"));
              contactQuery.Group = familyGroup.Id;
              Feed<Contact> friends = contactRequest.Get<Contact>(contactQuery);

              // Prepare for picasa query
              service = new PicasaService(applicationName);
              service.setUserCredentials(username, password);
              service.SetAuthenticationToken(service.QueryAuthenticationToken());

              allPhotos = new List<PicasaEntry>();

              foreach (var contact in friends.Entries) {
            try {
              string friendUsername = ParseUserName(contact);
              if (!string.IsNullOrEmpty(friendUsername)) {
            AlbumQuery query = new AlbumQuery();
            query.Uri = new Uri(PicasaQuery.CreatePicasaUri(friendUsername));

            PicasaFeed picasaFeed = service.Query(query);
            if (picasaFeed != null && picasaFeed.Entries.Count > 0) {
              foreach (PicasaEntry albumEntry in picasaFeed.Entries) {
                PhotoQuery photosQuery = new PhotoQuery(albumEntry.FeedUri);
                var photosFeed = (PicasaFeed)service.Query(photosQuery);
                foreach (PicasaEntry photoEntry in photosFeed.Entries) {
                  allPhotos.Add(photoEntry);
                }
              }
            }
              }
            }
            catch (LoggedException) {
              // Ignore the exception and continue.
            }
              }
        }
Exemplo n.º 18
0
        /////////////////////////////////////////////////////////////////////////////



        //////////////////////////////////////////////////////////////////////
        /// <summary>runs an authentication test</summary> 
        //////////////////////////////////////////////////////////////////////
        [Test] public void PhotosAuthenticationTest()
        {
            Tracing.TraceMsg("Entering PhotosAuthenticationTest");

            PicasaQuery query = new PicasaQuery();
            PicasaService service = new PicasaService("unittests");
            query.KindParameter = "album,tag"; 
            
            if (this.defaultPhotosUri != null)
            {
                if (this.userName != null)
                {
                    service.Credentials = new GDataCredentials(this.userName, this.passWord);
                }

                query.Uri = new Uri(this.defaultPhotosUri);
                AtomFeed feed = service.Query(query);

                ObjectModelHelper.DumpAtomObject(feed,CreateDumpFileName("PhotoAuthTest")); 

                if (feed != null && feed.Entries.Count > 0)
                {
                    Tracing.TraceMsg("Found a Feed " + feed.ToString());
                    DisplayExtensions(feed);

                    foreach (AtomEntry entry in feed.Entries)
                    {
                        Tracing.TraceMsg("Found an entry " + entry.ToString());
                        DisplayExtensions(entry);
                    }
                }
            }
        }
Exemplo n.º 19
0
        private static Google.Picasa.Album GetAlbum(PicasaService service, string id)
        {
            var query = new AlbumQuery(PicasaQuery.CreatePicasaUri("default"));
            var feed = service.Query(query);

            foreach (var album in feed.Entries.Select(e => new Google.Picasa.Album { AtomEntry = e }))
            {
                if (album.Id == id)
                    return album;
            }

            return null;
        }