public void NumPhotosRemainingTest()
 {
     PicasaEntry entry = new AlbumEntry(); 
     AlbumAccessor target = new AlbumAccessor(entry); 
     uint expected = 4; // TODO: Initialize to an appropriate value
     uint actual;
     target.NumPhotosRemaining = expected;
     actual = target.NumPhotosRemaining;
     Assert.AreEqual(expected, actual);
 }
Пример #2
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();
                }
            });
        }
Пример #3
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);
            }
        }
Пример #4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!Page.IsPostBack)
            {
                if (Session["feed"] != null)
                {
                    PicasaFeed feed = Session["feed"] as PicasaFeed;

                    foreach (PicasaEntry entry in feed.Entries)
                    {
                        AlbumAccessor myAlbum = new AlbumAccessor((PicasaEntry)entry);
                        entry.Etag = myAlbum.Id;
                    }
                    this.Repeater1.DataSource = feed.Entries;
                    this.Repeater1.DataBind();
                }

                if (Session["user"] != null)
                {
                    Label_user.Text = ((User)Session["user"]).Username;
                }
            }
        }
 public void AccessTest()
 {
     PicasaEntry entry = new AlbumEntry();
     AlbumAccessor target = new AlbumAccessor(entry);
     string expected = "TestValue"; 
     string actual;
     target.Access = expected;
     actual = target.Access;
     Assert.AreEqual(expected, actual);
 }
 public void BytesUsedTest()
 {
     PicasaEntry entry = new AlbumEntry();
     AlbumAccessor target = new AlbumAccessor(entry);
     uint expected = 12; // TODO: Initialize to an appropriate value
     uint actual;
     target.BytesUsed = expected;
     actual = target.BytesUsed;
     Assert.AreEqual(expected, actual);
 }
 public void CommentingEnabledTest()
 {
     PicasaEntry entry = new AlbumEntry();
     AlbumAccessor target = new AlbumAccessor(entry);
     bool expected = false; // TODO: Initialize to an appropriate value
     bool actual;
     target.CommentingEnabled = expected;
     actual = target.CommentingEnabled;
     Assert.AreEqual(expected, actual);
 }
 public void LatitudeTest()
 {
     PicasaEntry entry = new AlbumEntry();
     AlbumAccessor target = new AlbumAccessor(entry);
     double expected = 0F; // TODO: Initialize to an appropriate value
     double actual;
     target.Latitude = expected;
     actual = target.Latitude;
     Assert.AreEqual(expected, actual);
 }
      /*  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;
        }
Пример #10
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;
        }
    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>";
    }
Пример #12
0
        protected void XoaAlbum(PicasaEntry entry)
        {
            try
            {
                //xac nhan truoc khi xoa
                AlbumAccessor album = new AlbumAccessor(entry);
                DialogResult rs = MessageBox.Show("Bạn có chắc là muốn xoá Album <" + album.AlbumTitle + "> không?", "Warning!", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (rs == DialogResult.Yes)
                {
                    //Goi ham xoa
                    entry.Delete();
                    //Thong bao
                    DialogResult rs1 = MessageBox.Show("Xoá Album thành công", "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    Response.Redirect("Album.aspx");

                }
                else
                {
                    Response.Redirect("Album.aspx");
                }
            }

            catch
            {
            }
        }
Пример #13
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Page.Title = "Danh Sách Album";

            service.setUserCredentials("*****@*****.**", "doantruong");
            feed = service.Query(query);
            foreach (PicasaEntry entry in feed.Entries)
            {
                AlbumAccessor ac = new AlbumAccessor(entry);
                listAlbum.Add(ac);
            }
            if (!IsPostBack)
            {
                int soDong = LoadAlbum();
                FilterSTT(soDong, 0, 10);
            }
            this.GridViewPicasa.HeaderStyle.CssClass = "headerstyle";

            //photos

            string maAlbum = null;
            List<SPHOTO> listPhotos = new List<SPHOTO>();
            if(Request.QueryString["id"] != null)
            {
                maAlbum = Request.QueryString["id"].ToString();
            }
            if(maAlbum != null)
            {
                PhotoQuery Pquery = new PhotoQuery(PicasaQuery.CreatePicasaUri("*****@*****.**",maAlbum));
                feed = service.Query(Pquery);
                foreach (PicasaEntry entry in feed.Entries)
                {
                    SPHOTO temp = new SPHOTO();

                    temp.title = entry.Title.Text;
                    temp.thumbURL = entry.Media.Thumbnails[1].Attributes["url"] as string;
                    listPhotos.Add(temp);

                }
                ListViewPhotos.DataSource = listPhotos;
                ListViewPhotos.DataBind();
            }
            if (maAlbum != null)
            {
                //lay ma

                //lay thong tin va load len cac textbox
                for (int i = 0; i < listAlbum.Count; i++)
                {
                    if (listAlbum[i].Id == maAlbum)
                    {
                        currentAlbum = listAlbum[i];
                        break;
                    }
                }
                switch (currentAlbum.Access)
                {
                    case "public":
                        DropDownListAccess.SelectedIndex = 0;
                        break;

                    case "private":
                        DropDownListAccess.SelectedIndex = 1;
                        break;
                    case "protected":
                        DropDownListAccess.SelectedIndex = 2;
                        break;

                }
                txtalbumtitle.Text = currentAlbum.AlbumTitle;
                txtmieuta.Text = currentAlbum.AlbumSummary;
            }
        }
Пример #14
0
        protected void lbtnThemAlbum_Click(object sender, EventArgs e)
        {
            AlbumEntry newEntry = new AlbumEntry();

            currentAlbum = new AlbumAccessor(newEntry);
            switch (DropDownListAccess.SelectedIndex)
            {
                case 0:
                    currentAlbum.Access = "public";
                    break;
                case 1:
                    currentAlbum.Access = "private";
                    break;
                case 2:
                    currentAlbum.Access = "protected";
                    break;
            }
            newEntry.Title.Text = txtalbumtitle.Text;
            newEntry.Summary.Text = txtmieuta.Text;
            currentAlbum.AlbumAuthor = listAlbum[0].AlbumAuthor;
            currentAlbum.AlbumAuthorNickname = listAlbum[0].AlbumAuthorNickname;

            Uri feedUri = new Uri(PicasaQuery.CreatePicasaUri("*****@*****.**"));
            PicasaEntry createdEntry = (PicasaEntry)service.Insert(feedUri, newEntry);

            Response.Redirect("Album.aspx");
        }
Пример #15
0
        protected void lbtnCapNhatAlbum_Click(object sender, EventArgs e)
        {
            string maAlbum = Convert.ToString(Request.QueryString["id"]);
            for (int i = 0; i < listAlbum.Count; i++)
            {
                if (listAlbum[i].Id == maAlbum)
                {
                    currentAlbum = listAlbum[i];
                    break;
                }
            }
            foreach (PicasaEntry entry in feed.Entries)
            {
                if (entry.Id.ToString() == maAlbum)
                {
                    entry.Title.Text = txtalbumtitle.Text;
                    entry.Summary.Text = txtmieuta.Text;
                    currentAlbum = new AlbumAccessor(entry);
                    switch (DropDownListAccess.SelectedIndex)
                    {
                        case 0:
                            currentAlbum.Access = "public";
                            break;
                        case 1:
                            currentAlbum.Access = "private";
                            break;
                        case 2:
                            currentAlbum.Access = "protected";
                            break;
                    }
                    entry.Update();
                    break;
                }
            }

            Response.Redirect("Album.aspx");
        }
Пример #16
0
        protected void GridViewPicasa_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "XoaAlbum")
            {
                int index = Convert.ToInt32(e.CommandArgument);

                foreach (PicasaEntry entry in feed.Entries)
                {
                    AlbumAccessor ac = new AlbumAccessor(entry);
                    if(listAlbum[index].Id == ac.Id)
                        XoaAlbum(entry);
                }
            }
        }
Пример #17
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;
        }
 public void AlbumAccessorConstructorTest()
 {
     PicasaEntry entry = new AlbumEntry();
     AlbumAccessor target = new AlbumAccessor(entry);
     Assert.IsNotNull(target);
 }
        public List<AlbumAccessor> GetAlbums()
        {
            string uri = PicasaQuery.CreatePicasaUri("default");
            var data = GetItems(uri, PicasaQuery.Kinds.album);

            var result = new List<AlbumAccessor>();
            foreach (PicasaEntry entry in data)
            {
                var album = new AlbumAccessor(entry);
                result.Add(album);
            }
            return result;
        }
        public AlbumAccessor CreateAlbum(string title, string description = null, bool isPublic = false)
        {
            var service = GetPicasaService();

            AlbumEntry newEntry = new AlbumEntry();
            newEntry.Title.Text = title;
            if (description!=null)
                newEntry.Summary.Text = description;
            AlbumAccessor ac = new AlbumAccessor(newEntry);

            //set to "private" for a private album
            if (isPublic)
                ac.Access = "public";
            else
                ac.Access = "unlisted";

            Uri feedUri = new Uri(PicasaQuery.CreatePicasaUri("default"));

            PicasaEntry createdEntry;
            try
            {
                createdEntry = (PicasaEntry)service.Insert(feedUri, newEntry);
            }
            catch
            {
                //If a first error. Try recreate service 
                service = GetPicasaService(true);
                createdEntry = (PicasaEntry)service.Insert(feedUri, newEntry);
            }
            return new AlbumAccessor(createdEntry); 
        }
        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();

        }
        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;
        }