public Collection<AlbumInfo> GetAlbums(string username, string password)
        {
            List<AlbumInfo> data = new List<AlbumInfo>();

            if (!string.IsNullOrEmpty(username))
            {
                if (!string.IsNullOrEmpty(password))
                {
                    this.Service.setUserCredentials(username, password);
                }

                AlbumQuery query = new AlbumQuery(PicasaQuery.CreatePicasaUri(username));
                PicasaFeed feed = this.Service.Query(query);

                foreach (PicasaEntry album in feed.Entries)
                {
                    data.Add(new AlbumInfo(album));
                }
            }

            var sorted = data.OrderBy(i => i.Title).ToList();
            Collection<AlbumInfo> output = new Collection<AlbumInfo>(sorted);

            return output;
        }
Exemplo n.º 2
0
        private static void InitializeAlbums()
        {
            m_albums = new Albums();

            AlbumQuery albumQuery = new AlbumQuery();
            albumQuery.Uri = new Uri(PicasaQuery.CreatePicasaUri(ConfigurationManager.AppSettings.Get("PicasaWebUserId")));
            albumQuery.Access = PicasaQuery.AccessLevel.AccessPublic;

            PicasaFeed feed = PicasaService.Query(albumQuery);

            if (feed != null && feed.Entries.Count > 0)
            {
                foreach (PicasaEntry entry in feed.Entries)
                {
                    Album album = new Album();
                    album.Title = entry.Title.Text;
                    album.Summary = entry.Summary.Text.Replace("\r\n", "<br/>");
                    album.FeedUri = entry.FeedUri;
                    album.ThumbnailUrl = entry.Media.Thumbnails[0].Attributes["url"].ToString();
                    album.NumberOfPhotos = ((GPhotoNumPhotos)entry.ExtensionElements[5]).IntegerValue;

                    m_albums.Add(album);
                }
            }
        }
Exemplo n.º 3
0
 public void AlbumQueryConstructorTest()
 {
     string queryUri = "http://www.google.com/test";
     string expected = "http://www.google.com/test?kind=album"; 
     AlbumQuery target = new AlbumQuery(queryUri);
     Assert.AreEqual(new Uri(expected), target.Uri);
 }
Exemplo n.º 4
0
        public AlbumEntry findAlbumDetail(String albumId)
        {
            AlbumQuery query = new AlbumQuery("http://picasaweb.google.com/data/feed/api/user/default/albumid/" + albumId);
            //PicasaFeed feed = Service.Query(query);

               //if (feed.TotalResults > 0)
            //    return (AlbumEntry) feed.Entries[0];

            return null;
        }
Exemplo n.º 5
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;
        }
Exemplo n.º 6
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();
                }
            });
        }
Exemplo n.º 7
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.º 8
0
        public IList<PicasaEntry> findAllAlbums()
        {
            AlbumQuery query = new AlbumQuery("https://picasaweb.google.com/data/feed/api/user/default");
            Console.Out.WriteLine(query.Query);

            PicasaFeed feed = Service.Query(query);

            IList<PicasaEntry> albums = new List<PicasaEntry>();

            foreach (PicasaEntry entry in feed.Entries)
            {
                PicasaEntry album = entry;
                albums.Add(album);

            }

            return albums;
        }
Exemplo n.º 9
0
        protected void Page_Load(object sender, EventArgs e)
        {
            GotoAuthSubLink.Visible = false;

            if (Session["token"] != null)
            {
                Response.Redirect("Default.aspx");
            }
            else if (Request.QueryString["token"] != null)
            {
                User u = new User();
                u.Username = "******";
                u.Password = "******";

                PicasaService.setUserCredentials(u.Username, u.Password);

                AlbumQuery albumQuery = new AlbumQuery();
                albumQuery.Uri = new Uri(PicasaQuery.CreatePicasaUri(u.Username));
                //albumQuery.Access = PicasaQuery.AccessLevel.AccessPublic;

                PicasaFeed feed = PicasaService.Query(albumQuery);

                Session["feed"] = feed;
                Session["service"] = PicasaService;
                Session["user"] = u;

                if (feed.Entries.Count > 0)
                {
                    AlbumAccessor myAlbum = new AlbumAccessor((PicasaEntry)feed.Entries[0]);
                    Response.Redirect("Default.aspx?album=" + myAlbum.Id, true);
                }
                else
                {
                    Response.Redirect("Default.aspx", true);
                }
            }
            else //no auth data, print link
            {
                GotoAuthSubLink.Text = "Login to your Google Account";
                GotoAuthSubLink.Visible = true;
                GotoAuthSubLink.NavigateUrl = AuthSubUtil.getRequestUrl(Request.Url.ToString(),
                    "https://picasaweb.google.com/data/", false, true);
            }
        }
Exemplo n.º 10
0
        public IQueryable<Album> GoogleAlbums(CustomQueryArgs e)
        {
            var currentAlbums = Albums.ToArray();
            var googleAlbums = new List<Album>();

            foreach (var owner in Owners)
            {
                var query = new AlbumQuery(PicasaQuery.CreatePicasaUri(owner.Name));
                googleAlbums.AddRange(Picasa.GetService(owner).Query(query).Entries.Select(entry => new Google.Picasa.Album { AtomEntry = entry }).Where(a => currentAlbums.FirstOrDefault(ca => ca.Id == a.Id) == null).Select(a => new Album
                {
                    Id = a.Id,
                    Title = a.Title,
                    LastUpdated = a.Updated,
                    Owner = owner
                }));
            }

            return googleAlbums.AsQueryable();
        }
Exemplo n.º 11
0
        private bool checkAlbumExists(string albumName)
        {
            bool albumExists = false;
            AlbumQuery query = new AlbumQuery(PicasaQuery.CreatePicasaUri(this.user));
            PicasaFeed feed = null;

            try
            {
                feed = picasaService.Query(query);
            }
            catch(Exception)
            {
                return false;
            }

            foreach (PicasaEntry entry in feed.Entries)
            {
                if (entry.Title.Text.Equals(albumName)) albumExists = true;
            }
            return albumExists;
        }
Exemplo n.º 12
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.º 13
0
 public void AlbumQueryConstructorTest1()
 {
     AlbumQuery target = new AlbumQuery();
     Assert.IsNotNull(target);
 }
Exemplo n.º 14
0
        public bool isAuthorized(System.Security.Principal.IPrincipal User, string albumid)
        {
            if (User.IsInRole("Friends"))
                return true;

            AlbumQuery query = new AlbumQuery();
            PicasaEntry album = (PicasaEntry)service.Get(
                string.Format("http://picasaweb.google.com/data/entry/api/user/{0}/albumid/{1}", GetGUsername(), albumid)
                );

            string summary = album.Summary.Text;

            if (summary.ToLower() == "coworkers" && User.IsInRole("Coworkers"))
                return true;

            if (summary.ToLower() == "all")
                return true;

            return false;
        }
Exemplo n.º 15
0
        private void UpdateAlbumFeed()
        {
            AlbumQuery query = new AlbumQuery();

            this.AlbumList.Clear();

            
            query.Uri = new Uri(PicasaQuery.CreatePicasaUri(this.user));

            this.picasaFeed = this.picasaService.Query(query);

            if (this.picasaFeed != null && this.picasaFeed.Entries.Count > 0) 
            {
                foreach (PicasaEntry entry in this.picasaFeed.Entries)
                {
                    ListViewItem item = new ListViewItem(entry.Title.Text + 
                                    " (" + entry.GetPhotoExtensionValue(GPhotoNameTable.NumPhotos) + " )");
                    item.Tag = entry;
                    this.AlbumList.Items.Add(item);
                }
            }
            this.AlbumList.Update();
        }
Exemplo n.º 16
0
        public void ModifyAlbumSummary(string albumid, string summary)
        {
            AlbumQuery query = new AlbumQuery();
            PicasaEntry album = (PicasaEntry)service.Get(
                string.Format("http://picasaweb.google.com/data/entry/api/user/{0}/albumid/{1}", GetGUsername(), albumid)
                );

            album.Summary.Text = summary;
            album.Update();
        }
Exemplo n.º 17
0
 public AtomEntryCollection GetAllAlbums()
 {
     AlbumQuery query = new AlbumQuery(PicasaQuery.CreatePicasaUri(GetGUsername()));
     PicasaFeed feed = service.Query(query);
     return feed.Entries;
 }
        /// <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()));
        }
        protected virtual void Dispose(bool disposing)
        {
            if (!is_disposed) // only dispose once!
            {
                if (disposing)
                {
                    
                    m_albumService = null;
                    m_albumFeed = null;
                    m_albumQuery = null;
                    m_photoService = null;
                    m_photoQuery = null;
                    m_photoFeed = null;
                    m_userName = null;
                    m_serviceName = null;
                    m_albumName = null;
                }

            }
            this.is_disposed = true;
        }
Exemplo n.º 20
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;
        }
    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>";
    }
        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.
            }
              }
        }
        public List<PicasaWebAlbum> QueryAlbums(BackgroundWorker worker, int overallJobPercent)
        {
            // Create an authentication factory to deal with logging in.
            GDataGAuthRequestFactory authFactory = new GDataGAuthRequestFactory("lh2", this.m_serviceName);
            authFactory.AccountType = "GOOGLE_OR_HOSTED";


            this.m_albumQuery = new AlbumQuery(PicasaQuery.CreatePicasaUri("default"));
            this.m_albumQuery.Access = PicasaQuery.AccessLevel.AccessAll;
            this.m_albumService = new PicasaService(authFactory.ApplicationName);
            this.m_albumService.RequestFactory = authFactory;
           // this.m_albumService.setUserCredentials(this.m_userName, this.m_password);
            //string token = this.m_albumService.QueryAuthenticationToken();
            this.m_albumService.SetAuthenticationToken(this.mUserToken);
            List<PicasaWebAlbum> retval = new List<PicasaWebAlbum>();
            decimal count = ((decimal)overallJobPercent / 100) * 10;
            int smallCount = (int)count;
            try
            {
                worker.ReportProgress(0, (object)"Creating proxy");
                CreateAlbumProxy();
                worker.ReportProgress(smallCount, (object)"Proxy created");
                worker.ReportProgress(0, (object)"Querying google");
                this.m_albumFeed = this.m_albumService.Query(this.m_albumQuery);
                worker.ReportProgress(smallCount, (object)"Done");
            }
            catch (Exception e)
            {
                this.m_albumQuery = null;
                this.m_albumService.RequestFactory = null;
                this.m_albumService = null;
                this.m_albumFeed = null;
                retval = null;
                throw new Exception("PicasaReader failed when downloading album feed for " + this.m_userName, e);

            }
            if (this.m_albumFeed.Entries.Count > 0)
            {
                int percent = (int)Math.Round((decimal)((overallJobPercent - (smallCount * 2)) / this.m_albumFeed.Entries.Count), 0);
                worker.ReportProgress(0, (object)"Processing album data");
                foreach (PicasaEntry entry in this.m_albumFeed.Entries)
                {

                    AlbumAccessor ac = new AlbumAccessor(entry);

                    retval.Add(new PicasaWebAlbum(entry.Title.Text, entry.Updated, ac.NumPhotos, Convert.ToUInt64(ac.Id)));
                    worker.ReportProgress(percent, null);

                }
            }
            this.m_albumQuery = null;
            this.m_albumService.RequestFactory = null;
            this.m_albumService = null;
            this.m_albumFeed = null;
            return retval;
        }
Exemplo n.º 24
0
        private void UpdateAlbumFeed()
        {
            AlbumQuery query = new AlbumQuery();

            this.albumList.Clear();
            albumCalendar.BoldedDates = null;
            this.AlbumPicture.Image = null;
            this.mapLinkLabel.Hide();
            this.albumLabel.Hide();

            query.Uri = new Uri(PicasaQuery.CreatePicasaUri(this.user));

            try
            {
                this.picasaFeed = this.picasaService.Query(query);
            }
            catch (Google.GData.Client.GDataRequestException)
            {
                MessageBox.Show("You need to add the Picasaweb Service:\nLogin through your web browser and accept the terms of service."
                    + "\nIn addition, please check your internet connection and try again!");
                System.Diagnostics.Process.Start("www.picasaweb.google.com");
                this.googleAuthToken = null;
                login();
                return;
            }
            
            if (this.picasaFeed != null && this.picasaFeed.Entries.Count > 0)
            {
            foreach (PicasaEntry entry in this.picasaFeed.Entries)
            {
                albumList.Add(entry);
                albumCalendar.AddBoldedDate(entry.Published); //adds album dates to calendar as bold entries
            }
            }
            this.albumCalendar.UpdateBoldedDates();
            calendarUpdate();
        }
        private List<PicasaEntry> GetItems(string uri, PicasaQuery.Kinds kind, string searchText = null)
        {
            var service = GetPicasaService();
            KindQuery query;
            switch (kind)
            {
                case PicasaQuery.Kinds.album:
                    query = new AlbumQuery(uri);
                    break;
                case PicasaQuery.Kinds.photo:
                    query = new PhotoQuery(uri);
                    if (!String.IsNullOrWhiteSpace(searchText))
                        query.Query = searchText;
                    break;
                default:
                    throw new NotImplementedException("Unknown kind");
            }

            query.NumberToRetrieve = 1000;



            PicasaFeed feed;
            try
            {
                feed = service.Query(query);
            }
            catch
            {
                //If a first error. Try recreate service 
                service = GetPicasaService(true);
                feed = service.Query(query);
            }
                        
            var result = new List<PicasaEntry>();
            while (feed.Entries!=null)
            {
                foreach (PicasaEntry entry in feed.Entries)
                    result.Add(entry);

                if (String.IsNullOrWhiteSpace(feed.NextChunk))
                    break;

                switch (kind)
                {
                    case PicasaQuery.Kinds.album:
                        query = new AlbumQuery(feed.NextChunk);
                        break;
                    case PicasaQuery.Kinds.photo:
                        query = new PhotoQuery(feed.NextChunk);
                        break;
                    default:
                        throw new NotImplementedException("Unknown kind");
                }
                try
                {
                    feed = service.Query(query);
                }
                catch
                {
                    //If a first error. Try recreate service 
                    service = GetPicasaService(true);
                    feed = service.Query(query);
                }
            }
            return result;
       }
Exemplo n.º 26
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.º 27
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");


                }
            }
        }
      /*  public string LoginToGoogle(out string token)
        {
            GDataGAuthRequestFactory authFactory = new GDataGAuthRequestFactory("lh2", this.m_serviceName);
            authFactory.AccountType = "GOOGLE_OR_HOSTED";

            this.m_albumService = new PicasaService(authFactory.ApplicationName);
            try
            {
                this.m_albumService.setUserCredentials(this.m_userName, this.m_password);
                this.m_albumService.QueryAuthenticationToken(); // Authenticate the user immediately
            }
            catch (CaptchaRequiredException e)
            {
                token = e.Token;
                return e.Url;
            }
        }

        public string LoginToGoogle(out string token, string CAPTCHAAnswer, string CAPTCHAToken)
        {
            GDataGAuthRequestFactory authFactory = new GDataGAuthRequestFactory("lh2", this.m_serviceName);
            authFactory.AccountType = "GOOGLE_OR_HOSTED";
            string token = string.Empty;
            this.m_albumService = new PicasaService(authFactory.ApplicationName);
            authFactory.CaptchaAnswer = CAPTCHAAnswer;
            authFactory.CaptchaToken = CAPTCHAToken;
            this.m_albumService.setUserCredentials(this.m_userName, this.m_password);

            token = this.m_albumService.QueryAuthenticationToken(); // Authenticate the user immediately
            return token;


        }
        */
        public List<PicasaWebAlbum> QueryAlbums()
        {
            // Create an authentication factory to deal with logging in.
            GDataGAuthRequestFactory authFactory = new GDataGAuthRequestFactory("lh2", this.m_serviceName);
            authFactory.AccountType = "GOOGLE_OR_HOSTED";
                       
            this.m_albumService = new PicasaService(authFactory.ApplicationName);
            this.m_albumService.RequestFactory = authFactory;
            this.m_albumService.SetAuthenticationToken(this.mUserToken);
           
         
            this.m_albumQuery = new AlbumQuery(PicasaQuery.CreatePicasaUri("default"));
            this.m_albumQuery.Access = PicasaQuery.AccessLevel.AccessAll;
           

            List<PicasaWebAlbum> retval = new List<PicasaWebAlbum>();
           
            try
            {
                CreateAlbumProxy();
                this.m_albumFeed = this.m_albumService.Query(this.m_albumQuery);
                
            }
            catch (Exception e)
            {
                this.m_albumQuery = null;
                this.m_albumService.RequestFactory = null;
                this.m_albumService = null;
                this.m_albumFeed = null;
                retval = null;
                throw new Exception("PicasaReader failed when downloading album feed for "+this.m_userName, e);

            }
            foreach (PicasaEntry entry in this.m_albumFeed.Entries)
            {
                AlbumAccessor ac = new AlbumAccessor(entry);
                retval.Add(new PicasaWebAlbum(entry.Title.Text, entry.Updated,ac.NumPhotos,Convert.ToUInt64(ac.Id)));
            }
            this.m_albumQuery = null;
            this.m_albumService.RequestFactory = null;
            this.m_albumService = null;
            this.m_albumFeed = null;
            return retval;
        }